elct9620 / turn-based-game-model-prototype

The turn-based game model prototype for @BasalticStudio NewEra

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Turn-based Game Model Prototype

Test CucumberReports: Trun-based Game Model Prototype

This is designed for the BasalticStudio/NewEra battle system to provide a flexible and replayable implementation.

Demo on Repl.it: https://replit.com/@elct9620/turn-based-game-model-prototype?v=1

Concept

  • The "battle" is a closed system; others should not change its state.
  • All state is changed by "event" therefore we "aggregate events" to replay the state
    • The "event" has the same means as "domain event"
    • The "aggregate events" is the same as "event sourcing"
    • All "events" are "happened"
  • To make the battle changed, we use "service" to create an event
    • The event may be generated by a "command" that calls a service
    • The "service" may be bundled in a "context" to explain the scenario

Models

Battle View

module Battle
  class View
    # ...
    on Events::AttackEvent do |event|
      # ...
    end
  end
end
Column Type Description
id uuid The battle ID
player_id uuid The owner ID
finished_at datetime The battle finish time

Battle Event

The events happened in a battle with the version to sort it

battle = Battle.new # #<Battle id="UUID">
events = Battle::Event.by_id(battle_id: battle.id)

events.each do |event|
  battle.apply(event)
end

# Latest Battle State
Column Type Description
battle_view_id uuid The battle id
type varchar The event type (Rails STI)
version int The event sequence number (unique each battle view)
payload jsonb The event body

Actor

The primary role in the battle is to make interactions.

HealthPoint

The health value of the actor, if equal to zero means dead.

SuccessRate

The rate of success. eg. 50% can escape successful

  • The result will be fixed after created
  • Can be incremented by rate + rate
  • Can get a new result by rate.next

About

The turn-based game model prototype for @BasalticStudio NewEra

License:Apache License 2.0


Languages

Language:Ruby 92.3%Language:Gherkin 7.1%Language:Nix 0.6%