```
refactor(item): 优化物品添加逻辑并移除冗余代码 - 修改 ItemAdd 方法签名,从可变参数改为两个独立参数 itemId 和 itemCnt - 移除了对 model.ItemInfo 的依赖,简化调用方式 - 更新所有调用 ItemAdd 的地方以适配新接口 - 删除未使用的 imports 和注释掉的旧配置加载逻辑 - 修复购买物品时金币扣除与物品发放的一致性问题 - 增加玩家操作消耗塞尔豆的扣费逻辑(如宠物治疗、技能设置等) 此变更提升了代码简洁性和一致性,并增强了业务逻辑的准确性。 ```
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
"sync/atomic"
|
||||
|
||||
"blazing/modules/base/service"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
blservice "blazing/modules/blazing/service"
|
||||
"context"
|
||||
@@ -84,7 +83,7 @@ func (p *Player) UseCoins(t uint32) bool {
|
||||
if p.Info.Coins < t {
|
||||
return false
|
||||
}
|
||||
p.Info.Coins = p.Info.Coins - t
|
||||
|
||||
return true
|
||||
|
||||
}
|
||||
@@ -282,56 +281,50 @@ func replaceOneNumber(original [3]int) ([3]int, int, int) {
|
||||
}
|
||||
|
||||
// 添加物品 返回成功添加的物品
|
||||
func (p *Player) ItemAdd(t ...model.ItemInfo) (result []model.ItemInfo) {
|
||||
var ttt []model.ItemInfo
|
||||
for _, v := range t {
|
||||
func (p *Player) ItemAdd(ItemId, ItemCnt uint32) (result bool) {
|
||||
|
||||
switch v.ItemId {
|
||||
case 1: //塞尔豆
|
||||
p.Info.Coins = p.Info.Coins + v.ItemCnt
|
||||
switch ItemId {
|
||||
case 1: //塞尔豆
|
||||
p.Info.Coins = p.Info.Coins + ItemCnt
|
||||
return true
|
||||
case 3: //累计经验
|
||||
p.Info.ExpPool = p.Info.ExpPool + ItemCnt
|
||||
return true
|
||||
|
||||
case 3: //累计经验
|
||||
p.Info.ExpPool = p.Info.ExpPool + v.ItemCnt
|
||||
case 5: //金豆ItemAdd
|
||||
p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+ItemCnt*100))
|
||||
return true
|
||||
|
||||
case 5: //金豆ItemAdd
|
||||
p.User.SetGold(p.Info.UserID, uint32(p.User.GetGold(uint(p.Info.UserID))+v.ItemCnt*100))
|
||||
|
||||
default:
|
||||
ttt = append(ttt, v)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for _, v := range ttt {
|
||||
itemx, ok := xmlres.ItemsMAP[int(v.ItemId)]
|
||||
default:
|
||||
itemx, ok := xmlres.ItemsMAP[int(ItemId)]
|
||||
if !ok {
|
||||
cool.Loger.Error(context.TODO(), "物品不存在", v.ItemId)
|
||||
cool.Loger.Error(context.TODO(), "物品不存在", ItemId)
|
||||
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrSystemError200007)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
continue
|
||||
return false
|
||||
|
||||
}
|
||||
if itemx.Max == 0 {
|
||||
itemx.Max = 1
|
||||
}
|
||||
|
||||
if p.Service.Item.CheakItem(v.ItemId)+v.ItemCnt > uint32(itemx.Max) {
|
||||
if p.Service.Item.CheakItem(ItemId)+ItemCnt > uint32(itemx.Max) {
|
||||
|
||||
println(p.Info.UserID, "物品超过拥有最大限制", v.ItemId)
|
||||
println(p.Info.UserID, "物品超过拥有最大限制", ItemId)
|
||||
t1 := common.NewTomeeHeader(2601, p.Info.UserID)
|
||||
t1.Result = uint32(errorcode.ErrorCodes.ErrTooManyOfItem)
|
||||
|
||||
p.SendPack(t1.Pack(nil)) //准备包由各自发,因为协议不一样
|
||||
continue
|
||||
return false
|
||||
}
|
||||
p.Service.Item.AddItem(v.ItemId, v.ItemCnt)
|
||||
result = append(result, v)
|
||||
|
||||
p.Service.Item.AddItem(ItemId, ItemCnt)
|
||||
return true
|
||||
}
|
||||
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
func (player1 *Player) Kick() {
|
||||
|
||||
Reference in New Issue
Block a user