Skip to content

Commit

Permalink
Add Pridemalkin
Browse files Browse the repository at this point in the history
Fixes #206
  • Loading branch information
radar committed Apr 11, 2024
1 parent e71ed58 commit 6b1e86b
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/magic/abilities/static/mana_cost_adjustment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Magic
module Abilities
module Static
class ManaCostAdjustment
class ManaCostAdjustment < StaticAbility
attr_reader :source, :adjustment, :applies_to
def initialize(source:, adjustment:, applies_to:)
@source = source
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Magic
module Abilities
module Static
class PowerAndToughnessModification
class PowerAndToughnessModification < StaticAbility
attr_reader :source, :power, :toughness, :applicable_targets
def initialize(source:, power:, toughness:, applicable_targets:)
@source = source
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/bog_badger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ETB < TriggeredAbility::EnterTheBattlefield
def perform
if actor.kicked?
controller.creatures.each do |creature|
creature.grant_keyword(:menace, until_eot: true)
creature.grant_keyword(Keywords::MENACE, until_eot: true)
end
end
end
Expand Down
53 changes: 53 additions & 0 deletions lib/magic/cards/pridemalkin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Magic
module Cards
class Pridemalkin < Creature
card_name "Pridemalkin"
cost "{2}{G}"
type "Creature -- Cat"
power 2
toughness 1

class Choice < Magic::Choice
def choices
Magic::Targets::Choices.new(
choices: game.battlefield.by_any_type(T::Creature).controlled_by(owner),
amount: 1
)
end

def resolve!(target:)
actor.trigger_effect(
:add_counter,
source: actor,
target: target,
counter_type: Counters::Plus1Plus1
)
end
end

enters_the_battlefield do
game.choices.add(Choice.new(actor: actor))
end

class TrampleAddition < StaticAbility
def initialize(source:)
@source = source
end

def keywords
[Cards::Keywords::TRAMPLE]
end

def applies_to?(permanent)
permanent.counters.of_type(Magic::Counters::Plus1Plus1).any?
end

def applicable_targets
source.controller.creatures
end
end

def static_abilities = [TrampleAddition]
end
end
end
5 changes: 4 additions & 1 deletion lib/magic/cards/watcher_of_the_spheres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ReduceManaCost < Abilities::Static::ManaCostAdjustment
def initialize(source:)
@source = source
@adjustment = { generic: -1 }
@applies_to = -> (c) { c.flying? }
end

def applies_to?(card)
card.is_a?(Card) && card.flying?
end
end

Expand Down
2 changes: 0 additions & 2 deletions lib/magic/permanent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Permanent
:protections,
:modifiers,
:counters,
:keywords,
:keyword_grants,
:activated_abilities,
:state_triggered_abilities,
Expand Down Expand Up @@ -67,7 +66,6 @@ def initialize(game:, owner:, card:, token: false, cast: true, kicked: false, co
@attachments = []
@modifiers = []
@tapped = false
@keywords = card.keywords
@keyword_grants = card.keyword_grants
@counters = Counters::Collection.new([])
@damage = 0
Expand Down
6 changes: 5 additions & 1 deletion lib/magic/permanents/creature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def toughness
static_ability_mods.sum(&:toughness)
end

def keywords
card.keywords + static_ability_mods.flat_map(&:keywords)
end

def take_damage(damage)
@damage += damage
end
Expand All @@ -60,7 +64,7 @@ def attacking?
end

def static_ability_mods
game.battlefield.static_abilities.of_type(Abilities::Static::PowerAndToughnessModification).applies_to(self)
game.battlefield.static_abilities.applies_to(self)
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/magic/static_ability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Magic
class StaticAbility
def power
0
end

def toughness
0
end

def keywords
[]
end
end
end
65 changes: 65 additions & 0 deletions spec/cards/pridemalkin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require "spec_helper"

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

let(:pridemalkin) { Card("Pridemalkin") }

context "when pridemalkin is the only creature" do
it "adds the counter to itself" do
p1.add_mana(green: 3)
p1.cast(card: pridemalkin) do
_1.pay_mana(generic: { green: 2 }, green: 1)
end

game.tick!
permanent = creatures.by_name("Pridemalkin").first
game.resolve_choice!(target: permanent)

aggregate_failures do
expect(permanent.power).to eq(3)
expect(permanent.toughness).to eq(2)
expect(permanent.counters.of_type(Magic::Counters::Plus1Plus1).count).to eq(1)
expect(permanent.has_keyword?(:trample)).to eq(true)
end
end
end

context "when there is another creature" do
let!(:wood_elves) { ResolvePermanent("Wood Elves") }

it "adds the counter to wood elves" do
p1.add_mana(green: 3)
p1.cast(card: pridemalkin) do
_1.pay_mana(generic: { green: 2 }, green: 1)
end

game.tick!
game.resolve_choice!(target: wood_elves)

aggregate_failures do
expect(wood_elves.power).to eq(2)
expect(wood_elves.toughness).to eq(2)
expect(wood_elves.counters.of_type(Magic::Counters::Plus1Plus1).count).to eq(1)
expect(wood_elves.has_keyword?(:trample)).to eq(true)
end
end

it "adds the counter to pridemalkin, wood elves doesn't get trample" do
p1.add_mana(green: 3)
p1.cast(card: pridemalkin) do
_1.pay_mana(generic: { green: 2 }, green: 1)
end

game.tick!
permanent = creatures.by_name("Pridemalkin").first
game.resolve_choice!(target: permanent)

aggregate_failures do
expect(wood_elves.power).to eq(1)
expect(wood_elves.toughness).to eq(1)
expect(wood_elves.has_keyword?(:trample)).to eq(false)
end
end
end
end

0 comments on commit 6b1e86b

Please sign in to comment.