From 8bf17a8bdce1ab61ab373753ec1a0ae014ee4e0d Mon Sep 17 00:00:00 2001 From: Melledy <52122272+Melledy@users.noreply.github.com> Date: Wed, 27 Apr 2022 10:42:50 -0700 Subject: [PATCH] Fixed genesis crystals not being given to player --- .../emu/grasscutter/game/inventory/Inventory.java | 3 +++ .../game/managers/InventoryManager.java | 1 + .../java/emu/grasscutter/game/player/Player.java | 15 ++++++++++----- .../server/packet/recv/HandlerBuyGoodsReq.java | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/inventory/Inventory.java b/src/main/java/emu/grasscutter/game/inventory/Inventory.java index d407e077b..5ca0d022f 100644 --- a/src/main/java/emu/grasscutter/game/inventory/Inventory.java +++ b/src/main/java/emu/grasscutter/game/inventory/Inventory.java @@ -249,6 +249,9 @@ public class Inventory implements Iterable { case 202: // Mora getPlayer().setMora(player.getMora() + count); break; + case 203: // Genesis Crystals + getPlayer().setCrystals(player.getCrystals() + count); + break; } } diff --git a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java index 904d2cbdd..055d3da6d 100644 --- a/src/main/java/emu/grasscutter/game/managers/InventoryManager.java +++ b/src/main/java/emu/grasscutter/game/managers/InventoryManager.java @@ -923,6 +923,7 @@ public class InventoryManager { break; } + // Welkin if (useItem.getItemId() == 1202) { player.rechargeMoonCard(); used = 1; diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 826f65563..b4a22328d 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -294,6 +294,15 @@ public class Player { this.setProperty(PlayerProperty.PROP_PLAYER_SCOIN, mora); this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_SCOIN)); } + + public int getCrystals() { + return this.getProperty(PlayerProperty.PROP_PLAYER_MCOIN); + } + + public void setCrystals(int crystals) { + this.setProperty(PlayerProperty.PROP_PLAYER_MCOIN, crystals); + this.sendPacket(new PacketPlayerPropNotify(this, PlayerProperty.PROP_PLAYER_MCOIN)); + } private int getExpRequired(int level) { PlayerLevelData levelData = GameData.getPlayerLevelDataMap().get(level); @@ -550,11 +559,7 @@ public class Player { } public void rechargeMoonCard() { - LinkedList items = new LinkedList(); - for (int i = 0; i < 300; i++) { - items.add(new GameItem(203)); - } - inventory.addItems(items); + inventory.addItem(new GameItem(203, 300)); if (!moonCard) { moonCard = true; Date now = new Date(); diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java index c83808ada..1df08de43 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java @@ -32,7 +32,7 @@ public class HandlerBuyGoodsReq extends PacketHandler { if (sg.getHcoin() > 0 && session.getPlayer().getPrimogems() < buyGoodsReq.getBoughtNum() * sg.getHcoin()) { return; } - if (sg.getMcoin() > 0 && session.getPlayer().getProperty(PlayerProperty.PROP_PLAYER_MCOIN) < buyGoodsReq.getBoughtNum() * sg.getMcoin()) { + if (sg.getMcoin() > 0 && session.getPlayer().getCrystals() < buyGoodsReq.getBoughtNum() * sg.getMcoin()) { return; } @@ -46,7 +46,7 @@ public class HandlerBuyGoodsReq extends PacketHandler { session.getPlayer().setMora(session.getPlayer().getMora() - buyGoodsReq.getBoughtNum() * sg.getScoin()); session.getPlayer().setPrimogems(session.getPlayer().getPrimogems() - buyGoodsReq.getBoughtNum() * sg.getHcoin()); - session.getPlayer().setProperty(PlayerProperty.PROP_PLAYER_MCOIN, session.getPlayer().getProperty(PlayerProperty.PROP_PLAYER_MCOIN) - buyGoodsReq.getBoughtNum() * sg.getMcoin()); + session.getPlayer().setCrystals(session.getPlayer().getCrystals() - buyGoodsReq.getBoughtNum() * sg.getMcoin()); if (!itemsCache.isEmpty()) { for (GameItem gi : itemsCache.keySet()) {