Merge branch 'master' of https://github.com/magefree/mage into adventures

This commit is contained in:
Patrick Hulin 2019-12-11 22:15:38 -05:00
commit 383069f5eb
16 changed files with 223 additions and 41 deletions

View file

@ -1,4 +1,3 @@
package mage.abilities.common;
import mage.MageObject;
@ -8,6 +7,7 @@ import mage.constants.SetTargetPointer;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
/**
@ -44,14 +44,18 @@ public class ExploitCreatureTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
if (event.getTargetId().equals(getSourceId()) && event.getSourceId().equals(getSourceId())) {
if (!this.hasSourceObjectAbility(game, source, event)) {
return false;
Permanent sourcePermanent = null;
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent = game.getPermanent(getSourceId());
} else {
if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
}
this.setControllerId(event.getPlayerId());
return true; // if Exploits creature sacrifices itself, exploit triggers
}
return super.isInUseableZone(game, source, event);
if (sourcePermanent == null) {
return false;
}
return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override

View file

@ -1,5 +1,6 @@
package mage.abilities.common;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
@ -17,8 +18,6 @@ import mage.players.Player;
* @author TheElk801
*/
public class GodEternalDiesTriggeredAbility extends TriggeredAbilityImpl {
Boolean applied;
public GodEternalDiesTriggeredAbility() {
super(Zone.ALL, null, true);
@ -33,7 +32,7 @@ public class GodEternalDiesTriggeredAbility extends TriggeredAbilityImpl {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE) {
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
return zEvent.getFromZone() == Zone.BATTLEFIELD
&& (zEvent.getToZone() == Zone.GRAVEYARD
&& (zEvent.getToZone() == Zone.GRAVEYARD
|| zEvent.getToZone() == Zone.EXILED);
}
return false;
@ -41,24 +40,29 @@ public class GodEternalDiesTriggeredAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
applied = false;
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (zEvent.getTargetId().equals(this.getSourceId())) {
Permanent permanent = game.getPermanentOrLKIBattlefield(this.getSourceId());
// for cases where its triggered ability is removed, ex: Kasmina's Transmutation
if (permanent != null) {
for (Ability a : permanent.getAbilities()) {
if (a instanceof GodEternalDiesTriggeredAbility) {
applied = true;
}
}
}
if (applied) {
this.getEffects().clear();
this.addEffect(new GodEternalEffect(new MageObjectReference(zEvent.getTarget(), game)));
return true;
}
return false;
}
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
Permanent sourcePermanent = null;
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
sourcePermanent = game.getPermanent(getSourceId());
} else {
if (game.getShortLivingLKI(getSourceId(), Zone.BATTLEFIELD)) {
sourcePermanent = (Permanent) game.getLastKnownInformation(getSourceId(), Zone.BATTLEFIELD);
}
}
return applied;
if (sourcePermanent == null) {
return false;
}
return hasSourceObjectAbility(game, sourcePermanent, event);
}
@Override
@ -68,8 +72,8 @@ public class GodEternalDiesTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "When {this} dies or is put into exile from the battlefield, " +
"you may put it into its owner's library third from the top.";
return "When {this} dies or is put into exile from the battlefield, "
+ "you may put it into its owner's library third from the top.";
}
}
@ -104,4 +108,4 @@ class GodEternalEffect extends OneShotEffect {
}
return player.putCardOnTopXOfLibrary(card, game, source, 3);
}
}
}

View file

@ -0,0 +1,63 @@
package mage.abilities.keyword;
import mage.abilities.SpellAbility;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.ExileFromGraveCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.cards.Card;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.common.TargetCardInYourGraveyard;
import mage.util.CardUtil;
/**
* @author TheElk801
*/
public class EscapeAbility extends SpellAbility {
private static final FilterCard filter = new FilterCard();
static {
filter.add(AnotherPredicate.instance);
}
private final String manaCost;
private final int exileCount;
public EscapeAbility(Card card, String manaCost, int exileCount) {
super(new ManaCostsImpl(manaCost), card.getName() + " with escape");
this.newId();
this.zone = Zone.GRAVEYARD;
this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE;
this.manaCost = manaCost;
this.exileCount = exileCount;
Cost cost = new ExileFromGraveCost(new TargetCardInYourGraveyard(exileCount, filter));
cost.setText("");
this.addCost(cost);
}
private EscapeAbility(final EscapeAbility ability) {
super(ability);
this.manaCost = ability.manaCost;
this.exileCount = ability.exileCount;
}
@Override
public EscapeAbility copy() {
return new EscapeAbility(this);
}
@Override
public String getRule(boolean all) {
return getRule();
}
@Override
public String getRule() {
return "Escape — " + this.manaCost + ", Exile " + CardUtil.numberToText(this.exileCount) +
" other cards from your graveyard. <i>(You may cast this card from your graveyard for its escape cost.)</i>";
}
}

View file

@ -230,7 +230,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
@Override
public List<String> getRules() {
try {
return abilities.getRules(this.getName());
return getAbilities().getRules(this.getName());
} catch (Exception e) {
logger.info("Exception in rules generation for card: " + this.getName(), e);
}

View file

@ -3420,6 +3420,13 @@ public abstract class PlayerImpl implements Player, Serializable {
for (Ability ability : playableAbilities) {
if (ability.getSourceId() != null) {
playableObjects.add(ability.getSourceId());
// main card must be marked playable in GUI
MageObject object = game.getObject(ability.getSourceId());
if (object instanceof SplitCardHalf) {
UUID splitCardId = ((Card) object).getMainCard().getId();
playableObjects.add(splitCardId);
}
}
}
return playableObjects;