mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
refactor(server/players): Take a different approach to multichar
This changes how multicharacter support is implemented entirely. Instead there are now events for creating a new player & unloading a player. These should be called whenever a character is switched. Documentation will be added for `npwd:newPlayer` & `npwd:unloadPlayer`
This commit is contained in:
1 parent
2ec049ca12
commit
268bd4f4a4
11 files changed
+391
-377
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import { CreatePlayerInstance } from './player.interfaces';
|
||||
|
||||
export class Player {
|
||||
public readonly source: number;
|
||||
public readonly username: string;
|
||||
private _phoneNumber: string;
|
||||
private _identifier: string;
|
||||
private _firstname: string | null;
|
||||
private _lastname: string | null;
|
||||
|
||||
constructor({ source, identifier, phoneNumber, username }: CreatePlayerInstance) {
|
||||
this.source = source;
|
||||
this._identifier = identifier;
|
||||
this._phoneNumber = phoneNumber;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public getIdentifier(): string {
|
||||
return this._identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the identifier for a player, useful in systems with multicharacter
|
||||
* players
|
||||
* @param identifier {string} - Set the identifier for a player
|
||||
*/
|
||||
public setIdentifier(identifier: string): Player {
|
||||
this._identifier = identifier;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stored firstname for a user
|
||||
*/
|
||||
public getFirstName(): string | null {
|
||||
return this._firstname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the first name for a user
|
||||
* @param firstname {string} The first name to set for the user
|
||||
**/
|
||||
public setFirstName(firstname: string): Player {
|
||||
this._firstname = firstname;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stored lastname for a user
|
||||
**/
|
||||
public getLastName(): string | null {
|
||||
return this._lastname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the last name for a user
|
||||
* @param lastname {string} The last name to set for the user
|
||||
**/
|
||||
public setLastName(lastname: string): Player {
|
||||
this._lastname = lastname;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full name of the user
|
||||
**/
|
||||
public getName(): string | null {
|
||||
if (!this._firstname || !this._lastname) return null;
|
||||
return `${this._firstname} ${this._lastname}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored phone number for a user
|
||||
**/
|
||||
public getPhoneNumber(): string {
|
||||
return this._phoneNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stored phone number for a user
|
||||
**/
|
||||
public setPhoneNumber(number: string): Player {
|
||||
this._phoneNumber = number;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user