import { AutoWired , Singleton , Inject } from 'typescript-ioc' ; import { IParty , IPlayer } from '../../../shared/interfaces' ; import { AssetManager } from './asset-manager' ; import { PartyManager } from './party-manager' ; import { PlayerManager } from './player-manager' ; @ Singleton @ AutoWired export class PartyHelper { @ Inject private assetManager : AssetManager ; @ Inject private playerManager : PlayerManager ; @ Inject private partyManager : PartyManager ; public generateName ( ) { return this . assetManager . party ( ) ; } public teleportNear ( player , target ) { player . x = target . x ; player . y = target . y ; player . map = target . map ; } public createParty ( ) { const party = { name : '' , members : [ ] } ; do { party . name = this . generateName ( ) ; } while ( this . partyManager . getParty ( party . name ) ) ; return party ; } public getParty ( partyName ) { return this . partyManager . getParty ( partyName ) ; } public shareParty ( party ) { this . partyManager . addParty ( party ) ; } public removeParty ( party ) { this . partyManager . removeParty ( party ) ; } public playerJoin ( party , player ) { player . $party = party ; party . members . push ( player . name ) ; player . increaseStatistic ( 'Event/Party/Join' , 1 ) ; if ( party . members [ 0 ] !== player . name && player . $personalities . isActive ( 'Telesheep' ) ) { const leader = this . playerManager . getPlayer ( party . members [ 0 ] ) ; player . setPos ( leader . x , leader . y , leader . map , leader . region ) ; } } public playerLeave ( player ) { const party = player . $party ; if ( ! party ) return ; this . disband ( party ) ; } public disband ( party ) { party . members . forEach ( memberName => { const playerRef = this . playerManager . getPlayer ( memberName ) ; if ( ! playerRef ) return ; const leaveChoice = playerRef . $choices . getChoice ( 'PartyLeave' ) ; if ( leaveChoice ) playerRef . $choices . removeChoice ( leaveChoice ) ; playerRef . increaseStatistic ( 'Event/Party/Leave' , 1 ) ; playerRef . $party = null ; } ) ; this . removeParty ( party ) ; } public getPartyLeader ( party ) { return this . playerManager . getPlayer ( party . members [ 0 ] ) ; } }