Rewrite large portions of the Shop and general system

This commit is contained in:
Sam 2017-10-27 14:48:05 +01:00 committed by Alexander Meech
parent ef31ae126c
commit 42fc0c7829
28 changed files with 728 additions and 381 deletions

View File

@ -1377,97 +1377,97 @@ public enum Achievement
AchievementCategory.MOBA),
CAKE_WARS_WIN("Cake Dinners", 15000,
new String[]{"Cake Wars.Wins"},
new String[]{"Cake Wars Rumble.Wins", "Cake Wars Duos.Wins"},
new String[]{"Win 100 games of Cake Wars"},
new int[]{100},
AchievementCategory.CAKE_WARS),
CAKE_WARS_KILLS("Cake Slayer", 15000,
new String[]{"Cake Wars.Kills"},
new String[]{"+1 for each Kill"},
new int[]{10,50,100,250,500,750,1000},
new String[]{"Cake Wars Rumble.Kills", "Cake Wars Duos.Kills"},
new String[]{"Kill 1000 players in Cake Wars"},
new int[]{1000},
AchievementCategory.CAKE_WARS),
CAKE_WARS_BITES("Big Appetite", 0,
new String[]{"Cake Wars.Bites"},
new String[]{"+1 for each Cake Bite"},
new int[]{5,25,50,125,250,375,500},
CAKE_WARS_BITES("Big Appetite", 15000,
new String[]{"Cake Wars Rumble.Bites", "Cake Wars Duos.Bites"},
new String[]{"Take 500 bites of cake in Cake Wars"},
new int[]{500},
AchievementCategory.CAKE_WARS),
CAKE_WARS_EAT_WHOLE_CAKE("Greedy", 2000,
new String[]{"Cake Wars.EatWholeCake"},
new String[]{"Cake Wars Rumble.EatWholeCake", "Cake Wars Duos.EatWholeCake"},
new String[]{"Eat a whole cake"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_SURVIVE_10("This game has cakes?", 4000,
new String[]{"Cake Wars.Survive10"},
new String[]{"Cake Wars Rumble.Survive10", "Cake Wars Duos.Survive10"},
new String[]{"Survive 10 minutes without", "a cake"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_FIRST_BLOOD("Cold Baked Killer", 2000,
new String[]{"Cake Wars.FirstBlood"},
new String[]{"Cake Wars Rumble.FirstBlood", "Cake Wars Duos.FirstBlood"},
new String[]{"Get 10 First Bloods"},
new int[]{10},
AchievementCategory.CAKE_WARS),
CAKE_WARS_EAT_1("Starving", 2000,
new String[]{"Cake Wars.Eat1"},
new String[]{"Cake Wars Rumble.Eat1", "Cake Wars Duos.Eat1"},
new String[]{"Eat a cake within the first", "minute of the game"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_NO_DEATHS("You call that a challenge", 4000,
new String[]{"Cake Wars.NoDeaths"},
new String[]{"Cake Wars Rumble.NoDeaths", "Cake Wars Duos.NoDeaths"},
new String[]{"Win a game without dying"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_BUY_ALL("Team Player", 2000,
new String[]{"Cake Wars.BuyAll"},
new String[]{"Cake Wars Rumble.BuyAll", "Cake Wars Duos.BuyAll"},
new String[]{"Purchase all Team Upgrades", "within one game"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_WIN_WITHOUT_KILL("Love not War", 4000,
new String[]{"Cake Wars.NoKills"},
new String[]{"Cake Wars Rumble.NoKills", "Cake Wars Duos.NoKills"},
new String[]{"Win a game without killing", "a player"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_WIN_WITH_1("Last Crumb", 2000,
new String[]{"Cake Wars.WinWithOneBite"},
new String[]{"Cake Wars Rumble.WinWithOneBite", "Cake Wars Duos.WinWithOneBite"},
new String[]{"Win a game with only one", "bite of your cake left"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_WIN_IN_10("Gotta go fast", 2000,
new String[]{"Cake Wars.WinIn10"},
new String[]{"Cake Wars Rumble.WinIn10", "Cake Wars Duos.WinIn10"},
new String[]{"Win a game within 10", "minutes"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_FINAL_BITE("Last Laugh", 2000,
new String[]{"Cake Wars.FinalBite"},
new String[]{"Cake Wars Rumble.FinalBite", "Cake Wars Duos.FinalBite"},
new String[]{"Get the final bite on every", "cake within a game"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_OWN_ALL_BEACONS("I <3 Capture Points", 4000,
new String[]{"Cake Wars.OwnAllBeacons"},
new String[]{"Cake Wars Rumble.OwnAllBeacons", "Cake Wars Duos.OwnAllBeacons"},
new String[]{"Own all beacons for your team", "in one game"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_GET_GOOD("Get Good", 15000,
new String[]{"Cake Wars.GetGood"},
new String[]{"Cake Wars Rumble.GetGood", "Cake Wars Duos.GetGood"},
new String[]{"Kill a player while falling", "from a great height.", "Then save yourself from dying"},
new int[]{1},
AchievementCategory.CAKE_WARS),
CAKE_WARS_FLOOR_IS_LAVA("The Floor Is Lava", 15000,
new String[]{"Cake Wars.FloorIsLava"},
new String[]{"Cake Wars Rumble.FloorIsLava", "Cake Wars Duos.FloorIsLava"},
new String[]{"After the first 30 seconds of the game", "Only stand on player placed blocks", "", "Includes Deploy Platforms and", "near Shops"},
new int[]{1},
AchievementCategory.CAKE_WARS),

View File

@ -247,18 +247,23 @@ public enum AchievementCategory
CAKE_WARS("Cake Wars", null,
new StatDisplay[]
{
StatDisplay.WINS,
StatDisplay.GAMES_PLAYED,
new StatDisplay("Rumble", true),
StatDisplay.fromGame("Wins", GameDisplay.CakeWars4, "Wins"),
StatDisplay.fromGame("Games Play", GameDisplay.CakeWars4, "Wins", "Losses"),
StatDisplay.fromGame("Kills", GameDisplay.CakeWars4, "Kills"),
StatDisplay.fromGame("Deaths", GameDisplay.CakeWars4, "Deaths"),
StatDisplay.fromGame("Cake Bites", GameDisplay.CakeWars4, "Bites"),
StatDisplay.fromGame("Whole Cakes", GameDisplay.CakeWars4, "EatWholeCake"),
null,
StatDisplay.KILLS,
StatDisplay.DEATHS,
null,
StatDisplay.fromGame("Cake Bites", GameDisplay.CakeWars, "Bites"),
StatDisplay.fromGame("Whole Cakes", GameDisplay.CakeWars, "EatWholeCake"),
null,
StatDisplay.GEMS_EARNED,
new StatDisplay("Duos", true),
StatDisplay.fromGame("Wins", GameDisplay.CakeWarsDuos, "Wins"),
StatDisplay.fromGame("Games Play", GameDisplay.CakeWarsDuos, "Wins", "Losses"),
StatDisplay.fromGame("Kills", GameDisplay.CakeWarsDuos, "Kills"),
StatDisplay.fromGame("Deaths", GameDisplay.CakeWarsDuos, "Deaths"),
StatDisplay.fromGame("Cake Bites", GameDisplay.CakeWarsDuos, "Bites"),
StatDisplay.fromGame("Whole Cakes", GameDisplay.CakeWarsDuos, "EatWholeCake"),
},
Material.CAKE, 0, GameCategory.CLASSICS, null, false, GameDisplay.CakeWars.getGameId());
Material.CAKE, 0, GameCategory.CLASSICS, null, false, GameDisplay.CakeWars4.getGameId(), GameDisplay.CakeWarsDuos.getGameId());
private String _name;
private String[] _statsToPull;

View File

@ -109,7 +109,8 @@ public enum GameDisplay
BattleRoyale("Battle Royale", Material.DIAMOND_SWORD, (byte)0, GameCategory.EVENT, 72, false),
CakeWars("Cake Wars", Material.CAKE, (byte)0, GameCategory.ARCADE, 73, true),
CakeWars4("Cake Wars Rumble", Material.CAKE, (byte)0, GameCategory.CLASSICS, 73, true),
CakeWarsDuos("Cake Wars Duos", Material.CAKE, (byte)0, GameCategory.CLASSICS, 74, false),
GemHunters("Gem Hunters", Material.EMERALD, (byte) 0, GameCategory.SURVIVAL, 71, false),

View File

@ -23,7 +23,8 @@ import nautilus.game.arcade.game.games.build.Build;
import nautilus.game.arcade.game.games.build.modes.DukesOfDecoration;
import nautilus.game.arcade.game.games.build.modes.TeamBuild;
import nautilus.game.arcade.game.games.buildmavericks.BuildMavericks;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.modes.CakeWars4;
import nautilus.game.arcade.game.games.cakewars.modes.CakeWarsDuos;
import nautilus.game.arcade.game.games.cards.Cards;
import nautilus.game.arcade.game.games.castleassault.CastleAssault;
import nautilus.game.arcade.game.games.castleassault.CastleAssaultTDM;
@ -64,7 +65,6 @@ import nautilus.game.arcade.game.games.minecraftleague.MinecraftLeague;
import nautilus.game.arcade.game.games.minestrike.Minestrike;
import nautilus.game.arcade.game.games.minestrike.modes.SuperPaintstrike;
import nautilus.game.arcade.game.games.mineware.BawkBawkBattles;
import nautilus.game.arcade.game.games.moba.Moba;
import nautilus.game.arcade.game.games.moba.MobaClassic;
import nautilus.game.arcade.game.games.moba.training.MobaTraining;
import nautilus.game.arcade.game.games.monsterleague.MonsterLeague;
@ -245,7 +245,8 @@ public enum GameType
Pair.create(MinecraftVersion.Version1_9, "http://file.mineplex.com/ResStrikeGames19.zip")
}, true),
CakeWars(CakeWars.class, GameDisplay.CakeWars),
CakeWars4(CakeWars4.class, GameDisplay.CakeWars4),
CakeWarsDuos(CakeWarsDuos.class, GameDisplay.CakeWarsDuos),
Event(EventGame.class, GameDisplay.Event, new GameType[]{
GameType.BaconBrawl, GameType.Barbarians, GameType.Bridge, GameType.Build, GameType.Build,

View File

@ -1,6 +1,5 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.modules.Module;
public class CakeModule extends Module
@ -8,7 +7,7 @@ public class CakeModule extends Module
protected final CakeWars _game;
CakeModule(CakeWars game)
public CakeModule(CakeWars game)
{
_game = game;
}

View File

@ -19,23 +19,22 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.combat.DeathMessageType;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.AbsorptionFix;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeArcher;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeBuilder;
import nautilus.game.arcade.game.games.cakewars.kits.KitCakeWarrior;
import nautilus.game.arcade.game.games.cakewars.module.CakeIslandModule;
import nautilus.game.arcade.game.games.cakewars.module.CakePlayerModule;
import nautilus.game.arcade.game.games.cakewars.module.CakePointModule;
import nautilus.game.arcade.game.games.cakewars.module.CakeShopModule;
import nautilus.game.arcade.game.games.cakewars.module.CakeSpawnerModule;
import nautilus.game.arcade.game.games.cakewars.module.CakeTeamModule;
import nautilus.game.arcade.game.games.cakewars.island.CakeIslandModule;
import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule;
import nautilus.game.arcade.game.games.cakewars.capturepoint.CakePointModule;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopModule;
import nautilus.game.arcade.game.games.cakewars.general.CakeSpawnerModule;
import nautilus.game.arcade.game.games.cakewars.team.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.team.CakeTeamModule;
import nautilus.game.arcade.game.games.cakewars.trackers.EatAllCakesTracker;
import nautilus.game.arcade.game.games.cakewars.trackers.EatFirstMinuteTracker;
import nautilus.game.arcade.game.games.cakewars.trackers.FirstBloodStatTracker;
@ -94,9 +93,9 @@ public class CakeWars extends TeamGame
private boolean _colourTick;
@SuppressWarnings("unchecked")
public CakeWars(ArcadeManager manager)
public CakeWars(ArcadeManager manager, GameType gameType)
{
super(manager, GameType.CakeWars, new Kit[]
super(manager, gameType, new Kit[]
{
new KitCakeWarrior(manager),
new KitCakeArcher(manager),

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.capturepoint;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@ -9,6 +9,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import mineplex.core.common.util.F;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.modules.capturepoint.CapturePoint;
import nautilus.game.arcade.game.modules.capturepoint.CapturePointCaptureEvent;
@ -53,26 +54,23 @@ public class CakePointModule extends CakeModule
}
}
public boolean ownsNetherPoint(GameTeam team)
public int ownedNetherStarPoints(GameTeam team)
{
for (CapturePoint point : _game.getCapturePointModule().getCapturePoints())
{
if (point.getColour().equals(ChatColor.GOLD) && point.getOwner() != null && point.getOwner().equals(team))
{
return true;
}
}
return false;
return ownedPoints(team, ChatColor.GOLD);
}
public int ownedEmeraldPoints(GameTeam team)
{
return ownedPoints(team, ChatColor.GREEN);
}
private int ownedPoints(GameTeam team, ChatColor colour)
{
int i = 0;
for (CapturePoint point : _game.getCapturePointModule().getCapturePoints())
{
if (point.getColour().equals(ChatColor.GREEN) && point.getOwner() != null && point.getOwner().equals(team))
if (point.getColour().equals(colour) && point.getOwner() != null && point.getOwner().equals(team))
{
i++;
}

View File

@ -1,9 +0,0 @@
package nautilus.game.arcade.game.games.cakewars.data;
public enum CakeTeamItemType
{
PASSIVE_UPGRADE,
TRAP
}

View File

@ -5,7 +5,7 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.team.CakeTeam;
public class CakeWarsEatCakeEvent extends PlayerEvent
{

View File

@ -1,10 +1,11 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.general;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -18,6 +19,7 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@ -34,17 +36,19 @@ import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
public class CakePlayerModule extends CakeModule
{
static final ItemStack RUNE_OF_HOLDING = new ItemBuilder(Material.SKULL_ITEM, (byte) 1)
public static final ItemStack RUNE_OF_HOLDING = new ItemBuilder(Material.SKULL_ITEM, (byte) 1)
.setTitle(C.cPurpleB + "Rune of Holding")
.addLore("", "Preserves your inventory on death", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
static final ItemStack DEPLOY_PLATFORM = new ItemBuilder(Material.INK_SACK)
public static final ItemStack DEPLOY_PLATFORM = new ItemBuilder(Material.INK_SACK)
.setTitle(C.cYellowB + "Deploy Platform")
.addLore("", "Creates a platform of wool next to", "any block you click!", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
@ -200,7 +204,7 @@ public class CakePlayerModule extends CakeModule
@EventHandler(priority = EventPriority.HIGH)
public void playerInteractPlatform(PlayerInteractEvent event)
{
if (event.isCancelled())
if (event.isCancelled() || !_game.IsLive())
{
return;
}
@ -244,6 +248,34 @@ public class CakePlayerModule extends CakeModule
}
}
@EventHandler(priority = EventPriority.HIGH)
public void itemPickup(PlayerPickupItemEvent event)
{
if (event.isCancelled() || _game.IsLive())
{
return;
}
Player player = event.getPlayer();
GameTeam team = _game.GetTeam(player);
if (team == null)
{
return;
}
ItemStack itemStack = event.getItem().getItemStack();
if (itemStack.getType() == Material.WOOL || itemStack.getType() == Material.STAINED_CLAY)
{
itemStack.getData().setData(team.GetColorData());
}
else if (itemStack.getType() == Material.INK_SACK)
{
itemStack.getData().setData(DyeColor.getByWoolData(team.GetColorData()).getDyeData());
}
}
@EventHandler
public void itemCraft(CraftItemEvent event)
{
@ -259,4 +291,10 @@ public class CakePlayerModule extends CakeModule
{
return _placedBlocks;
}
public boolean isUsingRuneOfHolding(Player player)
{
return _storedInventory.containsKey(player);
}
}

View File

@ -1,7 +1,9 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.general;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Location;
import org.bukkit.Sound;
@ -9,23 +11,72 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItem;
import nautilus.game.arcade.game.games.cakewars.shop.CakeResource;
import nautilus.game.arcade.game.games.cakewars.shop.CakeTeamItem;
public class CakeSpawnerModule extends CakeModule
{
private static final int MIN_BLOCK_PLACE_DIST_SQUARED = 4;
private final Map<GameTeam, Location> _spawnerLocation;
public CakeSpawnerModule(CakeWars game)
{
super(game);
_spawnerLocation = new HashMap<>(8);
}
@EventHandler
public void prepare(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
{
return;
}
_game.GetTeamList().forEach(team ->
{
Location location = _game.WorldData.GetCustomLocs("GEN " + (team.GetName().toUpperCase())).get(0);
_spawnerLocation.put(team, location);
});
}
@EventHandler
public void blockPlace(BlockPlaceEvent event)
{
if (event.isCancelled())
{
return;
}
Location block = event.getBlock().getLocation();
for (Location location : _spawnerLocation.values())
{
if (UtilMath.offsetSquared(block, location) < MIN_BLOCK_PLACE_DIST_SQUARED)
{
event.setCancelled(true);
event.getPlayer().sendMessage(F.main("Game", "You cannot play blocks that close to a generator."));
return;
}
}
}
@EventHandler
@ -58,7 +109,7 @@ public class CakeSpawnerModule extends CakeModule
ItemStack itemStack = resource.getItemStack().clone();
itemStack.setAmount(amount);
Location location = _game.WorldData.GetCustomLocs("GEN " + (team.GetName().toUpperCase())).get(0);
Location location = _spawnerLocation.get(team);
boolean drop = true;
List<Player> players = new ArrayList<>();
Item item = null;

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.island;
import java.util.List;

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.island;
import java.util.ArrayList;
import java.util.HashMap;
@ -33,8 +33,8 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeIsland;
public class CakeIslandModule extends CakeModule
{

View File

@ -0,0 +1,14 @@
package nautilus.game.arcade.game.games.cakewars.modes;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
public class CakeWars4 extends CakeWars
{
public CakeWars4(ArcadeManager manager)
{
super(manager, GameType.CakeWars4);
}
}

View File

@ -0,0 +1,14 @@
package nautilus.game.arcade.game.games.cakewars.modes;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
public class CakeWarsDuos extends CakeWars
{
public CakeWarsDuos(ArcadeManager manager)
{
super(manager, GameType.CakeWarsDuos);
}
}

View File

@ -1,10 +1,12 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.shop;
import org.bukkit.inventory.ItemStack;
public interface CakeItem
{
CakeShopItemType getItemType();
ItemStack getItemStack();
int getCost();

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.shop;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack;
import mineplex.core.updater.UpdateType;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.module.CakeSpawnerModule;
import nautilus.game.arcade.game.games.cakewars.general.CakeSpawnerModule;
public enum CakeResource
{
@ -38,7 +38,7 @@ public enum CakeResource
@Override
public void handleDistribution(CakeSpawnerModule module, GameTeam team)
{
module.distributeItem(this, module.getGame().getCakePointModule().ownsNetherPoint(team) ? 1 : 0, team);
module.distributeItem(this, module.getGame().getCakePointModule().ownedNetherStarPoints(team), team);
}
};

View File

@ -1,19 +1,27 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.shop;
import org.bukkit.inventory.ItemStack;
public class CakeShopItem implements CakeItem
{
private final CakeShopItemType _itemType;
private final ItemStack _itemStack;
private final int _cost;
public CakeShopItem(ItemStack itemStack, int cost)
public CakeShopItem(CakeShopItemType itemType, ItemStack itemStack, int cost)
{
_itemType = itemType;
_itemStack = itemStack;
_cost = cost;
}
@Override
public CakeShopItemType getItemType()
{
return _itemType;
}
@Override
public ItemStack getItemStack()
{

View File

@ -0,0 +1,69 @@
package nautilus.game.arcade.game.games.cakewars.shop;
import mineplex.core.common.util.UtilItem.ItemCategory;
public enum CakeShopItemType
{
// Weapons
SWORD(ItemCategory.SWORD, false, false, true),
// Tools
AXE(ItemCategory.AXE, false, false, true),
PICKAXE(ItemCategory.PICKAXE, false, false, true),
SHEARS(null, false, false, true),
// Armour
HELMET(false, false, true),
CHESTPLATE(false, false, true),
LEGGINGS(false, false, true),
BOOTS(false, false, true),
// Blocks
BLOCK(true, false, true),
// Special
TEAM_UPGRADE(false, false, false),
TRAP(false, true, false),
// Other
OTHER(true, false, true);
private final ItemCategory _removeOnPurchase;
private final boolean _multiBuy;
private final boolean _onePerTeam;
private final boolean _isItem;
CakeShopItemType(boolean multiBuy, boolean onePerTeam, boolean isItem)
{
this(null, multiBuy, onePerTeam, isItem);
}
CakeShopItemType(ItemCategory removeOnPurchase, boolean multiBuy, boolean onePerTeam, boolean isItem)
{
_removeOnPurchase = removeOnPurchase;
_multiBuy = multiBuy;
_onePerTeam = onePerTeam;
_isItem = isItem;
}
public ItemCategory getRemoveOnPurchase()
{
return _removeOnPurchase;
}
public boolean isMultiBuy()
{
return _multiBuy;
}
public boolean isOnePerTeam()
{
return _onePerTeam;
}
public boolean isItem()
{
return _isItem;
}
}

View File

@ -1,9 +1,11 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.shop;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.Material;
@ -11,7 +13,9 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
@ -30,11 +34,11 @@ import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeShopItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItemType;
import nautilus.game.arcade.game.games.cakewars.general.CakePlayerModule;
import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeBearTrap;
import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeTNTTrap;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourcePage;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourceShop;
import nautilus.game.arcade.game.games.cakewars.ui.CakeResourceStarPage;
@ -42,12 +46,14 @@ import nautilus.game.arcade.game.games.cakewars.ui.CakeResourceStarPage;
public class CakeShopModule extends CakeModule
{
private static final int MIN_BLOCK_PLACE_DIST_SQUARED = 49;
private static final int MIN_BLOCK_PLACE_DIST_SQUARED = 25;
private final NewNPCManager _manager;
private final Map<NPC, CakeResource> _npcs;
private final CakeResourceShop _shop;
private final Map<CakeResource, List<CakeItem>> _items;
private final Map<Player, Set<CakeItem>> _ownedItems;
private final Map<GameTeam, Set<CakeItem>> _ownedTeamItems;
public CakeShopModule(CakeWars game)
{
@ -57,97 +63,111 @@ public class CakeShopModule extends CakeModule
_npcs = new HashMap<>();
_shop = new CakeResourceShop(game.getArcadeManager());
_items = new HashMap<>(CakeResource.values().length);
_ownedItems = new HashMap<>();
_ownedTeamItems = new HashMap<>(8);
_items.put(CakeResource.BRICK, Arrays.asList(
// Iron Set
new CakeShopItem(new ItemBuilder(Material.IRON_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 5),
new CakeShopItem(new ItemBuilder(Material.IRON_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 7),
new CakeShopItem(new ItemBuilder(Material.IRON_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 7),
new CakeShopItem(new ItemBuilder(Material.IRON_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 5),
new CakeShopItem(CakeShopItemType.HELMET,
new ItemBuilder(Material.IRON_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 5),
new CakeShopItem(CakeShopItemType.CHESTPLATE,
new ItemBuilder(Material.IRON_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 7),
new CakeShopItem(CakeShopItemType.LEGGINGS,
new ItemBuilder(Material.IRON_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 7),
new CakeShopItem(CakeShopItemType.BOOTS,
new ItemBuilder(Material.IRON_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 5),
// Sword
new CakeShopItem(new ItemStack(Material.DIAMOND_SWORD), 5),
new CakeShopItem(CakeShopItemType.SWORD, new ItemStack(Material.DIAMOND_SWORD), 5),
// Pickaxe
new CakeShopItem(new ItemStack(Material.IRON_PICKAXE), 3),
new CakeShopItem(CakeShopItemType.PICKAXE, new ItemStack(Material.IRON_PICKAXE), 3),
// Axe
new CakeShopItem(new ItemStack(Material.IRON_AXE), 3),
new CakeShopItem(CakeShopItemType.AXE, new ItemStack(Material.IRON_AXE), 3),
// Arrow
new CakeShopItem(new ItemStack(Material.ARROW, 3), 6),
new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.ARROW, 3), 6),
// Blocks
// Wool
new CakeShopItem(new ItemStack(Material.WOOL, 16), 3),
new CakeShopItem(CakeShopItemType.BLOCK, new ItemStack(Material.WOOL, 16), 3),
// Coloured Clay
new CakeShopItem(new ItemStack(Material.STAINED_CLAY, 8), 12),
new CakeShopItem(CakeShopItemType.BLOCK, new ItemStack(Material.STAINED_CLAY, 8), 12),
// Wood
new CakeShopItem(new ItemStack(Material.WOOD, 8), 12),
new CakeShopItem(CakeShopItemType.BLOCK, new ItemStack(Material.WOOD, 8), 12),
// End Stone
new CakeShopItem(new ItemStack(Material.ENDER_STONE, 4), 16),
new CakeShopItem(CakeShopItemType.BLOCK, new ItemStack(Material.ENDER_STONE, 8), 16),
// Deploy Platform
new CakeShopItem(CakePlayerModule.DEPLOY_PLATFORM, 5),
new CakeShopItem(CakeShopItemType.OTHER, CakePlayerModule.DEPLOY_PLATFORM, 5),
// Emerald
new CakeShopItem(new ItemStack(Material.EMERALD), 20)
)
);
new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.EMERALD), 20)
));
_items.put(CakeResource.EMERALD, Arrays.asList(
// Diamond Set
new CakeShopItem(new ItemBuilder(Material.DIAMOND_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(new ItemBuilder(Material.DIAMOND_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
new CakeShopItem(CakeShopItemType.HELMET,
new ItemBuilder(Material.DIAMOND_HELMET)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
new CakeShopItem(CakeShopItemType.CHESTPLATE,
new ItemBuilder(Material.DIAMOND_CHESTPLATE)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(CakeShopItemType.LEGGINGS,
new ItemBuilder(Material.DIAMOND_LEGGINGS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 20),
new CakeShopItem(CakeShopItemType.BOOTS,
new ItemBuilder(Material.DIAMOND_BOOTS)
.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1)
.build(), 10),
// Sword
new CakeShopItem(new ItemBuilder(Material.DIAMOND_SWORD)
new CakeShopItem(CakeShopItemType.SWORD, new ItemBuilder(Material.DIAMOND_SWORD)
.addEnchantment(Enchantment.DAMAGE_ALL, 1)
.build(), 10),
// Pickaxe
new CakeShopItem(new ItemStack(Material.DIAMOND_PICKAXE), 10),
new CakeShopItem(CakeShopItemType.PICKAXE, new ItemStack(Material.DIAMOND_PICKAXE), 10),
// Axe
new CakeShopItem(new ItemStack(Material.DIAMOND_AXE), 10),
new CakeShopItem(CakeShopItemType.AXE, new ItemStack(Material.DIAMOND_AXE), 10),
// Obsidian
new CakeShopItem(new ItemStack(Material.OBSIDIAN), 5),
new CakeShopItem(CakeShopItemType.BLOCK, new ItemStack(Material.OBSIDIAN), 5),
// Shears
new CakeShopItem(new ItemStack(Material.SHEARS), 5),
new CakeShopItem(CakeShopItemType.SHEARS, new ItemStack(Material.SHEARS), 5),
// Golden Apple
new CakeShopItem(new ItemStack(Material.GOLDEN_APPLE), 5),
new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.GOLDEN_APPLE), 5),
// Ender pearl
new CakeShopItem(new ItemStack(Material.ENDER_PEARL), 5),
new CakeShopItem(CakeShopItemType.OTHER, new ItemStack(Material.ENDER_PEARL), 5),
// Rune of Holding
new CakeShopItem(CakePlayerModule.RUNE_OF_HOLDING, 20)
new CakeShopItem(CakeShopItemType.OTHER, CakePlayerModule.RUNE_OF_HOLDING, 20),
// Traps
new CakeTNTTrap(12),
new CakeBearTrap(12)
));
}
@ -160,7 +180,7 @@ public class CakeShopModule extends CakeModule
_items.clear();
}
@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void prepare(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Prepare)
@ -170,25 +190,24 @@ public class CakeShopModule extends CakeModule
_game.CreatureAllowOverride = true;
for (GameTeam team : _game.GetTeamList())
_game.getCakeTeamModule().getCakeTeams().forEach((team, cakeTeam) ->
{
if (!team.IsTeamAlive())
{
continue;
}
String teamName = team.GetName().toUpperCase();
for (CakeResource resource : CakeResource.values())
{
Location location = _game.WorldData.GetCustomLocs("SHOP " + teamName + " " + resource.name()).get(0);
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory2d(location, _game.GetSpectatorLocation())));
location.setYaw(UtilAlg.GetYaw(UtilAlg.getTrajectory2d(location, cakeTeam.getCake())));
NPC npc = new NPC(-1, EntityType.VILLAGER, resource.getChatColor() + C.Bold + resource.getName() + " Shop", location, null, (byte) 0, null, null, null, null, "CAKE_NPC");
_manager.addNPC(npc, false);
_npcs.put(npc, resource);
}
}
team.GetPlayers(false).forEach(player -> _ownedItems.put(player, new HashSet<>()));
_ownedTeamItems.put(team, new HashSet<>());
});
_game.CreatureAllowOverride = false;
}
@ -264,7 +283,7 @@ public class CakeShopModule extends CakeModule
cakeTeam.getUpgrades().forEach((item, level) ->
{
if (level > 0 && item.getType() == CakeTeamItemType.PASSIVE_UPGRADE)
if (level > 0)
{
alive.forEach(player -> item.apply(player, level, cakeTeam.getCake()));
}
@ -272,6 +291,38 @@ public class CakeShopModule extends CakeModule
});
}
@EventHandler
public void playerDeath(PlayerDeathEvent event)
{
Player player = event.getEntity();
Set<CakeItem> items = _ownedItems.get(player);
if (items != null && !_game.getCakePlayerModule().isUsingRuneOfHolding(player))
{
items.removeIf(item -> !item.getItemType().isOnePerTeam());
}
}
public boolean ownsItem(Player player, CakeItem item)
{
return _ownedItems.get(player).contains(item);
}
public boolean ownsItem(GameTeam team, CakeItem item)
{
return _ownedTeamItems.get(team).contains(item);
}
public Set<CakeItem> getOwnedItems(Player player)
{
return _ownedItems.get(player);
}
public Set<CakeItem> getOwnedItems(GameTeam team)
{
return _ownedTeamItems.get(team);
}
public boolean isNearShop(Location location)
{
for (NPC npc : _npcs.keySet())

View File

@ -1,22 +1,15 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.shop;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.itemstack.ItemBuilder;
public enum CakeTeamItem implements CakeItem
@ -24,7 +17,6 @@ public enum CakeTeamItem implements CakeItem
PROTECTION(
"Protection",
CakeTeamItemType.PASSIVE_UPGRADE,
new ItemStack(Material.DIAMOND_CHESTPLATE),
4,
10
@ -44,7 +36,6 @@ public enum CakeTeamItem implements CakeItem
},
HASTE(
"Haste",
CakeTeamItemType.PASSIVE_UPGRADE,
new ItemStack(Material.GOLD_PICKAXE),
4,
10
@ -59,7 +50,6 @@ public enum CakeTeamItem implements CakeItem
},
SHARPNESS(
"Sharpness",
CakeTeamItemType.PASSIVE_UPGRADE,
new ItemStack(Material.DIAMOND_SWORD),
4,
10
@ -79,14 +69,12 @@ public enum CakeTeamItem implements CakeItem
},
RESOURCE(
"Resource Generator",
CakeTeamItemType.PASSIVE_UPGRADE,
new ItemStack(Material.NETHER_STAR),
4,
10
),
REGENERATION(
"Healing Station",
CakeTeamItemType.PASSIVE_UPGRADE,
new ItemStack(Material.GOLDEN_APPLE),
4,
10
@ -102,54 +90,15 @@ public enum CakeTeamItem implements CakeItem
}
}
},
TRAP_BEAR(
"Bear Trap",
CakeTeamItemType.TRAP,
new ItemStack(Material.TRIPWIRE_HOOK),
3
)
{
@Override
public void apply(Player player, int level, Location cake)
{
player.getWorld().playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 2, 1);
UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation().add(0, 1.5, 0), 0.25F, 0.25F, 0.25F, 0.5F, 30, ViewDist.NORMAL);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 80, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 80, 0, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 80, 0, false, false));
}
},
TRAP_TNT(
"TNT Trap",
CakeTeamItemType.TRAP,
new ItemStack(Material.TNT),
3
)
{
@Override
public void apply(Player player, int level, Location cake)
{
player.getWorld().playSound(player.getLocation(), Sound.EXPLODE, 2, 0.6F);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, player.getLocation().add(0, 1.5, 0), 0, 0, 0, 1, 1, ViewDist.NORMAL);
Vector direction = UtilAlg.getTrajectory2d(cake, player.getLocation());
direction.multiply(1.5);
direction.setY(1.3 + (Math.random() / 2D));
UtilAction.velocity(player, direction);
}
}
;
private final String _name;
private final CakeTeamItemType _type;
private final ItemStack _itemStack;
private final int[] _costs;
CakeTeamItem(String name, CakeTeamItemType type, ItemStack itemStack, int... costs)
CakeTeamItem(String name, ItemStack itemStack, int... costs)
{
_name = name;
_type = type;
_itemStack = new ItemBuilder(itemStack)
.setTitle(name)
.setGlow(true)
@ -161,16 +110,17 @@ public enum CakeTeamItem implements CakeItem
{
}
@Override
public CakeShopItemType getItemType()
{
return CakeShopItemType.TEAM_UPGRADE;
}
public String getName()
{
return _name;
}
public CakeTeamItemType getType()
{
return _type;
}
@Override
public ItemStack getItemStack()
{
@ -185,6 +135,6 @@ public enum CakeTeamItem implements CakeItem
@Override
public int getCost()
{
return _costs[0];
return 0;
}
}

View File

@ -0,0 +1,32 @@
package nautilus.game.arcade.game.games.cakewars.shop.trap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
public class CakeBearTrap extends CakeTrapItem
{
public CakeBearTrap(int cost)
{
super(new ItemStack(Material.TRIPWIRE_HOOK), cost, "Bear Trap");
}
@Override
public void onCakeInteract(Player player, Location cake)
{
player.getWorld().playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 2, 1);
UtilParticle.PlayParticleToAll(ParticleType.WITCH_MAGIC, player.getLocation().add(0, 1.5, 0), 0.25F, 0.25F, 0.25F, 0.5F, 30, ViewDist.NORMAL);
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 80, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 80, 0, false, false));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 80, 0, false, false));
}
}

View File

@ -0,0 +1,36 @@
package nautilus.game.arcade.game.games.cakewars.shop.trap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
public class CakeTNTTrap extends CakeTrapItem
{
public CakeTNTTrap(int cost)
{
super(new ItemStack(Material.TNT), cost, "TNT Trap");
}
@Override
public void onCakeInteract(Player player, Location cake)
{
player.getWorld().playSound(player.getLocation(), Sound.EXPLODE, 2, 0.6F);
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, player.getLocation().add(0, 1.5, 0), 0, 0, 0, 1, 1, ViewDist.NORMAL);
Vector direction = UtilAlg.getTrajectory2d(cake, player.getLocation());
direction.multiply(1.5);
direction.setY(1.3 + (Math.random() / 2D));
UtilAction.velocity(player, direction);
}
}

View File

@ -0,0 +1,33 @@
package nautilus.game.arcade.game.games.cakewars.shop.trap;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.itemstack.ItemBuilder;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopItem;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopItemType;
public abstract class CakeTrapItem extends CakeShopItem
{
private final String _name;
CakeTrapItem(ItemStack itemStack, int cost, String name)
{
super(CakeShopItemType.TRAP, new ItemBuilder(itemStack)
.setTitle(C.mItem + name)
.build(), cost);
_name = name;
}
public abstract void onCakeInteract(Player player, Location cake);
public String getName()
{
return _name;
}
}

View File

@ -1,4 +1,4 @@
package nautilus.game.arcade.game.games.cakewars.data;
package nautilus.game.arcade.game.games.cakewars.team;
import java.util.ArrayList;
import java.util.HashMap;
@ -16,6 +16,7 @@ import mineplex.core.hologram.HologramManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.shop.CakeTeamItem;
public class CakeTeam
{
@ -71,10 +72,10 @@ public class CakeTeam
.addPlayers(teamPlayers)
.start());
new Hologram(hologramManager, _shop, SHOP_HOLOGRAM_TEXT)
_holograms.add(new Hologram(hologramManager, _shop, SHOP_HOLOGRAM_TEXT)
.setHologramTarget(HologramTarget.WHITELIST)
.addPlayers(teamPlayers)
.start();
.start());
_cakeHologram = new Hologram(hologramManager, _cake.clone().add(0.5, 1.3, 0.5), CAKE_HOLOGRAM_TEXT)
.setHologramTarget(HologramTarget.WHITELIST)

View File

@ -1,8 +1,10 @@
package nautilus.game.arcade.game.games.cakewars.module;
package nautilus.game.arcade.game.games.cakewars.team;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.bukkit.Location;
@ -41,11 +43,12 @@ import nautilus.game.arcade.events.PlayerDeathOutEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeModule;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItemType;
import nautilus.game.arcade.game.games.cakewars.event.CakeWarsEatCakeEvent;
import nautilus.game.arcade.game.games.cakewars.shop.CakeItem;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopModule;
import nautilus.game.arcade.game.games.cakewars.shop.trap.CakeTrapItem;
import nautilus.game.arcade.world.WorldData;
public class CakeTeamModule extends CakeModule
@ -211,21 +214,40 @@ public class CakeTeamModule extends CakeModule
return;
}
cakeTeam.getUpgrades().entrySet().forEach(entry ->
{
CakeTeamItem item = entry.getKey();
CakeShopModule module = _game.getCakeShopModule();
if (item.getType() != CakeTeamItemType.TRAP || entry.getValue() == 0 || !Recharge.Instance.use(player, "Trap", 10000, false, false))
module.getOwnedItems(team).removeIf(item ->
{
if (!(item instanceof CakeTrapItem) || !Recharge.Instance.use(player, "Trap", 10000, false, false))
{
return;
return false;
}
_game.getArcadeManager().GetDamage().NewDamageEvent(player, null, null, DamageCause.CUSTOM, 2, false, true, false, "Trap", item.getName());
item.apply(player, entry.getValue(), cakeTeam.getCake());
Player damager = null;
for (Player teamMember : team.GetPlayers(true))
{
Set<CakeItem> items = module.getOwnedItems(teamMember);
Iterator<CakeItem> iterator = items.iterator();
while (iterator.hasNext())
{
if (iterator.next().equals(item))
{
damager = teamMember;
iterator.remove();
}
}
}
CakeTrapItem trapItem = (CakeTrapItem) item;
_game.getArcadeManager().GetDamage().NewDamageEvent(player, damager, null, DamageCause.CUSTOM, 2, false, true, false, "Trap", trapItem.getName());
trapItem.onCakeInteract(player, cakeTeam.getCake());
UtilTextMiddle.display(team.GetColor() + "TRAP SET OFF", "One of your traps as been set off!", 5, 20, 5, team.GetPlayers(true).toArray(new Player[0]));
UtilTextMiddle.display("", C.cRedB + "TRAPPED", 5, 20, 5, player);
entry.setValue(0);
return true;
});
_game.AddGems(player, 4, "Cake Bites", true, true);

View File

@ -1,7 +1,9 @@
package nautilus.game.arcade.game.games.cakewars.ui;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -13,7 +15,6 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilItem.ItemCategory;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.recharge.Recharge;
@ -23,8 +24,10 @@ import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.games.cakewars.CakeWars;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.shop.CakeItem;
import nautilus.game.arcade.game.games.cakewars.shop.CakeResource;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopItemType;
import nautilus.game.arcade.game.games.cakewars.shop.CakeShopModule;
public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceShop>
{
@ -32,12 +35,6 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
private static final ItemStack CLOSE_ITEM = new ItemBuilder(Material.BARRIER)
.setTitle(C.cRedB + "Close")
.build();
private static final ItemCategory[] REMOVE_ON_BUY =
{
ItemCategory.SWORD,
ItemCategory.PICKAXE,
ItemCategory.AXE
};
final CakeWars _game;
final CakeResource _resource;
@ -63,7 +60,9 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
for (CakeItem item : _items)
{
addButton(slot, prepareItem(item), new CakeShopButton(item));
CakeShopResult result = getResultPurchase(item);
addButton(slot, prepareItem(item, result), new CakeShopButton(item, result));
if (++slot % 9 == 8)
{
@ -77,10 +76,31 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
addButton(4, CLOSE_ITEM, (player, clickType) -> player.closeInventory());
}
ItemStack prepareItem(CakeItem item)
CakeShopResult getResultPurchase(CakeItem item)
{
CakeShopModule module = _game.getCakeShopModule();
CakeShopItemType itemType = item.getItemType();
ItemStack itemStack = _resource.getItemStack();
if (!itemType.isMultiBuy() && module.ownsItem(_player, item))
{
return CakeShopResult.ALREADY_OWNED;
}
else if (itemType.isOnePerTeam() && module.ownsItem(_team, item))
{
return CakeShopResult.ONLY_ONE;
}
else if (!UtilInv.contains(_player, itemStack.getType(), itemStack.getData().getData(), item.getCost()))
{
return CakeShopResult.NOT_ENOUGH_RESOURCES;
}
return CakeShopResult.SUCCESSFUL;
}
ItemStack prepareItem(CakeItem item, CakeShopResult result)
{
ItemBuilder builder = new ItemBuilder(item.getItemStack());
boolean canPurchase = canPurchase(_player, item);
handleTeamColours(builder);
@ -89,7 +109,7 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
"",
"Cost: " + _resource.getChatColor() + item.getCost() + " " + _resource.getName() + "s",
"",
canPurchase ? C.cGreen + "Click to purchase!" : C.cRed + "You do not have enough resources!"
result.getColour() + result.getFeedback()
);
return builder.build();
@ -109,13 +129,6 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
}
}
private boolean canPurchase(Player player, CakeItem item)
{
ItemStack resource = _resource.getItemStack();
return UtilInv.contains(player, resource.getType(), resource.getData().getData(), item.getCost());
}
private String getItemName(ItemStack itemStack)
{
if (itemStack.getType() == Material.STAINED_CLAY)
@ -130,14 +143,45 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
return ItemStackFactory.Instance.GetName(itemStack, true);
}
protected enum CakeShopResult
{
SUCCESSFUL(ChatColor.GREEN, "Click to purchase!"),
NOT_ENOUGH_RESOURCES(ChatColor.RED, "You do not have enough resources!"),
ALREADY_OWNED(ChatColor.RED, "You already have purchased this item."),
ONLY_ONE(ChatColor.RED, "Your team already owns this upgrade."),
MAX_TIER(ChatColor.RED, "Your team has already unlocked the maximum tier.");
private final ChatColor _colour;
private final String _feedback;
CakeShopResult(ChatColor colour, String feedback)
{
_colour = colour;
_feedback = feedback;
}
public ChatColor getColour()
{
return _colour;
}
public String getFeedback()
{
return _feedback;
}
}
private class CakeShopButton implements IButton
{
private final CakeItem _item;
private final CakeShopResult _result;
CakeShopButton(CakeItem item)
CakeShopButton(CakeItem item, CakeShopResult result)
{
_item = item;
_result = result;
}
@Override
@ -147,7 +191,14 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
{
return;
}
else if (_result != CakeShopResult.SUCCESSFUL)
{
player.sendMessage(F.main("Game", _result.getFeedback()));
playDenySound(player);
return;
}
CakeShopItemType itemType = _item.getItemType();
ItemStack resource = _resource.getItemStack();
ItemBuilder give = new ItemBuilder(_item.getItemStack());
Material material = give.getType();
@ -157,64 +208,62 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
give.setUnbreakable(true);
}
if (UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCost()))
UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCost());
handleTeamColours(give);
ItemStack giveItem = give.build();
PlayerInventory inventory = player.getInventory();
if (itemType.getRemoveOnPurchase() != null)
{
handleTeamColours(give);
ItemStack giveItem = give.build();
if (UtilItem.isHelmet(giveItem))
for (int i = 0; i < inventory.getSize(); i++)
{
player.getInventory().setHelmet(giveItem);
}
else if (UtilItem.isChestplate(giveItem))
{
player.getInventory().setChestplate(giveItem);
}
else if (UtilItem.isLeggings(giveItem))
{
player.getInventory().setLeggings(giveItem);
}
else if (UtilItem.isBoots(giveItem))
{
player.getInventory().setBoots(giveItem);
}
else
{
for (ItemCategory category : REMOVE_ON_BUY)
if (UtilItem.is(inventory.getItem(i), itemType.getRemoveOnPurchase()))
{
if (UtilItem.is(giveItem, category))
{
removeCategory(player, category);
break;
}
inventory.setItem(i, null);
}
UtilInv.insert(player, giveItem);
}
player.sendMessage(F.main("Game", "You purchased " + F.name(getItemName(giveItem))) + ".");
playAcceptSound(player);
refresh();
}
else
switch (itemType)
{
player.sendMessage(F.main("Game", "You do not have enough " + F.name(_resource.getName() + "s") + " to purchase this item."));
playDenySound(player);
case HELMET:
inventory.setHelmet(giveItem);
break;
case CHESTPLATE:
inventory.setChestplate(giveItem);
break;
case LEGGINGS:
inventory.setLeggings(giveItem);
break;
case BOOTS:
inventory.setBoots(giveItem);
break;
default:
if (itemType.isItem())
{
UtilInv.insert(player, giveItem);
}
break;
}
}
}
private void removeCategory(Player player, ItemCategory category)
{
PlayerInventory inventory = player.getInventory();
Set<CakeItem> ownedItems = _game.getCakeShopModule().getOwnedItems(player);
for (int i = 0; i < inventory.getSize(); i++)
{
if (UtilItem.is(inventory.getItem(i), category))
if (!itemType.isMultiBuy())
{
inventory.setItem(i, null);
ownedItems.removeIf(item -> item.getItemType().equals(itemType));
}
if (itemType.isOnePerTeam())
{
_game.getCakeShopModule().getOwnedItems(_team).add(_item);
}
ownedItems.add(_item);
player.sendMessage(F.main("Game", "You purchased " + F.name(getItemName(giveItem))) + ".");
playAcceptSound(player);
refresh();
}
}
}

View File

@ -17,11 +17,10 @@ import mineplex.core.recharge.Recharge;
import mineplex.core.shop.item.IButton;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.games.cakewars.data.CakeItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeResource;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeam;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItem;
import nautilus.game.arcade.game.games.cakewars.data.CakeTeamItemType;
import nautilus.game.arcade.game.games.cakewars.shop.CakeItem;
import nautilus.game.arcade.game.games.cakewars.shop.CakeResource;
import nautilus.game.arcade.game.games.cakewars.shop.CakeTeamItem;
import nautilus.game.arcade.game.games.cakewars.team.CakeTeam;
public class CakeResourceStarPage extends CakeResourcePage
{
@ -44,21 +43,47 @@ public class CakeResourceStarPage extends CakeResourcePage
for (CakeItem item : _items)
{
addButton(slot++, prepareItem(item), new CakeTeamItemButton((CakeTeamItem) item));
CakeTeamItem teamItem = (CakeTeamItem) item;
CakeShopResult result = getResultPurchase(teamItem);
addButton(slot, prepareItem(item, result), new CakeTeamItemButton(teamItem, result));
if (++slot % 9 == 8)
{
slot += 2;
}
}
}
@Override
ItemStack prepareItem(CakeItem item)
CakeShopResult getResultPurchase(CakeItem item)
{
CakeTeamItem teamItem = (CakeTeamItem) item;
int level = _cakeTeam.getUpgrades().get(item);
ItemStack itemStack = _resource.getItemStack();
if (level == teamItem.getCosts().length)
{
return CakeShopResult.MAX_TIER;
}
else if (!UtilInv.contains(_player, itemStack.getType(), itemStack.getData().getData(), teamItem.getCosts()[level]))
{
return CakeShopResult.NOT_ENOUGH_RESOURCES;
}
return CakeShopResult.SUCCESSFUL;
}
@Override
ItemStack prepareItem(CakeItem item, CakeShopResult result)
{
CakeTeamItem teamItem = (CakeTeamItem) item;
ItemBuilder builder = new ItemBuilder(item.getItemStack());
int level = _cakeTeam.getUpgrades().get(item);
boolean canPurchase = canPurchase(_player, teamItem, level);
boolean maxTier = teamItem.getCosts().length == level;
String name = C.mItem + teamItem.getName();
boolean maxTier = result == CakeShopResult.MAX_TIER;
if (teamItem.getType() == CakeTeamItemType.PASSIVE_UPGRADE && !maxTier)
if (!maxTier)
{
name += " " + UtilText.toRomanNumeral(level + 1);
}
@ -67,16 +92,7 @@ public class CakeResourceStarPage extends CakeResourcePage
if (maxTier)
{
builder.addLore("");
if (teamItem.getType() != CakeTeamItemType.PASSIVE_UPGRADE)
{
builder.addLore(C.cRed + "You have already purchased this", C.cRed + "consumable upgrade.");
}
else
{
builder.addLore(C.cRed + "You have already purchased the maximum", C.cRed + "tier for this upgrade.");
}
builder.addLore("", C.cRed + result.getColour() + result.getFeedback());
}
else
{
@ -84,7 +100,7 @@ public class CakeResourceStarPage extends CakeResourcePage
"",
"Cost: " + _resource.getChatColor() + teamItem.getCosts()[level] + " " + _resource.getName() + "s",
"",
canPurchase ? C.cGreen + "Click to purchase!" : C.cRed + "You do not have enough resources!"
result.getColour() + result.getFeedback()
);
}
@ -92,26 +108,18 @@ public class CakeResourceStarPage extends CakeResourcePage
return builder.build();
}
private boolean canPurchase(Player player, CakeTeamItem item, int level)
{
if (item.getCosts().length <= level)
{
return false;
}
ItemStack resource = _resource.getItemStack();
return UtilInv.contains(player, resource.getType(), resource.getData().getData(), item.getCosts()[level]);
}
private class CakeTeamItemButton implements IButton
{
private final CakeTeamItem _item;
private final CakeShopResult _result;
private final int _level;
CakeTeamItemButton(CakeTeamItem item)
CakeTeamItemButton(CakeTeamItem item, CakeShopResult result)
{
_item = item;
_result = result;
_level = _cakeTeam.getUpgrades().get(item);
}
@Override
@ -121,77 +129,52 @@ public class CakeResourceStarPage extends CakeResourcePage
{
return;
}
int level = _cakeTeam.getUpgrades().get(_item);
ItemStack resource = _resource.getItemStack();
if (_item.getCosts().length == level)
else if (_result != CakeShopResult.SUCCESSFUL)
{
if (_item.getType() != CakeTeamItemType.PASSIVE_UPGRADE)
{
player.sendMessage(F.main("Game", "You already have purchased this consumable upgrade."));
}
else
{
player.sendMessage(F.main("Game", "You have already purchased the maximum tier for this upgrade."));
}
player.sendMessage(F.main("Game", _result.getFeedback()));
playDenySound(player);
return;
}
if (UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCosts()[level]))
ItemStack resource = _resource.getItemStack();
UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCosts()[_level]);
int newLevel = _level + 1;
String name = F.name(_item.getName() + " " + UtilText.toRomanNumeral(newLevel));
String message = F.main("Game", F.color(_player.getName(), _team.GetColor().toString()) + " purchased the " + name + " team upgrade.");
for (Player other : _team.GetPlayers(false))
{
String name;
int newLevel = level + 1;
other.playSound(other.getLocation(), Sound.NOTE_PLING, 1, 0.6F);
other.sendMessage(message);
}
if (_item.getType() != CakeTeamItemType.PASSIVE_UPGRADE)
_cakeTeam.getUpgrades().put(_item, newLevel);
boolean ownsAll = true;
for (Entry<CakeTeamItem, Integer> entry : _cakeTeam.getUpgrades().entrySet())
{
if (entry.getValue() != entry.getKey().getCosts().length)
{
name = F.name(_item.getName());
ownsAll = false;
break;
}
else
}
if (ownsAll)
{
_team.GetPlayers(false).forEach(other ->
{
name = F.name(_item.getName() + " " + UtilText.toRomanNumeral(newLevel));
}
String message = F.main("Game", F.color(_player.getName(), _team.GetColor().toString()) + " purchased the " + name + " team upgrade.");
for (Player other : _team.GetPlayers(false))
{
other.playSound(other.getLocation(), Sound.NOTE_PLING, 1, 0.6F);
other.sendMessage(message);
}
_cakeTeam.getUpgrades().put(_item, newLevel);
boolean ownsAll = true;
for (Entry<CakeTeamItem, Integer> entry : _cakeTeam.getUpgrades().entrySet())
{
if (entry.getValue() != entry.getKey().getCosts().length && entry.getKey().getType() == CakeTeamItemType.PASSIVE_UPGRADE)
if (other.isOnline())
{
ownsAll = false;
break;
_game.AddStat(player, "BuyAll", 1, true, false);
}
}
if (ownsAll)
{
_team.GetPlayers(false).forEach(other ->
{
if (other.isOnline())
{
_game.AddStat(player, "BuyAll", 1, true, false);
}
});
}
playAcceptSound(player);
refresh();
}
else
{
player.sendMessage(F.main("Game", "You do not have enough " + F.name(_resource.getName() + "s") + " to purchase this upgrade."));
playDenySound(player);
});
}
playAcceptSound(player);
refresh();
}
}
}