diff options
| author | Jérémy Zurcher <jeremy@asynk.ch> | 2026-03-15 10:57:18 +0100 |
|---|---|---|
| committer | Jérémy Zurcher <jeremy@asynk.ch> | 2026-03-15 10:57:18 +0100 |
| commit | e4e09f936d38a89082f40354fdf451ad875baffa (patch) | |
| tree | 0b80d727e6e75fb46cc0b7f193dca24465baddb5 /lib/colonial_twilight/actions/action.rb | |
| parent | 7d7db184eacd1407c87d01355ae587acccccf7ac (diff) | |
| download | colonial-twilight-e4e09f936d38a89082f40354fdf451ad875baffa.zip colonial-twilight-e4e09f936d38a89082f40354fdf451ad875baffa.tar.gz | |
Rally & Agitate action classes
Diffstat (limited to 'lib/colonial_twilight/actions/action.rb')
| -rw-r--r-- | lib/colonial_twilight/actions/action.rb | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/colonial_twilight/actions/action.rb b/lib/colonial_twilight/actions/action.rb new file mode 100644 index 0000000..3be8483 --- /dev/null +++ b/lib/colonial_twilight/actions/action.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +module ColonialTwilight + module Actions + class GameAction + def initialize(faction:, space:, cost: 0, mode: nil) + @data = { + faction: faction, + space: space, + cost: cost, + mode: mode + } + validate! + end + + def faction + @data[:faction] + end + + def space + @data[:space] + end + + def cost + @data[:cost] + end + + def mode + @data[:mode] + end + + def to_h + @data.merge(type: self.class.name.split('::')[-1]) + end + + def validate! + raise "not applicable to #{@data[:space]}" unless self.class.applicable?(@data[:space]) + + available = self.class.available_modes(@data[:space]) + @data[:mode].each do |key, value| + raise "mode: #{key} is not available" unless available.key?(key) + + max_allowed = available[key] + raise "value: #{key} set to #{value}, max is #{max_allowed}" if value > max_allowed + end + end + + def apply! + raise NotImplementedError + end + + def revert! + raise NotImplementedError + end + + class << self + def op? + false + end + + def special? + false + end + + def applicable?(space) + raise NotImplementedError + end + + def available_modes(_space) + nil + end + + def possible_spaces(board) + board.search(&method(:applicable?)) + end + end + end + end +end |
