```
refactor(item): 优化物品添加逻辑并移除冗余代码 - 修改 ItemAdd 方法签名,从可变参数改为两个独立参数 itemId 和 itemCnt - 移除了对 model.ItemInfo 的依赖,简化调用方式 - 更新所有调用 ItemAdd 的地方以适配新接口 - 删除未使用的 imports 和注释掉的旧配置加载逻辑 - 修复购买物品时金币扣除与物品发放的一致性问题 - 增加玩家操作消耗塞尔豆的扣费逻辑(如宠物治疗、技能设置等) 此变更提升了代码简洁性和一致性,并增强了业务逻辑的准确性。 ```
This commit is contained in:
@@ -186,8 +186,8 @@ func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundIn
|
||||
EXP: exp * 2,
|
||||
}
|
||||
if refpet.Item != 0 {
|
||||
|
||||
items.ItemList = c.ItemAdd(model.ItemInfo{
|
||||
c.ItemAdd(refpet.Item, uint32(grand.Intn(2)+1))
|
||||
items.ItemList = append(items.ItemList, model.ItemInfo{
|
||||
ItemId: refpet.Item,
|
||||
ItemCnt: uint32(grand.Intn(2) + 1),
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
@@ -62,5 +62,6 @@ func (h *Controller) PlayerPetCure(data *nono.PetCureInboundInfo, c *player.Play
|
||||
c.Info.PetList[i].Cure()
|
||||
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
return
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func (h Controller) SetPetSkill(data *pet.ChangeSkillInfo, c *player.Player) (re
|
||||
if !c.UseCoins(100) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
|
||||
c.Info.Coins -= 50
|
||||
_, onpet, ok := c.FindPet(data.CatchTime)
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
@@ -42,6 +42,7 @@ func (h Controller) Skill_Sort(data *pet.C2S_Skill_Sort, c *player.Player) (resu
|
||||
if !c.UseCoins(100) {
|
||||
return result, errorcode.ErrorCodes.ErrSystemBusy
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
_, onpet, ok := c.FindPet(data.CapTm)
|
||||
if ok {
|
||||
var newskill []model.SkillInfo
|
||||
|
||||
@@ -1,72 +1,54 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"blazing/common/data/xmlres"
|
||||
"blazing/common/socket/errorcode"
|
||||
"blazing/logic/service/item"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/blazing/model"
|
||||
"blazing/modules/blazing/service"
|
||||
|
||||
dict "blazing/modules/dict/service"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
func (h Controller) Talk(data *item.TalkCountInboundInfo, c *player.Player) (result *item.TalkCountOutboundInfo, err errorcode.ErrorCode) {
|
||||
result = &item.TalkCountOutboundInfo{}
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
|
||||
tt, ok := t[data.ID]
|
||||
if ok {
|
||||
result.GiftCount = tt
|
||||
}
|
||||
return false
|
||||
})
|
||||
cid, ok := c.Service.Talk.Cheak(c.Info.MapID, int(data.ID))
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrResourceUnavailable
|
||||
}
|
||||
result.GiftCount = uint32(cid)
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
var talkcacche = make(map[string]uint32)
|
||||
//var talkcacche = make(map[string]uint32)
|
||||
|
||||
func (h Controller) TalkCate(data *item.TalkCateInboundInfo, c *player.Player) (result *item.DayTalkInfo, err errorcode.ErrorCode) {
|
||||
result = &item.DayTalkInfo{}
|
||||
result.OutList = make([]item.CateInfo, 0)
|
||||
for _, te := range xmlres.TalkConfig.Energies {
|
||||
if te.MapID == uint64(c.Info.MapID) && te.Type == uint64(data.ID) { //
|
||||
|
||||
_, ok := talkcacche[te.Name]
|
||||
if !ok {
|
||||
for _, v := range xmlres.ItemsMAP {
|
||||
if v.Name == te.Name {
|
||||
talkcacche[te.Name] = uint32(v.ID)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
randomNum := grand.Intn(10) + 1
|
||||
c.Service.Talk.Exec(func(t map[uint32]uint32) bool {
|
||||
if t == nil {
|
||||
t = make(map[uint32]uint32)
|
||||
|
||||
}
|
||||
_, ok := t[data.ID]
|
||||
if !ok {
|
||||
t[data.ID] = 0
|
||||
}
|
||||
|
||||
t[data.ID] += 1
|
||||
if t[data.ID] < uint32(te.CollectCnt) {
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: uint32(talkcacche[te.Name]), Count: uint32(randomNum)})
|
||||
c.ItemAdd(model.ItemInfo{ItemId: uint32(talkcacche[te.Name]), ItemCnt: uint32(randomNum)})
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
_, ok := c.Service.Talk.Cheak(c.Info.MapID, int(data.ID))
|
||||
if !ok {
|
||||
return result, errorcode.ErrorCodes.ErrResourceUnavailable
|
||||
}
|
||||
//更新次数
|
||||
config := service.TalkConfigServiceS.GetCache(int(data.ID))
|
||||
|
||||
for _, v := range config {
|
||||
count := grand.N(int(v.ItemMinCount), int(v.ItemMaxCount))
|
||||
|
||||
r := dict.DictInfoServiceS.DataID("fusion")
|
||||
trueitemid := gconv.Uint32(r[gconv.Uint32(v.ItemID)].Remark)
|
||||
ret := c.ItemAdd(trueitemid, uint32(count))
|
||||
if ret {
|
||||
result.OutList = append(result.OutList, item.CateInfo{ID: trueitemid, Count: uint32(count)})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
c.Service.Talk.Update(int(data.ID))
|
||||
|
||||
return result, 0
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import (
|
||||
"blazing/logic/service/player"
|
||||
"blazing/logic/service/task"
|
||||
"blazing/modules/blazing/model"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -74,7 +72,6 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
|
||||
if tt == nil {
|
||||
return result, 0 //通过PUB/SUB回包
|
||||
}
|
||||
result.ItemList = tt.ItemList
|
||||
|
||||
if tt.PetTypeId != 0 {
|
||||
r := model.GenPetInfo(int(tt.PetTypeId), 31, -1, 0, 0, 50)
|
||||
@@ -84,9 +81,13 @@ func (h Controller) Complete_Task(data *task.CompleteTaskInboundInfo, c *player.
|
||||
result.CaptureTime = r.CatchTime //这个写到后面,方便捕捉时间被修改后造成的时间不对问题
|
||||
}
|
||||
|
||||
ret := c.ItemAdd(result.ItemList...) //获取成功的条目
|
||||
for _, v := range tt.ItemList {
|
||||
ret := c.ItemAdd(v.ItemId, v.ItemCnt) //获取成功的条目
|
||||
if ret {
|
||||
result.ItemList = append(result.ItemList, v)
|
||||
}
|
||||
|
||||
copier.CopyWithOption(&result.ItemList, &ret, copier.Option{IgnoreEmpty: true, DeepCopy: true})
|
||||
}
|
||||
|
||||
return result, 0 //通过PUB/SUB回包
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ func (h Controller) ChangePlayerColor(data *user.ChangeColorInboundInfo, c *play
|
||||
if !c.UseCoins(200) { //如果花不了200,直接返回
|
||||
return
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
c.Info.Color = data.Color
|
||||
c.Info.Texture = 0
|
||||
result = &user.ChangeColorOutboundInfo{
|
||||
@@ -82,6 +83,7 @@ func (h Controller) ChangePlayerDoodle(data *user.ChangeDoodleInboundInfo, c *pl
|
||||
if !c.UseCoins(200) { //如果花不了200,直接返回
|
||||
return
|
||||
}
|
||||
c.Info.Coins -= 50
|
||||
c.Info.Texture = data.Id
|
||||
c.Info.Color = data.Color
|
||||
result = &user.ChangeDoodleOutboundInfo{
|
||||
|
||||
Reference in New Issue
Block a user