refactor(fight): 优化战斗逻辑代码结构,清理冗余代码

This commit is contained in:
1
2025-11-05 17:19:09 +00:00
parent 4d7064e59f
commit 3aff7f7ad6
4 changed files with 24 additions and 13 deletions

View File

@@ -162,9 +162,15 @@ func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (resu
// 战斗逃跑
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
if c.FightC != nil {
c.FightC.Over(c, info.BattleOverReason.PlayerEscape)
if c.FightC == nil {
return nil, 0
}
if !c.FightC.CanEscape() {
return nil, 0
}
c.FightC.Over(c, info.BattleOverReason.PlayerEscape)
return nil, 0
}

View File

@@ -69,21 +69,22 @@ func (h *Controller) PetRelease(
switch data.Flag {
case 0:
var temp []model.PetInfo
n, v, ok := utils.FindWithIndex(c.Info.PetList, func(item model.PetInfo) bool {
return item.CatchTime == data.CatchTime
})
if ok {
c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
t.Data = *v
t.InBag = 0
for _, v := range c.Info.PetList {
if v.CatchTime == uint32(data.CatchTime) {
c.Service.PetInfo_One_exec(data.CatchTime, func(t *model.PetEX) {
t.Data = v
t.InBag = 0
})
})
c.Info.PetList = append(c.Info.PetList[:n], c.Info.PetList[n+1:]...)
} else {
temp = append(temp, v)
}
}
c.Info.PetList = temp
// break // 只移除第一个匹配值,若需移除所有,可省略 break 继续循环
case 1:
//todo 背包

View File

@@ -15,6 +15,6 @@ type FightI interface {
Capture(c PlayerI, id uint32)
GetRand() *rand.Rand
LoadPercent(c PlayerI, percent int32)
CanEscape() bool
IsFirst(c PlayerI) bool
}

View File

@@ -36,6 +36,10 @@ type FightC struct {
closefight bool
}
func (f *FightC) CanEscape() bool {
return f.Info.Status != info.BattleStatus.FIGHT_WITH_PLAYER
}
func (f *FightC) Ownerid() uint32 {
return f.ownerID