import { ServerPackets , SERVER_PACKETS } from '@airbattle/protocol' ; import { BROADCAST_CHAT_SAY , BROADCAST_CHAT_SAY_REPEAT , CONNECTIONS_SEND_PACKETS , } from '../../../events' ; import { MainConnectionId , PlayerId } from '../../../types' ; import { System } from '../../system' ; export default class ChatSayBroadcast extends System { constructor ( { app } ) { super ( { app } ) ; this . listeners = { [ BROADCAST_CHAT_SAY_REPEAT ] : this . onChatSayRepeat , [ BROADCAST_CHAT_SAY ] : this . onChatSay , } ; } param senderId param recipientId onChatSayRepeat ( senderId , recipientId ) { const sender = this . storage . playerList . get ( senderId ) ; this . onChatSay ( senderId , sender . say . text , recipientId ) ; } param senderId param text onChatSay ( senderId , text , recipientId ? ) { this . log . chatSay ( senderId , text ) ; let recipients = null ; if ( recipientId ) { if ( this . storage . playerMainConnectionList . has ( recipientId ) ) { recipients = this . storage . playerMainConnectionList . get ( recipientId ) ; } else { return ; } } else { recipients = [ ... this . storage . broadcast . get ( senderId ) ] ; } this . emit ( CONNECTIONS_SEND_PACKETS , { c : SERVER_PACKETS . CHAT_SAY , id : senderId , text , } as ServerPackets . ChatSay , recipients ) ; } }