import { CTF_FLAG_STATE , CTF_TEAMS , ServerPackets , SERVER_PACKETS } from '@airbattle/protocol' ; import { BROADCAST_GAME_FLAG , CONNECTIONS_SEND_PACKETS } from '../../../../events' ; import { System } from '../../../../server/system' ; import { Flag , PlayerId } from '../../../../types' ; export default class GameFlagBroadcast extends System { constructor ( { app } ) { super ( { app } ) ; this . listeners = { [ BROADCAST_GAME_FLAG ] : this . onGameFlag , } ; } param flagTeam param playerId onGameFlag ( flagTeam , playerId = null ) { let flag = null ; if ( flagTeam === CTF_TEAMS . BLUE ) { flag = this . storage . mobList . get ( this . storage . ctfFlagBlueId ) as Flag ; } else { flag = this . storage . mobList . get ( this . storage . ctfFlagRedId ) as Flag ; } this . emit ( CONNECTIONS_SEND_PACKETS , { c : SERVER_PACKETS . GAME_FLAG , type : flag . owner . current === 0 ? CTF_FLAG_STATE . STATIC : CTF_FLAG_STATE . DYNAMIC , flag : flagTeam , id : flag . owner . current , posX : flag . position . x , posY : flag . position . y , blueteam : this . storage . gameEntity . match . blue , redteam : this . storage . gameEntity . match . red , } as ServerPackets . GameFlag , playerId === null ? [ ... this . storage . mainConnectionIdList ] : this . storage . playerMainConnectionList . get ( playerId ) ) ; } }