[M15] Added source to TriggeredAbility. Real fix for Genesis Hydra, works correctly now.

This commit is contained in:
magenoxx 2014-07-07 17:44:50 +04:00
parent f61597f111
commit b6bc7c6a51
5 changed files with 40 additions and 15 deletions

View file

@ -138,11 +138,17 @@ class GenesisHydraPutOntoBattlefieldEffect extends OneShotEffect {
return false; return false;
} }
Cards cards = new CardsImpl(); Cards cards = new CardsImpl();
int count = source.getManaCostsToPay().getX();
count = Math.min(controller.getLibrary().size(), count); Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
for (int i = 0; i < count; i++) { int count = 0;
Card card = controller.getLibrary().removeFromTop(game); if (obj != null && obj instanceof SpellAbility) {
cards.add(card); count = ((SpellAbility) obj).getManaCostsToPay().getX();
// using other var because of tooltip
int size = Math.min(controller.getLibrary().size(), count);
for (int i = 0; i < size; i++) {
Card card = controller.getLibrary().removeFromTop(game);
cards.add(card);
}
} }
if (cards.size() > 0) { if (cards.size() > 0) {

View file

@ -29,12 +29,6 @@
package mage.abilities; package mage.abilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
@ -42,6 +36,8 @@ import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard; import mage.game.permanent.PermanentCard;
import java.util.*;
/** /**
* *
@ -78,6 +74,7 @@ public class TriggeredAbilities extends HashMap<String, TriggeredAbility> {
if (object instanceof Permanent) { if (object instanceof Permanent) {
ability.setControllerId(((Permanent) object).getControllerId()); ability.setControllerId(((Permanent) object).getControllerId());
} }
ability.setSourceObject(object);
if (ability.checkTrigger(event, game)) { if (ability.checkTrigger(event, game)) {
UUID controllerId = ability.getControllerId(); UUID controllerId = ability.getControllerId();
ability.trigger(game, controllerId); ability.trigger(game, controllerId);

View file

@ -28,10 +28,12 @@
package mage.abilities; package mage.abilities;
import java.util.UUID; import mage.MageObject;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -41,7 +43,6 @@ public interface TriggeredAbility extends Ability {
void trigger(Game game, UUID controllerId); void trigger(Game game, UUID controllerId);
boolean checkTrigger(GameEvent event, Game game); boolean checkTrigger(GameEvent event, Game game);
boolean checkInterveningIfClause(Game game); boolean checkInterveningIfClause(Game game);
@Override
TriggeredAbility copy(); TriggeredAbility copy();
void setSourceObject(MageObject mageObject);
} }

View file

@ -28,7 +28,6 @@
package mage.abilities; package mage.abilities;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.constants.AbilityType; import mage.constants.AbilityType;
@ -36,6 +35,8 @@ import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -43,6 +44,7 @@ import mage.players.Player;
public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility { public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility {
protected boolean optional; protected boolean optional;
protected MageObject sourceObject;
public TriggeredAbilityImpl(Zone zone, Effect effect) { public TriggeredAbilityImpl(Zone zone, Effect effect) {
this(zone, effect, false); this(zone, effect, false);
@ -147,4 +149,12 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return sb.toString(); return sb.toString();
} }
public MageObject getSourceObject() {
return sourceObject;
}
public void setSourceObject(MageObject sourceObject) {
this.sourceObject = sourceObject;
}
} }

View file

@ -32,6 +32,7 @@ import mage.abilities.effects.Effect;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.stack.Spell;
/** /**
* *
@ -39,6 +40,8 @@ import mage.game.events.GameEvent;
*/ */
public class CastSourceTriggeredAbility extends TriggeredAbilityImpl { public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
public static final String SOURCE_CAST_SPELL_ABILITY = "sourceCastSpellAbility";
public CastSourceTriggeredAbility(Effect effect) { public CastSourceTriggeredAbility(Effect effect) {
this(effect, false); this(effect, false);
} }
@ -59,6 +62,14 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType().equals(GameEvent.EventType.SPELL_CAST) && event.getSourceId().equals(this.getSourceId())) { if (event.getType().equals(GameEvent.EventType.SPELL_CAST) && event.getSourceId().equals(this.getSourceId())) {
if (getSourceObject() != null && getSourceObject() instanceof Spell) {
Spell spell = (Spell)getSourceObject();
if (spell.getSpellAbility() != null) {
for (Effect effect : getEffects()) {
effect.setValue(SOURCE_CAST_SPELL_ABILITY, spell.getSpellAbility());
}
}
}
return true; return true;
} }
return false; return false;