From c8fcff2ede1407adc25edf8b6928e744c9e0d4be Mon Sep 17 00:00:00 2001 From: GanyusLeftHorn <1244229+GanyusLeftHorn@users.noreply.github.com> Date: Sat, 25 Jun 2022 00:06:37 -0700 Subject: [PATCH] Reset forge points every day to enable crafting of enhancement ores. --- .../grasscutter/data/excels/ForgeData.java | 6 ++- .../game/managers/forging/ForgingManager.java | 20 ++++++-- .../emu/grasscutter/game/player/Player.java | 51 ++++++++++++++++++- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/data/excels/ForgeData.java b/src/main/java/emu/grasscutter/data/excels/ForgeData.java index 6b6199197..554c9f446 100644 --- a/src/main/java/emu/grasscutter/data/excels/ForgeData.java +++ b/src/main/java/emu/grasscutter/data/excels/ForgeData.java @@ -6,7 +6,6 @@ import emu.grasscutter.data.GameResource; import emu.grasscutter.data.ResourceType; import emu.grasscutter.data.ResourceType.LoadPriority; import emu.grasscutter.data.common.ItemParamData; -import emu.grasscutter.data.common.OpenCondData; @ResourceType(name = {"ForgeExcelConfigData.json"}, loadPriority = LoadPriority.HIGHEST) public class ForgeData extends GameResource { @@ -19,6 +18,7 @@ public class ForgeData extends GameResource { private int queueNum; private int scoinCost; private int priority; + private int forgePoint; private List materialItems; @Override @@ -58,6 +58,10 @@ public class ForgeData extends GameResource { return priority; } + public int getForgePoint() { + return forgePoint; + } + public List getMaterialItems() { return materialItems; } diff --git a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java index 4edb6bf33..28257a685 100644 --- a/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java +++ b/src/main/java/emu/grasscutter/game/managers/forging/ForgingManager.java @@ -5,19 +5,15 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.mongodb.QueryBuilder; - import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.excels.ForgeData; import emu.grasscutter.data.excels.ItemData; import emu.grasscutter.game.inventory.GameItem; -import emu.grasscutter.game.inventory.ItemType; import emu.grasscutter.game.player.Player; import emu.grasscutter.game.props.ActionReason; import emu.grasscutter.game.props.WatcherTriggerType; -import emu.grasscutter.net.proto.ForgeStartReqOuterClass; import emu.grasscutter.net.proto.ForgeQueueDataOuterClass.ForgeQueueData; import emu.grasscutter.net.proto.ForgeQueueManipulateReqOuterClass.ForgeQueueManipulateReq; import emu.grasscutter.net.proto.ForgeQueueManipulateTypeOuterClass.ForgeQueueManipulateType; @@ -148,6 +144,13 @@ public class ForgingManager { } ForgeData forgeData = GameData.getForgeDataMap().get(req.getForgeId()); + + //Check if the player has sufficient forge points. + int requiredPoints = forgeData.getForgePoint() * req.getForgeCount(); + if (requiredPoints > this.player.getForgePoints()) { + this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); + return; + } // Check if we have enough of each material and consume. List material = new ArrayList<>(forgeData.getMaterialItems()); @@ -159,6 +162,9 @@ public class ForgingManager { this.player.sendPacket(new PacketForgeStartRsp(Retcode.RET_FORGE_POINT_NOT_ENOUGH)); //ToDo: Probably the wrong return code. } + // Consume forge points. + this.player.setForgePoints(this.player.getForgePoints() - requiredPoints); + // Create and add active forge. ActiveForgeData activeForge = new ActiveForgeData(); activeForge.setForgeId(req.getForgeId()); @@ -256,6 +262,12 @@ public class ForgingManager { GameItem returnMora = new GameItem(moraItem, data.getScoinCost() * forge.getCount()); returnItems.add(returnMora); + // Return forge points to the player. + int requiredPoints = data.getForgePoint() * forge.getCount(); + int newPoints = Math.min(this.player.getForgePoints() + requiredPoints, 300_000); + + this.player.setForgePoints(newPoints); + // Remove the forge queue. this.player.getActiveForges().remove(queueId - 1); this.sendForgeQueueDataNotify(true); diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index b2d13879c..0d4b4c096 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -76,6 +76,9 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.Getter; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.*; import java.util.concurrent.LinkedBlockingQueue; @@ -181,6 +184,7 @@ public class Player { private long springLastUsed; private HashMap mapMarks; private int nextResinRefresh; + private int lastDailyReset; @Deprecated @SuppressWarnings({"rawtypes", "unchecked"}) // Morphia only! @@ -447,14 +451,27 @@ public class Player { } public void setWorldLevel(int level) { - this.getWorld().setWorldLevel(newWorldLevel); - + this.getWorld().setWorldLevel(level); + this.setProperty(PlayerProperty.PROP_PLAYER_WORLD_LEVEL, level); this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_WORLD_LEVEL)); this.updateProfile(); } + public int getForgePoints() { + return this.getProperty(PlayerProperty.PROP_PLAYER_FORGE_POINT); + } + + public void setForgePoints(int value) { + if (value == this.getForgePoints()) { + return; + } + + this.setProperty(PlayerProperty.PROP_PLAYER_FORGE_POINT, value); + this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_FORGE_POINT)); + } + public int getPrimogems() { return this.getProperty(PlayerProperty.PROP_PLAYER_HCOIN); } @@ -796,6 +813,14 @@ public class Player { return showAvatarList; } + public int getLastDailyReset() { + return this.lastDailyReset; + } + + public void setLastDailyReset(int value) { + this.lastDailyReset = value; + } + public boolean inMoonCard() { return moonCard; } @@ -1316,6 +1341,10 @@ public class Player { this.resetSendPlayerLocTime(); } } + + // Handle daily reset. + this.doDailyReset(); + // Expedition var timeNow = Utils.getCurrentSeconds(); var needNotify = false; @@ -1340,8 +1369,26 @@ public class Player { this.getResinManager().rechargeResin(); } + private void doDailyReset() { + // Check if we should execute a daily reset on this tick. + int currentTime = Utils.getCurrentSeconds(); + var currentDate = LocalDate.ofInstant(Instant.ofEpochSecond(currentTime), ZoneId.systemDefault()); + var lastResetDate = LocalDate.ofInstant(Instant.ofEpochSecond(this.getLastDailyReset()), ZoneId.systemDefault()); + if (!currentDate.isAfter(lastResetDate)) { + return; + } + + Grasscutter.getLogger().info("Executing daily reset logic ..."); + + // We should - now execute all the resetting logic we need. + // Reset forge points. + this.setForgePoints(300_000); + + // Done. Update last reset time. + this.setLastDailyReset(currentTime); + } public void resetSendPlayerLocTime() { this.nextSendPlayerLocTime = System.currentTimeMillis() + 5000;