```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(game): 宠物融合系统添加物品消耗异常处理

- 在宠物融合过程中添加物品扣除失败的错误检查
- 当物品不足时返回ErrInsufficientItems错误码

fix(pet): 宠物仓库管理功能增加数据库操作错误处理

- 在宠物释放到仓库和从仓库取出时验证数据库更新结果
- 添加宠物背包切换功能的错误检查机制

feat(fight):
This commit is contained in:
昔念
2026-03-19 14:50:11 +08:00
parent e2ac5a6325
commit b558f46d7a
10 changed files with 142 additions and 63 deletions

View File

@@ -66,7 +66,10 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
// utils.CountSliceElements(data.Item1[:])
for _, v := range data.Item1 {
c.Service.Item.UPDATE(v, -1)
err := c.Service.Item.UPDATE(v, -1)
if err != nil {
return result, errorcode.ErrorCodes.ErrInsufficientItems
}
}
result = &pet.PetFusionInfo{

View File

@@ -85,7 +85,9 @@ func (h Controller) PetReleaseToWarehouse(
return nil, errorcode.ErrorCodes.ErrCannotReleaseNonWarehouse
}
player.Service.Pet.UPdateFree(data.CatchTime, 1)
if !player.Service.Pet.UPdateFree(data.CatchTime, 1) {
return nil, errorcode.ErrorCodes.ErrSystemError
}
return nil, err
}
@@ -96,7 +98,10 @@ func (h Controller) PetRetrieveFromWarehouse(
//如果背包没找到,再放入背包
if _, _, ok := player.FindPet(data.CatchTime); !ok {
player.Service.Pet.UPdateFree(data.CatchTime, 0)
if !player.Service.Pet.UPdateFree(data.CatchTime, 0) {
return nil, errorcode.ErrorCodes.ErrSystemError
}
}
return nil, 0
@@ -127,7 +132,10 @@ func (h Controller) TogglePetBagWarehouse(
if index < 0 || index >= len(player.Info.PetList) {
return result, errorcode.ErrorCodes.ErrPokemonIDMismatch
}
player.Service.Pet.UPdate(*pet)
err := player.Service.Pet.UPdate(*pet)
if err != nil {
return result, errorcode.ErrorCodes.ErrSystemError
}
player.Info.PetList = append(player.Info.PetList[:index], player.Info.PetList[index+1:]...)
}

View File

@@ -11,33 +11,34 @@ type Effect1044 struct {
node.EffectNode
damageMultiplierActive bool
multiplierDuration int
can bool
}
func (e *Effect1044) OnSkill() bool {
// 检查对手是否有能力提升状态可以吸取
var sub bool
for i, v := range e.Ctx().Opp.Prop[:] {
if v > 0 {
sub = true
e.Ctx().Our.SetProp(e.Ctx().Our, int8(i), v)
e.Ctx().Opp.SetProp(e.Ctx().Our, int8(i), 0)
if e.Ctx().Opp.SetProp(e.Ctx().Our, int8(i), 0) {
e.can = true
e.Ctx().Our.SetProp(e.Ctx().Our, int8(i), v)
}
}
}
if sub {
e.GenSub(&Effect1044_sub{}, int(e.Args()[1].IntPart()))
}
return true
}
type Effect1044_sub struct {
node.EffectNode
}
func (e *Effect1044_sub) Damage_Mul(_ *info.DamageZone) bool {
func (e *Effect1044) Damage_Mul(t *info.DamageZone) bool {
if !e.can {
return true
}
if t.Type != info.DamageType.Red {
return true
}
t.Mul(2)
return true
}
func init() {

View File

@@ -220,7 +220,9 @@ type ClientData struct {
}
func (p *ClientData) GetPlayer(userid uint32) *Player { //TODO 这里待优化,可能存在内存泄漏问题
if p.Player == nil {
p.Player = NewPlayer(p.Conn)
}
_, ok := Mainplayer.LoadOrStore(userid, p)
if !ok {
p.Player = NewPlayer(p.Conn)