refactor: 重构战斗系统为统一动作包结构
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-06 00:58:23 +08:00
committed by cnb
parent 141ba67014
commit f433a26a6d
12 changed files with 683 additions and 158 deletions

View File

@@ -2,7 +2,6 @@ package controller
import (
"blazing/common/socket/errorcode"
"blazing/modules/player/model"
"blazing/logic/service/fight"
"blazing/logic/service/fight/info"
@@ -31,7 +30,7 @@ func (h Controller) UseSkill(data *UseSkillInInfo, c *player.Player) (result *fi
if err := h.checkFightStatus(c); err != 0 {
return nil, err
}
go c.FightC.UseSkill(c, data.SkillId)
h.dispatchFightActionEnvelope(c, buildLegacyUseSkillEnvelope(data))
return nil, 0
}
@@ -41,31 +40,7 @@ func (h Controller) UseSkillAt(data *UseSkillAtInboundInfo, c *player.Player) (r
if err := h.checkFightStatus(c); err != 0 {
return nil, err
}
actorIndex := int(data.ActorIndex)
targetIndex := int(data.TargetIndex)
targetRelation := data.TargetRelation
// 前端未显式给 relation 时,按 AtkType 兜底3=自己1=己方,其他按对方。
if targetRelation > fight.SkillTargetAlly {
switch data.AtkType {
case 3:
targetRelation = fight.SkillTargetSelf
case 1:
targetRelation = fight.SkillTargetAlly
default:
targetRelation = fight.SkillTargetOpponent
}
}
switch targetRelation {
case fight.SkillTargetSelf:
targetIndex = actorIndex
go c.FightC.UseSkillAt(c, data.SkillId, actorIndex, fight.EncodeTargetIndex(targetIndex, false))
case fight.SkillTargetAlly:
go c.FightC.UseSkillAt(c, data.SkillId, actorIndex, fight.EncodeTargetIndex(targetIndex, false))
default:
go c.FightC.UseSkillAt(c, data.SkillId, actorIndex, fight.EncodeTargetIndex(targetIndex, true))
}
h.dispatchFightActionEnvelope(c, buildIndexedUseSkillEnvelope(data))
return nil, 0
}
@@ -74,8 +49,7 @@ func (h Controller) Escape(data *EscapeFightInboundInfo, c *player.Player) (resu
if err := h.checkFightStatus(c); err != 0 {
return nil, err
}
go c.FightC.Over(c, model.BattleOverReason.PlayerEscape)
h.dispatchFightActionEnvelope(c, buildLegacyEscapeEnvelope())
return nil, 0
}
@@ -84,7 +58,7 @@ func (h Controller) ChangePet(data *ChangePetInboundInfo, c *player.Player) (res
if err := h.checkFightStatus(c); err != 0 {
return nil, err
}
go c.FightC.ChangePet(c, data.CatchTime)
h.dispatchFightActionEnvelope(c, buildLegacyChangeEnvelope(data))
return nil, -1
}
@@ -123,7 +97,7 @@ func (h Controller) UsePetItemInboundInfo(data *UsePetItemInboundInfo, c *player
}
}
go c.FightC.UseItem(c, data.CatchTime, data.ItemId)
h.dispatchFightActionEnvelope(c, buildLegacyUseItemEnvelope(data))
return nil, -1
}
@@ -132,6 +106,6 @@ func (h Controller) FightChat(data *ChatInfo, c *player.Player) (result *fight.N
if err := h.checkFightStatus(c); err != 0 {
return nil, err
}
go c.FightC.Chat(c, data.Message)
h.dispatchFightActionEnvelope(c, buildChatEnvelope(data))
return nil, -1
}