Skip to content

Commit

Permalink
Add Dire Fleet Warmonger
Browse files Browse the repository at this point in the history
Fixes #228
  • Loading branch information
radar committed Feb 8, 2024
1 parent 6e2c0bd commit fa198e4
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/magic/battlefield_filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ def battlefield = game.battlefield
def controller = source.controller
def creatures = battlefield.creatures
def creatures_you_control = creatures.controlled_by(controller)
def other_creatures_you_control = creatures_you_control - [source]
end
end
6 changes: 1 addition & 5 deletions lib/magic/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def toughness(power)
end

def keywords(*keywords)
const_set(:KEYWORDS, Keywords[*keywords])
const_set(:KEYWORDS, Keywords.list(*keywords))

include Cards::KeywordHandlers::Prowess if keywords.include?(:prowess)
end
Expand Down Expand Up @@ -89,10 +89,6 @@ def initialize(game: Game.new, owner:)
@controller = @owner = owner
end

def types
type_line.scan(/\w+/)
end

def inspect
"#<Card name:#{name}>"
end
Expand Down
36 changes: 36 additions & 0 deletions lib/magic/cards/dire_fleet_warmonger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Magic
module Cards
class DireFleetWarmonger < Creature
card_name "Dire Fleet Warmonger"
type "Creature -- Orc Pirate"
cost generic: 1, black: 1, red: 1
power 3
toughness 3

class Choice < Magic::Choice
def target_choices
other_creatures_you_control
end

def resolve!(choice:)
trigger_effect(:sacrifice, target: choice)
trigger_effect(:modify_power_toughness, power: 2, toughness: 2, target: source)
trigger_effect(:grant_keyword, keyword: :trample, target: source)
end
end


def event_handlers
{
Events::BeginningOfCombat => -> (receiver, event) do
return unless event.active_player == owner

game.choices.add(DireFleetWarmonger::Choice.new(source: receiver))


end
}
end
end
end
end
8 changes: 6 additions & 2 deletions lib/magic/cards/keywords.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ def initialize(amount)
end
end

def self.[](*keywords)
def self.list(*keywords)
keywords.map do |keyword|
const_get(keyword.upcase)
one(keyword)
end
end

def self.one(keyword)
const_get(keyword.upcase)
end

class KeywordGrant
attr_reader :keyword, :until_eot

Expand Down
4 changes: 2 additions & 2 deletions lib/magic/cards/odric_lunarch_marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def event_handlers
Events::BeginningOfCombat => -> (receiver, event) do
controller = receiver.controller

applicable_keywords = Keywords[
applicable_keywords = Keywords.list(
:first_strike,
:flying,
:deathtouch,
Expand All @@ -25,7 +25,7 @@ def event_handlers
:skulk,
:trample,
:vigilance,
]
)

applicable_keywords.each do |keyword|
next unless controller.creatures.any? { |creature| creature.has_keyword?(keyword) }
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/cards/shared/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def trigger_effect(effect, source: self, **args)
game.add_effect(Effects::Exile.new(source: source, **args))
when :gain_life
game.add_effect(Effects::GainLife.new(source: source, target: source.controller, **args))
when :grant_keyword
game.add_effect(Effects::GrantKeyword.new(source: source, **args))
when :lose_life
game.add_effect(Effects::LoseLife.new(source: source, **args))
when :modify_power_toughness
Expand All @@ -37,6 +39,8 @@ def trigger_effect(effect, source: self, **args)
game.add_effect(Effects::PhaseOut.new(source: source, **args))
when :return_to_owners_hand
game.add_effect(Effects::ReturnToOwnersHand.new(source: source, **args))
when :sacrifice
game.add_effect(Effects::Sacrifice.new(source: source, **args))
when :tap
game.add_effect(Effects::Tap.new(source: source, **args))
else
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/cards/shared/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def artifact_creature_type(types)
type("#{T::Artifact} #{T::Creature} -- #{creature_types(types)}")
end
end

def types
type_line.scan(/\w+/)
end
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/choice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ def initialize(source:)
@source = source
end

def trigger_effect(effect, **args)
source.trigger_effect(effect, **args)
end

def controller = source.controller

def to_s = inspect
Expand Down
17 changes: 17 additions & 0 deletions lib/magic/effects/grant_keyword.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Magic
module Effects
class GrantKeyword < TargetedEffect
attr_reader :keyword

def initialize(keyword:, **args)
super(**args)
@keyword = keyword
end


def resolve!
target.grant_keyword(Keywords.one(keyword))
end
end
end
end
10 changes: 10 additions & 0 deletions lib/magic/effects/sacrifice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Magic
module Effects
class Sacrifice < TargetedEffect
def resolve!
target.sacrifice!
end

end
end
end
6 changes: 1 addition & 5 deletions lib/magic/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def colors(*colors)
end

def keywords(*keywords)
const_set(:KEYWORDS, Keywords[*keywords])
const_set(:KEYWORDS, Keywords.list(*keywords))

include Cards::KeywordHandlers::Prowess if keywords.include?(:prowess)
end
Expand Down Expand Up @@ -93,10 +93,6 @@ def death_triggers
[]
end

def types
type_line.scan(/\w+/)
end

def permanent?
true
end
Expand Down
28 changes: 28 additions & 0 deletions spec/cards/dire_fleet_warmonger_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "spec_helper"

RSpec.describe Magic::Cards::DireFleetWarmonger do
include_context "two player game"

let!(:permanent) { ResolvePermanent("Dire Fleet Warmonger") }
let!(:wood_elves) { ResolvePermanent("Wood Elves") }

context "beginning of combat, may sacrifice another creature" do
before do
skip_to_combat!
end

it "is offered a choice" do
choice = game.choices.last
expect(choice).to be_a(described_class::Choice)
expect(choice.target_choices).to eq([wood_elves])

game.resolve_choice!(choice: wood_elves)

expect(wood_elves.card.zone).to be_graveyard

expect(permanent.power).to eq(5)
expect(permanent.toughness).to eq(5)
expect(permanent.trample?).to eq(true)
end
end
end

0 comments on commit fa198e4

Please sign in to comment.