Loot for World Events

This commit is contained in:
Shaun Bennett 2015-06-29 22:32:40 -05:00
parent d07c319581
commit e0284e2eb0
11 changed files with 245 additions and 16 deletions

View File

@ -100,7 +100,11 @@ public class Clans extends JavaPlugin
new FriendManager(this, _clientManager, preferenceManager, portal);
new InventoryManager(this, _clientManager);
_clansManager = new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, chat, webServerAddress);
// Enable custom-gear related managers
PacketHandler packetHandler = new PacketHandler(this);
GearManager customGear = new GearManager(this, packetHandler);
_clansManager = new ClansManager(this, serverStatusManager.getCurrentServerName(), _clientManager, _donationManager, blockRestore, teleport, chat, customGear, webServerAddress);
new Recipes(this);
new Farming(this);
new BuildingShop(_clansManager, _clientManager, _donationManager);
@ -113,10 +117,6 @@ public class Clans extends JavaPlugin
((CraftWorld) world).getHandle().spigotConfig.itemMerge = 0;
}
// Enable custom-gear related managers
PacketHandler packetHandler = new PacketHandler(this);
GearManager customGear = new GearManager(this, packetHandler);
//Updates
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Updater(this), 1, 1);

View File

@ -40,6 +40,7 @@ import mineplex.game.clans.clans.commands.ClansAllyChatCommand;
import mineplex.game.clans.clans.commands.ClansChatCommand;
import mineplex.game.clans.clans.commands.ClansCommand;
import mineplex.game.clans.clans.commands.ServerTimeCommand;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.regions.ClansRegions;
import mineplex.game.clans.clans.repository.ClanTerritory;
import mineplex.game.clans.clans.repository.tokens.ClanMemberToken;
@ -53,6 +54,7 @@ import mineplex.game.clans.fields.Field;
import mineplex.game.clans.gameplay.Gameplay;
import mineplex.game.clans.gameplay.safelog.LoggingManager;
import mineplex.game.clans.gameplay.safelog.npc.NPCManager;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.spawn.Spawn;
import mineplex.minecraft.game.classcombat.Class.ClassManager;
import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken;
@ -113,7 +115,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
public String[] denyClan = new String[] {
"neut", "neutral", "sethome", "promote", "demote", "admin", "help", "create", "disband", "delete", "invite", "join", "kick", "ally", "trust", "claim", "unclaim", "territory", "home"};
public ClansManager(JavaPlugin plugin, String serverName, CoreClientManager clientManager, DonationManager donationManager, BlockRestore blockRestore, Teleport teleport, Chat chat, String webServerAddress)
public ClansManager(JavaPlugin plugin, String serverName, CoreClientManager clientManager, DonationManager donationManager, BlockRestore blockRestore, Teleport teleport, Chat chat, GearManager gearManager, String webServerAddress)
{
super("Clans Manager", plugin);
@ -146,7 +148,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
new Spawn(plugin);
new NPCManager(this);
new LoggingManager(plugin);
new GoldManager(this, _clientManager, donationManager);
GoldManager goldManager = new GoldManager(this, _clientManager, donationManager);
DamageManager damageManager = new DamageManager(plugin, _combatManager, new NpcManager(plugin, creature), disguiseManager);
@ -173,7 +175,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
ClanEnergyManager clanEnergyManager = new ClanEnergyManager(plugin, this, clientManager, donationManager);
_worldEvent = new WorldEventManager(plugin, this, damageManager);
LootManager lootManager = new LootManager(gearManager, goldManager);
_worldEvent = new WorldEventManager(plugin, this, damageManager, lootManager);
for (ClanToken token : _clanDataAccess.getRepository().retrieveClans())
{

View File

@ -0,0 +1,21 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
import mineplex.game.clans.items.GearManager;
public class GearLoot implements ILoot
{
private GearManager _gearManager;
public GearLoot(GearManager gearManager)
{
_gearManager = gearManager;
}
@Override
public void dropLoot(Location location)
{
_gearManager.spawnItem(location);
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.economy.GoldManager;
public class GoldLoot implements ILoot
{
private GoldManager _goldManager;
private int _min;
private int _max;
public GoldLoot(GoldManager goldManager, int min, int max)
{
_goldManager = goldManager;
_min = min;
_max = max;
}
@Override
public void dropLoot(Location location)
{
int count = _min + UtilMath.r(_max - _min);
_goldManager.dropGold(location, count);
}
}

View File

@ -0,0 +1,27 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
import mineplex.core.common.util.UtilMath;
import mineplex.game.clans.items.economy.GoldToken;
public class GoldTokenLoot implements ILoot
{
private int _minGold;
private int _maxGold;
public GoldTokenLoot(int minGold, int maxGold)
{
_minGold = minGold;
_maxGold = maxGold;
}
@Override
public void dropLoot(Location location)
{
int gold = _minGold + UtilMath.r(_maxGold - _minGold);
GoldToken token = new GoldToken(gold);
location.getWorld().dropItemNaturally(location, token.toItemStack());
}
}

View File

@ -0,0 +1,9 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
public interface ILoot
{
public void dropLoot(Location location);
}

View File

@ -0,0 +1,41 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilMath;
public class ItemLoot implements ILoot
{
private Material _material;
private byte _data;
private int _min;
private int _max;
public ItemLoot(Material material)
{
this(material, 1, 1);
}
public ItemLoot(Material material, int min, int max)
{
this(material, (byte) 0, min, max);
}
public ItemLoot(Material material, byte data, int min, int max)
{
_material = material;
_data = data;
_min = min;
_max = max;
}
@Override
public void dropLoot(Location location)
{
int count = _min + UtilMath.r(_max - _min);
ItemStack item = new ItemStack(_material, count, (short) 0, _data);
location.getWorld().dropItemNaturally(location, item);
}
}

View File

@ -0,0 +1,68 @@
package mineplex.game.clans.clans.loot;
import org.bukkit.Location;
import org.bukkit.Material;
import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.items.GearManager;
import mineplex.game.clans.items.generation.WeightSet;
public class LootManager
{
private GearManager _gearManager;
private GoldManager _goldManager;
private WeightSet<ILoot> _commonSet;
private WeightSet<ILoot> _rareSet;
public LootManager(GearManager gearManager, GoldManager goldManager)
{
_gearManager = gearManager;
_goldManager = goldManager;
_commonSet = new WeightSet<ILoot>();
_rareSet = new WeightSet<ILoot>();
populateCommon();
populateRare();
}
private void populateCommon()
{
// Food
_commonSet.add(5, new ItemLoot(Material.CARROT, 1, 5));
_commonSet.add(5, new ItemLoot(Material.APPLE, 1, 3));
_commonSet.add(5, new ItemLoot(Material.COOKED_BEEF, 1, 3));
_commonSet.add(5, new ItemLoot(Material.RAW_BEEF, 1, 4));
_commonSet.add(5, new ItemLoot(Material.POTATO_ITEM, 1, 5));
// Armor
_commonSet.add(2, new ItemLoot(Material.IRON_HELMET, 1, 1));
_commonSet.add(2, new ItemLoot(Material.IRON_CHESTPLATE, 1, 1));
_commonSet.add(2, new ItemLoot(Material.IRON_LEGGINGS, 1, 1));
_commonSet.add(2, new ItemLoot(Material.IRON_BOOTS, 1, 1));
// Gear
_commonSet.add(2, new GearLoot(_gearManager));
// Gold
_commonSet.add(5, new GoldLoot(_goldManager, 100, 1000));
_commonSet.add(5, new GoldTokenLoot(100, 1000));
}
private void populateRare()
{
// Gear
_rareSet.add(10, new GearLoot(_gearManager));
}
public void dropCommon(Location location)
{
_commonSet.generateRandom().dropLoot(location);
}
public void dropRare(Location location)
{
_rareSet.generateRandom().dropLoot(location);
}
}

View File

@ -29,6 +29,7 @@ import mineplex.core.scoreboard.elements.ScoreboardElement;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.loot.LootManager;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
@ -42,11 +43,12 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
private ClansManager _clansManager;
private EventTerrainFinder _terrainFinder;
private DamageManager _damageManager;
private LootManager _lootManager;
private long _lastEventEnd;
private long _nextEventStart;
public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager)
public WorldEventManager(JavaPlugin plugin, ClansManager clansManager, DamageManager damageManager, LootManager lootManager)
{
super("World Event", plugin);
@ -54,6 +56,7 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
_terrainFinder = new EventTerrainFinder(this, clansManager);
_clansManager = clansManager;
_damageManager = damageManager;
_lootManager = lootManager;
_events = new LinkedList<WorldEvent>();
_lastEventEnd = System.currentTimeMillis();
updateNextEventTime();
@ -179,6 +182,11 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
return _damageManager;
}
public LootManager getLoot()
{
return _lootManager;
}
public EventTerrainFinder getTerrainFinder()
{
return _terrainFinder;

View File

@ -2,15 +2,22 @@ package mineplex.game.clans.clans.worldevent.event.undead;
import java.util.HashSet;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilWorld;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.EventState;
@ -60,7 +67,6 @@ public class UndeadCamp extends WorldEvent
@Override
protected void customTick()
{
System.out.println("tick");
if (getState() == EventState.PREPARE)
{
if (_hutCur < _hutMax) createHut();
@ -332,15 +338,29 @@ public class UndeadCamp extends WorldEvent
_poleCur++;
}
@EventHandler
public void onChestOpen(EntityInteractEvent event)
private void openChest(Block block)
{
Block block = event.getBlock();
_chests.remove(block);
// Effect
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.ENDER_CHEST.getId());
setBlock(block, Material.AIR);
// Loot
int count = 1 + UtilMath.r(3);
for (int i = 0; i < count; i++)
getEventManager().getLoot().dropCommon(block.getLocation());
}
@EventHandler
public void onChestOpen(PlayerInteractEvent event)
{
Block block = event.getClickedBlock();
if (_chests.contains(block))
{
setBlock(event.getBlock(), Material.AIR);
openChest(block);
event.setCancelled(true);
_chests.remove(block);
}
}
}

View File

@ -12,7 +12,7 @@ public class WeightSet<T>
private Set<Weight<T>> _weights;
private WeightSet()
public WeightSet()
{
_weights = new HashSet<Weight<T>>();
}
@ -49,6 +49,11 @@ public class WeightSet<T>
}
}
public void add(int weight, T element)
{
_weights.add(new Weight<T>(weight, element));
}
private int getTotalWeight()
{
int total = 0;