Skip to content

Commit

Permalink
Add Heliod God of the Sun
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Nov 10, 2024
1 parent 38e4d12 commit 682bf07
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 25 deletions.
4 changes: 0 additions & 4 deletions lib/magic/abilities/static/keyword_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def self.keyword_grants(*keywords)
define_method(:keyword_grants) { keywords }
end

def initialize(source:)
@source = source
end

def apply_to(permanent)
if applicable_targets.include?(permanent)
keyword_grants
Expand Down
4 changes: 0 additions & 4 deletions lib/magic/abilities/static/type_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def self.type_grants(*keywords)
define_method(:type_grants) { keywords }
end

def initialize(source:)
@source = source
end

def applies_to?(target)
applicable_targets.include?(target)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module Magic
module Abilities
module Static
class TypeModification < StaticAbility
class TypeRemoval < StaticAbility
attr_reader :source, :applicable_targets
def initialize(source:)
@source = source

def self.type_removal(*types)
define_method(:type_removal) { types }
end

def applies_to?(target)
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/barrin_tolarian_archmage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Cards
power 2
toughness 2
cost "{1}{U}{U}"
type "#{T::Legendary} #{T::Creature} -- #{creature_types("Human Wizard")}"
type "#{T::Super::Legendary} #{T::Creature} -- #{creature_types("Human Wizard")}"
end

class BarrinTolarianArchmage < Creature
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/basri_ket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Magic
module Cards
class BasriKet < Planeswalker
card_name "Basri Ket"
type T::Legendary, T::Planeswalker, "Basri"
type T::Super::Legendary, T::Planeswalker, "Basri"
loyalty 3

class Emblem < Magic::Emblem
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/dryad_of_the_ilysian_grove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Cards

class DryadOfTheIlysianGrove < Creature
# Parent class here should be called "Continuous Effect as per Rule 611"
class TypeModification < Abilities::Static::TypeModification
class TypeModification < Abilities::Static::TypeGrant
def initialize(source:)
@source = source
end
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/elderfang_ritualist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Cards
class ElderfangRitualist < Creature
class Choice < Choice::SearchGraveyard
def choices
controller.graveyard.by_type("Elf")
controller.graveyard.cards.all("Elf")
end

def choice_amount
Expand Down
48 changes: 48 additions & 0 deletions lib/magic/cards/heliod_god_of_the_sun.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Magic
module Cards
HeliodGodOfTheSun = Creature("Heliod, God of the Sun") do
type T::Super::Legendary, T::Enchantment, T::Creature, "God"
cost "{3}{W}"
keywords :indestructible
power 5
toughness 6

class TypeModification < Abilities::Static::TypeRemoval
def initialize(source:)
@source = source
end

def type_removal
[
T::Creature
]
end

def applicable_targets
if controller.devotion(:white) >= 5
[]
else
[source]
end
end
end

class VigilanceGrant < Abilities::Static::KeywordGrant
def keyword_grants
[Keywords::VIGILANCE]
end

def applicable_targets
controller.creatures - [source]
end
end

def static_abilities
[
TypeModification,
VigilanceGrant,
]
end
end
end
end
2 changes: 1 addition & 1 deletion lib/magic/cards/mangara_the_diplomat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Magic
module Cards
MangaraTheDiplomat = Creature("Mangara, the Diplomat") do
cost generic: 3, white: 1
type T::Legendary, T::Creature, *creature_types("Human Cleric")
type T::Super::Legendary, T::Creature, *creature_types("Human Cleric")
power 2
toughness 4
keywords :lifelink
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/odric_lunarch_marshal.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Magic
module Cards
OdricLunarchMarshal = Creature("Odric, Lunarch Marshal") do
type T::Legendary, T::Creature, *creature_types("Human Soldier")
type T::Super::Legendary, T::Creature, *creature_types("Human Soldier")
cost generic: 3, white: 1
power 3
toughness 3
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/sanctum_of_calm_waters.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Magic
module Cards
SanctumOfCalmWaters = Enchantment("Sanctum of Calm Waters") do
type T::Legendary, T::Enchantment, "Shrine"
type T::Super::Legendary, T::Enchantment, "Shrine"
cost generic: 3, blue: 1

def event_handlers
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/sanctum_of_tranquil_light.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Magic
module Cards
SanctumOfTranquilLight = Enchantment("Sanctum of Tranquil Light") do
type T::Legendary, T::Enchantment, "Shrine"
type T::Super::Legendary, T::Enchantment, "Shrine"
cost white: 1
end

Expand Down
4 changes: 2 additions & 2 deletions lib/magic/cards/shared/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def enchantment_creature_type(types)
end

def legendary_creature_type(types)
set_types(T::Legendary, T::Creature, *creature_types(types))
set_types(T::Super::Legendary, T::Creature, *creature_types(types))
end

def planeswalker(name)
set_types(T::Legendary, T::Planeswalker, name)
set_types(T::Super::Legendary, T::Planeswalker, name)
end

def type(*types)
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/permanent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ def phase_in!
@phased_out = false
end

def devotion(color)
card.cost.send(color) || 0
end

private

def remove_until_eot_keyword_grants!
Expand Down
8 changes: 5 additions & 3 deletions lib/magic/permanents/continuous_effects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ def modifiers_by_type(type)
end

def calculate_types
[
types = [
*card.types,
*permanent.attachments.flat_map(&:type_grants),
*static_abilities_for(permanent).of_type(Abilities::Static::TypeModification).flat_map(&:type_grants),
*static_abilities_for(permanent).of_type(Abilities::Static::TypeGrant).flat_map(&:type_grants),
*modifiers_by_type(Modifications::AdditionalType).flat_map(&:type_grants),
].uniq
]

types -= static_abilities_for(permanent).of_type(Abilities::Static::TypeRemoval).flat_map(&:type_removal)
end

def calculate_keywords
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,9 @@ def protected_from?(card)
def add_counter(counter_type:, amount: 1)
@counters = Counters::Collection.new(@counters + [counter_type.new] * amount)
end

def devotion(color)
permanents.sum { |permanent| permanent.devotion(color) }
end
end
end
2 changes: 1 addition & 1 deletion lib/magic/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def permanent?
end

def legendary?
type?(T::Legendary)
type?(T::Super::Legendary)
end
end

Expand Down
40 changes: 40 additions & 0 deletions spec/cards/heliod_god_of_the_sun_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "spec_helper"

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

let!(:heliod) { ResolvePermanent("Heliod, God of The Sun") }

it "is indestructible" do
expect(heliod).to be_indestructible
end

context "devotion" do
it "is not a creature" do
expect(heliod).not_to be_creature
end

context "with 2x nine lives (4 pips) and itself" do
before do
2.times do
ResolvePermanent("Nine Lives")
end

game.tick!
end

it "is a creature" do
expect(heliod).to be_creature
end
end
end

context "vigilance static ability" do
let(:wood_elves) { ResolvePermanent("Wood Elves") }

it "grants vigilance to all creatures" do
expect(wood_elves).to be_vigilant
expect(heliod).not_to be_vigilant
end
end
end

0 comments on commit 682bf07

Please sign in to comment.