A "MMORTS" game built on my Monxterz.StatePlatform back-end. The back-end is responsible for maintaining state and enforcing state mutation rules. However the back-end remains agnostic to specifics about the particular game.
JS scripts define state mutation rules. These scripts run on the server in a sandbox. Check out the following examples for how state is mutated and maintained.
let state = game.state(entity);
state.type = 'Character';
state.hp = 100;
state.xp = 0;
const attackerEntity = context.entities[0];
const attacker = game.state(attackerEntity);
const defenderEntity = context.entities[1];
const defender = game.state(defenderEntity);
defender.hp -= attacker.strength;
if (isDead(defender)) {
defender.hp = 0;
defender.statusMessage = 'Dead';
}
The platform makes testing these scripts straightforward. The tests are written in C# to match the rest of the stack. This might seem a little strange, but these tests use a generated C# GameStateClient which can also be used in the Game UI itself.
GameEntityState character = await game.Create.Character();
var characterState = game.State(character);
Assert.Equal("Character", characterState.type);
Assert.Equal(100, characterState.hp);
Assert.Equal(0, characterState.xp);
game.State(attacker).strength = 13;
game.State(defender).hp = 17;
await game.Call.Attack(attacker, defender);
// Enemy's hp should be reduced by the attacker's strength
Assert.Equal(4, game.State(defender).hp);
You can use the game engine of your choice for the front-end. This example uses Blazor because it makes for very rapid development for me. I have Unity examples as well.
async Task Attack()
{
...
await game.Call.Attack(selectedCharacter.Entity, selectedTheirCharacter.Entity);
...
}
MORTS: Multiplayer Online Real-Time Strategy (Game)