feat(fight): 优化精灵切换逻辑并添加切换动作队列

This commit is contained in:
1
2025-09-19 06:58:42 +00:00
parent 981da549c7
commit 6900c66cb0
2 changed files with 18 additions and 6 deletions

View File

@@ -18,9 +18,11 @@ import (
type FightC struct {
Info info.NoteReadyToFightInfo
ownerID uint32 // 战斗发起者ID
Our *input.Input //始终等于房主ID
Opp *input.Input //对手ID
ownerID uint32 // 战斗发起者ID
Our *input.Input //始终等于房主ID
Opp *input.Input //对手ID
Switch []*ActiveSwitchAction
rand *rand.Rand
StartTime time.Time
actionChan chan BattleActionI // 所有操作统一从这里进入
@@ -237,10 +239,12 @@ func (f *FightC) battleLoop() {
}
if a, isExpelled := action.(*ActiveSwitchAction); isExpelled {
//fmt.Println("对方死亡切换")
f.Broadcast(func(ff *input.Input) {
ff.Player.SendChangePet(a.Reason)
f.Broadcast(func(ff *input.Input) {
if ff.Player.ID() == a.PlayerID { //先给自身广播
ff.Player.SendChangePet(a.Reason)
}
})
if f.GetInputByAction(action, false).CanChange {
@@ -557,8 +561,15 @@ func (f *FightC) enterturn(fattack, sattack BattleActionI) {
}
f.Broadcast(func(ff *input.Input) {
for _, v := range f.Switch {
if ff.Player.ID() != v.PlayerID{
ff.Player.SendChangePet(v.Reason)
}
}
ff.Player.SendAttackValue(ret)
})
f.Switch = []*ActiveSwitchAction{}
}

View File

@@ -43,6 +43,7 @@ func (f *FightC) ChangePet(c common.PlayerI, id uint32) {
ret := &ActiveSwitchAction{
BaseAction: NewBaseAction(c.GetInfo().UserID),
}
f.Switch = append(f.Switch, ret)
f.GetInputByPlayer(c, false).CurrentPet, ret.Reason = f.GetInputByPlayer(c, false).GetPet(id)