refactor(item): 统一物品操作接口并优化金币处理逻辑

This commit is contained in:
1
2025-12-16 06:54:27 +00:00
parent 39dc79f706
commit 49b4c8cf2a
10 changed files with 47 additions and 28 deletions

View File

@@ -64,7 +64,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Playe
isbuycot := c.ItemAdd(uint32(gconv.Uint32(r.ItemID)), uint32(data.Count))
if isbuycot {
c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold)
c.User.UpdateGold(c.Info.UserID, -gconv.Float64(usegold))
result = &item.S2C_GoldBuyProductInfo{
Gold: c.User.GetGold(uint(c.Info.UserID)),
PayGold: usegold,

View File

@@ -6,6 +6,8 @@ import (
"blazing/logic/service/fight"
"blazing/logic/service/item"
"blazing/logic/service/player"
"github.com/gogf/gf/v2/util/gconv"
)
func (h Controller) ITEM_SALE(data *item.C2S_ITEM_SALE, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
@@ -17,6 +19,6 @@ func (h Controller) ITEM_SALE(data *item.C2S_ITEM_SALE, c *player.Player) (resul
c.Info.Coins += uint32(int64(data.Amount) * int64(xmlres.ItemsMAP[int(data.ItemId)].SellPrice))
}
c.Service.Item.SubItem(data.ItemId, data.Amount)
c.Service.Item.UPDATE(data.ItemId, -gconv.Int(data.Amount))
return result, 0
}

View File

@@ -63,7 +63,7 @@ func (h Controller) ItemUsePet(data *item.C2S_USE_PET_ITEM_OUT_OF_FIGHT, c *play
}
c.Service.Item.SubItem(data.ItemID, 1)
c.Service.Item.UPDATE(data.ItemID, -1)
result = &item.S2C_USE_PET_ITEM_OUT_OF_FIGHT{}
onpet.CalculatePetPane(false)
copier.Copy(&result, onpet)
@@ -82,6 +82,6 @@ func (h Controller) ResetNature(data *item.C2S_PET_RESET_NATURE, c *player.Playe
onpet.Nature = data.Nature
onpet.CalculatePetPane(false)
c.Service.Item.SubItem(data.ItemId, 1)
c.Service.Item.UPDATE(data.ItemId, -1)
return result, 0
}