Fix GameSummary showing an incorrect amout of shards

This commit is contained in:
Sam 2018-01-22 14:05:28 +00:00 committed by Alexander Meech
parent 248c109627
commit d267c15845
4 changed files with 51 additions and 34 deletions

View File

@ -791,6 +791,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _gameCreationManager; return _gameCreationManager;
} }
public GameRewardManager getGameRewardManager()
{
return _gameRewardManager;
}
public GameHostManager GetGameHostManager() public GameHostManager GetGameHostManager()
{ {
return _gameHostManager; return _gameHostManager;

View File

@ -2,23 +2,20 @@ package nautilus.game.arcade.game.modules.gamesummary;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import mineplex.core.common.jsonchat.HoverEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import com.google.common.util.concurrent.AtomicDouble;
import mineplex.core.achievement.Achievement; import mineplex.core.achievement.Achievement;
import mineplex.core.achievement.AchievementData; import mineplex.core.achievement.AchievementData;
import mineplex.core.achievement.AchievementLog; import mineplex.core.achievement.AchievementLog;
import mineplex.core.achievement.AchievementManager; import mineplex.core.achievement.AchievementManager;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
import mineplex.core.common.currency.GlobalCurrency; import mineplex.core.common.currency.GlobalCurrency;
import mineplex.core.common.jsonchat.HoverEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilServer;
@ -26,7 +23,6 @@ import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent; import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GemData;
import nautilus.game.arcade.game.modules.Module; import nautilus.game.arcade.game.modules.Module;
import nautilus.game.arcade.game.modules.gamesummary.components.AchievementSummaryComponent; import nautilus.game.arcade.game.modules.gamesummary.components.AchievementSummaryComponent;
import nautilus.game.arcade.game.modules.gamesummary.components.ExperienceSummaryComponent; import nautilus.game.arcade.game.modules.gamesummary.components.ExperienceSummaryComponent;
@ -89,15 +85,7 @@ public class GameSummaryModule extends Module
}; };
addComponent(new GemSummaryComponent(player -> getGame().GetGems(player), GlobalCurrency.GEM.getColor(), GlobalCurrency.GEM.getPrefix())); addComponent(new GemSummaryComponent(player -> getGame().GetGems(player), GlobalCurrency.GEM.getColor(), GlobalCurrency.GEM.getPrefix()));
addComponent(new ShardSummaryComponent(getGame().getArcadeManager(), player -> addComponent(new ShardSummaryComponent(getGame().getArcadeManager(), player -> Pair.create(player, getGame().getArcadeManager().getGameRewardManager().getBaseShardsEarned(player))));
{
AtomicDouble total = new AtomicDouble();
Map<String, GemData> gems = getGame().GetGems(player);
gems.values().forEach(gemData -> total.getAndAdd(gemData.Gems));
return Pair.create(player, (int) total.get());
}));
addComponent(new ExperienceSummaryComponent(experienceFunction)); addComponent(new ExperienceSummaryComponent(experienceFunction));
addComponent(new LevelUpSummaryComponent(experienceFunction)); addComponent(new LevelUpSummaryComponent(experienceFunction));
addComponent(new AchievementSummaryComponent(getGame().getArcadeManager())); addComponent(new AchievementSummaryComponent(getGame().getArcadeManager()));
@ -114,7 +102,7 @@ public class GameSummaryModule extends Module
ArcadeManager manager = getGame().getArcadeManager(); ArcadeManager manager = getGame().getArcadeManager();
if (!manager.IsRewardGems() || !manager.IsRewardStats() || !manager.IsRewardAchievements()) if (!manager.IsRewardGems() || !manager.IsRewardStats() || !manager.IsRewardAchievements() || manager.GetGame().getGameLiveTime() == 0)
{ {
return; return;
} }

View File

@ -82,7 +82,7 @@ public class ShardSummaryComponent extends GameSummaryComponent<Pair<Player, Int
} }
} }
text.add(get(baseShards, "Earning " + baseShards + " Gems")); text.add(get(baseShards, "Earning " + baseShards + " Game Gems"));
if (extraMult > 0) if (extraMult > 0)
{ {

View File

@ -1,5 +1,6 @@
package nautilus.game.arcade.managers; package nautilus.game.arcade.managers;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -34,6 +35,7 @@ import nautilus.game.arcade.game.GemData;
*/ */
public class GameRewardManager implements Listener public class GameRewardManager implements Listener
{ {
public enum Perm implements Permission public enum Perm implements Permission
{ {
SHARD_MULT_1, SHARD_MULT_1,
@ -48,15 +50,18 @@ public class GameRewardManager implements Listener
boolean DoubleGem = false; boolean DoubleGem = false;
boolean TimeReward = true; boolean TimeReward = true;
private final Map<Player, Integer> _baseShardsEarned;
public GameRewardManager(ArcadeManager manager) public GameRewardManager(ArcadeManager manager)
{ {
Manager = manager; Manager = manager;
Manager.getPluginManager().registerEvents(this, Manager.getPlugin()); _baseShardsEarned = new HashMap<>();
UtilServer.RegisterEvents(this);
generatePermissions(); generatePermissions();
} }
private void generatePermissions() private void generatePermissions()
{ {
PermissionGroup.ULTRA.setPermission(Perm.SHARD_MULT_1, true, true); PermissionGroup.ULTRA.setPermission(Perm.SHARD_MULT_1, true, true);
@ -129,7 +134,7 @@ public class GameRewardManager implements Listener
} }
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void GameStateChange(GameStateChangeEvent event) public void gameDead(GameStateChangeEvent event)
{ {
if (event.GetState() != GameState.Dead) if (event.GetState() != GameState.Dead)
{ {
@ -139,6 +144,17 @@ public class GameRewardManager implements Listener
UtilServer.getPlayersCollection().forEach(player -> GiveGems(event.GetGame(), player)); UtilServer.getPlayersCollection().forEach(player -> GiveGems(event.GetGame(), player));
} }
@EventHandler(priority = EventPriority.MONITOR)
public void gameDeadCleanup(GameStateChangeEvent event)
{
if (event.GetState() != GameState.Dead)
{
return;
}
_baseShardsEarned.clear();
}
private void GiveGems(Game game, Player player) private void GiveGems(Game game, Player player)
{ {
if (!Manager.IsRewardGems()) if (!Manager.IsRewardGems())
@ -147,7 +163,7 @@ public class GameRewardManager implements Listener
} }
double gameMult = game.GemMultiplier; double gameMult = game.GemMultiplier;
Map<String, GemData> gems = game.GetGems(player); Map<String, GemData> gems = game.GetGems(player);
if (gems == null) if (gems == null)
{ {
@ -158,22 +174,25 @@ public class GameRewardManager implements Listener
int gemsToReward; int gemsToReward;
// Calculate the base gems earned in this game // Calculate the base gems earned in this game
int gemsEarned = 0;
for (GemData data : gems.values())
{ {
int gemsEarned = 0; gemsEarned += (int) data.Gems;
for (GemData data : gems.values())
gemsEarned += (int) data.Gems;
if (gemsEarned <= 0)
gemsEarned = 1;
baseGemsEarned = (int) (gemsEarned * gameMult);
gemsToReward = baseGemsEarned;
} }
if (gemsEarned <= 0)
{
gemsEarned = 1;
}
baseGemsEarned = (int) (gemsEarned * gameMult);
gemsToReward = baseGemsEarned;
// Award players shards equal to base gems, plus booster bonuses. // Award players shards equal to base gems, plus booster bonuses.
final int baseShardsEarned = baseGemsEarned; final int baseShardsEarned = baseGemsEarned;
int shardsToReward = baseShardsEarned; int shardsToReward = baseShardsEarned;
_baseShardsEarned.put(player, baseShardsEarned);
// Gem Boooster // Gem Boooster
Booster booster = Manager.getBoosterManager().getActiveBooster(); Booster booster = Manager.getBoosterManager().getActiveBooster();
@ -220,7 +239,7 @@ public class GameRewardManager implements Listener
} }
int accountId = Manager.GetClients().getAccountId(player); int accountId = Manager.GetClients().getAccountId(player);
double shardMult = 0; double shardMult = 0;
for (Perm shardMultPerm : Perm.values()) for (Perm shardMultPerm : Perm.values())
@ -235,7 +254,7 @@ public class GameRewardManager implements Listener
{ {
shardsToReward += shardsToReward * shardMult; shardsToReward += shardsToReward * shardMult;
} }
if (!game.CrownsEnabled) if (!game.CrownsEnabled)
{ {
Manager.GetDonation().rewardCurrency(GlobalCurrency.GEM, player, "Earned " + game.GetName(), gemsToReward); Manager.GetDonation().rewardCurrency(GlobalCurrency.GEM, player, "Earned " + game.GetName(), gemsToReward);
@ -265,4 +284,9 @@ public class GameRewardManager implements Listener
Manager.GetStatsManager().incrementStat(player, game.GetName() + ".CrownsEarned", gemsToReward); Manager.GetStatsManager().incrementStat(player, game.GetName() + ".CrownsEarned", gemsToReward);
} }
} }
public Integer getBaseShardsEarned(Player player)
{
return _baseShardsEarned.get(player);
}
} }