```
refactor(item): 优化物品添加逻辑并移除冗余代码 - 修改 ItemAdd 方法签名,从可变参数改为两个独立参数 itemId 和 itemCnt - 移除了对 model.ItemInfo 的依赖,简化调用方式 - 更新所有调用 ItemAdd 的地方以适配新接口 - 删除未使用的 imports 和注释掉的旧配置加载逻辑 - 修复购买物品时金币扣除与物品发放的一致性问题 - 增加玩家操作消耗塞尔豆的扣费逻辑(如宠物治疗、技能设置等) 此变更提升了代码简洁性和一致性,并增强了业务逻辑的准确性。 ```
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
@@ -15,8 +14,8 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
tt, ok := xmlres.ItemsMAP[int(data.ItemId)]
|
||||
if ok && tt.Price != 0 && c.UseCoins(data.Count*uint32(tt.Price)) {
|
||||
|
||||
r := c.ItemAdd(model.ItemInfo{ItemId: data.ItemId, ItemCnt: data.Count})
|
||||
if len(r) != 0 {
|
||||
r := c.ItemAdd(data.ItemId, data.Count)
|
||||
if r {
|
||||
return &item.BuyOutboundInfo{
|
||||
ItemId: data.ItemId,
|
||||
Level: 1,
|
||||
@@ -25,6 +24,7 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
}, 0
|
||||
}
|
||||
//购买失败,返还豆子
|
||||
|
||||
c.Info.Coins += data.Count * uint32(tt.Price)
|
||||
}
|
||||
|
||||
@@ -34,22 +34,22 @@ func (h Controller) BuyItem(data *item.BuyInboundInfo, c *player.Player) (result
|
||||
}, 0
|
||||
}
|
||||
func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (result *item.BuyMultiOutboundInfo, err errorcode.ErrorCode) {
|
||||
var rrr []model.ItemInfo
|
||||
|
||||
for _, v := range data.ItemIds {
|
||||
_, ok := xmlres.ItemsMAP[int(v)]
|
||||
iteminfo, ok := xmlres.ItemsMAP[int(v)]
|
||||
|
||||
if ok {
|
||||
rrr = append(rrr, model.ItemInfo{ItemId: uint32(v), ItemCnt: 1})
|
||||
if !c.UseCoins(uint32(iteminfo.Price)) {
|
||||
break
|
||||
}
|
||||
if c.ItemAdd(v, 1) {
|
||||
c.Info.Coins -= uint32(iteminfo.Price)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
r := c.ItemAdd(rrr...)
|
||||
if len(r) != 0 {
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
}, 0
|
||||
}
|
||||
return &item.BuyMultiOutboundInfo{
|
||||
|
||||
Coins: c.Info.Coins,
|
||||
@@ -57,22 +57,25 @@ func (h Controller) BuyMItem(data *item.BuyMultiInboundInfo, c *player.Player) (
|
||||
}
|
||||
func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, c *player.Player) (result *item.S2C_GoldBuyProductInfo, err errorcode.ErrorCode) {
|
||||
r := xmlres.GoldProductMap[int(data.ProductID)]
|
||||
|
||||
if !c.UseGold(uint32(data.Count) * uint32(gconv.Uint32(r.Price)*100)) {
|
||||
usegold := uint32(data.Count) * uint32(gconv.Uint32(r.Price)*100)
|
||||
if !c.UseGold(usegold) {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
r1 := c.ItemAdd(model.ItemInfo{ItemId: uint32(gconv.Uint32(r.ItemID)), ItemCnt: uint32(data.Count)})
|
||||
isbuycot := len(r1)
|
||||
|
||||
usegold := uint32(uint32(len(r1))) * uint32(gconv.Uint32(r.Price)*100)
|
||||
c.User.SetGold(c.Info.UserID, c.User.GetGold(uint(c.Info.UserID))-usegold)
|
||||
|
||||
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)
|
||||
result = &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
PayGold: usegold,
|
||||
Reserved: 0,
|
||||
}
|
||||
}
|
||||
result = &item.S2C_GoldBuyProductInfo{
|
||||
Gold: c.User.GetGold(uint(c.Info.UserID)),
|
||||
PayGold: uint32(isbuycot) * uint32(gconv.Uint32(r.Price)),
|
||||
PayGold: 0,
|
||||
Reserved: 0,
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user