Skip to content

Commit 515adaf

Browse files
authored
Merge pull request #518 from radar/copilot/wittering-marmot
Implement Adventurer's Inn card
2 parents 7e85073 + fc49ac0 commit 515adaf

File tree

14 files changed

+308
-3
lines changed

14 files changed

+308
-3
lines changed

lib/magic/cards/adventurers_inn.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Magic
2+
module Cards
3+
AdventurersInn = Card("Adventurer's Inn") do
4+
type T::Land, T::Lands::Town
5+
6+
enters_the_battlefield do
7+
controller.gain_life(2)
8+
end
9+
end
10+
11+
class AdventurersInn < Card
12+
def enters_tapped?
13+
false
14+
end
15+
16+
class ManaAbility < Magic::TapManaAbility
17+
choices :colorless
18+
end
19+
20+
def activated_abilities = [ManaAbility]
21+
end
22+
end
23+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module Magic
2+
module Cards
3+
BaronAirshipKingdom = Card("Baron, Airship Kingdom") do
4+
type T::Land, T::Lands::Town
5+
end
6+
7+
class BaronAirshipKingdom < Card
8+
def enters_tapped?
9+
true
10+
end
11+
12+
class ManaAbility < Magic::TapManaAbility
13+
choices :blue, :red
14+
end
15+
16+
def activated_abilities = [ManaAbility]
17+
end
18+
end
19+
end

lib/magic/cards/shared/events.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def trigger_effect(effect, source: self, **args)
5959
game.add_effect(Effects::ReturnTargetFromGraveyardToBattlefield.new(source: source, **args))
6060
when :return_to_owners_hand
6161
game.add_effect(Effects::ReturnToOwnersHand.new(source: source, **args))
62+
when :reveal_cards
63+
game.add_effect(Effects::RevealCards.new(source: source, **args))
6264
when :sacrifice
6365
game.add_effect(Effects::Sacrifice.new(source: source, **args))
6466
when :tap

lib/magic/cards/town_greeter.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module Magic
2+
module Cards
3+
TownGreeter = Creature("Town Greeter") do
4+
cost "{1}{G}"
5+
creature_type "Human Citizen"
6+
power 1
7+
toughness 1
8+
9+
enters_the_battlefield do
10+
cards = controller.mill(4)
11+
game.add_choice(TownGreeter::Choice.new(actor: self, milled_cards: cards))
12+
end
13+
end
14+
15+
class TownGreeter
16+
class Choice < Magic::Choice::May
17+
def initialize(actor:, milled_cards:)
18+
super(actor: actor)
19+
@cards = milled_cards
20+
end
21+
22+
def choices
23+
@cards.filter(Filter[:lands])
24+
end
25+
26+
def resolve!(target:)
27+
trigger_effect(:move_card_zone, from: target.zone, target: target, to: controller.hand)
28+
end
29+
end
30+
end
31+
end
32+
end

lib/magic/cards/world_map.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module Magic
2+
module Cards
3+
WorldMap = Artifact("World Map") do
4+
cost generic: 1
5+
end
6+
7+
class WorldMap < Artifact
8+
class BasicLandChoice < Magic::Choice::SearchLibrary
9+
def initialize(actor:)
10+
super(
11+
actor: actor,
12+
to_zone: :hand,
13+
reveal: true,
14+
filter: Filter[:basic_lands]
15+
)
16+
end
17+
end
18+
19+
class LandChoice < Magic::Choice::SearchLibrary
20+
def initialize(actor:)
21+
super(
22+
actor: actor,
23+
to_zone: :hand,
24+
reveal: true,
25+
filter: Filter[:lands]
26+
)
27+
end
28+
end
29+
30+
class SearchForBasicLand < ActivatedAbility
31+
costs "{1}, {T}, Sacrifice {this}"
32+
33+
def resolve!
34+
game.choices.add(BasicLandChoice.new(actor: source))
35+
end
36+
end
37+
38+
class SearchForLand < ActivatedAbility
39+
costs "{3}, {T}, Sacrifice {this}"
40+
41+
def resolve!
42+
game.choices.add(LandChoice.new(actor: source))
43+
end
44+
end
45+
46+
def activated_abilities = [SearchForBasicLand, SearchForLand]
47+
end
48+
end
49+
end

lib/magic/choice/search_library.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ class Choice
33
class SearchLibrary < Choice
44
extend TargetNormalizer
55

6-
attr_reader :enters_tapped, :to_zone, :choices, :upto
7-
def initialize(actor:, filter:, enters_tapped: false, upto: 1, to_zone:)
6+
attr_reader :enters_tapped, :reveal, :to_zone, :choices, :upto
7+
def initialize(actor:, filter:, enters_tapped: false, reveal: false, upto: 1, to_zone:)
88
@upto = upto
9+
@reveal = reveal
910
@to_zone = to_zone
1011
@choices = actor.controller.library.filter(filter)
1112
super(actor: actor)
@@ -19,6 +20,7 @@ def resolve!(targets:)
1920
target.resolve!(enters_tapped: enters_tapped)
2021
end
2122
when :hand
23+
trigger_effect(:reveal_cards, target: targets) if reveal
2224
targets.map do |target|
2325
target.move_to_hand!
2426
end

lib/magic/effects/reveal_cards.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Magic
2+
module Effects
3+
class RevealCards < TargetedEffect
4+
def inspect
5+
"#<Effects::RevealCards player=#{source.controller.name} cards=#{target.map(&:name).join(", ")}>"
6+
end
7+
8+
def resolve!
9+
game.notify!(
10+
Events::CardsRevealed.new(cards: Array(target))
11+
)
12+
end
13+
end
14+
end
15+
end

lib/magic/events/cards_revealed.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Magic
2+
module Events
3+
class CardsRevealed
4+
attr_reader :cards
5+
6+
def initialize(cards:)
7+
@cards = cards
8+
end
9+
10+
def inspect
11+
"#<Events::CardsRevealed cards=#{cards.map(&:name).join(", ")}>"
12+
end
13+
end
14+
end
15+
end

lib/magic/player.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def shuffle!
196196
end
197197

198198
def mill(amount)
199-
amount.times do
199+
cards = amount.times.map do
200200
card = library.mill
201201
card.move_to_graveyard!
202202
game.notify!(
@@ -205,7 +205,10 @@ def mill(amount)
205205
card: card,
206206
)
207207
)
208+
card
208209
end
210+
211+
CardList.new(cards)
209212
end
210213

211214
def scry(amount:, top:, bottom:)

lib/magic/types/lands.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Magic
33
module Types
44
module Lands
55
Gate = "Gate".freeze
6+
Town = "Town".freeze
67
class BasicLand
78
def self.==(other)
89
self.name.split("::").last == other

0 commit comments

Comments
 (0)