优化代码

This commit is contained in:
flswld
2023-03-14 15:29:18 +08:00
parent 2ce948a5ce
commit 2c35fc0df4
12 changed files with 559 additions and 587 deletions
+11 -13
View File
@@ -74,20 +74,19 @@ func (g *GameManager) BuyGoodsReq(player *model.Player, payloadMsg pb.Message) {
return
}
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, 201) < costHcoinCount {
if g.GetPlayerItemCount(player.PlayerID, 201) < costHcoinCount {
return
}
ok := g.CostUserItem(player.PlayerID, []*ChangeItem{{ItemId: 201, ChangeCount: costHcoinCount}})
if !ok {
return
}
g.CostUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 201,
ChangeCount: costHcoinCount,
}})
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: buyItemId,
ChangeCount: buyItemCount,
}}, true, uint16(proto.ActionReasonType_ACTION_REASON_SHOP))
req.Goods.BoughtNum = dbItem.GetItemCount(player, buyItemId)
req.Goods.BoughtNum = g.GetPlayerItemCount(player.PlayerID, buyItemId)
buyGoodsRsp := &proto.BuyGoodsRsp{
ShopType: req.ShopType,
@@ -104,14 +103,13 @@ func (g *GameManager) McoinExchangeHcoinReq(player *model.Player, payloadMsg pb.
}
count := req.Hcoin
dbItem := player.GetDbItem()
if dbItem.GetItemCount(player, 203) < count {
if g.GetPlayerItemCount(player.PlayerID, 203) < count {
return
}
ok := g.CostUserItem(player.PlayerID, []*ChangeItem{{ItemId: 203, ChangeCount: count}})
if !ok {
return
}
g.CostUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 203,
ChangeCount: count,
}})
g.AddUserItem(player.PlayerID, []*ChangeItem{{
ItemId: 201,