From 34f718b2ec6d0ef262892f3477ff45c29a273960 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 16 Jul 2016 06:27:16 -0500 Subject: [PATCH] Fix improper gem/shard reward handling --- .../nautilus/game/arcade/ArcadeManager.java | 10 ++- ...GemManager.java => GameRewardManager.java} | 66 +++++++++++-------- 2 files changed, 42 insertions(+), 34 deletions(-) rename Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/{GameGemManager.java => GameRewardManager.java} (88%) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java index c47833359..7bffad2da 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ArcadeManager.java @@ -73,7 +73,6 @@ import nautilus.game.arcade.command.GameCommand; import nautilus.game.arcade.command.KitUnlockCommand; import nautilus.game.arcade.command.RequiredRankCommand; import nautilus.game.arcade.command.WriteCommand; -import nautilus.game.arcade.command.*; import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.game.Game; import nautilus.game.arcade.game.Game.GameState; @@ -91,7 +90,6 @@ import org.bukkit.*; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.block.Chest; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Entity; @@ -147,7 +145,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation // Managers private GameCreationManager _gameCreationManager; - private GameGemManager _gameGemManager; + private GameRewardManager _gameRewardManager; private GameManager _gameManager; private GameLobbyManager _gameLobbyManager; private GamePlayerManager _gamePlayerManager; @@ -279,7 +277,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation // Managers _gameChatManager = new GameChatManager(this); _gameCreationManager = new GameCreationManager(this); - _gameGemManager = new GameGemManager(this); + _gameRewardManager = new GameRewardManager(this); _gameManager = new GameManager(this); _gameLobbyManager = new GameLobbyManager(this, packetHandler); _gameHostManager = new GameHostManager(this); @@ -510,9 +508,9 @@ public class ArcadeManager extends MiniPlugin implements IRelation return _gameManager; } - public GameGemManager GetGameGemManager() + public GameRewardManager GetGameGemManager() { - return _gameGemManager; + return _gameRewardManager; } public GamePlayerManager GetGamePlayerManager() diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java similarity index 88% rename from Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java rename to Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java index 23ede3d63..c39b46247 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java @@ -3,6 +3,7 @@ package nautilus.game.arcade.managers; import java.lang.reflect.Field; import java.util.HashMap; +import org.bukkit.Bukkit; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -37,14 +38,17 @@ import nautilus.game.arcade.game.GameTeam.PlayerState; import nautilus.game.arcade.game.GemData; import net.minecraft.server.v1_8_R3.EntityHuman; -public class GameGemManager implements Listener +/** + * This class is used to reward gems and shards at the end of a game, or when players leave the server. + */ +public class GameRewardManager implements Listener { ArcadeManager Manager; boolean DoubleGem = false; boolean TimeReward = true; - public GameGemManager(ArcadeManager manager) + public GameRewardManager(ArcadeManager manager) { Manager = manager; @@ -159,18 +163,23 @@ public class GameGemManager implements Listener if (gems == null) return; - int earned = 0; + final int baseGemsEarned; + int gemsToReward; - for (GemData data : gems.values()) - earned += (int)data.Gems; + // Calculate the base gems earned in this game + { + int gemsEarned = 0; - if (earned <= 0) - earned = 1; + for (GemData data : gems.values()) + gemsEarned += (int) data.Gems; - earned = (int) (earned * gameMult); + if (gemsEarned <= 0) + gemsEarned = 1; + + baseGemsEarned = (int) (gemsEarned * gameMult); + gemsToReward = baseGemsEarned; + } - int total = earned; - String oldName = player.getName(); if(Manager.GetClients().Get(player).getDisguisedAs() != null) @@ -179,27 +188,28 @@ public class GameGemManager implements Listener System.out.println("Gems for " + Manager.GetClients().Get(player).GetPlayerName()); } - final int baseShards = total; - int shards = baseShards; + // Award players shards equal to base gems, plus booster bonuses. + final int baseShardsEarned = baseGemsEarned; + int shardsToReward = baseShardsEarned; - //Gem Boooster + // Gem Boooster Booster booster = Manager.getBoosterManager().getActiveBooster(); if (game.GemBoosterEnabled && booster != null) { - shards += baseShards * booster.getMultiplier(); + shardsToReward *= booster.getMultiplier(); } - //Gem Finder + // Gem Finder if (game.GemHunterEnabled) { int gemFinder = Manager.GetAchievement().get(player.getName(), Achievement.GLOBAL_GEM_HUNTER).getLevel(); if (gemFinder > 0) { - total += (int)(earned * (gemFinder * 0.25)); + gemsToReward += (int)(baseGemsEarned * (gemFinder * 0.25)); } } - //Time Reward + // Time Reward if (TimeReward) { long timeOnline = Utility.currentTimeMillis() - Manager.GetClients().Get(player).getNetworkSessionLoginTime(); @@ -211,34 +221,34 @@ public class GameGemManager implements Listener if (hoursOnline > 5) hoursOnline = 5; - total += (int)(earned * (hoursOnline * 0.2)); + gemsToReward += (int)(baseGemsEarned * (hoursOnline * 0.2)); } } if (DoubleGem && game.GemDoubleEnabled) - total += earned; + gemsToReward += baseGemsEarned; Rank rank = Manager.GetClients().Get(player).GetRank(); int accountId = Manager.GetClients().getAccountId(player); if (rank == rank.ULTRA) - shards += baseShards * 0.5; + shardsToReward += baseShardsEarned * 0.5; else if (rank == rank.HERO) - shards += baseShards * 1; + shardsToReward += baseShardsEarned * 1; else if (rank == rank.LEGEND) - shards += baseShards * 1.5; + shardsToReward += baseShardsEarned * 1.5; else if (rank.has(Rank.TITAN)) - shards += baseShards * 2; + shardsToReward += baseShardsEarned * 2; - Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), player.getUniqueId(), total); + Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), player.getUniqueId(), gemsToReward); if (accountId != -1) { - Manager.GetDonation().rewardCoinsUntilSuccess(null, "Earned", player.getName(), accountId, shards); + Manager.GetDonation().rewardCoinsUntilSuccess(null, "Earned", player.getName(), accountId, shardsToReward); } //Stats - Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total); - Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", total); + Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", gemsToReward); + Manager.GetStatsManager().incrementStat(player, game.GetName()+".GemsEarned", gemsToReward); if(Manager.GetClients().Get(player).getDisguisedAs() != null) { @@ -359,7 +369,7 @@ public class GameGemManager implements Listener totalGems += earnedGems; } - final int baseShards = totalGems; + final int baseShards = earnedGems; int shards = baseShards; double extraMult = 0;