Fixes gh-608 - loadout "first" will be given on join and each battle after

When a player joins a warzone for the first time, they will be given a
loadout called "first" instead of the default loadout. After they have died
once, they will receive the default loadout. Players will also be assigned
the "first" loadout every battle if they are on the default loadout when
the battle ends.

I do not know how servers will deal with players who might constantly leave
and rejoin the zone in order to get the loadout back. This could be fixed
with a war change if it becomes necessary (maybe remember the player until
the battle ends). But, as always, if a server does not want to have a
"first" loadout in a warzone, they do not have to create one.
This commit is contained in:
cmastudios 2013-03-07 18:13:39 -06:00
parent 6b35645150
commit 8dac3f4ea9
2 changed files with 24 additions and 14 deletions

View File

@ -387,6 +387,9 @@ public class Warzone {
if (!this.getLoadoutSelections().keySet().contains(player.getName())) {
isFirstRespawn = true;
this.getLoadoutSelections().put(player.getName(), new LoadoutSelection(true, 0));
} else if (this.isReinitializing) {
isFirstRespawn = true;
this.getLoadoutSelections().get(player.getName()).setStillInSpawn(true);
} else {
this.getLoadoutSelections().get(player.getName()).setStillInSpawn(true);
}
@ -1328,28 +1331,34 @@ public class Warzone {
// - repawn timer + this method is why inventories were getting wiped as players exited the warzone.
HashMap<String, HashMap<Integer, ItemStack>> loadouts = playerTeam.getInventories().resolveLoadouts();
List<String> sortedNames = LoadoutYmlMapper.sortNames(loadouts);
if (sortedNames.contains("first")) {
sortedNames.remove("first");
}
int currentIndex = selection.getSelectedIndex();
int i = 0;
Iterator<String> it = sortedNames.iterator();
while (it.hasNext()) {
String name = (String)it.next();
if (i == currentIndex) {
if (playerTeam.getTeamConfig().resolveBoolean(TeamConfig.PLAYERLOADOUTASDEFAULT) && name.equals("default")) {
// Use player's own inventory as loadout
this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player));
} else {
// Use the loadout from the list in the settings
this.resetInventory(playerTeam, player, loadouts.get(name));
}
while (it.hasNext()) {
String name = (String) it.next();
if (i == currentIndex) {
if (playerTeam.getTeamConfig().resolveBoolean(TeamConfig.PLAYERLOADOUTASDEFAULT) && name.equals("default")) {
// Use player's own inventory as loadout
this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player));
} else if (isFirstRespawn && loadouts.containsKey("first") && name.equals("default")) {
// Get the loadout for the first spawn
this.resetInventory(playerTeam, player, loadouts.get("first"));
} else {
// Use the loadout from the list in the settings
this.resetInventory(playerTeam, player, loadouts.get(name));
}
if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) {
War.war.msg(player, "Equipped " + name + " loadout (sneak to switch).");
} else if (isToggle) {
War.war.msg(player, "Equipped " + name + " loadout.");
}
}
i++;
}
}
i++;
}
}
}

View File

@ -820,7 +820,8 @@ public class WarPlayerListener implements Listener {
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size());
boolean hasFirstLoadout = playerTeam.getInventories().resolveLoadouts().containsKey("first");
int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size() - (hasFirstLoadout ? 1 : 0));
selection.setSelectedIndex(currentIndex);
playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);