Fix GameSummary showing an incorrect amout of shards
This commit is contained in:
parent
248c109627
commit
d267c15845
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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,11 +50,14 @@ 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();
|
||||||
}
|
}
|
||||||
@ -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())
|
||||||
@ -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;
|
int gemsEarned = 0;
|
||||||
|
|
||||||
for (GemData data : gems.values())
|
for (GemData data : gems.values())
|
||||||
|
{
|
||||||
gemsEarned += (int) data.Gems;
|
gemsEarned += (int) data.Gems;
|
||||||
|
}
|
||||||
|
|
||||||
if (gemsEarned <= 0)
|
if (gemsEarned <= 0)
|
||||||
|
{
|
||||||
gemsEarned = 1;
|
gemsEarned = 1;
|
||||||
|
}
|
||||||
|
|
||||||
baseGemsEarned = (int) (gemsEarned * gameMult);
|
baseGemsEarned = (int) (gemsEarned * gameMult);
|
||||||
gemsToReward = baseGemsEarned;
|
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();
|
||||||
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user