Skip to content

Commit f7df111

Browse files
committed
Add Land Tax
1 parent 3937187 commit f7df111

16 files changed

+193
-37
lines changed

lib/magic/card_list.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,12 @@ def select(&condition)
9595
def reject(&condition)
9696
self.class.new(super(&condition))
9797
end
98+
99+
# filters are an array of methods to filter by
100+
def filter(filters)
101+
self.class.new(filters.reduce(self) do |cards, filter|
102+
cards.send(filter)
103+
end)
104+
end
98105
end
99106
end

lib/magic/cards/fabled_passage.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,9 @@ def target_choices(receiver)
77
receiver.controller.library.basic_lands
88
end
99

10-
class Choice < Magic::Choice::SearchLibraryForBasicLand
10+
class Choice < Magic::Choice::SearchLibrary
1111
def initialize(actor:)
12-
super(actor: actor, enters_tapped: true)
13-
end
14-
15-
def choices
16-
controller.library.basic_lands
12+
super(actor: actor, to_zone: :battlefield, filter: Filter[:basic_lands], upto: 1, enters_tapped: true)
1713
end
1814

1915
def resolve!(target:)

lib/magic/cards/font_of_fertility.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ module Cards
66
end
77

88
class FontOfFertility < Enchantment
9-
class Choice < Magic::Choice::SearchLibraryForBasicLand
9+
class Choice < Magic::Choice::SearchLibrary
1010
def initialize(actor:)
11-
super(actor: actor, enters_tapped: true)
11+
super(
12+
actor: actor,
13+
to_zone: :battlefield,
14+
enters_tapped: true,
15+
filter: Filter[:basic_lands]
16+
)
1217
end
1318
end
1419

lib/magic/cards/land_tax.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module Magic
2+
module Cards
3+
class LandTax < Enchantment
4+
card_name "Land Tax"
5+
cost white: 1
6+
7+
class UpkeepChoice < Magic::Choice::May
8+
def resolve!
9+
game.add_choice(SearchChoice.new(actor: actor))
10+
end
11+
end
12+
13+
class SearchChoice < Magic::Choice::SearchLibrary
14+
def initialize(actor:)
15+
super(actor: actor, upto: 3, to_zone: :hand, filter: Filter[:basic_lands])
16+
end
17+
end
18+
19+
class BeginningOfYourUpkeepTrigger < TriggeredAbility::BeginningOfYourUpkeep
20+
def should_perform?
21+
opponent_controls_more_lands = game.opponents(controller).any? { _1.lands.count > controller.lands.count }
22+
super && opponent_controls_more_lands
23+
end
24+
25+
def call
26+
game.add_choice(UpkeepChoice.new(actor: actor))
27+
end
28+
end
29+
30+
def event_handlers
31+
{
32+
Events::BeginningOfUpkeep => BeginningOfYourUpkeepTrigger
33+
}
34+
end
35+
end
36+
end
37+
end

lib/magic/cards/rampant_growth.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module Cards
55
end
66

77
class RampantGrowth < Sorcery
8-
class Choice < Magic::Choice::SearchLibraryForBasicLand
8+
class Choice < Magic::Choice::SearchLibrary
99
def initialize(actor:)
10-
super(actor: actor, enters_tapped: true)
10+
super(actor: actor, to_zone: :battlefield, enters_tapped: true, filter: Filter[:basic_lands])
1111
end
1212
end
1313

lib/magic/choice/search_library.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module Magic
2+
class Choice
3+
class SearchLibrary < Choice
4+
extend TargetNormalizer
5+
6+
attr_reader :enters_tapped, :to_zone, :choices, :upto
7+
def initialize(actor:, filter:, enters_tapped: false, upto: 1, to_zone:)
8+
@upto = upto
9+
@to_zone = to_zone
10+
@choices = actor.controller.library.filter(filter)
11+
super(actor: actor)
12+
@enters_tapped = enters_tapped
13+
end
14+
15+
def resolve!(targets:)
16+
case to_zone
17+
when :battlefield
18+
targets.map do |target|
19+
target.resolve!(enters_tapped: enters_tapped)
20+
end
21+
when :hand
22+
targets.map do |target|
23+
target.move_to_hand!
24+
end
25+
end.tap { controller.shuffle! }
26+
end
27+
28+
normalize_targets :resolve!
29+
end
30+
end
31+
end

lib/magic/choice/search_library_for_basic_land.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

lib/magic/events/beginning_of_upkeep.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(player:)
88
end
99

1010
def inspect
11-
"#<Events::BeginningOfUpkeep>"
11+
"#<Events::BeginningOfUpkeep player=#{player}>"
1212
end
1313
end
1414
end

lib/magic/filter.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Magic
2+
class Filter < SimpleDelegator
3+
def self.[](*filters)
4+
new(filters)
5+
end
6+
end
7+
end

lib/magic/target_normalizer.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Magic
2+
module TargetNormalizer
3+
def normalize_targets(method_name)
4+
original_method = instance_method(method_name)
5+
6+
define_method(method_name) do |target: nil, targets: []|
7+
targets = [target] if target
8+
resolutions = original_method.bind(self).call(targets: targets)
9+
target ? resolutions.first : resolutions
10+
end
11+
end
12+
end
13+
end

0 commit comments

Comments
 (0)