1.1.4 • Published 3 months ago

tokyoclient-ts v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

tokyoclient-ts

tokyoclient-ts is a Typescript client library for connecting to a Tokyo game server and controlling a ship in the game. It provides functionality to interact with the game server, receive events, and control the ship using a simple bot implementation.

Methods

Controller(): Returns a controller for controlling the game with actions (rotate, throttle, fire).

setGamePlan(callback, perMs): Sets up a game plan by executing the provided function at regular intervals.

setOnOpenfn(): Sets the function to handle 'OnOpen' events for the WebSocket communication.

close(): Closes the WebSocket connection.

Utilities

estimateDistance(): Calculates the Euclidean distance between two players based on their coordinates.

calculateRotationAngle(): Calculates the angle (in radians) a player needs to rotate to face the target player.

Usage

To use tokyoclient-ts, follow these steps:

  1. Install the package using:
npm i tokyoclient-ts`
  1. Initialize the Game client with your credentials
  const client = new TokyoGameClient({
    serverHost: "combat.sege.dev",
    apiKey: "std0101",
    userName: "std0101",
    useSecureConnection: true, // scheme wss: or ws:
  });

  // Initialize the Game client instance
  const client = new TokyoGameClient(config);
  
  // Get your own controller
  const controller = client.Controller();
  1. Implement your own algorithm to respond to how things happen in the map (provided in state object below)
  client.setGamePlan((state) => {
    // can use provided utility functions here
    console.log("Current map state: ", state);
    controller.throttle(0.2);
    const angle = getRandomFloat(0.1, 1.0, 1) * 2 * Math.PI;
    controller.rotate(angle);
    controller.fire();
  }, 1000);
  1. Run your program and observe the client interacting with the Tokyo game server.

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests for any improvements or bug fixes.

1.1.4

3 months ago

1.1.3

6 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago