From 6178891026b14c85f2a48931796c1ad723f56121 Mon Sep 17 00:00:00 2001 From: Ryan Bigg Date: Thu, 1 Feb 2024 07:23:44 +1100 Subject: [PATCH] Add Short Sword Fixes #247 --- lib/magic/card_builder.rb | 4 +++ lib/magic/cards/equipment.rb | 62 ++++++++++++++++++++++++++++++++++ lib/magic/cards/short_sword.rb | 17 ++++++++++ spec/cards/short_sword_spec.rb | 24 +++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 lib/magic/cards/equipment.rb create mode 100644 lib/magic/cards/short_sword.rb create mode 100644 spec/cards/short_sword_spec.rb diff --git a/lib/magic/card_builder.rb b/lib/magic/card_builder.rb index 160550f..1d555ed 100644 --- a/lib/magic/card_builder.rb +++ b/lib/magic/card_builder.rb @@ -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) diff --git a/lib/magic/cards/equipment.rb b/lib/magic/cards/equipment.rb new file mode 100644 index 0000000..42c6f12 --- /dev/null +++ b/lib/magic/cards/equipment.rb @@ -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 diff --git a/lib/magic/cards/short_sword.rb b/lib/magic/cards/short_sword.rb new file mode 100644 index 0000000..54a9aa1 --- /dev/null +++ b/lib/magic/cards/short_sword.rb @@ -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 diff --git a/spec/cards/short_sword_spec.rb b/spec/cards/short_sword_spec.rb new file mode 100644 index 0000000..a29f785 --- /dev/null +++ b/spec/cards/short_sword_spec.rb @@ -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