Tweaking on ghast.

Added gadget costs
Working on Gadget shop.
This commit is contained in:
Jonathan Williams 2013-10-26 08:50:12 -05:00
parent ca3979f4fa
commit 39cf5c3ed1
19 changed files with 471 additions and 10 deletions

Binary file not shown.

View File

@ -35,6 +35,11 @@ public class GadgetManager extends MiniPlugin
_gadgets.add(new Halloween2013_BatGun(this));
_gadgets.add(new Halloween2013_Helmet(this));
}
public HashSet<Gadget> getGadgets()
{
return _gadgets;
}
//Disallows two armor gadgets in same slot.
public void RemoveArmor(Player player, ArmorSlot slot)

View File

@ -16,7 +16,7 @@ public class Halloween2013_BatGun extends ItemGadget
{
public Halloween2013_BatGun(GadgetManager manager)
{
super(manager, "Halloween2013_BatGun", "Bat Gun", Material.COAL_BLOCK, (byte)0);
super(manager, "Halloween2013_BatGun", "Bat Gun", 10000, Material.COAL_BLOCK, (byte)0);
}
@Override

View File

@ -15,7 +15,7 @@ public class Halloween2013_Helmet extends ArmorGadget
{
public Halloween2013_Helmet(GadgetManager manager)
{
super(manager, "Halloween2013_Helmet", "Pumpkin Kings Head", ArmorSlot.Helmet, Material.PUMPKIN, (byte)0);
super(manager, "Halloween2013_Helmet", "Pumpkin Kings Head", -1, ArmorSlot.Helmet, Material.PUMPKIN, (byte)0);
}
@Override

View File

@ -22,17 +22,15 @@ public abstract class ArmorGadget extends Gadget
private Material _material;
private byte _data;
public ArmorGadget(GadgetManager manager, String code, String name, ArmorSlot slot, Material mat, byte data)
public ArmorGadget(GadgetManager manager, String code, String name, int cost, ArmorSlot slot, Material mat, byte data)
{
super(manager, code, name);
super(manager, code, name, cost);
_slot = slot;
_material = mat;
_data = data;
}
public ArmorSlot GetSlot()
{
return _slot;

View File

@ -19,13 +19,15 @@ public abstract class Gadget implements Listener
private String _code;
private String _name;
private int _cost;
public Gadget(GadgetManager manager, String code, String name)
public Gadget(GadgetManager manager, String code, String name, int cost)
{
Manager = manager;
_code = code;
_name = name;
_cost = cost;
Manager.GetPlugin().getServer().getPluginManager().registerEvents(this, Manager.GetPlugin());
}
@ -40,6 +42,11 @@ public abstract class Gadget implements Listener
return _code;
}
public int getCost()
{
return _cost;
}
public HashSet<Player> GetOwners()
{
return _owners;

View File

@ -16,9 +16,9 @@ public abstract class ItemGadget extends Gadget
private Material _material;
private byte _data;
public ItemGadget(GadgetManager manager, String code, String name, Material mat, byte data)
public ItemGadget(GadgetManager manager, String code, String name, int cost, Material mat, byte data)
{
super(manager, code, name);
super(manager, code, name, cost);
_material = mat;
_data = data;

View File

@ -0,0 +1,24 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.pet.Pet;
import mineplex.core.shop.item.IButton;
public class ActivatePetButton implements IButton
{
private Pet _pet;
private GadgetPage _page;
public ActivatePetButton(Pet pet, GadgetPage page)
{
_pet = pet;
_page = page;
}
@Override
public void Clicked(Player player)
{
_page.ActivatePet(player, _pet);
}
}

View File

@ -0,0 +1,14 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
public class CloseButton implements IButton
{
@Override
public void Clicked(Player player)
{
player.closeInventory();
}
}

View File

@ -0,0 +1,24 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.pet.Pet;
import mineplex.core.shop.item.IButton;
public class DeactivatePetButton implements IButton
{
private Pet _pet;
private GadgetPage _page;
public DeactivatePetButton(Pet pet, GadgetPage page)
{
_pet = pet;
_page = page;
}
@Override
public void Clicked(Player player)
{
_page.DeactivatePet(player);
}
}

View File

@ -0,0 +1,165 @@
package mineplex.hub.gadget.ui;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.server.v1_6_R3.EntityPlayer;
import net.minecraft.server.v1_6_R3.Item;
import net.minecraft.server.v1_6_R3.Packet100OpenWindow;
import net.minecraft.server.v1_6_R3.Packet103SetSlot;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.Pet;
import mineplex.core.pet.PetExtra;
import mineplex.core.pet.PetManager;
import mineplex.core.pet.PetShop;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.AnvilContainer;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.gadget.GadgetManager;
import mineplex.hub.gadget.types.Gadget;
import mineplex.hub.mount.MountManager;
public class GadgetPage extends ShopPageBase<GadgetManager, GadgetShop>
{
private MountManager _mountPlugin;
public GadgetPage(GadgetManager plugin, GadgetShop shop, MountManager mountPlugin, CoreClientManager clientManager, DonationManager donationManager, String name, Player player)
{
super(plugin, shop, clientManager, donationManager, name, player, 45);
_mountPlugin = mountPlugin;
BuildPage();
}
protected void BuildPage()
{
int slot = 1;
for (Gadget gadget : Plugin.getGadgets())
{
List<String> itemLore = new ArrayList<String>();
itemLore.add(C.cYellow + gadget.getCost() + " Gems");
itemLore.add(C.cBlack);
if (DonationManager.Get(Player.getName()).OwnsUnknownPackage(pet.GetPetName()))
{
if (Plugin.hasActivePet(Player.getName()) && Plugin.getActivePet(Player.getName()).getType() == pet.GetPetType())
{
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Deactivate " + Plugin.Get(Player).GetPets().get(pet.GetPetType()), new String[] {}, 1, false, false), new DeactivatePetButton(pet, this));
}
else
{
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Activate " + Plugin.Get(Player).GetPets().get(pet.GetPetType()), new String[] {}, 1, false, false), new ActivatePetButton(pet, this));
}
}
else
{
if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Gems) >= pet.GetCost(CurrencyType.Gems))
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Purchase " + pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, false, false), new PetButton(pet, this));
else
setItem(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Purchase " + pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false));
}
slot++;
}
slot = 22;
for (PetExtra petExtra : Plugin.GetFactory().GetPetExtras())
{
List<String> itemLore = new ArrayList<String>();
if (!Plugin.hasActivePet(Player.getName()))
{
itemLore.add(C.cWhite + "You must have an active pet to use this!");
getInventory().setItem(slot, new ShopItem(petExtra.GetMaterial(), (byte)0, C.cRed + petExtra.GetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false).getHandle());
}
else
{
AddButton(slot, new ShopItem(petExtra.GetMaterial(), (byte)0, "Rename " + Plugin.getActivePet(Player.getName()).getCustomName() + " for " + C.cYellow + petExtra.GetCost(CurrencyType.Gems) + C.cGreen + " Gems", itemLore.toArray(new String[itemLore.size()]), 1, false, false), new RenamePetButton(this));
}
slot++;
}
}
protected void addGadget(Gadget gadget)
{
List<String> itemLore = new ArrayList<String>();
itemLore.add(C.cYellow + gadget.getCost() + " Gems");
itemLore.add(C.cBlack);
if (DonationManager.Get(Player.getName()).OwnsUnknownPackage(gadget.GetCode()))
{
if (Plugin.hasActivePet(Player.getName()) && Plugin.getActivePet(Player.getName()).getType() == pet.GetPetType())
{
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Deactivate " + Plugin.Get(Player).GetPets().get(pet.GetPetType()), new String[] {}, 1, false, false), new DeactivatePetButton(pet, this));
}
else
{
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Activate " + Plugin.Get(Player).GetPets().get(pet.GetPetType()), new String[] {}, 1, false, false), new ActivatePetButton(pet, this));
}
}
else
{
if (DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Gems) >= pet.GetCost(CurrencyType.Gems))
AddButton(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Purchase " + pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, false, false), new PetButton(pet, this));
else
setItem(slot, new ShopItem(Material.MONSTER_EGG, (byte)pet.GetPetType().getTypeId(), "Purchase " + pet.GetPetName(), itemLore.toArray(new String[itemLore.size()]), 1, true, false));
}
}
public void PurchasePet(final Player player, final Pet pet)
{
renamePet(player, pet, true);
}
public void renameCurrentPet(Player player)
{
PlayAcceptSound(player);
Creature currentPet = Plugin.getActivePet(player.getName());
renamePet(player, new Pet(currentPet.getCustomName(), currentPet.getType(), 1), false);
}
public void renamePet(Player player, Pet pet, boolean petPurchase)
{
PlayAcceptSound(player);
PetTagPage petTagPage = new PetTagPage(Plugin, Shop, ClientManager, DonationManager, "Repairing", Player, pet, petPurchase);
EntityPlayer entityPlayer = ((CraftPlayer)Player).getHandle();
int containerCounter = entityPlayer.nextContainerCounter();
entityPlayer.playerConnection.sendPacket(new Packet100OpenWindow(containerCounter, 8, "Repairing", 9, true));
entityPlayer.activeContainer = new AnvilContainer(entityPlayer.inventory, petTagPage.getInventory());
entityPlayer.activeContainer.windowId = containerCounter;
entityPlayer.activeContainer.addSlotListener(entityPlayer);
entityPlayer.playerConnection.sendPacket(new Packet103SetSlot(containerCounter, 0, new net.minecraft.server.v1_6_R3.ItemStack(Item.NAME_TAG)));
Shop.SetCurrentPageForPlayer(Player, petTagPage);
}
public void ActivatePet(Player player, Pet pet)
{
PlayAcceptSound(player);
Plugin.AddPetOwner(player, pet.GetPetType(), player.getLocation());
Player.closeInventory();
}
public void DeactivatePet(Player player)
{
PlayAcceptSound(player);
Plugin.RemovePet(player, true);
Player.closeInventory();
}
}

View File

@ -0,0 +1,29 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.gadget.GadgetManager;
import mineplex.hub.mount.MountManager;
public class GadgetShop extends ShopBase<GadgetManager>
{
private MountManager _mountManager;
public GadgetShop(GadgetManager plugin, MountManager mountManager, CoreClientManager manager, DonationManager donationManager)
{
super(plugin, manager, donationManager, "Gadget Shop", CurrencyType.Gems);
_mountManager = mountManager;
}
@Override
protected ShopPageBase<GadgetManager, ? extends ShopBase<GadgetManager>> BuildPagesFor(Player player)
{
return new GadgetPage(Plugin, this, _mountManager, ClientManager, DonationManager, " Gadgets", player);
}
}

View File

@ -0,0 +1,24 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.pet.Pet;
import mineplex.core.shop.item.IButton;
public class PetButton implements IButton
{
private Pet _pet;
private GadgetPage _page;
public PetButton(Pet pet, GadgetPage page)
{
_pet = pet;
_page = page;
}
@Override
public void Clicked(Player player)
{
_page.PurchasePet(player, _pet);
}
}

View File

@ -0,0 +1,16 @@
package mineplex.hub.gadget.ui;
import java.util.Comparator;
import mineplex.core.pet.Pet;
public class PetSorter implements Comparator<Pet>
{
public int compare(Pet a, Pet b)
{
if (a.GetPetType().getTypeId() < b.GetPetType().getTypeId())
return -1;
return 1;
}
}

View File

@ -0,0 +1,107 @@
package mineplex.hub.gadget.ui;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.DonationManager;
import mineplex.core.pet.Pet;
import mineplex.core.pet.PetExtra;
import mineplex.core.pet.PetManager;
import mineplex.core.pet.PetShop;
import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.pet.repository.token.PetToken;
import mineplex.core.shop.page.ConfirmationPage;
import mineplex.core.shop.page.ShopPageBase;
import net.minecraft.server.v1_6_R3.Item;
import net.minecraft.server.v1_6_R3.ItemStack;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class PetTagPage extends ShopPageBase<PetManager, PetShop>
{
private String _tagName = "Pet Tag";
private Pet _pet;
private boolean _petPurchase;
public PetTagPage(PetManager plugin, PetShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, Pet pet, boolean petPurchase)
{
super(plugin, shop, clientManager, donationManager, name, player, 3);
_pet = pet;
_petPurchase = petPurchase;
BuildPage();
Player.setLevel(5);
}
@Override
protected void BuildPage()
{
inventory.setItem(0, new ItemStack(Item.NAME_TAG));
ButtonMap.put(0, new CloseButton());
ButtonMap.put(1, new CloseButton());
ButtonMap.put(2, new SelectTagButton(this));
}
@Override
public void PlayerClosed()
{
super.PlayerClosed();
Player.setLevel(0);
}
public void SelectTag()
{
if (ChatColor.stripColor(_tagName).length() > 16)
{
UtilPlayer.message(Player, F.main(Plugin.GetName(), ChatColor.RED + "Pet name cannot be longer than 16 characters."));
PlayDenySound(Player);
return;
}
PetExtra tag = new PetExtra("Rename " + _pet.GetName() + " to " + _tagName, Material.NAME_TAG, 1000);
_pet.setDisplayName(C.cGreen + "Purchase " + _tagName);
Shop.OpenPageForPlayer(Player, new ConfirmationPage<PetManager, PetShop>(Plugin, Shop, ClientManager, DonationManager, new Runnable()
{
public void run()
{
PetChangeToken token = new PetChangeToken();
token.Name = Player.getName();
token.PetType = _pet.GetPetType().toString();
token.PetName = _tagName;
PetToken petToken = new PetToken();
petToken.PetType = token.PetType;
if (_petPurchase)
{
Plugin.GetRepository().AddPet(token);
Plugin.addPetOwnerToQueue(Player.getName(), _pet.GetPetType());
}
else
{
Plugin.GetRepository().UpdatePet(token);
}
Plugin.Get(Player).GetPets().put(_pet.GetPetType(), token.PetName);
Player.closeInventory();
}
}, null, _petPurchase ? _pet : tag, CurrencyType.Gems, Player));
}
public void SetTagName(String tagName)
{
_tagName = tagName;
}
}

View File

@ -0,0 +1,21 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
public class RenamePetButton implements IButton
{
private GadgetPage _page;
public RenamePetButton(GadgetPage page)
{
_page = page;
}
@Override
public void Clicked(Player player)
{
_page.renameCurrentPet(player);
}
}

View File

@ -0,0 +1,21 @@
package mineplex.hub.gadget.ui;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
public class SelectTagButton implements IButton
{
private PetTagPage _page;
public SelectTagButton(PetTagPage page)
{
_page = page;
}
@Override
public void Clicked(Player player)
{
_page.SelectTag();
}
}

View File

@ -63,6 +63,11 @@ public class EntityGhast extends EntityFlying implements IMonster {
this.motY += d1 / d3 * 0.1D;
this.motZ += d2 / d3 * 0.1D;
double d5 = this.i - this.locX;
double d6 = this.bn - this.locZ;
this.aN = this.yaw = -((float) Math.atan2(d5, d6)) * 180.0F / 3.1415927F;
return;
}

View File

@ -40,7 +40,8 @@ public class MobGhast extends CreatureBase<Ghast>
@Override
public void Update(UpdateEvent event)
{
if (event.getType() == UpdateType.TICK)
Move();
}
private void Move()