Skip to content

Commit

Permalink
Add Short Sword
Browse files Browse the repository at this point in the history
Fixes #247
  • Loading branch information
radar committed Jan 31, 2024
1 parent 6079d97 commit 6178891
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/magic/card_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def Artifact(name, &block)
Card(name, Magic::Cards::Artifact, &block)
end

def Equipment(name, &block)
Card(name, Magic::Cards::Equipment, &block)
end

def Card(name, base_class = Magic::Card, &block)
card = Class.new(base_class, &block)
card.const_set(:NAME, name)
Expand Down
62 changes: 62 additions & 0 deletions lib/magic/cards/equipment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Magic
module Cards
class Equipment < Card
TYPE_LINE = "Artifact -- Equipment"


def self.equip(cost)
equip = Class.new(ActivatedAbility) do
def costs
[Costs::Mana.new(generic: 1)]
end

def target_choices
game.battlefield.creatures.controlled_by(controller)
end

def resolve!(target:)
target.attachments << source
end
end

define_method(:activated_abilities) do
[equip]
end
end

def resolve!(target:)
permanent = super()
permanent.attach_to!(target)
end

def single_target?
true
end

def resolve!(target:)
permanent = super()
permanent.attach_to!(target)
end

def power_modification
0
end

def toughness_modification
0
end

def keyword_grants
[]
end

def type_grants
[]
end

def can_activate_ability?(_)
true
end
end
end
end
17 changes: 17 additions & 0 deletions lib/magic/cards/short_sword.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Magic
module Cards
ShortSword = Equipment("Short Sword") do
cost generic: 1

equip 1

def power_modification
1
end

def toughness_modification
1
end
end
end
end
24 changes: 24 additions & 0 deletions spec/cards/short_sword_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'spec_helper'

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

subject(:permanent) { ResolvePermanent("Short Sword") }

context "equips, gives a +1/+1" do
let!(:wood_elves) { ResolvePermanent("Wood Elves", owner: p1) }

it "buffs wood elves" do
p1.add_mana(white: 1)
p1.activate_ability(ability: permanent.activated_abilities.first) do
_1.targeting(wood_elves)
_1.pay_mana(generic: { white: 1 })
end

expect(wood_elves.attachments.count).to eq(1)
expect(wood_elves.attachments.first.name).to eq("Short Sword")
expect(wood_elves.power).to eq(2)
expect(wood_elves.toughness).to eq(2)
end
end
end

0 comments on commit 6178891

Please sign in to comment.