Don't bother with these checks in ItemLayout

This commit is contained in:
libraryaddict 2014-11-28 09:30:57 +13:00
parent 8d12b8e565
commit d5d9e2eb14
5 changed files with 148 additions and 310 deletions

View File

@ -62,9 +62,7 @@ public class ItemLayout
else else
break; break;
} }
ItemStack itemToInsert = items[i]; itemArray[slot] = items[i];
if (itemToInsert != null)
itemArray[slot] = itemToInsert;
} }
return itemArray; return itemArray;

View File

@ -1,15 +1,11 @@
package nautilus.game.arcade.game.games.searchanddestroy; package nautilus.game.arcade.game.games.searchanddestroy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.itemstack.ComplexItemLayout; import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder; import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow; import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow;
@ -18,234 +14,72 @@ import nautilus.game.arcade.kit.Kit;
public class KitManager public class KitManager
{ {
private class KitTree public class UpgradeKit
{ {
Kit baseKit; UpgradeKit _daddy;
Kit[] tier2; Kit _kit;
HashMap<Kit, Kit[]> tier3; ArrayList<UpgradeKit> _children;
int[] _path;
int _kitSlot;
public KitTree(Kit baseKit, Kit[] tier2, HashMap<Kit, Kit[]> tier3) public UpgradeKit(UpgradeKit daddy, Kit me, ArrayList<UpgradeKit> children, int kitSlot, int... pathSlots)
{ {
this.baseKit = baseKit; _kitSlot = kitSlot;
this.tier2 = tier2; _path = pathSlots;
this.tier3 = tier3; _daddy = daddy;
} _kit = me;
_children = children;
public int getTier(Kit kit)
{
if (baseKit == kit)
return 1;
for (Kit k : tier2)
if (k == kit)
return 2;
for (Kit[] ki : tier3.values())
{
for (Kit k : ki)
{
if (k == kit)
return 3;
}
}
return -1;
}
public Kit[] getOwned(Kit kit)
{
int tier = getTier(kit);
if (tier == 2)
{
return new Kit[]
{
kit, baseKit
};
}
else if (tier == 3)
{
for (Kit k : tier2)
{
for (Kit k1 : tier3.get(k))
{
if (k1 == kit)
{
return new Kit[]
{
kit, baseKit, k1
};
}
}
}
}
return new Kit[]
{
kit
};
}
public Kit[] getUnowned(Kit kit)
{
int tier = getTier(kit);
Kit[] kits = new Kit[7 - tier];
int i = 0;
if (tier == 1)
{
for (Kit k1 : tier2)
kits[i] = k1;
for (Kit[] k : tier3.values())
for (Kit k1 : k)
kits[i] = k1;
}
if (tier == 2)
{
for (Kit k1 : tier2)
if (k1 != kit)
kits[i] = k1;
for (Kit[] k : tier3.values())
for (Kit k1 : k)
kits[i] = k1;
}
if (tier == 3)
{
for (Kit k1 : tier2)
kits[i] = k1;
for (Kit[] k : tier3.values())
for (Kit k1 : k)
if (k1 != kit)
kits[i] = k1;
}
return kits;
}
public Kit[] getEvolve(Kit kit)
{
if (baseKit == kit)
{
return tier2;
}
if (tier3.containsKey(kit))
{
return tier3.get(kit);
}
return new Kit[0];
}
public char getLetter(Kit kit)
{
if (baseKit == kit)
return 'a';
for (int i = 0; i < 2; i++)
{
if (tier2[i] == kit)
return "bc".toCharArray()[i];
for (int a = 0; a < 2; a++)
{
Kit k = tier3.get(tier2[i])[a];
if (k == kit)
return (i == 0 ? "de" : "fg").toCharArray()[a];
}
}
return ' ';
} }
} }
private ArrayList<KitTree> kits = new ArrayList<KitTree>(); private ArrayList<UpgradeKit> kits = new ArrayList<UpgradeKit>();
private SearchAndDestroy _search; private SearchAndDestroy _search;
private ComplexItemLayout kitLayout = new ComplexItemLayout("XXXXAXXXX", "XXXbXcXXX", "XXBXXXCXX", "XX(de)XXX(fg)XX",
"XXdeXXfgX", "XDXEXFXGX");
public KitManager(SearchAndDestroy search) public KitManager(SearchAndDestroy search)
{ {
ArcadeManager man = search.getArcadeManager(); ArcadeManager man = search.getArcadeManager();
_search = search; _search = search;
{ {
Kit bow_T1 = new KitBow(man); ArrayList<UpgradeKit> children1 = new ArrayList<UpgradeKit>();
Kit bow_T2_1 = new KitBow(man); ArrayList<UpgradeKit> children2 = new ArrayList<UpgradeKit>();
Kit bow_T2_2 = new KitBow(man); ArrayList<UpgradeKit> children3 = new ArrayList<UpgradeKit>();
Kit bow_T3_1 = new KitBow(man);
Kit bow_T3_2 = new KitBow(man); UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4);
Kit bow_T3_3 = new KitBow(man); kits.add(bow1);
Kit bow_T3_4 = new KitBow(man); UpgradeKit bow2 = new UpgradeKit(bow1, new KitBow(man), children2, 20, 12);
HashMap<Kit, Kit[]> tier3 = new HashMap<Kit, Kit[]>(); kits.add(bow2);
tier3.put(bow_T2_1, new Kit[] UpgradeKit bow3 = new UpgradeKit(bow1, new KitBow(man), children3, 24, 14);
{ kits.add(bow3);
bow_T3_1, bow_T3_2 UpgradeKit bow4 = new UpgradeKit(bow2, new KitBow(man), new ArrayList<UpgradeKit>(), 46, 29, 37);
}); kits.add(bow4);
tier3.put(bow_T2_2, new Kit[] UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList<UpgradeKit>(), 50, 29, 39);
{ kits.add(bow5);
bow_T3_3, bow_T3_4 UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList<UpgradeKit>(), 51, 33, 41);
}); kits.add(bow6);
KitTree tree = new KitTree(bow_T1, new Kit[] UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList<UpgradeKit>(), 53, 33, 43);
{ kits.add(bow7);
bow_T2_1, bow_T2_2 children2.add(bow4);
}, tier3); children2.add(bow5);
kits.add(tree); children3.add(bow6);
children3.add(bow7);
} }
// TODO Create kits
} }
public Kit[] getKits() public Kit[] getKits()
{ {
Kit[] kitArray = new Kit[kits.size() * 9]; Kit[] kitArray = new Kit[kits.size()];
int i = 0; for (int i = 0; i < kitArray.length; i++)
for (KitTree tree : kits)
{ {
kitArray[i++] = tree.baseKit; kitArray[i] = kits.get(i)._kit;
for (Entry<Kit, Kit[]> entry : tree.tier3.entrySet())
{
kitArray[i++] = entry.getKey();
for (Kit kit : entry.getValue())
{
kitArray[i++] = kit;
}
}
} }
return kitArray; return kitArray;
} }
/** public ArrayList<UpgradeKit> getUpgradeKits()
* Opens whenever he can upgrade to a new kit. So it opens on tier 1 and 2. He could also possibly view this anytime he wanted
* just to look?
*/
public void openKitTree(Player player)
{ {
ItemStack[] items = new ItemStack[27]; return kits;
Kit hisKit = _search.GetKit(player);
boolean canEvolve = true;
for (KitTree tree : kits)
{
int tier = tree.getTier(hisKit);
if (tier > 0)
{
// Found his KitTree
Kit[] owned = tree.getOwned(hisKit);
for (Kit kit : owned)
{
char c = tree.getLetter(kit);
kitLayout.generate(items, c, makeItem(kit), false);
kitLayout.generate(items, Character.toLowerCase(c), new ItemStack(Material.STAINED_GLASS_PANE), false);
}
if (canEvolve)
{
Kit[] evolve = tree.getEvolve(hisKit);
for (Kit kit : evolve)
{
kitLayout.generate(items, tree.getLetter(kit), makeItem(kit), false);
}
}
for (Kit kit : tree.getUnowned(hisKit))
{
char c = tree.getLetter(kit);
kitLayout.generate(items, Character.toUpperCase(c),
new ItemBuilder(Material.STONE).setTitle(ChatColor.DARK_RED + "LOCKED").build(), false);
}
break;
}
}
}
private ItemStack makeItem(Kit kit)
{
return new ItemBuilder(kit.GetItemInHand()).setTitle(kit.GetName()).build();
} }
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
@ -279,8 +280,9 @@ public class SearchAndDestroy extends TeamGame
@EventHandler @EventHandler
public void onGameEnd(GameStateChangeEvent event) public void onGameEnd(GameStateChangeEvent event)
{ {
if (event.GetState() == GameState.End && !getBombs().isEmpty()) if (event.GetState() == GameState.End)
{ {
HandlerList.unregisterAll(evolve);
for (TeamBomb bomb : getBombs()) for (TeamBomb bomb : getBombs())
{ {
if (bomb.getTeam().IsTeamAlive()) if (bomb.getTeam().IsTeamAlive())
@ -296,6 +298,8 @@ public class SearchAndDestroy extends TeamGame
} }
} }
private KitEvolve evolve;
public SearchAndDestroy(ArcadeManager manager) public SearchAndDestroy(ArcadeManager manager)
{ {
super(manager, GameType.SearchAndDestroy, new Kit[0], new String[] super(manager, GameType.SearchAndDestroy, new Kit[0], new String[]
@ -303,6 +307,7 @@ public class SearchAndDestroy extends TeamGame
"A test game of", "Search and Destroy" "A test game of", "Search and Destroy"
}); });
setKits(kitManager.getKits()); setKits(kitManager.getKits());
evolve = new KitEvolve(manager.GetPlugin(), this, kitManager.getUpgradeKits());
InventoryClick = true; InventoryClick = true;
WorldTimeSet = -1; WorldTimeSet = -1;
WorldBoundaryKill = false; WorldBoundaryKill = false;

View File

@ -16,10 +16,11 @@ import nautilus.game.arcade.kit.Perk;
public class KitBow extends KitHuman public class KitBow extends KitHuman
{ {
private static int bowNo = 0;
public KitBow(ArcadeManager manager) public KitBow(ArcadeManager manager)
{ {
super(manager, "Bow", KitAvailability.Free, new String[] super(manager, "Bow" + ++bowNo, bowNo == 1 ? KitAvailability.Free : KitAvailability.Hide, new String[]
{ {
"A basic kit with a bow" "A basic kit with a bow"
}, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW)); }, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW));

View File

@ -32,127 +32,127 @@ import nautilus.game.arcade.gui.button.SpectatorButton;
public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop> public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
{ {
private ArcadeManager _arcadeManager; private ArcadeManager _arcadeManager;
public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager,
{ DonationManager donationManager, Player player)
super(plugin, shop, clientManager, donationManager, "Spectator Menu", player); {
_arcadeManager = arcadeManager; super(plugin, shop, clientManager, donationManager, "Spectator Menu", player);
BuildPage(); _arcadeManager = arcadeManager;
} BuildPage();
}
@Override @Override
protected void BuildPage() protected void BuildPage()
{ {
int playerCount = _arcadeManager.GetGame().GetPlayers(true).size(); int playerCount = _arcadeManager.GetGame().GetPlayers(true).size();
List<GameTeam> teamList = _arcadeManager.GetGame().GetTeamList(); List<GameTeam> teamList = _arcadeManager.GetGame().GetTeamList();
if (teamList.size() == 1 && playerCount < 28) if (teamList.size() == 1 && playerCount < 28)
buildSingleTeam(teamList.get(0), playerCount); buildSingleTeam(teamList.get(0), playerCount);
else else
buildMultipleTeams(teamList, playerCount); buildMultipleTeams(teamList, playerCount);
} }
private void buildSingleTeam(GameTeam team, int playerCount) private void buildSingleTeam(GameTeam team, int playerCount)
{ {
setItem(13, getTeamItem(team, playerCount)); setItem(13, getTeamItem(team, playerCount));
int slot = 19; int slot = 19;
for (Player other : team.GetPlayers(true)) for (Player other : team.GetPlayers(true))
{ {
addPlayerItem(slot, team, other); addPlayerItem(slot, team, other);
if ((slot + 2) % 9 == 0) if ((slot + 2) % 9 == 0)
slot += 3; slot += 3;
else else
slot++; slot++;
} }
} }
private void buildMultipleTeams(List<GameTeam> teamList, int playerCount) private void buildMultipleTeams(List<GameTeam> teamList, int playerCount)
{ {
int currentRow = 0; int currentRow = 0;
for (GameTeam team : teamList) for (GameTeam team : teamList)
{ {
ArrayList<Player> teamPlayers = team.GetPlayers(true); ArrayList<Player> teamPlayers = team.GetPlayers(true);
int rowsNeeded = (teamPlayers.size() / 8) + 1; int rowsNeeded = (teamPlayers.size() / 8) + 1;
for (int row = 0; row < rowsNeeded; row++) for (int row = 0; row < rowsNeeded; row++)
{ {
int woolSlot = (row * 9) + (currentRow * 9); int woolSlot = (row * 9) + (currentRow * 9);
// TODO Need to handle too many players in a better way
if (woolSlot >= getSize())
continue;
// TODO Need to handle too many players in a better way setItem(woolSlot, getTeamItem(team, teamPlayers.size()));
if (woolSlot >= getSize())
continue;
setItem(woolSlot, getTeamItem(team, teamPlayers.size())); int startPlayerIndex = row * 9;
for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && playerIndex < startPlayerIndex + 9; playerIndex++)
{
Player other = teamPlayers.get(playerIndex);
int slot = woolSlot + 1 + playerIndex;
int startPlayerIndex = row * 9; // TODO Need to handle too many players in a better way
for (int playerIndex = startPlayerIndex; playerIndex < teamPlayers.size() && playerIndex < startPlayerIndex + 9; playerIndex++) if (slot >= getSize())
{ continue;
Player other = teamPlayers.get(playerIndex);
int slot = woolSlot + 1 + playerIndex;
// TODO Need to handle too many players in a better way addPlayerItem(slot, team, other);
if (slot >= getSize()) }
continue; }
addPlayerItem(slot, team, other); // Add a line in between teams if the player count is low enough and there are less than 4 teams
} if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26)
} currentRow += 2;
else
currentRow += rowsNeeded;
}
}
// Add a line in between teams if the player count is low enough and there are less than 4 teams private void addPlayerItem(int slot, GameTeam team, Player other)
if (rowsNeeded == 1 && teamList.size() < 4 && playerCount <= 26) {
currentRow += 2; ItemStack playerItem = getPlayerItem(team, other);
else ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false);
currentRow += rowsNeeded; AddButton(slot, shopItem, new SpectatorButton(_arcadeManager, Player, other));
} }
}
private void addPlayerItem(int slot, GameTeam team, Player other) private ItemStack getTeamItem(GameTeam team, int playerCount)
{ {
ItemStack playerItem = getPlayerItem(team, other); ItemStack item = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor()));
ShopItem shopItem = new ShopItem(playerItem, other.getName(), other.getName(), 1, false, false);
AddButton(slot, shopItem, new SpectatorButton(_arcadeManager, Player, other));
}
private ItemStack getTeamItem(GameTeam team, int playerCount) ItemMeta meta = item.getItemMeta();
{ meta.setDisplayName(team.GetFormattedName());
ItemStack item = new ItemStack(Material.WOOL, 1, (short)0, UtilColor.chatColorToWoolData(team.GetColor())); meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount));
item.setItemMeta(meta);
ItemMeta meta = item.getItemMeta(); return item;
meta.setDisplayName(team.GetFormattedName()); }
meta.setLore(Arrays.asList(" ", ChatColor.RESET + C.cYellow + "Players Alive: " + C.cWhite + playerCount));
item.setItemMeta(meta);
return item; private ItemStack getPlayerItem(GameTeam team, Player other)
} {
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
private ItemStack getPlayerItem(GameTeam team, Player other) double distance = UtilMath.offset(Player, other);
{ double heightDifference = other.getLocation().getY() - Player.getLocation().getY();
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
double distance = UtilMath.offset(Player, other); ArrayList<String> lore = new ArrayList<String>();
double heightDifference = other.getLocation().getY() - Player.getLocation().getY(); lore.add(" ");
lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName());
lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance));
lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference));
lore.add(" ");
lore.add(ChatColor.RESET + C.Line + "Click to Spectate");
SkullMeta skullMeta = ((SkullMeta) item.getItemMeta());
skullMeta.setOwner(other.getName());
skullMeta.setDisplayName(team.GetColor() + other.getName());
skullMeta.setLore(lore);
item.setItemMeta(skullMeta);
ArrayList<String> lore = new ArrayList<String>(); return item;
lore.add(" "); }
lore.add(ChatColor.RESET + C.cYellow + "Kit: " + C.cWhite + _arcadeManager.GetGame().GetKit(other).GetName());
lore.add(ChatColor.RESET + C.cYellow + "Distance: " + C.cWhite + UtilMath.trim(1, distance));
lore.add(ChatColor.RESET + C.cYellow + "Height Difference: " + C.cWhite + UtilMath.trim(1, heightDifference));
lore.add(" ");
lore.add(ChatColor.RESET + C.Line + "Click to Spectate");
SkullMeta skullMeta = ((SkullMeta) item.getItemMeta());
skullMeta.setOwner(other.getName());
skullMeta.setDisplayName(team.GetColor() + other.getName());
skullMeta.setLore(lore);
item.setItemMeta(skullMeta);
return item;
}
} }