mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
[M15] Added source to TriggeredAbility. Real fix for Genesis Hydra, works correctly now.
This commit is contained in:
parent
f61597f111
commit
b6bc7c6a51
5 changed files with 40 additions and 15 deletions
|
@ -138,12 +138,18 @@ class GenesisHydraPutOntoBattlefieldEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
Cards cards = new CardsImpl();
|
||||
int count = source.getManaCostsToPay().getX();
|
||||
count = Math.min(controller.getLibrary().size(), count);
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
||||
Object obj = getValue(CastSourceTriggeredAbility.SOURCE_CAST_SPELL_ABILITY);
|
||||
int count = 0;
|
||||
if (obj != null && obj instanceof SpellAbility) {
|
||||
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) {
|
||||
controller.revealCards("Genesis Hydra", cards, game);
|
||||
|
|
|
@ -29,12 +29,6 @@
|
|||
|
||||
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.constants.Zone;
|
||||
import mage.game.Game;
|
||||
|
@ -42,6 +36,8 @@ import mage.game.events.GameEvent;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -78,6 +74,7 @@ public class TriggeredAbilities extends HashMap<String, TriggeredAbility> {
|
|||
if (object instanceof Permanent) {
|
||||
ability.setControllerId(((Permanent) object).getControllerId());
|
||||
}
|
||||
ability.setSourceObject(object);
|
||||
if (ability.checkTrigger(event, game)) {
|
||||
UUID controllerId = ability.getControllerId();
|
||||
ability.trigger(game, controllerId);
|
||||
|
|
|
@ -28,10 +28,12 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -41,7 +43,6 @@ public interface TriggeredAbility extends Ability {
|
|||
void trigger(Game game, UUID controllerId);
|
||||
boolean checkTrigger(GameEvent event, Game game);
|
||||
boolean checkInterveningIfClause(Game game);
|
||||
@Override
|
||||
TriggeredAbility copy();
|
||||
|
||||
void setSourceObject(MageObject mageObject);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AbilityType;
|
||||
|
@ -36,6 +35,8 @@ import mage.constants.Zone;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -43,6 +44,7 @@ import mage.players.Player;
|
|||
public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility {
|
||||
|
||||
protected boolean optional;
|
||||
protected MageObject sourceObject;
|
||||
|
||||
public TriggeredAbilityImpl(Zone zone, Effect effect) {
|
||||
this(zone, effect, false);
|
||||
|
@ -147,4 +149,12 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public MageObject getSourceObject() {
|
||||
return sourceObject;
|
||||
}
|
||||
|
||||
public void setSourceObject(MageObject sourceObject) {
|
||||
this.sourceObject = sourceObject;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import mage.abilities.effects.Effect;
|
|||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
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 static final String SOURCE_CAST_SPELL_ABILITY = "sourceCastSpellAbility";
|
||||
|
||||
public CastSourceTriggeredAbility(Effect effect) {
|
||||
this(effect, false);
|
||||
}
|
||||
|
@ -59,6 +62,14 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl {
|
|||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
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 false;
|
||||
|
|
Loading…
Reference in a new issue