From 40eeba9d90ba02fcd8f4e555e46833fbcbc4b719 Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Thu, 25 Aug 2022 14:45:57 +0930 Subject: [PATCH] refactor some itemdepot lookups for later --- .../game/player/PlayerProgressManager.java | 7 ++---- .../packet/recv/HandlerBuyGoodsReq.java | 22 ++++++++----------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java index 958444f53..4532c4b68 100644 --- a/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java +++ b/src/main/java/emu/grasscutter/game/player/PlayerProgressManager.java @@ -209,11 +209,8 @@ public class PlayerProgressManager extends BasePlayerDataManager { this.player.getUnlockedScenePoints(sceneId).add(pointId); // Give primogems and Adventure EXP for unlocking. - var primos = new GameItem(GameData.getItemDataMap().get(201), 5); - this.player.getInventory().addItem(primos, ActionReason.UnlockPointReward); - - var exp = new GameItem(GameData.getItemDataMap().get(102), isStatue ? 50 : 10); - this.player.getInventory().addItem(exp, ActionReason.UnlockPointReward); + this.player.getInventory().addItem(201, 5, ActionReason.UnlockPointReward); + this.player.getInventory().addItem(102, isStatue ? 50 : 10, ActionReason.UnlockPointReward); // this.player.sendPacket(new PacketPlayerPropChangeReasonNotify(this.player.getProperty(PlayerProperty.PROP_PLAYER_EXP), PlayerProperty.PROP_PLAYER_EXP, PropChangeReason.PROP_CHANGE_REASON_PLAYER_ADD_EXP)); 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 e76fc49b8..973eac9f7 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerBuyGoodsReq.java @@ -1,6 +1,5 @@ package emu.grasscutter.server.packet.recv; -import emu.grasscutter.data.GameData; import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.props.ActionReason; @@ -11,11 +10,8 @@ import emu.grasscutter.net.packet.Opcodes; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.proto.BuyGoodsReqOuterClass; -import emu.grasscutter.net.proto.ItemParamOuterClass; -import emu.grasscutter.net.proto.ShopGoodsOuterClass; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp; -import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify; import emu.grasscutter.utils.Utils; import java.util.ArrayList; @@ -34,6 +30,7 @@ public class HandlerBuyGoodsReq extends PacketHandler { return; // Don't trust your users' input + var player = session.getPlayer(); List targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId()); for (int goodsId : targetShopGoodsId) { Optional sg2 = configShop.stream().filter(x -> x.getGoodsId() == goodsId).findFirst(); @@ -42,7 +39,7 @@ public class HandlerBuyGoodsReq extends PacketHandler { ShopInfo sg = sg2.get(); int currentTs = Utils.getCurrentSeconds(); - ShopLimit shopLimit = session.getPlayer().getGoodsLimit(sg.getGoodsId()); + ShopLimit shopLimit = player.getGoodsLimit(sg.getGoodsId()); int bought = 0; if (shopLimit != null) { if (currentTs > shopLimit.getNextRefreshTime()) { @@ -50,7 +47,7 @@ public class HandlerBuyGoodsReq extends PacketHandler { } else { bought = shopLimit.getHasBoughtInPeriod(); } - session.getPlayer().save(); + player.save(); } if ((bought + buyGoodsReq.getBuyCount() > sg.getBuyLimit()) && sg.getBuyLimit() != 0) { @@ -61,17 +58,16 @@ public class HandlerBuyGoodsReq extends PacketHandler { costs.add(new ItemParamData(202, sg.getScoin())); costs.add(new ItemParamData(201, sg.getHcoin())); costs.add(new ItemParamData(203, sg.getMcoin())); - if (!session.getPlayer().getInventory().payItems(costs, buyGoodsReq.getBuyCount())) { + if (!player.getInventory().payItems(costs, buyGoodsReq.getBuyCount())) { return; } - session.getPlayer().addShopLimit(sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg)); - GameItem item = new GameItem(GameData.getItemDataMap().get(sg.getGoodsItem().getId())); - item.setCount(buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount()); - session.getPlayer().getInventory().addItem(item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop - session.send(new PacketBuyGoodsRsp(buyGoodsReq.getShopType(), session.getPlayer().getGoodsLimit(sg.getGoodsId()).getHasBoughtInPeriod(), Stream.of(buyGoodsReq.getGoods()).filter(x -> x.getGoodsId() == goodsId).findFirst().get())); + player.addShopLimit(sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg)); + GameItem item = new GameItem(sg.getGoodsItem().getId(), buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount()); + player.getInventory().addItem(item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop + session.send(new PacketBuyGoodsRsp(buyGoodsReq.getShopType(), player.getGoodsLimit(sg.getGoodsId()).getHasBoughtInPeriod(), Stream.of(buyGoodsReq.getGoods()).filter(x -> x.getGoodsId() == goodsId).findFirst().get())); } - session.getPlayer().save(); + player.save(); } }