package fight import ( "blazing/logic/service/fight/info" "blazing/logic/service/fight/input" ) // BuildFightStateStartEnvelope 构造开战阶段的统一状态包。 func (f *FightC) BuildFightStateStartEnvelope() info.FightStateEnvelope { return f.buildFightStateEnvelope(info.FightStatePhaseStart, 2504) } // BuildFightStateSkillHurtEnvelope 构造技能结算阶段的统一状态包。 func (f *FightC) BuildFightStateSkillHurtEnvelope() info.FightStateEnvelope { envelope := f.buildFightStateEnvelope(info.FightStatePhaseSkillHurt, 2505) envelope.SkillHurt = &info.FightSkillHurtState{ Left: f.collectAttackValues(f.Our), Right: f.collectAttackValues(f.Opp), } return envelope } // BuildFightStateChangeEnvelope 构造切宠阶段的统一状态包。 func (f *FightC) BuildFightStateChangeEnvelope(change info.ChangePetInfo) info.FightStateEnvelope { envelope := f.buildFightStateEnvelope(info.FightStatePhaseChange, 2407) envelope.Change = &change return envelope } // BuildFightStateOverEnvelope 构造结束阶段的统一状态包。 func (f *FightC) BuildFightStateOverEnvelope() info.FightStateEnvelope { envelope := f.buildFightStateEnvelope(info.FightStatePhaseOver, 2506) envelope.Meta.WinnerID = f.FightOverInfo.WinnerId envelope.Meta.Reason = f.FightOverInfo.Reason return envelope } // BuildFightStateLoadEnvelope 构造加载阶段的统一状态包。 func (f *FightC) BuildFightStateLoadEnvelope(userID, percent uint32) info.FightStateEnvelope { envelope := f.buildFightStateEnvelope(info.FightStatePhaseLoad, 2441) envelope.Load = &info.FightLoadState{ UserID: userID, Percent: percent, } return envelope } // BuildFightStateChatEnvelope 构造聊天阶段的统一状态包。 func (f *FightC) BuildFightStateChatEnvelope(senderID uint32, senderNickname, message string) info.FightStateEnvelope { envelope := f.buildFightStateEnvelope(info.FightStatePhaseChat, 50002) envelope.Chat = &info.FightChatState{ SenderID: senderID, SenderNickname: senderNickname, Message: message, } return envelope } // buildFightStateEnvelope 组装左右两侧通用快照和元数据。 func (f *FightC) buildFightStateEnvelope(phase info.FightStatePhase, legacyCmd uint32) info.FightStateEnvelope { if f == nil { return info.FightStateEnvelope{Phase: phase} } return info.FightStateEnvelope{ Phase: phase, Left: snapshotFighterStates(SideOur, f.Our), Right: snapshotFighterStates(SideOpp, f.Opp), Meta: info.FightStateMeta{ Round: uint32(f.Round), WinnerID: f.FightOverInfo.WinnerId, Reason: f.FightOverInfo.Reason, LegacyCmd: legacyCmd, }, } } // snapshotFighterStates 把指定侧的战斗位数组转成统一 fighter 快照。 func snapshotFighterStates(side int, fighters []*input.Input) []info.FighterState { states := make([]info.FighterState, 0, len(fighters)) for position, fighter := range fighters { if fighter == nil { continue } state := info.FighterState{ Side: side, Position: position, } if fighter.Player != nil && fighter.Player.GetInfo() != nil { state.UserID = fighter.Player.GetInfo().UserID } if fighter.AttackValue != nil { state.Status = fighter.AttackValue.Status state.Prop = fighter.AttackValue.Prop } currentPet := fighter.CurrentPet() if currentPet == nil { states = append(states, state) continue } state.ControllerUserID = currentPet.ControllerUserID state.PetID = currentPet.Info.ID state.CatchTime = currentPet.Info.CatchTime state.Name = currentPet.Info.Name state.HP = currentPet.Info.Hp state.MaxHP = currentPet.Info.MaxHp state.Level = currentPet.Info.Level if len(currentPet.Info.SkillList) > 0 { state.Skills = append(state.Skills, currentPet.Info.SkillList...) } states = append(states, state) } return states }