UNPKG

pw-js-world

Version:

An optional package for PW-JS-Api, aims to serve world purposes.

256 lines (255 loc) 5.6 kB
import type { ProtoGen } from "pw-js-api"; import type { Point } from "./types/index.js"; export interface IPlayer { /** * ID of the player. */ playerId: number; /** * ID of the player's account. */ accountId: string; /** * Name of the player. */ username: string; /** * ID of the player's equipped smiley. */ face: number; /** * String, could be an admin or developer. */ role: string; /** * If player is bot user's friend. */ isFriend: boolean; /** * Position of the user. * * Note: This helper does not simulate physics so positions will always be inaccurate. */ position?: Point; /** * If player is the world owner. */ isWorldOwner: boolean; /** * Rights */ rights: IPlayerRights; /** * current world state. */ states: IPlayerWorldState; /** * List of active effects the player has. */ effects: PlayerEffect[]; /** * If this player is the bot. */ isMe: boolean; } export interface IPlayerRights { /** * If the player has edit rights. */ canEdit: boolean; /** * If the player has god rights. */ canGod: boolean; /** * If the player has the ability to toggle minimap. */ canToggleMinimap: boolean; /** * If the player has the ability to change the world settings. */ canChangeWorldSettings: boolean; /** * List of commands (string) the player can use. */ availableCommands: string[]; } export interface IPlayerWorldState { /** * Number of gold coins the player has. */ coinsGold: number; /** * Number of blue coins the player has. */ coinsBlue: number; /** * Number of times the player died. */ deaths: number; /** * Coordinates of collected coins? */ collectedItems: Point[]; /** * If player has gold crown on. */ hasGoldCrown: boolean; /** * If player has won the world. */ hasSilverCrown: boolean; /** * Zero indexed, map of the player's switch state. */ switches: boolean[]; /** * If player is in god mode right now. */ godmode: boolean; /** * If player is in mod mode right now. */ modmode: boolean; /** * ID of the team the player is associated with right now. */ teamId: number; /** * Instance of counters associated with the player. */ counters: PlayerCounters; } export interface IPlayerEffect { /** * The ID of the effect. */ effectId: number; /** * If applicable, the duration of the effect. */ duration?: number; /** * If applicable, the strength of the effect. (For example speed or multi jump effect) */ strength?: number; } export default class Player { /** * ID of the player. */ playerId: number; /** * ID of the player's account. */ accountId: string; /** * Name of the player. */ username: string; /** * ID of the player's equipped smiley. */ face: number; /** * String, could be an admin or developer. */ role: string; /** * If player is bot user's friend. */ isFriend: boolean; /** * Position of the user. * * Note: This helper does not simulate physics so positions will always be inaccurate. */ position?: Point; /** * If player is the world owner. */ isWorldOwner: boolean; /** * Rights */ rights: IPlayerRights; /** * current world state. */ states: IPlayerWorldState; /** * List of active effects the player has. */ effects: PlayerEffect[]; /** * If this player is the bot. */ isMe: boolean; constructor(props: ProtoGen.PlayerProperties, states?: IPlayerWorldState | boolean); /** * This is destructive, this is only for on reset packet. */ resetState(): void; /** * Destructive. */ resetRights(): void; } export declare class PlayerEffect { /** * The ID of the effect. */ effectId: number; /** * If applicable, the duration of the effect. */ duration?: number; /** * If applicable, the strength of the effect. (For example speed or multi jump effect) */ strength?: number; /** * The time the effect occurred. */ triggeredAt: number; constructor(effect: IPlayerEffect, triggeredAt?: number); /** * Note: If this effect is non timed, this will always return false. */ get hasExpired(): boolean; /** * Milliseconds showing how long before this expires. * * Note: If this effect is non timed, this will return infinity. */ get remaining(): number; } /** * Index based */ declare enum CounterKeys { WHITE = 0, GRAY = 1, BLACK = 2, RED = 3, ORANGE = 4, YELLOW = 5, GREEN = 6, CYAN = 7, BLUE = 8, MAGENTA = 9 } export declare class PlayerCounters { readonly scores: number[]; constructor(scores?: number[]); /** * Returns the current score of the player's counter for that colour. * * Can be ID (counter id) or colour (use as predefined). * * If the colour given is unknown, it will error. Capitalisation is irrelevant. */ get(id: number): number | undefined; get(id: keyof typeof CounterKeys): number | undefined; } export {};