import { Mod } from "../mod" ; export class PartyMember extends Mod { private members : Map < number , boolean > ; private divElement : Array < HTMLDivElement > ; startMod ( ) { this . params = this . settings . option . vip . general ; if ( this . params . party_member_on_map ) { Logger . info ( '- enabled PartyMember' ) ; this . members = new Map ( ) ; this . divElement = [ ] ; const pmomCss = document . createElement ( 'style' ) ; pmomCss . id = 'pmomCss' ; pmomCss . innerHTML = `
                .pmomStatus {
                    width: 15px;
                    height: 30px;
                    position: absolute;
                    bottom: -6px;
                    right: 12px;
                }
                .pmomOnMap {
                    background: url(./assets/ui/server/state_3.png);
                    background-position: center;
                }
                .pmomNotInMap {
                    background: url(./assets/ui/server/state_1.png);
                    background-position: center;
                }
            ` ; this . wGame . document . getElementsByTagName ( 'head' ) [ 0 ] . appendChild ( pmomCss ) ; this . on ( this . wGame . dofus . connectionManager , 'PartyJoinMessage' , ( ) => this . updatePartyMembers ( ) ) ; this . on ( this . wGame . dofus . connectionManager , 'PartyUpdateMessage' , ( ) => this . updatePartyMembers ( ) ) ; this . on ( this . wGame . dofus . connectionManager , 'PartyMemberEjectedMessage' , ( ) => this . updatePartyMembers ( ) ) ; this . on ( this . wGame . dofus . connectionManager , 'PartyMemberRemoveMessage' , ( ) => this . updatePartyMembers ( ) ) ; this . on ( this . wGame . dofus . connectionManager , 'PartyNewMemberMessage' , ( ) => this . updatePartyMembers ( ) ) ; this . on ( this . wGame . dofus . connectionManager , 'GameRolePlayShowActorMessage' , ( e ) => this . updateMember ( e , true ) ) ; this . on ( this . wGame . dofus . connectionManager , 'GameContextRemoveElementMessage' , ( e ) => this . updateMember ( e , false ) ) ; this . on ( this . wGame . dofus . connectionManager , 'MapComplementaryInformationsDataMessage' , ( e ) => this . updateMemberOnMapChange ( e ) ) ; this . updatePartyMembers ( ) ; } } private updateDOM ( ) { let i = 0 ; this . members . forEach ( ( status , memberId ) => { if ( memberId != this . wGame . isoEngine . actorManager . userId ) { const divMember = this . wGame . document . getElementsByClassName ( 'member' ) [ i ] ; this . addStatusToMember ( divMember , status ) ; } i ++ ; } ) ; } private addStatusToMember ( divMember , memberStatus ) { if ( divMember != null ) { const className = memberStatus ? 'pmomOnMap' : 'pmomNotInMap' ; let divStatus = divMember . lastElementChild as any ; if ( divStatus && divStatus . classList . contains ( 'pmomStatus' ) ) { divStatus . classList . replace ( divStatus . classList . item ( 1 ) , className ) ; } else { divStatus = document . createElement ( 'div' ) ; divStatus . className = 'pmomStatus' ; divStatus . classList . add ( className ) ; this . divElement . push ( divStatus ) ; divMember . appendChild ( divStatus ) ; } } } private updatePartyMembers ( ) { const oldMembers = this . members ; this . members . clear ( ) ; if ( this . wGame . gui . party . currentParty && this . wGame . gui . party . currentParty . _childrenList . length > 0 ) { const mapId = this . wGame . isoEngine . mapRenderer . mapId ; this . wGame . gui . party . currentParty . _childrenList . forEach ( ( m ) => { let isOnMap = mapId == m . memberData . mapId ; if ( oldMembers . has ( m . memberData . id ) ) isOnMap = oldMembers . get ( m . memberData . id ) ; this . members . set ( m . memberData . id , isOnMap ) ; } ) ; this . updateDOM ( ) ; } } private updateMember ( data , isOnMap ) { if ( this . wGame . gui . party . currentParty && this . wGame . gui . party . currentParty . _childrenList . length > 0 ) { const playerId = isOnMap ? data . informations . contextualId : data . id ; if ( this . members . has ( playerId ) ) this . members . set ( playerId , isOnMap ) ; this . updateDOM ( ) ; } } private updateMemberOnMapChange ( data ) { if ( this . wGame . gui . party . currentParty && this . wGame . gui . party . currentParty . _childrenList . length > 0 ) { const actorsId = [ ] ; data . actors . forEach ( ( actor ) => { if ( actor . contextualId > 0 ) actorsId . push ( actor . contextualId ) ; } ) ; this . members . forEach ( ( status , member ) => this . members . set ( member , actorsId . includes ( member ) ) ) ; this . updateDOM ( ) ; } } private destroy ( ) { if ( this . divElement != null && this . divElement . length > 0 ) { this . divElement . forEach ( ( e ) => { if ( e != null && e . parentElement ) e . remove ( ) ; } ) ; this . divElement = [ ] ; } } public reset ( ) { super . reset ( ) ; this . destroy ( ) ; const pmomCss = this . wGame . document . getElementById ( 'pmomCss' ) ; if ( pmomCss && pmomCss . parentElement ) pmomCss . parentElement . removeChild ( pmomCss ) ; } }