Files
bl/logic/controller/PET_FUSION.go
昔念 852ba53350 ```
fix(pet): 修复宠物融合与删除逻辑中的数据访问问题

- 在 PET_FUSION 控制器中注释掉调试代码并修正融合时使用的捕获时间参数
- 优化 player 模块中 Pet_del 方法的切片删除逻辑,避免潜在的数据竞争
- 修复 fight loop 中对手宠物列表的错误引用
- 调整数据库查询条件,将 id 字段从关键字搜索移至精确匹配字段
- 宠物服务中添加插入失败时的重试机制,并默认 free 状态为 1
```
2025-12-06 01:41:38 +08:00

75 lines
2.4 KiB
Go

package controller
import (
"blazing/common/data/xmlres"
"blazing/common/socket/errorcode"
"blazing/logic/service/pet"
"blazing/logic/service/player"
"blazing/modules/blazing/model"
"blazing/modules/blazing/service"
"github.com/alpacahq/alpacadecimal"
)
func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result *pet.PetFusionInfo, err errorcode.ErrorCode) {
if !c.UseCoins(1000) {
return result, errorcode.ErrorCodes.ErrSystemBusy
}
// g.Dump(c.Info.PetList)
//防止同一只
if data.Mcatchtime == data.Auxcatchtime {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady
}
_, Mcatchpetinfo, ok := c.FindPet(data.Mcatchtime)
if !ok {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
}
if xmlres.PetMAP[int(Mcatchpetinfo.ID)].FuseMaster == 0 {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
}
_, Auxpetinfo, ok := c.FindPet(data.Auxcatchtime)
if !ok {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady2
}
if xmlres.PetMAP[int(Auxpetinfo.ID)].FuseSub == 0 {
return result, errorcode.ErrorCodes.ErrPokemonNotFusionReady3
}
//println(len(c.Info.PetList), data.Mcatchtime, data.Auxcatchtime, Mcatchpetinfo.CatchTime, Auxpetinfo.CatchTime)
///性格生成
var natureId int32 = -1
if Auxpetinfo.Nature == Mcatchpetinfo.Nature {
natureId = int32(Auxpetinfo.Nature)
}
resid := int(service.NewPetFusionService().Data(Mcatchpetinfo.ID, Auxpetinfo.ID, Mcatchpetinfo.Level+Auxpetinfo.Level))
if resid == 0 {
//todo失败降低等级
return &pet.PetFusionInfo{}, 0
}
effect := int(service.NewPetFusionMaterialService().Data(data.Item1))
dv1 := alpacadecimal.NewFromInt(2).Div(alpacadecimal.NewFromInt(3)).Mul(alpacadecimal.NewFromInt(int64(Mcatchpetinfo.Dv)))
dv2 := alpacadecimal.NewFromInt(1).Div(alpacadecimal.NewFromInt(3)).Mul(alpacadecimal.NewFromInt(int64(Auxpetinfo.Dv)))
dv := dv1.Add(dv2).Add(alpacadecimal.NewFromInt(1)).IntPart()
r := model.GenPetInfo(resid, int(dv), int(natureId), effect, -1, 1)
r.OldCatchTime = Mcatchpetinfo.CatchTime
c.Service.Pet.PetAdd(r)
println(len(c.Info.PetList), data.Mcatchtime, data.Auxcatchtime, Mcatchpetinfo.CatchTime, Auxpetinfo.CatchTime)
c.Pet_del(data.Auxcatchtime)
c.Pet_del(data.Mcatchtime)
//fmt.Println(len(c.Info.PetList))
// g.Dump(c.Info.PetList)
//todo材料扣除
return &pet.PetFusionInfo{
ObtainTime: r.CatchTime,
SoulID: 1000017,
StarterCpTm: r.ID,
CostItemFlag: 0,
}, 0
}