refactor: 统一战斗报文发送逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-08 12:26:37 +08:00
committed by cnb
parent 4b89588c22
commit ca96be3905
7 changed files with 210 additions and 363 deletions

View File

@@ -276,6 +276,9 @@ func (f *FightC) setActionAttackValue(act action.BattleActionI) {
}
attacker.AttackValue.ActorIndex = uint32(act.GetActorIndex())
targetIndex, _ := DecodeTargetIndex(act.GetTargetIndex())
if _, resolvedIndex, ok := f.resolveActionTarget(act); ok && resolvedIndex >= 0 {
targetIndex = resolvedIndex
}
attacker.AttackValue.TargetIndex = uint32(targetIndex)
}
@@ -316,6 +319,25 @@ func (f *FightC) GetInputByPlayerAt(c common.PlayerI, actorIndex int, isOpposite
return f.getInputByUserID(c.GetInfo().UserID, actorIndex, isOpposite)
}
func (f *FightC) resolveActionTarget(c action.BattleActionI) (*input.Input, int, bool) {
if c == nil {
return nil, -1, false
}
attacker := f.getInputByUserID(c.GetPlayerID(), c.GetActorIndex(), false)
if attacker == nil {
return nil, -1, false
}
encodedTargetIndex := c.GetTargetIndex()
targetIndex, targetIsOpposite := DecodeTargetIndex(encodedTargetIndex)
if !targetIsOpposite {
return attacker.TeamSlotAt(targetIndex), targetIndex, false
}
if target, resolvedIndex := attacker.OpponentSlotAtOrNextLiving(targetIndex); target != nil {
return target, resolvedIndex, true
}
return attacker.OpponentSlotAt(targetIndex), targetIndex, true
}
func (f *FightC) GetInputByAction(c action.BattleActionI, isOpposite bool) *input.Input {
if c == nil {
if isOpposite {
@@ -327,8 +349,8 @@ func (f *FightC) GetInputByAction(c action.BattleActionI, isOpposite bool) *inpu
if !isOpposite {
return f.getInputByUserID(c.GetPlayerID(), index, false)
}
targetIndex, targetIsOpposite := DecodeTargetIndex(c.GetTargetIndex())
return f.getInputByUserID(c.GetPlayerID(), targetIndex, targetIsOpposite)
target, _, _ := f.resolveActionTarget(c)
return target
}
// 玩家使用技能
@@ -377,7 +399,7 @@ func (f *FightC) GetRound() uint32 {
}
func (f *FightC) Chat(c common.PlayerI, msg string) {
f.GetInputByPlayer(c, true).Player.SendPackCmd(50002, &user.ChatOutboundInfo{
f.sendFightPacket(f.GetInputByPlayer(c, true).Player, fightPacketChat, &user.ChatOutboundInfo{
SenderId: c.GetInfo().UserID,
SenderNickname: c.GetInfo().Nick,
Message: utils.RemoveLast(msg),
@@ -392,7 +414,7 @@ func (f *FightC) LoadPercent(c common.PlayerI, percent int32) {
if f.Info.Status == info.BattleMode.FIGHT_WITH_NPC {
return
}
f.GetInputByPlayer(c, true).Player.SendPackCmd(2441, &info.LoadPercentOutboundInfo{
f.sendFightPacket(f.GetInputByPlayer(c, true).Player, fightPacketLoadPercentNotice, &info.LoadPercentOutboundInfo{
Id: c.GetInfo().UserID,
Percent: uint32(percent),
})