mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-25 20:56:28 +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);
|
this.player.getUnlockedScenePoints(sceneId).add(pointId);
|
||||||
|
|
||||||
// Give primogems and Adventure EXP for unlocking.
|
// Give primogems and Adventure EXP for unlocking.
|
||||||
var primos = new GameItem(GameData.getItemDataMap().get(201), 5);
|
this.player.getInventory().addItem(201, 5, ActionReason.UnlockPointReward);
|
||||||
this.player.getInventory().addItem(primos, ActionReason.UnlockPointReward);
|
this.player.getInventory().addItem(102, isStatue ? 50 : 10, ActionReason.UnlockPointReward);
|
||||||
|
|
||||||
var exp = new GameItem(GameData.getItemDataMap().get(102), isStatue ? 50 : 10);
|
|
||||||
this.player.getInventory().addItem(exp, 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));
|
// 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;
|
package emu.grasscutter.server.packet.recv;
|
||||||
|
|
||||||
import emu.grasscutter.data.GameData;
|
|
||||||
import emu.grasscutter.data.common.ItemParamData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
import emu.grasscutter.game.inventory.GameItem;
|
import emu.grasscutter.game.inventory.GameItem;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
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.PacketHandler;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.BuyGoodsReqOuterClass;
|
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.game.GameSession;
|
||||||
import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp;
|
import emu.grasscutter.server.packet.send.PacketBuyGoodsRsp;
|
||||||
import emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify;
|
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -34,6 +30,7 @@ public class HandlerBuyGoodsReq extends PacketHandler {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Don't trust your users' input
|
// Don't trust your users' input
|
||||||
|
var player = session.getPlayer();
|
||||||
List<Integer> targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId());
|
List<Integer> targetShopGoodsId = List.of(buyGoodsReq.getGoods().getGoodsId());
|
||||||
for (int goodsId : targetShopGoodsId) {
|
for (int goodsId : targetShopGoodsId) {
|
||||||
Optional<ShopInfo> sg2 = configShop.stream().filter(x -> x.getGoodsId() == goodsId).findFirst();
|
Optional<ShopInfo> sg2 = configShop.stream().filter(x -> x.getGoodsId() == goodsId).findFirst();
|
||||||
@ -42,7 +39,7 @@ public class HandlerBuyGoodsReq extends PacketHandler {
|
|||||||
ShopInfo sg = sg2.get();
|
ShopInfo sg = sg2.get();
|
||||||
|
|
||||||
int currentTs = Utils.getCurrentSeconds();
|
int currentTs = Utils.getCurrentSeconds();
|
||||||
ShopLimit shopLimit = session.getPlayer().getGoodsLimit(sg.getGoodsId());
|
ShopLimit shopLimit = player.getGoodsLimit(sg.getGoodsId());
|
||||||
int bought = 0;
|
int bought = 0;
|
||||||
if (shopLimit != null) {
|
if (shopLimit != null) {
|
||||||
if (currentTs > shopLimit.getNextRefreshTime()) {
|
if (currentTs > shopLimit.getNextRefreshTime()) {
|
||||||
@ -50,7 +47,7 @@ public class HandlerBuyGoodsReq extends PacketHandler {
|
|||||||
} else {
|
} else {
|
||||||
bought = shopLimit.getHasBoughtInPeriod();
|
bought = shopLimit.getHasBoughtInPeriod();
|
||||||
}
|
}
|
||||||
session.getPlayer().save();
|
player.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((bought + buyGoodsReq.getBuyCount() > sg.getBuyLimit()) && sg.getBuyLimit() != 0) {
|
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(202, sg.getScoin()));
|
||||||
costs.add(new ItemParamData(201, sg.getHcoin()));
|
costs.add(new ItemParamData(201, sg.getHcoin()));
|
||||||
costs.add(new ItemParamData(203, sg.getMcoin()));
|
costs.add(new ItemParamData(203, sg.getMcoin()));
|
||||||
if (!session.getPlayer().getInventory().payItems(costs, buyGoodsReq.getBuyCount())) {
|
if (!player.getInventory().payItems(costs, buyGoodsReq.getBuyCount())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.getPlayer().addShopLimit(sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg));
|
player.addShopLimit(sg.getGoodsId(), buyGoodsReq.getBuyCount(), ShopSystem.getShopNextRefreshTime(sg));
|
||||||
GameItem item = new GameItem(GameData.getItemDataMap().get(sg.getGoodsItem().getId()));
|
GameItem item = new GameItem(sg.getGoodsItem().getId(), buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount());
|
||||||
item.setCount(buyGoodsReq.getBuyCount() * sg.getGoodsItem().getCount());
|
player.getInventory().addItem(item, ActionReason.Shop, true); // fix: not notify when got virtual item from shop
|
||||||
session.getPlayer().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.send(new PacketBuyGoodsRsp(buyGoodsReq.getShopType(), session.getPlayer().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