programming-game
Version:
The client for programming game, an mmorpg that you interact with entirely through code.
60 lines (59 loc) • 2 kB
TypeScript
import { BatchedEvents, Boundary, ClientSideUnit, EventMap, GameObject, InstanceName, Intent, PlayersSeekingParty, RawEvents, OnTick } from "./types";
export type OnEvent = <T extends keyof RawEvents>(instance: InstanceName, charId: string, eventName: T, evt: RawEvents[T]) => void;
export type SetIntent = (intent: {
c: string;
i: InstanceName;
intent: Intent;
unitId: string;
}) => void;
/**
* Base class for the client.
* This class cares about the events, but NOT the implementation of the events.
* Helpful for testing the server/client integration without firing up websockets.
*/
export declare class BaseClient {
private onTick;
private heartBeatInterval?;
private setIntent;
private onEvent?;
constructor({ onTick, onEvent, setIntent, tickInterval, }: {
onTick: OnTick;
onEvent?: OnEvent;
setIntent: SetIntent;
/**
* Controls how often onTick is called when there's no new data from the server.
*/
tickInterval: number;
});
private lastOnTick;
protected innerState: {
gameTime: number;
instances: {
[key: string]: {
time: number;
characters: Record<string, {
units: Record<string, ClientSideUnit>;
gameObjects: Record<string, GameObject>;
}>;
playersSeekingParty: PlayersSeekingParty;
boundary?: Boundary;
};
};
arenaDurations: Record<string, number>;
};
private initializeInstance;
clearState: () => void;
eventsHandler: (events: BatchedEvents) => void;
runOnTick: () => void;
/**
* Handles events coming from the server.
*/
socketEventHandlers: EventMap;
private updateUnit;
/**
* Called when the unit completes a cast, or craft, or other action that takes time.
*/
private clearUnitActions;
private updateNpc;
private updatePlayer;
}