enjine 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -1
- data/README.md +2 -1
- data/docs/ARCHITECTURE.md +2 -0
- data/docs/DESIGN.md +12 -5
- data/docs/MECHANICS_COVERAGE.md +32 -4
- data/docs/guides/api.md +51 -0
- data/docs/guides/card-data-format.md +21 -1
- data/docs/guides/deck-builder.md +18 -0
- data/docs/plans/commander.md +63 -0
- data/docs/reference/decisions.md +5 -1
- data/lib/enjine/actions/cast.rb +2 -1
- data/lib/enjine/card_definition.rb +24 -3
- data/lib/enjine/cli/text.rb +23 -1
- data/lib/enjine/cli.rb +2 -1
- data/lib/enjine/color_identity.rb +38 -0
- data/lib/enjine/decisions/commander_zone.rb +36 -0
- data/lib/enjine/deck.rb +73 -14
- data/lib/enjine/deck_builder.rb +62 -18
- data/lib/enjine/engine/casting/alt_casting.rb +1 -0
- data/lib/enjine/engine/casting/permissions.rb +2 -2
- data/lib/enjine/engine/commander.rb +125 -0
- data/lib/enjine/engine/damage.rb +1 -0
- data/lib/enjine/engine/emblems.rb +1 -1
- data/lib/enjine/engine/pregame.rb +1 -0
- data/lib/enjine/engine/priority.rb +1 -0
- data/lib/enjine/engine/rules.rb +1 -1
- data/lib/enjine/engine/state_based_actions.rb +1 -0
- data/lib/enjine/engine/triggers.rb +1 -1
- data/lib/enjine/engine/zones.rb +1 -0
- data/lib/enjine/format.rb +53 -0
- data/lib/enjine/fuzz.rb +17 -0
- data/lib/enjine/game.rb +4 -3
- data/lib/enjine/player.rb +2 -1
- data/lib/enjine/rules_monitor.rb +25 -1
- data/lib/enjine/setup.rb +10 -4
- data/lib/enjine/snapshot/player_checks.rb +47 -0
- data/lib/enjine/snapshot.rb +4 -1
- data/lib/enjine/state.rb +33 -14
- data/lib/enjine/version.rb +1 -1
- data/lib/enjine/view.rb +18 -1
- data/lib/enjine.rb +2 -0
- metadata +6 -1
data/lib/enjine/player.rb
CHANGED
|
@@ -17,7 +17,8 @@ module Enjine
|
|
|
17
17
|
}
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
# Whether the deck is legal for `format` (Enjine::Format).
|
|
21
|
+
def ready?(format = Format::CONSTRUCTED) = @deck.valid?(format)
|
|
21
22
|
|
|
22
23
|
# True while any game this player is seated in has not ended.
|
|
23
24
|
def playing? = @games.keys.any? { |game| !game.over? }
|
data/lib/enjine/rules_monitor.rb
CHANGED
|
@@ -22,6 +22,8 @@ module Enjine
|
|
|
22
22
|
@stats = Hash.new(0)
|
|
23
23
|
@lands_this_turn = Hash.new(0)
|
|
24
24
|
@loyalty_activations = Hash.new(0)
|
|
25
|
+
@commander_casts = Hash.new(0)
|
|
26
|
+
@cast_from_command = []
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
def state = @game.state
|
|
@@ -109,6 +111,7 @@ module Enjine
|
|
|
109
111
|
|
|
110
112
|
def zone_changed!(event)
|
|
111
113
|
land_played!(event) if event.reason == "play_land"
|
|
114
|
+
@cast_from_command << event.new_id if event.reason == "cast" && event.from == "command"
|
|
112
115
|
return unless event.reason == "resolve" && event.to == "graveyard" && defn(event.card).permanent?
|
|
113
116
|
|
|
114
117
|
finding("608.3", "permanent spell #{event.card} went to the graveyard on resolution")
|
|
@@ -144,6 +147,7 @@ module Enjine
|
|
|
144
147
|
def spell_cast!(event)
|
|
145
148
|
card = defn(event.card)
|
|
146
149
|
@stats["cast:#{event.card}"] += 1
|
|
150
|
+
@commander_casts[event.player] += 1 if @cast_from_command.delete(event.object) # CR 903.8
|
|
147
151
|
return if card.instant_speed? || event.during_resolution # CR 608.2g: timing doesn't apply
|
|
148
152
|
|
|
149
153
|
caster = event.player
|
|
@@ -181,7 +185,7 @@ module Enjine
|
|
|
181
185
|
end
|
|
182
186
|
|
|
183
187
|
# Permanents and emblems, whose static abilities function in the command zone (CR 114.4).
|
|
184
|
-
def static_holders = state.battlefield +
|
|
188
|
+
def static_holders = state.battlefield + state.emblem_ids
|
|
185
189
|
|
|
186
190
|
# The static abilities of permanents on the battlefield and emblems that apply to `obj` now, matched on printed types.
|
|
187
191
|
def applying_statics(obj)
|
|
@@ -252,6 +256,26 @@ module Enjine
|
|
|
252
256
|
check_damage_life!
|
|
253
257
|
check_sba! if @game.pending_decision&.kind == "priority"
|
|
254
258
|
check_hand_size!
|
|
259
|
+
check_commander!
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# CR 903.8, 903.10a, independently of the engine's counters: the casts from the command zone seen as events
|
|
263
|
+
# are the tax's count, and nobody survives 21 combat damage from one commander.
|
|
264
|
+
def check_commander!
|
|
265
|
+
return unless state.format.commander?
|
|
266
|
+
|
|
267
|
+
state.players.each do |pl|
|
|
268
|
+
casts = @commander_casts[pl.name]
|
|
269
|
+
if pl.commander_casts.to_i != casts
|
|
270
|
+
finding("903.8",
|
|
271
|
+
"#{pl.name} has cast their commander #{casts} times but the tax counts #{pl.commander_casts.to_i}")
|
|
272
|
+
end
|
|
273
|
+
next if pl.lost || state.over?
|
|
274
|
+
|
|
275
|
+
finding("903.10a", "#{pl.name} survived 21 combat damage from one commander") if (pl.commander_damage || {}).values.any? do
|
|
276
|
+
it >= 21
|
|
277
|
+
end
|
|
278
|
+
end
|
|
255
279
|
end
|
|
256
280
|
|
|
257
281
|
# CR 613.4, recomputed independently: printed (or a 7b setting effect) + counters + active pump effects
|
data/lib/enjine/setup.rb
CHANGED
|
@@ -8,15 +8,19 @@ module Enjine
|
|
|
8
8
|
#
|
|
9
9
|
# The catalog and decklists are captured at compile time and shared by every game,
|
|
10
10
|
# so later deck edits never affect an existing Setup.
|
|
11
|
+
#
|
|
12
|
+
# `format:` picks the rules (Enjine::Format): constructed by default; `:duel_commander` plays Commander
|
|
13
|
+
# (CR 903), and each deck then names its commander.
|
|
11
14
|
class Setup
|
|
12
|
-
attr_reader :players, :catalog, :decklists, :outside
|
|
15
|
+
attr_reader :players, :catalog, :decklists, :outside, :format, :commanders
|
|
13
16
|
|
|
14
|
-
def initialize(*players)
|
|
17
|
+
def initialize(*players, format: Format::CONSTRUCTED)
|
|
18
|
+
@format = Format.fetch(format)
|
|
15
19
|
players = players.flatten
|
|
16
20
|
raise ArgumentError, "a game needs exactly 2 players" unless players.size == 2
|
|
17
21
|
raise ArgumentError, "player names must differ" if players.map(&:name).uniq.size != 2
|
|
18
22
|
|
|
19
|
-
players.each { |p| raise PlayerNotReady.new(p.deck.errors, name: p.name) unless p.ready? }
|
|
23
|
+
players.each { |p| raise PlayerNotReady.new(p.deck.errors(@format), name: p.name) unless p.ready?(@format) }
|
|
20
24
|
|
|
21
25
|
@players = players.freeze
|
|
22
26
|
@catalog = Catalog.new
|
|
@@ -24,13 +28,15 @@ module Enjine
|
|
|
24
28
|
@catalog.freeze
|
|
25
29
|
@decklists = players.map { |p| p.deck.card_ids.freeze }.freeze
|
|
26
30
|
@outside = players.map { |p| p.deck.outside_ids.freeze }.freeze # CR 400.11a: the cards they own outside the game
|
|
31
|
+
@commanders = players.map { |p| p.deck.commander }.freeze # CR 903.3: the card each player leads with, or nil
|
|
27
32
|
freeze
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
def names = @players.map(&:name)
|
|
31
36
|
|
|
32
37
|
def new_game(seed:)
|
|
33
|
-
Game.start(catalog: @catalog, names: names, decklists: @decklists, seed: seed, outside: @outside
|
|
38
|
+
Game.start(catalog: @catalog, names: names, decklists: @decklists, seed: seed, outside: @outside,
|
|
39
|
+
format: @format, commanders: @commanders).tap do |game|
|
|
34
40
|
@players.each { |p| p.seat(game) }
|
|
35
41
|
end
|
|
36
42
|
end
|
|
@@ -38,6 +38,53 @@ module Enjine
|
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
# The format and the commanders (CR 903.3): constructed has none; a Commander game has one per player, and
|
|
42
|
+
# only a player's own commander card (besides emblems, CR 114.1) is ever in the command zone. Absent in
|
|
43
|
+
# snapshots of constructed games.
|
|
44
|
+
def build_commanders(state, data)
|
|
45
|
+
state.format = Format.fetch(data.fetch("format", Format::CONSTRUCTED.name))
|
|
46
|
+
state.commanders = data.fetch("commanders", [nil, nil]).dup.freeze
|
|
47
|
+
state.commander_returns = data.fetch("commander_returns", []).dup
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def validate_commanders(data, catalog, errors)
|
|
51
|
+
format = Format::ALL.find { it.name == data.fetch("format", Format::CONSTRUCTED.name) }
|
|
52
|
+
return errors << "format: unknown #{data["format"].inspect}" unless format
|
|
53
|
+
|
|
54
|
+
commanders = data.fetch("commanders", [nil, nil])
|
|
55
|
+
listed = commanders.is_a?(Array) && commanders.size == 2 && commanders.all? { it.nil? || (it.is_a?(String) && catalog[it]&.id == it) }
|
|
56
|
+
return errors << "commanders: must be a list of 2 card ids or nulls" unless listed
|
|
57
|
+
|
|
58
|
+
errors << "commanders: a Commander game has one each (CR 903.3)" if format.commander? && commanders.any?(&:nil?)
|
|
59
|
+
errors << "commanders: only a Commander game has them (CR 903.3)" if !format.commander? && commanders.any?
|
|
60
|
+
return unless errors.empty? # the objects and players are well formed
|
|
61
|
+
|
|
62
|
+
validate_commander_zone(data, commanders, errors)
|
|
63
|
+
validate_commander_progress(data, commanders, errors)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def validate_commander_zone(data, commanders, errors)
|
|
67
|
+
data["objects"].each do |obj|
|
|
68
|
+
next unless obj["zone"].to_s == "command" && obj.fetch("kind", "card") == "card"
|
|
69
|
+
|
|
70
|
+
unless commanders[obj["owner"]] == obj["card"]
|
|
71
|
+
errors << "#{obj["id"]}: only emblems and its owner's commander are in the command zone (CR 114.1, 903.6)"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Casts from the command zone (CR 903.8) and combat damage by each commander (CR 903.10a).
|
|
77
|
+
def validate_commander_progress(data, commanders, errors)
|
|
78
|
+
data["players"].each_with_index do |pl, i|
|
|
79
|
+
path = "players[#{i}]"
|
|
80
|
+
casts = pl.fetch("commander_casts", 0)
|
|
81
|
+
errors << "#{path}.commander_casts: must be a non-negative integer" unless non_negative?(casts)
|
|
82
|
+
damage = pl.fetch("commander_damage", {})
|
|
83
|
+
ok = damage.is_a?(Hash) && damage.all? { |card, n| commanders.include?(card) && non_negative?(n) }
|
|
84
|
+
errors << "#{path}.commander_damage: must map commander card ids to non-negative integers" unless ok
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
41
88
|
# Pool mana kept apart: restricted (CR 106.6) and/or kept until end of combat (CR 702.189a):
|
|
42
89
|
# [{"mana" => "C", "spend_only" => {...}, "until" => "end_of_combat"}]; absent in older snapshots.
|
|
43
90
|
def validate_restricted_mana(list, errors, path)
|
data/lib/enjine/snapshot.rb
CHANGED
|
@@ -29,6 +29,7 @@ module Enjine
|
|
|
29
29
|
validate_extra_turns(data, errors)
|
|
30
30
|
validate_extra_phases(data, errors)
|
|
31
31
|
validate_outside(data, catalog, errors)
|
|
32
|
+
validate_commanders(data, catalog, errors)
|
|
32
33
|
errors
|
|
33
34
|
end
|
|
34
35
|
|
|
@@ -59,6 +60,7 @@ module Enjine
|
|
|
59
60
|
state.extra_turns = deep_copy(data.fetch("extra_turns", { "queue" => [], "begun" => [] }))
|
|
60
61
|
state.extra_phases = deep_copy(data.fetch("extra_phases", State.no_extra_phases))
|
|
61
62
|
state.outside_lists = data.fetch("outside_lists", [[], []]).map { |l| l.dup.freeze }.freeze
|
|
63
|
+
build_commanders(state, data)
|
|
62
64
|
state.repeat_cleanup = data.fetch("repeat_cleanup", false)
|
|
63
65
|
state.combat_damage_pass = data["combat_damage_pass"]
|
|
64
66
|
state.attacks_declared = data.fetch("attacks_declared", 0)
|
|
@@ -100,6 +102,8 @@ module Enjine
|
|
|
100
102
|
pl.designations = hash.fetch("designations", []).dup # CR 702.195b (Engine::Designations)
|
|
101
103
|
pl.counters = hash.fetch("counters", {}).dup # CR 122.1: counters other than poison
|
|
102
104
|
pl.pool_sources = deep_copy(hash.fetch("pool_sources", [])) # Engine::ManaSources#add_mana!
|
|
105
|
+
pl.commander_casts = hash["commander_casts"] # CR 903.8; absent: never cast from the command zone
|
|
106
|
+
pl.commander_damage = hash["commander_damage"]&.dup # CR 903.10a; absent: none dealt
|
|
103
107
|
end
|
|
104
108
|
end
|
|
105
109
|
|
|
@@ -192,7 +196,6 @@ module Enjine
|
|
|
192
196
|
errors << "#{path}: #{kind}s can only exist in the #{home} zone" unless zone == home
|
|
193
197
|
errors << "#{path}.ability: must be an ability reference" unless obj["ability"].is_a?(String)
|
|
194
198
|
end
|
|
195
|
-
errors << "#{path}: only emblems are in the command zone (CR 114.1)" if zone == "command" && kind != "emblem"
|
|
196
199
|
counters = obj.fetch("counters", {})
|
|
197
200
|
unless counters.is_a?(Hash) && counters.all? { |k, v| Mechanics::Counters.valid?(k) && non_negative?(v) }
|
|
198
201
|
errors << "#{path}.counters: must map counter kinds to non-negative integers"
|
data/lib/enjine/state.rb
CHANGED
|
@@ -31,7 +31,9 @@ module Enjine
|
|
|
31
31
|
:speed, # nil (no speed) or 1-4 (CR 702.179), see Engine::Speed
|
|
32
32
|
:designations, # player designations, e.g. "enduring_story" (CR 702.195b), see Engine::Designations
|
|
33
33
|
:counters, # nil or {kind => n}: counters other than poison (CR 122.1), see Engine#add_player_counters!
|
|
34
|
-
:pool_sources
|
|
34
|
+
:pool_sources, # nil or [{"mana", "from"}]: sources of pool mana made by artifacts (Engine#add_mana!)
|
|
35
|
+
:commander_casts, # nil or n: times they cast their commander from the command zone (CR 903.8)
|
|
36
|
+
:commander_damage) do # nil or {commander card id => n}: combat damage dealt to them by each (CR 903.10a)
|
|
35
37
|
def zone(name)
|
|
36
38
|
case name
|
|
37
39
|
when :library then library
|
|
@@ -57,14 +59,15 @@ module Enjine
|
|
|
57
59
|
def optional_h
|
|
58
60
|
{ "speed" => speed, "designations" => designations.to_a.empty? ? nil : designations.dup,
|
|
59
61
|
"counters" => counters.nil? || counters.empty? ? nil : counters.dup,
|
|
60
|
-
"pool_sources" => pool_sources.nil? || pool_sources.empty? ? nil : deep(pool_sources)
|
|
62
|
+
"pool_sources" => pool_sources.nil? || pool_sources.empty? ? nil : deep(pool_sources),
|
|
63
|
+
"commander_casts" => commander_casts&.positive? ? commander_casts : nil,
|
|
64
|
+
"commander_damage" => commander_damage.nil? || commander_damage.empty? ? nil : commander_damage.dup }.compact
|
|
61
65
|
end
|
|
62
66
|
end
|
|
63
67
|
|
|
64
68
|
# The complete, mutable state of one game. Plain data only: everything here
|
|
65
69
|
# round-trips through #to_h / Snapshot.load, and Marshal copies it cheaply.
|
|
66
70
|
class State
|
|
67
|
-
STARTING_LIFE = 20
|
|
68
71
|
PLAYER_ZONES = %i[library hand graveyard].freeze
|
|
69
72
|
# `phased_out` is not a zone of the rules: phased-out permanents are on the battlefield but treated as
|
|
70
73
|
# though they don't exist (CR 702.26b, 702.26d), so they are kept apart from `battlefield`. The command
|
|
@@ -82,20 +85,25 @@ module Enjine
|
|
|
82
85
|
# The definition ids each player started the game with outside it (CR 400.11a, 100.4), like
|
|
83
86
|
# `decklists`: a restart begins from these again. What is still outside is PlayerState#outside.
|
|
84
87
|
attr_accessor :outside_lists
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
# The rules the game was set up with (Enjine::Format), and each player's commander card id or nil (CR 903.3).
|
|
89
|
+
# Like `decklists`, a restart begins from these again.
|
|
90
|
+
attr_accessor :format, :commanders
|
|
91
|
+
# Object ids of commanders put into a graveyard, exile, hand or library since state-based actions were last
|
|
92
|
+
# checked, whose owner may still send them to the command zone (CR 903.9, Engine::Commander).
|
|
93
|
+
attr_accessor :commander_returns
|
|
94
|
+
|
|
95
|
+
def self.initial(names:, decklists:, seed:, outside: nil, format: Format::CONSTRUCTED, commanders: nil)
|
|
87
96
|
state = new
|
|
97
|
+
state.format = format
|
|
98
|
+
state.commanders = (commanders || names.map { nil }).freeze
|
|
99
|
+
state.commander_returns = []
|
|
88
100
|
state.seed = seed
|
|
89
101
|
state.rng = Rng.from_seed(seed)
|
|
90
102
|
state.decklists = decklists.map { |l| l.dup.freeze }.freeze
|
|
91
103
|
state.outside_lists = (outside || names.map { [] }).map { |l| l.dup.freeze }.freeze
|
|
92
|
-
state.players = names.each_with_index.map { |name, i| new_player(name, state.outside_lists[i]) }
|
|
104
|
+
state.players = names.each_with_index.map { |name, i| new_player(name, state.outside_lists[i], format.starting_life) }
|
|
93
105
|
state.objects = {}
|
|
94
|
-
state.
|
|
95
|
-
state.stack = []
|
|
96
|
-
state.exile = []
|
|
97
|
-
state.phased_out = []
|
|
98
|
-
state.command = []
|
|
106
|
+
SHARED_ZONES.each { state.public_send("#{it}=", []) }
|
|
99
107
|
state.attackers = {}
|
|
100
108
|
state.blockers = {}
|
|
101
109
|
state.effects = []
|
|
@@ -119,8 +127,8 @@ module Enjine
|
|
|
119
127
|
# with after them (Engine::TurnStructure); "combats" counts combat phases begun this turn.
|
|
120
128
|
def self.no_extra_phases = { "pending" => [], "queue" => [], "combats" => 0 }
|
|
121
129
|
|
|
122
|
-
def self.new_player(name, outside = [])
|
|
123
|
-
PlayerState.new(name: name, life:
|
|
130
|
+
def self.new_player(name, outside = [], life = Format::CONSTRUCTED.starting_life)
|
|
131
|
+
PlayerState.new(name: name, life: life, poison: 0, library: [], hand: [], graveyard: [],
|
|
124
132
|
mana_pool: Mana.empty_pool, lands_played: 0, drew_from_empty: false, lost: nil,
|
|
125
133
|
mulligans: 0, kept: false, mulligan_choice: nil, turn_log: {}, game_log: {}, last_turn_log: {}, restricted_mana: [],
|
|
126
134
|
outside: outside.dup)
|
|
@@ -131,6 +139,10 @@ module Enjine
|
|
|
131
139
|
end
|
|
132
140
|
|
|
133
141
|
def object(id) = objects.fetch(id)
|
|
142
|
+
|
|
143
|
+
# The emblems in the command zone: the only objects there whose abilities function (CR 114.4, 113.6). A
|
|
144
|
+
# commander waiting there (CR 903.6) has none that do.
|
|
145
|
+
def emblem_ids = (command || []).select { objects[it]&.kind == "emblem" }
|
|
134
146
|
def opponent(index) = 1 - index
|
|
135
147
|
def over? = !result.nil?
|
|
136
148
|
|
|
@@ -145,7 +157,14 @@ module Enjine
|
|
|
145
157
|
"attackers" => attackers.dup, "blockers" => blockers.dup, "effects" => effects.map { deep_dup(it) },
|
|
146
158
|
**DEEP_FIELDS.to_h { [it, deep_dup(public_send(it))] },
|
|
147
159
|
"repeat_cleanup" => repeat_cleanup, "combat_damage_pass" => combat_damage_pass,
|
|
148
|
-
"attacks_declared" => attacks_declared }.merge("outside_lists" => (outside_lists || []).map(&:dup))
|
|
160
|
+
"attacks_declared" => attacks_declared }.merge("outside_lists" => (outside_lists || []).map(&:dup)).merge(format_h)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# What a Commander game adds to a snapshot; a constructed game's is unchanged.
|
|
164
|
+
def format_h
|
|
165
|
+
return {} unless format.commander?
|
|
166
|
+
|
|
167
|
+
{ "format" => format.name, "commanders" => commanders.dup, "commander_returns" => commander_returns.dup }
|
|
149
168
|
end
|
|
150
169
|
|
|
151
170
|
# Nested fields #to_h deep-copies as they are.
|
data/lib/enjine/version.rb
CHANGED
data/lib/enjine/view.rb
CHANGED
|
@@ -23,7 +23,7 @@ module Enjine
|
|
|
23
23
|
"stack" => state.stack.map { object_view(engine, it) },
|
|
24
24
|
"exile" => state.exile.map { exiled_view(engine, it, viewer) },
|
|
25
25
|
"phased_out" => state.phased_out.map { object_view(engine, it) },
|
|
26
|
-
"command" =>
|
|
26
|
+
"command" => state.command.map { command_view(engine, it) },
|
|
27
27
|
"pending" => pending_view(engine, viewer),
|
|
28
28
|
"result" => state.result&.dup,
|
|
29
29
|
"effects" => state.effects.map { it.except("controller").merge("controller" => engine.name(it["controller"])) },
|
|
@@ -31,6 +31,11 @@ module Enjine
|
|
|
31
31
|
}
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# What is in the command zone, all public: emblems (CR 114) and commanders (CR 903.6).
|
|
35
|
+
def command_view(engine, id)
|
|
36
|
+
engine.object(id).kind == "emblem" ? emblem_view(engine, engine.object(id)) : object_view(engine, id)
|
|
37
|
+
end
|
|
38
|
+
|
|
34
39
|
# An emblem in the command zone (CR 114): public, with its owner and abilities.
|
|
35
40
|
def emblem_view(engine, obj)
|
|
36
41
|
{ "id" => obj.id, "kind" => "emblem", "owner" => engine.name(obj.owner),
|
|
@@ -60,6 +65,7 @@ module Enjine
|
|
|
60
65
|
"graveyard" => player.graveyard.map { object_view(engine, it) }
|
|
61
66
|
}
|
|
62
67
|
view.merge!(public_extras(player))
|
|
68
|
+
view.merge!(commander_view(engine, engine.state.players.index(player)))
|
|
63
69
|
view["hand"] = player.hand.map { object_view(engine, it) } if sees_hand
|
|
64
70
|
view["outside"] = outside_view(engine, player) if sees_hand # CR 400.11a: only its owner knows their sideboard
|
|
65
71
|
view["library"] = player.library.map { object_view(engine, it) } if sees_library
|
|
@@ -74,6 +80,17 @@ module Enjine
|
|
|
74
80
|
"pool_sources" => Snapshot.deep_copy(player.pool_sources) }.reject { |_, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) }
|
|
75
81
|
end
|
|
76
82
|
|
|
83
|
+
# A Commander game's public facts about a player (CR 903): their commander, what it would cost to cast from
|
|
84
|
+
# the command zone (CR 903.8) and the combat damage each commander has dealt them (CR 903.10a).
|
|
85
|
+
def commander_view(engine, index)
|
|
86
|
+
card = engine.state.commanders[index]
|
|
87
|
+
return {} unless card
|
|
88
|
+
|
|
89
|
+
damage = engine.player(index).commander_damage || {}
|
|
90
|
+
{ "commander" => engine.catalog.fetch(card).name, "commander_tax" => engine.commander_tax(index),
|
|
91
|
+
"commander_damage" => damage.to_h { |id, n| [engine.catalog.fetch(id).name, n] } }
|
|
92
|
+
end
|
|
93
|
+
|
|
77
94
|
# The cards a player owns outside the game (CR 400.11a): not objects, so no ids (CR 400.11).
|
|
78
95
|
def outside_view(engine, player)
|
|
79
96
|
player.outside.map do |card|
|
data/lib/enjine.rb
CHANGED
|
@@ -12,6 +12,8 @@ require_relative "enjine/mechanics"
|
|
|
12
12
|
end
|
|
13
13
|
Dir[File.join(__dir__, "enjine/mechanics/**/*.rb")].each { |f| require f }
|
|
14
14
|
require_relative "enjine/characteristics"
|
|
15
|
+
require_relative "enjine/format"
|
|
16
|
+
require_relative "enjine/color_identity"
|
|
15
17
|
require "json"
|
|
16
18
|
require "digest"
|
|
17
19
|
require_relative "enjine/tokens"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enjine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mehmet Cetin
|
|
@@ -30,6 +30,7 @@ files:
|
|
|
30
30
|
- docs/guides/api.md
|
|
31
31
|
- docs/guides/card-data-format.md
|
|
32
32
|
- docs/guides/deck-builder.md
|
|
33
|
+
- docs/plans/commander.md
|
|
33
34
|
- docs/plans/dsl-gaps.md
|
|
34
35
|
- docs/plans/standard.md
|
|
35
36
|
- docs/reference/abilities.md
|
|
@@ -59,10 +60,12 @@ files:
|
|
|
59
60
|
- lib/enjine/characteristics.rb
|
|
60
61
|
- lib/enjine/cli.rb
|
|
61
62
|
- lib/enjine/cli/text.rb
|
|
63
|
+
- lib/enjine/color_identity.rb
|
|
62
64
|
- lib/enjine/decisions.rb
|
|
63
65
|
- lib/enjine/decisions/bottom.rb
|
|
64
66
|
- lib/enjine/decisions/casting.rb
|
|
65
67
|
- lib/enjine/decisions/combat.rb
|
|
68
|
+
- lib/enjine/decisions/commander_zone.rb
|
|
66
69
|
- lib/enjine/decisions/discard.rb
|
|
67
70
|
- lib/enjine/decisions/effect_choice.rb
|
|
68
71
|
- lib/enjine/decisions/enter_choice.rb
|
|
@@ -90,6 +93,7 @@ files:
|
|
|
90
93
|
- lib/enjine/engine/characteristics.rb
|
|
91
94
|
- lib/enjine/engine/class_levels.rb
|
|
92
95
|
- lib/enjine/engine/combat.rb
|
|
96
|
+
- lib/enjine/engine/commander.rb
|
|
93
97
|
- lib/enjine/engine/copies.rb
|
|
94
98
|
- lib/enjine/engine/damage.rb
|
|
95
99
|
- lib/enjine/engine/defined_power_toughness.rb
|
|
@@ -115,6 +119,7 @@ files:
|
|
|
115
119
|
- lib/enjine/engine/zones.rb
|
|
116
120
|
- lib/enjine/errors.rb
|
|
117
121
|
- lib/enjine/events.rb
|
|
122
|
+
- lib/enjine/format.rb
|
|
118
123
|
- lib/enjine/frames.rb
|
|
119
124
|
- lib/enjine/fuzz.rb
|
|
120
125
|
- lib/enjine/game.rb
|