diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java index 36e6b1158..98f5a29a7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/Moba.java @@ -17,12 +17,15 @@ import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.DebugCommand; import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.game.TeamGame; +import nautilus.game.arcade.game.games.moba.gold.GoldManager; import nautilus.game.arcade.game.games.moba.kit.*; import nautilus.game.arcade.game.games.moba.kit.anath.HeroAnath; +import nautilus.game.arcade.game.games.moba.kit.bob.HeroBob; import nautilus.game.arcade.game.games.moba.kit.dana.HeroDana; import nautilus.game.arcade.game.games.moba.kit.devon.HeroDevon; import nautilus.game.arcade.game.games.moba.kit.hattori.HeroHattori; import nautilus.game.arcade.game.games.moba.recall.Recall; +import nautilus.game.arcade.game.games.moba.shop.MobaShop; import nautilus.game.arcade.game.games.moba.structure.point.CapturePoint; import nautilus.game.arcade.game.games.moba.structure.tower.Tower; import nautilus.game.arcade.game.modules.compass.CompassModule; @@ -59,6 +62,9 @@ public class Moba extends TeamGame private final Set _listeners = new HashSet<>(); + private final MobaShop _shop; + private final GoldManager _goldManager; + public Moba(ArcadeManager manager) { super(manager, GameType.MOBA, new Kit[] { new KitPlayer(manager) }, DESCRIPTION); @@ -68,6 +74,7 @@ public class Moba extends TeamGame new HeroDevon(Manager), new HeroAnath(Manager), new HeroDana(Manager), + new HeroBob(Manager) }; PrepareAutoAnnounce = false; @@ -92,6 +99,14 @@ public class Moba extends TeamGame Listener recall = new Recall(this); _listeners.add(recall); + MobaShop shop = new MobaShop(this); + _shop = shop; + _listeners.add(shop); + + GoldManager goldManager = new GoldManager(this); + _goldManager = goldManager; + _listeners.add(goldManager); + registerDebugCommand(new DebugCommand("kit", Rank.ADMIN) { @Override @@ -356,7 +371,7 @@ public class Moba extends TeamGame continue; } - HeroKit heroKit = getRandomKit(player); + HeroKit heroKit = getFirstKit(player); MobaPlayer mobaPlayer = getData(player); mobaPlayer.Role = heroKit.getRole(); @@ -543,7 +558,7 @@ public class Moba extends TeamGame return null; } - private HeroKit getRandomKit(Player player) + private HeroKit getFirstKit(Player player) { MobaPlayer mobaPlayer = getData(player); @@ -551,17 +566,17 @@ public class Moba extends TeamGame { MobaRole role = getRandomRole(player); - return getRandomKit(role); + return getFirstKit(role); } else if (mobaPlayer.Kit == null) { - return getRandomKit(mobaPlayer.Role); + return getFirstKit(mobaPlayer.Role); } return null; } - private HeroKit getRandomKit(MobaRole role) + private HeroKit getFirstKit(MobaRole role) { for (HeroKit kit : _kits) { @@ -607,4 +622,19 @@ public class Moba extends TeamGame return players; } + + public List getCapturePoints() + { + return _capturePoints; + } + + public MobaShop getShop() + { + return _shop; + } + + public GoldManager getGoldManager() + { + return _goldManager; + } } \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/gold/GoldManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/gold/GoldManager.java new file mode 100644 index 000000000..cfd386e62 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/gold/GoldManager.java @@ -0,0 +1,135 @@ +package nautilus.game.arcade.game.games.moba.gold; + +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.DebugCommand; +import nautilus.game.arcade.game.Game.GameState; +import nautilus.game.arcade.game.GameTeam; +import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.structure.point.CapturePoint; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public class GoldManager implements Listener +{ + + private static final int GOLD_PER_5 = 20; + private static final int GOLD_PER_CAPTURE_5 = 5; + + private final Moba _host; + + private final Map _playerGold; + + public GoldManager(Moba host) + { + _host = host; + + _playerGold = new HashMap<>(); + + host.registerDebugCommand(new DebugCommand("gold", Rank.ADMIN) + { + @Override + public void Execute(Player caller, String[] args) + { + if (args.length < 1) + { + caller.sendMessage(F.main("Debug", "/gold ")); + return; + } + + try + { + int amount = Integer.parseInt(args[0]); + + addGold(caller, amount); + caller.sendMessage(F.main("Debug", "Gave yourself " + F.elem(args[0]) + " gold.")); + } + catch (NumberFormatException e) + { + caller.sendMessage(F.main("Debug", F.elem(args[0]) + " is not a number.")); + } + } + }); + } + + @EventHandler + public void prepare(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + for (Player player : _host.GetPlayers(true)) + { + _playerGold.put(player, 0); + } + } + + @EventHandler + public void passiveGain(UpdateEvent event) + { + if (event.getType() != UpdateType.SEC_05 || !_host.IsLive()) + { + return; + } + + // Every player passive + for (Player player : _host.GetPlayers(true)) + { + addGold(player, GOLD_PER_5); + } + + // Capture points + for (CapturePoint point : _host.getCapturePoints()) + { + GameTeam owner = point.getOwner(); + + if (owner == null) + { + continue; + } + + for (Player player : owner.GetPlayers(true)) + { + addGold(player, GOLD_PER_CAPTURE_5); + } + } + } + + public void addGold(Player player, int amount) + { + _playerGold.put(player, _playerGold.get(player) + amount); + } + + public void removeGold(Player player, int amount) + { + _playerGold.put(player, _playerGold.get(player) - amount); + } + + public boolean hasGold(Player player, int amount) + { + return _playerGold.get(player) >= amount; + } + + /** + * Returns a map binding the player to the amount of gold they currently have. + * + * @return An unmodifiable version of the internal map used. If you want to edit the player's gold consider using the other methods within this class. + */ + public Map getPlayerGoldMap() + { + return Collections.unmodifiableMap(_playerGold); + } + + + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/CooldownCalculateEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/CooldownCalculateEvent.java new file mode 100644 index 000000000..93c0cee45 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/CooldownCalculateEvent.java @@ -0,0 +1,49 @@ +package nautilus.game.arcade.game.games.moba.kit; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class CooldownCalculateEvent extends PlayerEvent +{ + + private static final HandlerList _handlers = new HandlerList(); + + private final long _initialCooldown; + private long _cooldown; + + public CooldownCalculateEvent(Player who, long cooldown) + { + super(who); + + _initialCooldown = cooldown; + _cooldown = cooldown; + } + + public void setCooldown(long cooldown) + { + _cooldown = cooldown; + } + + public void decreaseCooldown(double factor) + { + _cooldown = (long) ((double) _initialCooldown * factor); + } + + public long getCooldown() + { + return _cooldown; + } + + public static HandlerList getHandlerList() + { + return _handlers; + } + + @Override + public HandlerList getHandlers() + { + return getHandlerList(); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroKit.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroKit.java index bdb8dc67d..cf31fe78e 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroKit.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroKit.java @@ -2,13 +2,18 @@ package nautilus.game.arcade.game.games.moba.kit; import mineplex.core.common.util.C; import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.moba.Moba; import nautilus.game.arcade.game.games.moba.MobaRole; +import nautilus.game.arcade.game.games.moba.kit.common.SkillBow; +import nautilus.game.arcade.game.games.moba.kit.common.SkillSword; +import nautilus.game.arcade.game.games.moba.shop.MobaItem; import nautilus.game.arcade.kit.Kit; import nautilus.game.arcade.kit.KitAvailability; import nautilus.game.arcade.kit.Perk; @@ -19,6 +24,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; +import java.util.List; + public class HeroKit extends Kit { @@ -140,7 +147,10 @@ public class HeroKit extends Kit inventory.setItem(AMMO_SLOT, _ammo); inventory.setItem(RECALL_SLOT, RECALL_ITEM); - for (Perk perk : GetPerks()) + Moba host = (Moba) Manager.GetGame(); + List ownedItems = host.getShop().getOwnedItems(player); + + perkLoop: for (Perk perk : GetPerks()) { if (!(perk instanceof HeroSkill)) { @@ -149,7 +159,39 @@ public class HeroKit extends Kit HeroSkill skill = (HeroSkill) perk; - skill.giveItem(player); + // Sword upgrades + if (skill instanceof SkillSword) + { + for (MobaItem item : ownedItems) + { + if (UtilItem.isSword(item.getItem())) + { + player.getInventory().setItem(skill.getSlot(), item.getItem()); + continue perkLoop; + } + } + } + // Bow upgrades + else if (skill instanceof SkillBow) + { + for (MobaItem item : ownedItems) + { + if (item.getItem().getType() == Material.BOW) + { + player.getInventory().setItem(skill.getSlot(), item.getItem()); + continue perkLoop; + } + } + } + + if (skill.isOnCooldown(player)) + { + player.getInventory().setItem(skill.getSlot(), skill.getCooldownItem()); + } + else + { + skill.giveItem(player); + } } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroSkill.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroSkill.java index 6a63a8db3..991e2afe5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroSkill.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/HeroSkill.java @@ -240,7 +240,11 @@ public class HeroSkill extends Perk long start = _lastSkill.get(player.getUniqueId()); long cooldown = _cooldown; - //TODO Shop cooldown reduction + // Modify the cooldown with respect to the upgrade items purchased from the shop + CooldownCalculateEvent cooldownEvent = new CooldownCalculateEvent(player, cooldown); + UtilServer.CallEvent(cooldownEvent); + + cooldown = cooldownEvent.getCooldown(); boolean done = UtilTime.elapsed(start, cooldown); @@ -338,6 +342,11 @@ public class HeroSkill extends Perk return _slot; } + public ItemStack getCooldownItem() + { + return _cooldownItem; + } + public boolean isOnCooldown(Player player) { return _lastSkill.containsKey(player.getUniqueId()); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/anath/SkillFlameDash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/anath/SkillFlameDash.java index 5c65b976a..e51aa1004 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/anath/SkillFlameDash.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/anath/SkillFlameDash.java @@ -41,11 +41,5 @@ public class SkillFlameDash extends DashSkill Block fBlock = block; Manager.runSyncLater(() -> Manager.GetBlockRestore().add(fBlock.getRelative(BlockFace.UP), Material.FIRE.getId(), (byte) 0, 5000), 10); } - - @Override - public void postDash(Player player) - { - Manager.GetBlockRestore().restore(player.getLocation().getBlock()); - } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/HeroBob.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/HeroBob.java new file mode 100644 index 000000000..82ad6b064 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/HeroBob.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.moba.kit.bob; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.moba.MobaRole; +import nautilus.game.arcade.game.games.moba.kit.HeroKit; +import nautilus.game.arcade.kit.Perk; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +public class HeroBob extends HeroKit +{ + + private static final String[] DESCRIPTION = { + "Something something" + }; + + private static final Perk[] PERKS = { + new SkillPaint(0), + new SkillHappyTrees(1), + new SkillBeatTheDevil(2), + new SkillBuildPainting(3) + }; + + private static final ItemStack IN_HAND = new ItemStack(Material.PAINTING); + + private static final ItemStack AMMO = new ItemBuilder(Material.SNOW_BALL) + .setTitle(C.cYellowB + "Paint") + .build(); + + public HeroBob(ArcadeManager manager) + { + super(manager, "Robert Ross", DESCRIPTION, PERKS, IN_HAND, MobaRole.MAGE); + + setAmmo(AMMO, 500); + setMaxAmmo(8); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBeatTheDevil.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBeatTheDevil.java new file mode 100644 index 000000000..596b43a76 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBeatTheDevil.java @@ -0,0 +1,47 @@ +package nautilus.game.arcade.game.games.moba.kit.bob; + +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import nautilus.game.arcade.game.games.moba.kit.common.DashSkill; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SkillBeatTheDevil extends DashSkill +{ + + private static final String[] DESCRIPTION = { + "Dash along the ground, leaving fire behind you.", + }; + private static final ItemStack SKILL_ITEM = new ItemStack(Material.FEATHER); + + public SkillBeatTheDevil(int slot) + { + super("Beat The Devil Out Of It", DESCRIPTION, SKILL_ITEM, slot); + + setCooldown(12000); + + _collide = false; + _velocityTime = 800; + _velocityStopOnEnd = true; + } + + @Override + public void dashTick(Player player) + { + player.getWorld().playSound(player.getLocation(), player.getTicksLived() % 2 == 0 ? Sound.DOOR_OPEN : Sound.DOOR_CLOSE, 1, 0.5F); + + for (int i = 0; i < 10; i++) + { + UtilParticle.playColoredParticleToAll(Color.RED, ParticleType.RED_DUST, UtilAlg.getRandomLocation(player.getLocation().add(0, 1, 0), 2), 1, ViewDist.LONG); + } + } +} + diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBuildPainting.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBuildPainting.java new file mode 100644 index 000000000..63a42f160 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillBuildPainting.java @@ -0,0 +1,206 @@ +package nautilus.game.arcade.game.games.moba.kit.bob; + +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilMath; +import mineplex.core.projectile.IThrown; +import mineplex.core.projectile.ProjectileUser; +import mineplex.core.recharge.Recharge; +import nautilus.game.arcade.game.games.moba.kit.HeroSkill; +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.entity.Entity; +import org.bukkit.entity.FallingBlock; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.ItemSpawnEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.HashSet; +import java.util.Map.Entry; +import java.util.Set; + +public class SkillBuildPainting extends HeroSkill implements IThrown +{ + + private static final String[] DESCRIPTION = { + "Bob Ross" + }; + private static final BlockFace[] AXIS = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST }; + private static final byte[][] PAINTING = { + { + 3, 3, 3, 3, 0, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3 + }, + { + 3, 3, 0, 0, 0, 0, 3, 3, 0, 0, 0, 3, 3, 3, 3 + }, + { + 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 3, 3, 3 + }, + { + 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 13, 3 + }, + { + 3, 3, 0, 0, 0, 3, 3, 3, 5, 3, 3, 13, 3, 13, 3 + }, + { + 3, 3, 8, 8, 8, 8, 3, 5, 5, 5, 3, 13, 13, 13, 13 + }, + { + 3, 3, 8, 8, 8, 8, 3, 3, 12, 3, 13, 13, 13, 13, 13 + }, + { + 3, 3, 7, 7, 7, 7, 7, 3, 12, 3, 3, 12, 3, 12, 3 + }, + { + 5, 7, 7, 7, 7, 7, 7, 5, 12, 5, 5, 12, 5, 12, 5 + } + }; + + private static final ItemStack SKILL_ITEM = new ItemStack(Material.NETHER_STAR); + + public SkillBuildPainting(int slot) + { + super("The Joy Of Painting", DESCRIPTION, SKILL_ITEM, slot, ActionType.ANY); + + setCooldown(60000); + } + + @EventHandler + public void interact(PlayerInteractEvent event) + { + if (!isSkillItem(event)) + { + return; + } + + Player player = event.getPlayer(); + + if (!Recharge.Instance.use(player, GetName() + " Trigger", 5000, false, false)) + { + return; + } + + useActiveSkill(player, 4000); + + Set blocks = new HashSet<>(); + + Vector direction = player.getLocation().getDirection().normalize().setY(0); + Location start = player.getLocation().add(direction); + BlockFace facing = getFace(start.getYaw() + 180F); + Block center = start.getBlock().getRelative(facing).getRelative(BlockFace.UP); + + float leftYaw = start.getYaw() - 90; + BlockFace leftSide = getFace(leftYaw); + + for (int i = 0; i < 7; i++) + { + center = center.getRelative(leftSide); + } + + BlockFace rightSide = leftSide.getOppositeFace(); + + // Rows + for (int y = 0; y < PAINTING.length; y++) + { + byte[] row = PAINTING[y]; + + // Column in row + for (int x = 0; x < row.length; x++) + { + Block result = center; + + for (int i = 0; i < x; i++) + { + result = result.getRelative(rightSide); + } + + result = result.getRelative(0, 8, 0); + + for (int i = 0; i < y; i++) + { + result = result.getRelative(BlockFace.DOWN); + } + + Block fResult = result; + byte blockData = row[x]; + + Manager.runSyncLater(() -> + { + blocks.add(fResult); + Manager.GetBlockRestore().add(fResult, Material.WOOL.getId(), blockData, Long.MAX_VALUE); + + }, UtilMath.r(40)); + } + } + + Manager.runSyncLater(() -> + { + for (Block block : blocks) + { + if (Math.random() < 0.2) + { + FallingBlock fallingBlock = block.getWorld().spawnFallingBlock(block.getLocation().add(0.5, 0.5, 0.5), block.getType(), block.getData()); + + fallingBlock.setVelocity(direction.clone().multiply(1 + (Math.random() * 0.4))); + Manager.GetProjectile().AddThrow(fallingBlock, player, this, 2000, true, true, true, false, 0.5F); + } + + Manager.GetBlockRestore().restore(block); + } + }, 80); + } + + @EventHandler + public void itemSpawn(ItemSpawnEvent event) + { + if (event.getEntity().getItemStack().getType() == Material.WOOL) + { + event.setCancelled(true); + } + } + + @Override + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + damage(data); + } + + @Override + public void Idle(ProjectileUser data) + { + + } + + @Override + public void Expire(ProjectileUser data) + { + damage(data); + } + + private void damage(ProjectileUser data) + { + Entity entity = data.getThrown(); + data.getThrown().getWorld().playEffect(entity.getLocation(), Effect.STEP_SOUND, Material.WOOL, (byte) 0); + + for (Entry entry : UtilEnt.getInRadius(entity.getLocation(), 3).entrySet()) + { + Manager.GetDamage().NewDamageEvent(entry.getKey(), data.getThrower(), null, DamageCause.BLOCK_EXPLOSION, 5, true, true, false, UtilEnt.getName(data.getThrower()), GetName()); + } + + data.getThrown().remove(); + } + + private BlockFace getFace(float yaw) + { + return AXIS[Math.round(yaw / 90F) & 0x3]; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillHappyTrees.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillHappyTrees.java new file mode 100644 index 000000000..3b429be01 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillHappyTrees.java @@ -0,0 +1,174 @@ +package nautilus.game.arcade.game.games.moba.kit.bob; + +import mineplex.core.common.util.*; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilParticle.ParticleType; +import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import nautilus.game.arcade.game.games.moba.kit.HeroSkill; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.*; +import java.util.Map.Entry; + +public class SkillHappyTrees extends HeroSkill +{ + + private static final String[] DESCRIPTION = { + "Bob Ross" + }; + + private static final ItemStack SKILL_ITEM = new ItemStack(Material.SAPLING); + + private final Set _data = new HashSet<>(); + + public SkillHappyTrees(int slot) + { + super("Happy Little Trees", DESCRIPTION, SKILL_ITEM, slot, ActionType.ANY); + + setCooldown(15000); + } + + @EventHandler + public void interact(PlayerInteractEvent event) + { + if (!isSkillItem(event)) + { + return; + } + + Player player = event.getPlayer(); + + useSkill(player); + _data.add(new HappyTreeData(player)); + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + { + return; + } + + Iterator iterator = _data.iterator(); + + while (iterator.hasNext()) + { + HappyTreeData data = iterator.next(); + + if (UtilTime.elapsed(data.Start, 9000)) + { + iterator.remove(); + } + else if (data.Tree1 == null) + { + data.Tree1 = buildTree(data.Center); + } + else if (data.Tree2 == null) + { + data.Tree2 = buildTree(data.Center); + } + + if (UtilTime.elapsed(data.Start, 2000)) + { + healPlayers(data.Owner, data.Tree1); + healPlayers(data.Owner, data.Tree2); + } + } + } + + private Block buildTree(Location center) + { + Location start = UtilAlg.getRandomLocation(center, 5, 0, 5); + Map blocks = getTree(start); + + for (Entry entry : blocks.entrySet()) + { + Manager.runSyncLater(() -> Manager.GetBlockRestore().add(entry.getKey(), entry.getValue().getId(), (byte) 0, (long) (6000 + (Math.random() * 1000))), UtilMath.r(60)); + } + + return start.getBlock(); + } + + private Map getTree(Location start) + { + Block last = start.getBlock().getRelative(BlockFace.DOWN); + Map blocks = new HashMap<>(); + + // Trunk + for (int i = 0; i < 5; i++) + { + Block next = last.getRelative(BlockFace.UP); + last = next; + blocks.put(next, Material.LOG); + } + + last = last.getRelative(BlockFace.DOWN).getRelative(BlockFace.DOWN); + + // Bottom Leaves + for (Block block : UtilBlock.getInBoundingBox(last.getLocation().add(2, 1, 2), last.getLocation().subtract(2, 0, 2), false)) + { + blocks.put(block, Material.LEAVES); + } + + last = last.getRelative(BlockFace.UP).getRelative(BlockFace.UP); + + // Middle Leaves + for (Block block : UtilBlock.getInBoundingBox(last.getLocation().add(1, 0, 1), last.getLocation().subtract(1, 0, 1), false)) + { + blocks.put(block, Material.LEAVES); + } + + last = last.getRelative(BlockFace.UP); + + // Top Leaves + blocks.put(last.getRelative(BlockFace.NORTH), Material.LEAVES); + blocks.put(last.getRelative(BlockFace.WEST), Material.LEAVES); + blocks.put(last.getRelative(BlockFace.EAST), Material.LEAVES); + blocks.put(last.getRelative(BlockFace.SOUTH), Material.LEAVES); + blocks.put(last.getRelative(BlockFace.UP), Material.LEAVES); + + return blocks; + } + + private void healPlayers(Player owner, Block block) + { + for (LivingEntity entity : UtilEnt.getInRadius(block.getLocation(), 5).keySet()) + { + // Don't heal enemies + if (!isTeamDamage(entity, owner)) + { + continue; + } + + entity.setHealth(Math.min(entity.getHealth() + 2, entity.getMaxHealth())); + UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, entity.getLocation().add(0, 1, 0), 0.5F, 0.5F, 0.5F, 0.1F, 4, ViewDist.LONG); + } + } + + private class HappyTreeData + { + public Player Owner; + public long Start; + public Location Center; + public Block Tree1; + public Block Tree2; + + public HappyTreeData(Player owner) + { + Owner = owner; + Start = System.currentTimeMillis(); + Center = owner.getLocation(); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillPaint.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillPaint.java new file mode 100644 index 000000000..df990d0dd --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/bob/SkillPaint.java @@ -0,0 +1,100 @@ +package nautilus.game.arcade.game.games.moba.kit.bob; + +import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilEnt; +import mineplex.core.common.util.UtilEvent.ActionType; +import mineplex.core.common.util.UtilMath; +import mineplex.core.projectile.IThrown; +import mineplex.core.projectile.ProjectileUser; +import nautilus.game.arcade.game.games.moba.kit.HeroSkill; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.entity.Snowball; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import java.util.Random; + +public class SkillPaint extends HeroSkill implements IThrown +{ + + private static final String[] DESCRIPTION = { + "Bob Ross" + }; + private static final byte[] COLOURS = { 14, 1, 4, 5, 3, 11, 0}; + + private static final ItemStack SKILL_ITEM = new ItemStack(Material.DIAMOND_BARDING); + + public SkillPaint(int slot) + { + super("1-Inch Brush", DESCRIPTION, SKILL_ITEM, slot, ActionType.ANY); + } + + @EventHandler + public void interact(PlayerInteractEvent event) + { + if (!isSkillItem(event)) + { + return; + } + + Player player = event.getPlayer(); + + if (!_kit.useAmmo(player, 1)) + { + return; + } + + useSkill(player); + + Snowball snowball = player.launchProjectile(Snowball.class); + + Manager.GetProjectile().AddThrow(snowball, player, this, -1, true, true, true, false, 0.5F); + } + + @Override + public void Collide(LivingEntity target, Block block, ProjectileUser data) + { + Player thrower = (Player) data.getThrower(); + Random random = UtilMath.random; + + if (target != null) + { + thrower.playSound(thrower.getLocation(), Sound.LAVA_POP, 1, 1.3F); + Manager.GetDamage().NewDamageEvent(target, thrower, (Projectile) data.getThrown(), DamageCause.PROJECTILE, 2, true, true, false, UtilEnt.getName(thrower), GetName()); + } + + for (Block nearby : UtilBlock.getBlocksInRadius(data.getThrown().getLocation(), 2)) + { + if (UtilBlock.airFoliage(nearby)) + { + continue; + } + + Manager.GetBlockRestore().add(nearby, Material.STAINED_CLAY.getId(), COLOURS[random.nextInt(COLOURS.length)], (long) (3000 + (Math.random() * 500))); + } + + for (LivingEntity entity : UtilEnt.getInRadius(data.getThrown().getLocation(), 2).keySet()) + { + Manager.GetDamage().NewDamageEvent(entity, thrower, (Projectile) data.getThrown(), DamageCause.PROJECTILE, 2, true, true, false, UtilEnt.getName(thrower), GetName()); + } + } + + @Override + public void Idle(ProjectileUser data) + { + + } + + @Override + public void Expire(ProjectileUser data) + { + + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/DashSkill.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/DashSkill.java index 85952a767..b9e51c378 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/DashSkill.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/DashSkill.java @@ -175,8 +175,13 @@ public class DashSkill extends HeroSkill LivingEntity entity = entry.getKey(); double scale = entry.getValue(); - // If player hit themselves or the entity has already been hit - if (player.equals(entity) || !Recharge.Instance.use(player, GetName() + " by " + player.getName(), 500, false, false) && _collideOnce) + // If player hit themselves + if (player.equals(entity)) + { + continue; + } + + if (!(entity instanceof Player) || !Recharge.Instance.use((Player) entity, GetName() + " by " + player.getName(), 500, false, false) && _collideOnce) { continue; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/SkillSword.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/SkillSword.java index 7aa94f22a..864c35188 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/SkillSword.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/common/SkillSword.java @@ -4,6 +4,7 @@ import mineplex.core.common.util.C; import mineplex.core.itemstack.ItemBuilder; import nautilus.game.arcade.game.games.moba.kit.HeroSkill; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; public class SkillSword extends HeroSkill diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillDanaDash.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillDanaDash.java index f4efd724e..f6ca20836 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillDanaDash.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillDanaDash.java @@ -60,12 +60,12 @@ public class SkillDanaDash extends DashSkill if (entity instanceof Player) { damage = 10; - UtilAction.velocity(entity, new Vector(Math.random() / 2 - 0.25, 2, Math.random() / 2 - 0.25)); + UtilAction.velocity(entity, new Vector(Math.random() / 2 - 0.25, 1, Math.random() / 2 - 0.25)); } else { damage = 6; - UtilAction.velocity(entity, new Vector(Math.random() - 0.5, 1, Math.random() - 0.5)); + UtilAction.velocity(entity, new Vector(Math.random() - 0.5, 0.5, Math.random() - 0.5)); } entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_HIT, 1, 0.5F); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillRally.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillRally.java index cd5c004db..c0ac9b8a2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillRally.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/dana/SkillRally.java @@ -73,7 +73,7 @@ public class SkillRally extends HeroSkill @EventHandler public void updateLand(UpdateEvent event) { - if (event.getType() != UpdateType.FASTEST) + if (event.getType() != UpdateType.TICK) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillNinjaBlade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillNinjaBlade.java index 9f4fe1071..9e8546707 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillNinjaBlade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillNinjaBlade.java @@ -66,16 +66,12 @@ public class SkillNinjaBlade extends HeroSkill Player player = event.GetDamagerPlayer(false); Player damageePlayer = event.GetDamageePlayer(); - if (player != null && damageePlayer != null) + if (player == null || damageePlayer == null || isTeamDamage(damageePlayer, player)) { - Game game = Manager.GetGame(); - if (game.GetTeam(player).equals(game.GetTeam(damageePlayer))) - { - return; - } + return; } - if (player == null || !_active.contains(player.getUniqueId()) || player.getItemInHand() == null || player.getItemInHand().getType() != Material.DIAMOND_SWORD) + if (!_active.contains(player.getUniqueId()) || player.getItemInHand() == null || player.getItemInHand().getType() != Material.DIAMOND_SWORD) { return; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillSnowball.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillSnowball.java index 5ad950ee0..2d353db1c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillSnowball.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/kit/hattori/SkillSnowball.java @@ -82,13 +82,11 @@ public class SkillSnowball extends HeroSkill implements IThrown @Override public void Idle(ProjectileUser data) { - data.getThrown().remove(); } @Override public void Expire(ProjectileUser data) { - data.getThrown().remove(); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItem.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItem.java new file mode 100644 index 000000000..7cabddd2a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItem.java @@ -0,0 +1,50 @@ +package nautilus.game.arcade.game.games.moba.shop; + +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class MobaItem +{ + + private final ItemStack _item; + private final int _cost; + private List _effects; + + public MobaItem(ItemStack item, int cost) + { + _item = item; + _cost = cost; + } + + public MobaItem addEffects(MobaItemEffect... effects) + { + if (_effects == null) + { + _effects = new ArrayList<>(effects.length); + } + + for (MobaItemEffect effect : _effects) + { + _effects.add(effect); + } + return this; + } + + public ItemStack getItem() + { + return _item; + } + + public int getCost() + { + return _cost; + } + + public List getEffects() + { + return _effects; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItemEffect.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItemEffect.java new file mode 100644 index 000000000..8af399784 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaItemEffect.java @@ -0,0 +1,17 @@ +package nautilus.game.arcade.game.games.moba.shop; + +import nautilus.game.arcade.game.games.moba.kit.CooldownCalculateEvent; +import org.bukkit.entity.Player; + +public class MobaItemEffect +{ + + public void onCooldownCheck(CooldownCalculateEvent event) + { + } + + public void onDeath(Player killed, Player killer) + { + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaMainMenu.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaMainMenu.java deleted file mode 100644 index b080347bb..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaMainMenu.java +++ /dev/null @@ -1,89 +0,0 @@ -package nautilus.game.arcade.game.games.moba.shop; - -import mineplex.core.common.util.UtilUI; -import mineplex.core.itemstack.ItemBuilder; -import mineplex.core.menu.Button; -import mineplex.core.menu.Menu; -import nautilus.game.arcade.ArcadeManager; -import nautilus.game.arcade.game.games.moba.MobaPlayer; -import nautilus.game.arcade.game.games.moba.kit.HeroKit; -import nautilus.game.arcade.game.games.moba.kit.HeroSkill; -import nautilus.game.arcade.game.games.moba.kit.common.SkillSword; -import nautilus.game.arcade.kit.Perk; -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; -import org.bukkit.inventory.ItemStack; - -import java.util.ArrayList; -import java.util.List; - -public class MobaMainMenu extends Menu -{ - - private static final int SLOTS = 27; - - private final MobaPlayer _player; - - public MobaMainMenu(MobaPlayer player, ArcadeManager plugin) - { - super(player.Kit.GetName() + " Shop", plugin); - - _player = player; - } - - @Override - protected Button[] setUp(Player player) - { - Button[] buttons = new Button[SLOTS]; - HeroKit kit = _player.Kit; - List skills = new ArrayList<>(3); - - for (Perk perk : kit.GetPerks()) - { - if (!(perk instanceof HeroSkill)) - { - continue; - } - - skills.add((HeroSkill) perk); - } - - int slots[] = UtilUI.getIndicesFor(skills.size(), 1, 3); - - for (HeroSkill skill : skills) - { - - } - - return buttons; - } - - private ItemStack getMainMenuItem(HeroSkill skill) - { - ItemBuilder builder; - - if (skill instanceof SkillSword) - { - builder = - } - } - - class MobaMainButton extends Button - { - - private MobaPlayer _player; - - public MobaMainButton(MobaPlayer player, ArcadeManager plugin) - { - super(item, plugin); - - _player = player; - } - - @Override - public void onClick(Player player, ClickType clickType) - { - - } - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java index d40d78dd1..0518b8c21 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShop.java @@ -1,10 +1,21 @@ package nautilus.game.arcade.game.games.moba.shop; +import mineplex.core.common.Rank; +import mineplex.core.common.util.*; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.CombatComponent; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; import nautilus.game.arcade.events.GameStateChangeEvent; +import nautilus.game.arcade.game.DebugCommand; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.moba.Moba; import nautilus.game.arcade.game.games.moba.MobaPlayer; +import nautilus.game.arcade.game.games.moba.MobaRole; +import nautilus.game.arcade.game.games.moba.kit.CooldownCalculateEvent; +import nautilus.game.arcade.game.games.moba.shop.assassin.MobaAssassinShop; import org.bukkit.Location; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -13,22 +24,29 @@ import org.bukkit.entity.Villager.Profession; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import java.util.*; +import java.util.Map.Entry; public class MobaShop implements Listener { private final Moba _host; - private final List _entities; - private final Map> _upgrades; + private final Map _entities; + private final Map _roleMenus; + private final Map> _upgrades; public MobaShop(Moba host) { _host = host; - _entities = new ArrayList<>(2); + _entities = new HashMap<>(2); + _roleMenus = new HashMap<>(4); _upgrades = new HashMap<>(); + + // Create menus + _roleMenus.put(MobaRole.ASSASSIN, new MobaAssassinShop(host, this)); } @EventHandler @@ -41,6 +59,7 @@ public class MobaShop implements Listener List locations = _host.WorldData.GetDataLocs("CYAN"); + _host.CreatureAllowOverride = true; for (Location location : locations) { Villager villager = location.getWorld().spawn(location, Villager.class); @@ -48,20 +67,61 @@ public class MobaShop implements Listener villager.setProfession(Profession.LIBRARIAN); villager.setAgeLock(true); villager.setRemoveWhenFarAway(false); + villager.setCustomName(C.cGoldB + "GOLD UPGRADES"); + villager.setCustomNameVisible(true); + UtilEnt.vegetate(villager); + UtilEnt.silence(villager, true); + UtilEnt.CreatureForceLook(villager, 0, UtilAlg.GetYaw(UtilAlg.getTrajectory(villager.getLocation(), _host.GetSpectatorLocation()))); - _entities.add(villager); + _entities.put(villager, location); } - } - - public void purchaseUpgrade(Player player, MobaUpgrade upgrade) - { - _upgrades.putIfAbsent(player, new HashSet<>(3)); - _upgrades.get(player).add(upgrade); + _host.CreatureAllowOverride = false; } private void openShop(MobaPlayer player) { + MobaShopMenu menu = _roleMenus.get(player.Role); + if (menu == null) + { + player.Player.sendMessage(F.main("Game", "There isn't an upgrade shop for that kit yet.")); + return; + } + + menu.open(player.Player); + } + + @EventHandler + public void npcMove(UpdateEvent event) + { + if (event.getType() != UpdateType.FASTEST) + { + return; + } + + for (Entry entry : _entities.entrySet()) + { + LivingEntity entity = entry.getKey(); + Location location = entry.getValue(); + + ((CraftLivingEntity) entity).getHandle().setPosition(location.getX(), location.getY(), location.getZ()); + } + } + + @EventHandler + public void npcDamage(EntityDamageEvent event) + { + for (Entry entry : _entities.entrySet()) + { + LivingEntity entity = entry.getKey(); + + if (entity.equals(event.getEntity())) + { + entity.setFireTicks(0); + event.setCancelled(true); + return; + } + } } @EventHandler @@ -83,9 +143,9 @@ public class MobaShop implements Listener return; } - Player player = (Player) clicked; + Player player = (Player) clicker; - for (LivingEntity shop : _entities) + for (LivingEntity shop : _entities.keySet()) { if (clicked.equals(shop)) { @@ -93,6 +153,7 @@ public class MobaShop implements Listener if (data == null) { + player.sendMessage(F.main("Game", "You don't appear to have any data?")); return; } @@ -101,4 +162,93 @@ public class MobaShop implements Listener } } } + + public void purchaseItem(Player player, MobaItem item) + { + player.sendMessage(F.main("Game", "Purchased " + F.greenElem(item.getItem().getItemMeta().getDisplayName()) + ".")); + _host.getGoldManager().removeGold(player, item.getCost()); + _upgrades.get(player).add(item); + } + + public boolean ownsItem(Player player, MobaItem item) + { + return _upgrades.get(player).contains(item); + } + + public List getOwnedItems(Player player) + { + return _upgrades.get(player); + } + + /* + Handle MobaItem events + */ + + @EventHandler + public void prepare(GameStateChangeEvent event) + { + if (event.GetState() != GameState.Prepare) + { + return; + } + + for (Player player : _host.GetPlayers(true)) + { + _upgrades.put(player, new ArrayList<>()); + } + } + + @EventHandler + public void cooldownCalculate(CooldownCalculateEvent event) + { + Player player = event.getPlayer(); + List items = _upgrades.get(player); + + for (MobaItem item : items) + { + if (item.getEffects() == null) + { + continue; + } + + for (MobaItemEffect effect : item.getEffects()) + { + effect.onCooldownCheck(event); + } + } + } + + @EventHandler + public void combatDeath(CombatDeathEvent event) + { + CombatComponent component = event.GetLog().GetKiller(); + + if (component == null || !component.IsPlayer() || !(event.GetEvent().getEntity() instanceof Player)) + { + return; + } + + Player killed = (Player) event.GetEvent().getEntity(); + Player killer = UtilPlayer.searchExact(component.getUniqueIdOfEntity()); + + if (killer == null) + { + return; + } + + List items = _upgrades.get(killer); + + for (MobaItem item : items) + { + if (item.getEffects() == null) + { + continue; + } + + for (MobaItemEffect effect : item.getEffects()) + { + effect.onDeath(killed, killer); + } + } + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategory.java new file mode 100644 index 000000000..224433e3f --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategory.java @@ -0,0 +1,47 @@ +package nautilus.game.arcade.game.games.moba.shop; + +import org.bukkit.inventory.ItemStack; + +import java.util.List; + +public class MobaShopCategory +{ + + private final String _name; + private final List _items; + private final ItemStack _menuItem; + private boolean _allowMultiple; + + public MobaShopCategory(String name, List items, ItemStack menuItem) + { + _name = name; + _items = items; + _menuItem = menuItem; + } + + public String getName() + { + return _name; + } + + public List getItems() + { + return _items; + } + + public ItemStack getMenuItem() + { + return _menuItem; + } + + public MobaShopCategory allowMultiple(boolean allow) + { + _allowMultiple = allow; + return this; + } + + public boolean isAllowingMultiple() + { + return _allowMultiple; + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategoryMenu.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategoryMenu.java new file mode 100644 index 000000000..3dd51cc3a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopCategoryMenu.java @@ -0,0 +1,96 @@ +package nautilus.game.arcade.game.games.moba.shop; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.menu.Button; +import mineplex.core.menu.Menu; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.moba.Moba; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +public class MobaShopCategoryMenu extends Menu +{ + + private static final int SLOTS = 27; + private static final int STARTING_SLOT = 10; + + private final Moba _host; + private final MobaShop _shop; + private final MobaShopCategory _category; + + public MobaShopCategoryMenu(Moba host, MobaShop shop, MobaShopCategory category, ArcadeManager plugin) + { + super(category.getName() + " Shop", plugin); + + _host = host; + _shop = shop; + _category = category; + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[SLOTS]; + int slot = STARTING_SLOT; + + for (MobaItem item : _category.getItems()) + { + ItemBuilder builder = new ItemBuilder(item.getItem()); + boolean owns = _shop.ownsItem(player, item); + boolean canPurchase = _host.getGoldManager().hasGold(player, item.getCost()); + + builder.setTitle((canPurchase ? C.cGreen : C.cRed) + item.getItem().getItemMeta().getDisplayName()); + + if (owns) + { + builder.addLore(C.cRed + "You already have purchased this upgrade"); + } + else + { + builder.addLore("Cost: " + C.cGold + item.getCost()); + + if (canPurchase) + { + builder.addLore(C.cGreen + "Click to purchase"); + } + else + { + builder.addLore(C.cRed + "You cannot afford this item."); + } + } + + buttons[slot++] = new MobaPurchaseButton(builder.build(), getPlugin(), item); + } + + return buttons; + } + + class MobaPurchaseButton extends Button + { + + private MobaItem _item; + + public MobaPurchaseButton(ItemStack itemStack, ArcadeManager plugin, MobaItem item) + { + super(itemStack, plugin); + + _item = item; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + boolean owns = _shop.ownsItem(player, _item); + boolean canPurchase = _host.getGoldManager().hasGold(player, _item.getCost()); + + if (!owns && canPurchase) + { + _shop.purchaseItem(player, _item); + player.closeInventory(); + } + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopMenu.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopMenu.java new file mode 100644 index 000000000..5c3d4582e --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaShopMenu.java @@ -0,0 +1,124 @@ +package nautilus.game.arcade.game.games.moba.shop; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.UtilUI; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.menu.Button; +import mineplex.core.menu.Menu; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.MobaRole; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public class MobaShopMenu extends Menu +{ + + private static final int SLOTS = 27; + + private final Moba _host; + private final MobaShop _shop; + private final List _categories; + + public MobaShopMenu(Moba host, MobaShop shop, MobaRole role) + { + super(role.getName() + " Upgrade Shop", host.getArcadeManager()); + + _host = host; + _shop = shop; + _categories = new ArrayList<>(); + } + + protected void addCategory(MobaShopCategory category) + { + _categories.add(category); + } + + @Override + protected Button[] setUp(Player player) + { + Button[] buttons = new Button[SLOTS]; + int[] slots = UtilUI.getIndicesFor(_categories.size(), 1); + int slot = 0; + + for (MobaShopCategory category : _categories) + { + ItemBuilder builder; + MobaItem owned = null; + + for (MobaItem item : category.getItems()) + { + if (_shop.ownsItem(player, item)) + { + owned = item; + break; + } + } + + if (owned == null) + { + builder = new ItemBuilder(category.getMenuItem()); + } + else + { + builder = new ItemBuilder(owned.getItem()); + } + + builder.setTitle(C.cGreen + category.getName()); + builder.addLore("", "Not sure what to put here", ""); + + if (category.isAllowingMultiple()) + { + builder.addLore(C.cWhite + "Current Upgrades:"); + boolean ownsAtLeastOne = false; + + for (MobaItem item : category.getItems()) + { + if (_shop.ownsItem(player, item)) + { + ownsAtLeastOne = true; + builder.addLore(" - " + item.getItem().getItemMeta().getDisplayName()); + } + } + + if (!ownsAtLeastOne) + { + builder.addLore(" - None"); + } + } + else + { + builder.addLore(C.cWhite + "Current Upgrade: " + (owned == null ? C.cGray + "None" : owned.getItem().getItemMeta().getDisplayName())); + } + + builder.addLore("", C.cYellow + "Click to view the upgrades."); + + buttons[slots[slot++]] = new MobaCategoryButton(builder.build(), getPlugin(), category); + } + + return buttons; + } + + class MobaCategoryButton extends Button + { + + private MobaShopCategory _category; + + public MobaCategoryButton(ItemStack itemStack, ArcadeManager plugin, MobaShopCategory category) + { + super(itemStack, plugin); + + _category = category; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + new MobaShopCategoryMenu(_host, _shop, _category, getPlugin()).open(player); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgrade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgrade.java deleted file mode 100644 index 55312fdc6..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgrade.java +++ /dev/null @@ -1,19 +0,0 @@ -package nautilus.game.arcade.game.games.moba.shop; - -import org.bukkit.inventory.ItemStack; - -public class MobaUpgrade -{ - - private ItemStack _item; - - public MobaUpgrade(ItemStack item) - { - _item = item; - } - - public ItemStack getItem() - { - return _item; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgradeType.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgradeType.java deleted file mode 100644 index 432e868a8..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/MobaUpgradeType.java +++ /dev/null @@ -1,13 +0,0 @@ -package nautilus.game.arcade.game.games.moba.shop; - -public enum MobaUpgradeType -{ - - SWORD, - BOW, - HELMET, - CHEST, - LEGS, - BOOTS - -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/assassin/MobaAssassinShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/assassin/MobaAssassinShop.java new file mode 100644 index 000000000..5908c9c6a --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/assassin/MobaAssassinShop.java @@ -0,0 +1,43 @@ +package nautilus.game.arcade.game.games.moba.shop.assassin; + +import mineplex.core.common.util.C; +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.game.games.moba.Moba; +import nautilus.game.arcade.game.games.moba.MobaRole; +import nautilus.game.arcade.game.games.moba.shop.MobaItem; +import nautilus.game.arcade.game.games.moba.shop.MobaShop; +import nautilus.game.arcade.game.games.moba.shop.MobaShopCategory; +import nautilus.game.arcade.game.games.moba.shop.MobaShopMenu; +import nautilus.game.arcade.game.games.moba.shop.effects.MobaKillHealEffect; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; + +import java.util.Arrays; + +public class MobaAssassinShop extends MobaShopMenu +{ + + private static final MobaShopCategory SWORD = new MobaShopCategory("Sword", Arrays.asList( + new MobaItem(new ItemBuilder(Material.GOLD_SWORD) + .setTitle(C.cGreenB + "Sword of Time") + .build(), 800) + .addEffects( + new MobaKillHealEffect(3) + ), + new MobaItem(new ItemBuilder(Material.IRON_SWORD) + .setTitle(C.cYellowB + "Adventurer's Sword") + .build(), 1000), + new MobaItem(new ItemBuilder(Material.DIAMOND_SWORD) + .setTitle(C.cDRedB + "Pumpkin King's Blade") + .addEnchantment(Enchantment.DAMAGE_ALL, 3) + .build(), 1750) + ), new ItemStack(Material.WOOD_SWORD)); + + public MobaAssassinShop(Moba host, MobaShop shop) + { + super(host, shop, MobaRole.ASSASSIN); + + addCategory(SWORD); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/common/CooldownUpgrade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/common/CooldownUpgrade.java deleted file mode 100644 index 0c7d0c84c..000000000 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/common/CooldownUpgrade.java +++ /dev/null @@ -1,22 +0,0 @@ -package nautilus.game.arcade.game.games.moba.shop.common; - -import nautilus.game.arcade.game.games.moba.shop.MobaUpgrade; -import org.bukkit.inventory.ItemStack; - -public class CooldownUpgrade extends MobaUpgrade -{ - - private double _reductionFactor; - - public CooldownUpgrade(ItemStack item, double reductionFactor) - { - super(item); - - _reductionFactor = reductionFactor; - } - - public double getReductionFactor() - { - return _reductionFactor; - } -} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaCDREffect.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaCDREffect.java new file mode 100644 index 000000000..ea6b08db8 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaCDREffect.java @@ -0,0 +1,22 @@ +package nautilus.game.arcade.game.games.moba.shop.effects; + +import nautilus.game.arcade.game.games.moba.kit.CooldownCalculateEvent; +import nautilus.game.arcade.game.games.moba.shop.MobaItemEffect; +import org.bukkit.entity.Player; + +public class MobaCDREffect extends MobaItemEffect +{ + + private double _factor; + + public MobaCDREffect(double factor) + { + _factor = factor; + } + + @Override + public void onCooldownCheck(CooldownCalculateEvent event) + { + event.decreaseCooldown(_factor); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaKillHealEffect.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaKillHealEffect.java new file mode 100644 index 000000000..4aaca0a0c --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/shop/effects/MobaKillHealEffect.java @@ -0,0 +1,21 @@ +package nautilus.game.arcade.game.games.moba.shop.effects; + +import nautilus.game.arcade.game.games.moba.shop.MobaItemEffect; +import org.bukkit.entity.Player; + +public class MobaKillHealEffect extends MobaItemEffect +{ + + private double _health; + + public MobaKillHealEffect(double health) + { + _health = health; + } + + @Override + public void onDeath(Player killed, Player killer) + { + killer.setHealth(Math.min(killer.getMaxHealth(), killer.getHealth() + _health)); + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePoint.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePoint.java index 3c5167baa..c97b92bee 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePoint.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePoint.java @@ -168,6 +168,12 @@ public class CapturePoint private void setOwner(GameTeam team) { + // Same team + if (_owner != null && _owner.equals(team)) + { + return; + } + _owner = team; setBeaconColour(team); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePointCaptureEvent.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePointCaptureEvent.java index 4383350aa..c7443a151 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePointCaptureEvent.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/moba/structure/point/CapturePointCaptureEvent.java @@ -1,11 +1,8 @@ package nautilus.game.arcade.game.games.moba.structure.point; -import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import java.util.List; - public class CapturePointCaptureEvent extends Event {