mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 03:05:34 +00:00
refactor some itemdepot lookups for later
This commit is contained in:
parent
5565a13df8
commit
40eeba9d90
@ -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));
|
||||
|
||||
|
@ -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<Integer> targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId());
|
||||
for (int goodsId : targetShopGoodsId) {
|
||||
Optional<ShopInfo> 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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user