Start on a kit manager

This commit is contained in:
libraryaddict 2014-11-27 06:44:46 +13:00
parent 34e320dfee
commit 1bb4d902c6

View File

@ -0,0 +1,251 @@
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.itemstack.ItemBuilder;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.searchanddestroy.kits.KitBow;
import nautilus.game.arcade.kit.Kit;
public class KitManager
{
private class KitTree
{
Kit baseKit;
Kit[] tier2;
HashMap<Kit, Kit[]> tier3;
public KitTree(Kit baseKit, Kit[] tier2, HashMap<Kit, Kit[]> tier3)
{
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 ' ';
}
}
private ArrayList<KitTree> kits = new ArrayList<KitTree>();
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);
}
// TODO Create kits
}
public Kit[] getKits()
{
Kit[] kitArray = new Kit[kits.size() * 9];
int i = 0;
for (KitTree tree : kits)
{
kitArray[i++] = tree.baseKit;
for (Entry<Kit, Kit[]> entry : tree.tier3.entrySet())
{
kitArray[i++] = entry.getKey();
for (Kit kit : entry.getValue())
{
kitArray[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)
{
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();
}
}