From 178a5bf3469d0aaf028d770b492a6003ad7e2386 Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Mon, 30 May 2022 08:49:25 -0600 Subject: [PATCH] Flattened out CarnelianOrbOfDragonkind and GeneratorServant to make more readable --- .../cards/c/CarnelianOrbOfDragonkind.java | 47 +++++++++++------- .../src/mage/cards/g/GeneratorServant.java | 48 ++++++++++++------- 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/CarnelianOrbOfDragonkind.java b/Mage.Sets/src/mage/cards/c/CarnelianOrbOfDragonkind.java index 1382ebd5c1a..e61ea2c3d8b 100644 --- a/Mage.Sets/src/mage/cards/c/CarnelianOrbOfDragonkind.java +++ b/Mage.Sets/src/mage/cards/c/CarnelianOrbOfDragonkind.java @@ -36,7 +36,6 @@ public final class CarnelianOrbOfDragonkind extends CardImpl { public CarnelianOrbOfDragonkind(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{2}{R}"); - // {T}: Add {R}. If that mana is spent on a Dragon creature spell, it gains haste until end of turn. Mana mana = Mana.RedMana(1); @@ -68,14 +67,26 @@ class CarnelianOrbOfDragonkindWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.MANA_PAID) { - MageObject target = game.getObject(event.getTargetId()); - if (event.getSourceId() != null - && event.getSourceId().equals(this.getSourceId()) && target != null && target.isCreature(game) && target.hasSubtype(SubType.DRAGON, game) && event.getFlag()) { - if (target instanceof Spell) { - this.creatures.add(((Spell) target).getCard().getId()); - } - } + if (event.getType() != GameEvent.EventType.MANA_PAID) { + return; + } + + MageObject target = game.getObject(event.getTargetId()); + if (target == null || !(target instanceof Spell)) { + return; + } + + // Mana from Orb + if (!event.getFlag()) { + return; + } + + if (event.getSourceId() == null || !event.getSourceId().equals(this.getSourceId())) { + return; + } + + if (target.isCreature(game) && target.hasSubtype(SubType.DRAGON, game)) { + this.creatures.add(((Spell) target).getCard().getId()); } } @@ -109,15 +120,15 @@ class CarnelianOrbOfDragonkindHasteEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { CarnelianOrbOfDragonkindWatcher watcher = game.getState().getWatcher(CarnelianOrbOfDragonkindWatcher.class, source.getSourceId()); - if (watcher != null) { - for (Permanent perm : game.getBattlefield().getAllActivePermanents()) { - if (watcher.creatureCastWithOrbsMana(perm.getId())) { - perm.addAbility(HasteAbility.getInstance(), source.getSourceId(), game); - } - } - return true; + if (watcher == null) { + return false; } - return false; - } + for (Permanent perm : game.getBattlefield().getAllActivePermanents()) { + if (watcher.creatureCastWithOrbsMana(perm.getId())) { + perm.addAbility(HasteAbility.getInstance(), source.getSourceId(), game); + } + } + return true; + } } diff --git a/Mage.Sets/src/mage/cards/g/GeneratorServant.java b/Mage.Sets/src/mage/cards/g/GeneratorServant.java index 9b3e06bbc52..52e191a8e52 100644 --- a/Mage.Sets/src/mage/cards/g/GeneratorServant.java +++ b/Mage.Sets/src/mage/cards/g/GeneratorServant.java @@ -37,7 +37,7 @@ public final class GeneratorServant extends CardImpl { this.power = new MageInt(2); this.toughness = new MageInt(1); - // {T}, Sacrifice Generator Servant: Add {C}{C}. If that mana is spent on a creature spell, it gains haste until end of turn. + // {T}, Sacrifice Generator Servant: Add {C}{C}. If that mana is spent on a creature spell, it gains haste until end of turn. Mana mana = Mana.ColorlessMana(2); mana.setFlag(true); // used to indicate this mana ability SimpleManaAbility ability = new SimpleManaAbility(Zone.BATTLEFIELD, mana, new TapSourceCost()); @@ -68,14 +68,26 @@ class GeneratorServantWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.MANA_PAID) { - MageObject target = game.getObject(event.getTargetId()); - if (event.getSourceId() != null - && event.getSourceId().equals(this.getSourceId()) && target != null && target.isCreature(game) && event.getFlag()) { - if (target instanceof Spell) { - this.creatures.add(((Spell) target).getCard().getId()); - } - } + if (event.getType() != GameEvent.EventType.MANA_PAID) { + return; + } + + MageObject target = game.getObject(event.getTargetId()); + if (target == null || !(target instanceof Spell)) { + return; + } + + // Mana from Generator Servant + if (!event.getFlag()) { + return; + } + + if (event.getSourceId() == null || !event.getSourceId().equals(this.getSourceId())) { + return; + } + + if (target.isCreature(game)) { + this.creatures.add(((Spell) target).getCard().getId()); } } @@ -109,15 +121,15 @@ class GeneratorServantHasteEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { GeneratorServantWatcher watcher = game.getState().getWatcher(GeneratorServantWatcher.class, source.getSourceId()); - if (watcher != null) { - for (Permanent perm : game.getBattlefield().getAllActivePermanents()) { - if (watcher.creatureCastWithServantsMana(perm.getId())) { - perm.addAbility(HasteAbility.getInstance(), source.getSourceId(), game); - } - } - return true; + if (watcher == null) { + return false; } - return false; - } + for (Permanent perm : game.getBattlefield().getAllActivePermanents()) { + if (watcher.creatureCastWithServantsMana(perm.getId())) { + perm.addAbility(HasteAbility.getInstance(), source.getSourceId(), game); + } + } + return true; + } }