Don't bother with these checks in ItemLayout
This commit is contained in:
parent
8d12b8e565
commit
d5d9e2eb14
@ -62,9 +62,7 @@ public class ItemLayout
|
||||
else
|
||||
break;
|
||||
}
|
||||
ItemStack itemToInsert = items[i];
|
||||
if (itemToInsert != null)
|
||||
itemArray[slot] = itemToInsert;
|
||||
itemArray[slot] = items[i];
|
||||
|
||||
}
|
||||
return itemArray;
|
||||
|
@ -1,15 +1,11 @@
|
||||
package nautilus.game.arcade.game.games.searchanddestroy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.itemstack.ComplexItemLayout;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow;
|
||||
@ -18,234 +14,72 @@ import nautilus.game.arcade.kit.Kit;
|
||||
public class KitManager
|
||||
{
|
||||
|
||||
private class KitTree
|
||||
public class UpgradeKit
|
||||
{
|
||||
Kit baseKit;
|
||||
Kit[] tier2;
|
||||
HashMap<Kit, Kit[]> tier3;
|
||||
UpgradeKit _daddy;
|
||||
Kit _kit;
|
||||
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;
|
||||
this.tier2 = tier2;
|
||||
this.tier3 = tier3;
|
||||
}
|
||||
|
||||
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 ' ';
|
||||
_kitSlot = kitSlot;
|
||||
_path = pathSlots;
|
||||
_daddy = daddy;
|
||||
_kit = me;
|
||||
_children = children;
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<KitTree> kits = new ArrayList<KitTree>();
|
||||
private ArrayList<UpgradeKit> kits = new ArrayList<UpgradeKit>();
|
||||
private SearchAndDestroy _search;
|
||||
private ComplexItemLayout kitLayout = new ComplexItemLayout("XXXXAXXXX", "XXXbXcXXX", "XXBXXXCXX", "XX(de)XXX(fg)XX",
|
||||
"XXdeXXfgX", "XDXEXFXGX");
|
||||
|
||||
public KitManager(SearchAndDestroy search)
|
||||
{
|
||||
ArcadeManager man = search.getArcadeManager();
|
||||
_search = search;
|
||||
{
|
||||
Kit bow_T1 = new KitBow(man);
|
||||
Kit bow_T2_1 = new KitBow(man);
|
||||
Kit bow_T2_2 = new KitBow(man);
|
||||
Kit bow_T3_1 = new KitBow(man);
|
||||
Kit bow_T3_2 = new KitBow(man);
|
||||
Kit bow_T3_3 = new KitBow(man);
|
||||
Kit bow_T3_4 = new KitBow(man);
|
||||
HashMap<Kit, Kit[]> tier3 = new HashMap<Kit, Kit[]>();
|
||||
tier3.put(bow_T2_1, new Kit[]
|
||||
{
|
||||
bow_T3_1, bow_T3_2
|
||||
});
|
||||
tier3.put(bow_T2_2, new Kit[]
|
||||
{
|
||||
bow_T3_3, bow_T3_4
|
||||
});
|
||||
KitTree tree = new KitTree(bow_T1, new Kit[]
|
||||
{
|
||||
bow_T2_1, bow_T2_2
|
||||
}, tier3);
|
||||
kits.add(tree);
|
||||
ArrayList<UpgradeKit> children1 = new ArrayList<UpgradeKit>();
|
||||
ArrayList<UpgradeKit> children2 = new ArrayList<UpgradeKit>();
|
||||
ArrayList<UpgradeKit> children3 = new ArrayList<UpgradeKit>();
|
||||
|
||||
UpgradeKit bow1 = new UpgradeKit(null, new KitBow(man), children1, 4);
|
||||
kits.add(bow1);
|
||||
UpgradeKit bow2 = new UpgradeKit(bow1, new KitBow(man), children2, 20, 12);
|
||||
kits.add(bow2);
|
||||
UpgradeKit bow3 = new UpgradeKit(bow1, new KitBow(man), children3, 24, 14);
|
||||
kits.add(bow3);
|
||||
UpgradeKit bow4 = new UpgradeKit(bow2, new KitBow(man), new ArrayList<UpgradeKit>(), 46, 29, 37);
|
||||
kits.add(bow4);
|
||||
UpgradeKit bow5 = new UpgradeKit(bow2, new KitBow(man), new ArrayList<UpgradeKit>(), 50, 29, 39);
|
||||
kits.add(bow5);
|
||||
UpgradeKit bow6 = new UpgradeKit(bow3, new KitBow(man), new ArrayList<UpgradeKit>(), 51, 33, 41);
|
||||
kits.add(bow6);
|
||||
UpgradeKit bow7 = new UpgradeKit(bow3, new KitBow(man), new ArrayList<UpgradeKit>(), 53, 33, 43);
|
||||
kits.add(bow7);
|
||||
children2.add(bow4);
|
||||
children2.add(bow5);
|
||||
children3.add(bow6);
|
||||
children3.add(bow7);
|
||||
|
||||
}
|
||||
|
||||
// TODO Create kits
|
||||
}
|
||||
|
||||
public Kit[] getKits()
|
||||
{
|
||||
Kit[] kitArray = new Kit[kits.size() * 9];
|
||||
int i = 0;
|
||||
for (KitTree tree : kits)
|
||||
Kit[] kitArray = new Kit[kits.size()];
|
||||
for (int i = 0; i < kitArray.length; i++)
|
||||
{
|
||||
kitArray[i++] = tree.baseKit;
|
||||
for (Entry<Kit, Kit[]> entry : tree.tier3.entrySet())
|
||||
{
|
||||
kitArray[i++] = entry.getKey();
|
||||
for (Kit kit : entry.getValue())
|
||||
{
|
||||
kitArray[i++] = kit;
|
||||
}
|
||||
}
|
||||
kitArray[i] = kits.get(i)._kit;
|
||||
}
|
||||
return kitArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
public ArrayList<UpgradeKit> getUpgradeKits()
|
||||
{
|
||||
ItemStack[] items = new ItemStack[27];
|
||||
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();
|
||||
return kits;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
@ -279,8 +280,9 @@ public class SearchAndDestroy extends TeamGame
|
||||
@EventHandler
|
||||
public void onGameEnd(GameStateChangeEvent event)
|
||||
{
|
||||
if (event.GetState() == GameState.End && !getBombs().isEmpty())
|
||||
if (event.GetState() == GameState.End)
|
||||
{
|
||||
HandlerList.unregisterAll(evolve);
|
||||
for (TeamBomb bomb : getBombs())
|
||||
{
|
||||
if (bomb.getTeam().IsTeamAlive())
|
||||
@ -296,6 +298,8 @@ public class SearchAndDestroy extends TeamGame
|
||||
}
|
||||
}
|
||||
|
||||
private KitEvolve evolve;
|
||||
|
||||
public SearchAndDestroy(ArcadeManager manager)
|
||||
{
|
||||
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"
|
||||
});
|
||||
setKits(kitManager.getKits());
|
||||
evolve = new KitEvolve(manager.GetPlugin(), this, kitManager.getUpgradeKits());
|
||||
InventoryClick = true;
|
||||
WorldTimeSet = -1;
|
||||
WorldBoundaryKill = false;
|
||||
|
@ -16,10 +16,11 @@ import nautilus.game.arcade.kit.Perk;
|
||||
|
||||
public class KitBow extends KitHuman
|
||||
{
|
||||
private static int bowNo = 0;
|
||||
|
||||
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"
|
||||
}, new Perk[0], EntityType.SKELETON, new ItemStack(Material.BOW));
|
||||
|
@ -34,7 +34,8 @@ public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
|
||||
{
|
||||
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;
|
||||
@ -84,7 +85,6 @@ public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
|
||||
{
|
||||
int woolSlot = (row * 9) + (currentRow * 9);
|
||||
|
||||
|
||||
// TODO Need to handle too many players in a better way
|
||||
if (woolSlot >= getSize())
|
||||
continue;
|
||||
@ -122,7 +122,7 @@ public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
|
||||
|
||||
private ItemStack getTeamItem(GameTeam team, int playerCount)
|
||||
{
|
||||
ItemStack item = new ItemStack(Material.WOOL, 1, (short)0, UtilColor.chatColorToWoolData(team.GetColor()));
|
||||
ItemStack item = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor()));
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(team.GetFormattedName());
|
||||
|
Loading…
Reference in New Issue
Block a user