GithubHelp home page GithubHelp logo

keshav2010 / rtsmultiplayerpoc Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 5.0 3.82 MB

Multiplayer RTS Game Server written in NodeJS . The project serves 2 purpose, first my love for RTS games, 2nd me trying to see how much performance i can squeeze out of nodejs server. Hosted on railway.app, Check out the url below (the url may need some 2-3 refreshes, as it takes a while for the server to spin up from sleep)

Home Page: https://rtsmultiplayerpoc-dev.up.railway.app/

JavaScript 3.22% HTML 6.18% Dockerfile 0.06% TypeScript 90.54%
node-js nodejs-server rts-game rtsp-server xstate game game-development html5 multiplayer-game websocket-game websockets state-machine typescript webpack procedural-generation procedural-map-generator tilemap

rtsmultiplayerpoc's Introduction

RTSMultiplayerPOC

Node.js CI

Multiplayer RTS Dedicated Game Server written in NodeJS for a small-scale game.

Approach

  1. Client send their Inputs/State
  2. Server pushes client requests in a FIFO approach
  3. Server update game state in each tick (gameserver may ideally have a tick rate of say 10, i.e 100ms are allocated for each tick)
  4. Server also builds a cumulativeUpdate packet (delta updates)
  5. Server send back delta updates (stored in cumulativeUpdate array) back to all clients

This is a timestep based approach that makes sure server only send delta updates back to all clients instead of whole game state.

Preview (Debug info is displayed for each unit)

Image from Gyazo

Both the GIFs shows basic boid avoidance behaviour Image from Gyazo

Getting Started

  1. Build the client side code, this includes phaser related code that is used to draw/render game on the browser.

npm run build

  1. Once done, simply run the server.

npx ts-node server.ts

  1. Check the port where server is running and you're good to go.
    1. Create game room
    2. open another window on same url, click on join room (it may take few seconds)

rtsmultiplayerpoc's People

Contributors

keshav2010 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rtsmultiplayerpoc's Issues

Fix Soldiers Attack

Issues in attack code, assumes different state machine (which isn't implemented yet)

Basic Economy and spawn mechanism

Auto spawn units at a dedicated spawn point selected by user during spawn-selection-state.
The cost of spawning unit must be deducted from player's resources, which are also incrementing slowly over period of time.

Improve Soldier Mechanics

  • Fix bug : When selecting more than 1 unit for an attack, only 1 proceeds with the order rest do not follow the command immediately (and requires multiple attempts)
  • Fix : Use UUID to generate soldier unit IDs
  • Fix : Scenario when target unit is killed while some attackers are still in "ChaseTarget" mode. (possible that unit in chaseTarget state can have reference to target that is not registered anymore) ( setAttackTarget, getAttackTarget functions added)

Game Objective Implementation : [Last Man Standing]

Game Mode : Last Man Standing

Last-Man-standing requires player to select their spawn position (by placing their castle on the map)

Each player starts with some 100 resources, and can spend them on following

1. Spawn Soldiers (spearman, knights)
3. Territory Flag
4. Resource Mine

Note: Soldiers are not immediately spawned, rather they are queued and are spawned after their training is completed (takes around 10-15 seconds). Only 1 soldier can be trained at a time.

Territory Flag ๐Ÿด : A TF / Territory-Flag enables you to capture a region, it takes 10 seconds to complete a TF.
It is important to note that other individuals on the map can see your TF during its construction phase.

Resource Mine ๐Ÿ›๏ธ : enables you to increase your storage limit, by default you can only have maximum of 100 resources, and each resource-mine grants you +20 extra storage capacity.
A Resource-Mine can only be built within your territory (that is occupied by building TF or main castle).
Each TF, can have only 1 RM

By destroying enemy's Territory-Flag, and building your own at that point you can get access to their resource-mine.


Economy

All players start with 100 resources.

The rate of growth of resources slowly degrades, and eventually stops. (unless you have a RM)

  • Each Resource-Mine grants you 0.2 resources / second. (exact value may change) (in #39 )

Each Kill grants you same resources as cost of the killed unit. (may change eventually)

There is a upper limit to resources, by default you can have maximum of 100 resources, but each RM grants you +20 extra storage space.

When your RM is captured / destroyed, your storage capacity is immediately affected, therefore if you've 150 resources and your RM is destroyed, your resource will fallback to 100, as well as your resource-growth rate will also be affected.

When you capture enemy's RM, you gain full control of RM, and you also get usual benefits out of it.
When you destroy enemy's RM, you will get limited loot but not all of the resources of an RM.

Ranking

Ranking is based on following parameter
% of area captured + army size

Allies and Conversation

  • Players can send emojis to each other
  • Players can donate their resources to others.

Simple Session/Room implementation

  • - Game Server and Web server (serving HTML) still managed by same node server instance
  • - User can create a session (socket.io namespace) and share sessionId (max 5 people per room, and we can expect each server instance to manage few 100s client connection, good enough for a basic test prototype.
  • - main server spawns child processes (node's cluster module), which are responsible for managing sessions.
  • - unique id for each session, and investigate socket.io's namespace functionality

Game Objective - Capture Flag

CF

  • 1. captures nearby territory
  • 2. can be deleted (player gets back some 70-80% of the resources back)
  • 3. can be destroyed by enemy soldiers (enemy unit gains some resources)
  • 4. **can only be built over unoccupied land

PlayerState --- has-a --- CF

A Player can have atmost 4 CFs

property:

  1. health
  2. state ( READY or IN_PROGRESS)

render scene area seperately at client side

The server side scene where all the soldiers movements are being simulated, should be rendered properly at client side.

as of now, the scene is being rendered as part of the whole canvas, instead it be rendered as an object over which several instances
then are placed (including soldiers, and other units).

This eventually will be transformed to support isometric view later

Implement Isometric View for the game

We'd like the final version to look similar to the phaser example shown here:
image

  1. Backend maintains the quadtree and a 2D representation of scene, and is unaware of the isometric nature.
  2. Backend for now, will have only 1 single scene, though eventually we will be generating maps procedurally.

--

  1. Client renders the isometric view of the scene grid, which it receives from client.

Refactor code for packet handling at server side and refactor related code

  1. Retire PendingUpdateManager
  2. retire seperate queue for server side events and client init packets, all events including server side events should be queued to the same culumativeUpdate array.
  3. code refactoring, mostly related to handling of socket instance associated with a player, remove dependency of GameStateManager over user defined classes to make it more generic and reusable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.