mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
reworked some abilities which use card.moveToExile
This commit is contained in:
parent
098796f86e
commit
129a477f56
3 changed files with 87 additions and 85 deletions
|
@ -4,6 +4,7 @@ package mage.abilities.effects.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
@ -18,7 +19,7 @@ public class ExileAndGainLifeEqualPowerTargetEffect extends OneShotEffect {
|
|||
staticText = "Exile target creature. Its controller gains life equal to its power";
|
||||
}
|
||||
|
||||
public ExileAndGainLifeEqualPowerTargetEffect(final ExileAndGainLifeEqualPowerTargetEffect effect) {
|
||||
private ExileAndGainLifeEqualPowerTargetEffect(final ExileAndGainLifeEqualPowerTargetEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
@ -30,16 +31,17 @@ public class ExileAndGainLifeEqualPowerTargetEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
Player player = game.getPlayer(permanent.getControllerId());
|
||||
if (player != null) {
|
||||
int creaturePower = permanent.getPower().getValue();
|
||||
permanent.moveToExile(null, null, source, game);
|
||||
game.getState().processAction(game);
|
||||
player.gainLife(creaturePower, game, source);
|
||||
}
|
||||
if (permanent == null) {
|
||||
return false;
|
||||
}
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
Player player = game.getPlayer(permanent.getControllerId());
|
||||
if (controller == null || player == null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
int creaturePower = permanent.getPower().getValue();
|
||||
controller.moveCards(permanent, Zone.EXILED, source, game);
|
||||
player.gainLife(creaturePower, game, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class ExileTargetAndSearchGraveyardHandLibraryEffect extends SearchTargetGraveyardHandLibraryForCardNameAndExileEffect {
|
||||
|
@ -20,7 +21,7 @@ public class ExileTargetAndSearchGraveyardHandLibraryEffect extends SearchTarget
|
|||
super(graveyardExileOptional, searchWhatText, searchForText);
|
||||
}
|
||||
|
||||
public ExileTargetAndSearchGraveyardHandLibraryEffect(final ExileTargetAndSearchGraveyardHandLibraryEffect effect) {
|
||||
private ExileTargetAndSearchGraveyardHandLibraryEffect(final ExileTargetAndSearchGraveyardHandLibraryEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
@ -36,13 +37,15 @@ public class ExileTargetAndSearchGraveyardHandLibraryEffect extends SearchTarget
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (exileTarget != null) {
|
||||
Permanent permanentToExile = game.getPermanent(exileTarget.getFirstTarget());
|
||||
if (permanentToExile != null) {
|
||||
targetPlayerId = permanentToExile.getControllerId();
|
||||
result = permanentToExile.moveToExile(null, "", source, game);
|
||||
this.applySearchAndExile(game, source, permanentToExile.getName(), targetPlayerId);
|
||||
}
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null || exileTarget == null) {
|
||||
return result;
|
||||
}
|
||||
Permanent permanentToExile = game.getPermanent(exileTarget.getFirstTarget());
|
||||
if (permanentToExile != null) {
|
||||
targetPlayerId = permanentToExile.getControllerId();
|
||||
result = player.moveCards(permanentToExile, Zone.EXILED, source, game);
|
||||
this.applySearchAndExile(game, source, permanentToExile.getName(), targetPlayerId);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -13,23 +13,24 @@ import mage.game.Game;
|
|||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
* 702.53. Haunt
|
||||
*
|
||||
* <p>
|
||||
* 702.53a Haunt is a triggered ability. "Haunt" on a permanent means "When this
|
||||
* permanent is put into a graveyard from the battlefield, exile it haunting
|
||||
* target creature." "Haunt" on an instant or sorcery spell means "When this
|
||||
* spell is put into a graveyard during its resolution, exile it haunting target
|
||||
* creature."
|
||||
*
|
||||
* <p>
|
||||
* 702.53b Cards that are in the exile zone as the result of a haunt ability
|
||||
* "haunt" the creature targeted by that ability. The phrase "creature it
|
||||
* haunts" refers to the object targeted by the haunt ability, regardless of
|
||||
* whether or not that object is still a creature.
|
||||
*
|
||||
* <p>
|
||||
* 702.53c Triggered abilities of cards with haunt that refer to the haunted
|
||||
* creature can trigger in the exile zone.
|
||||
*
|
||||
|
@ -46,7 +47,7 @@ public class HauntAbility extends TriggeredAbilityImpl {
|
|||
addSubAbility(new HauntExileAbility(creatureHaunt));
|
||||
}
|
||||
|
||||
public HauntAbility(final HauntAbility ability) {
|
||||
private HauntAbility(final HauntAbility ability) {
|
||||
super(ability);
|
||||
this.usedFromExile = ability.usedFromExile;
|
||||
this.creatureHaunt = ability.creatureHaunt;
|
||||
|
@ -59,51 +60,46 @@ public class HauntAbility extends TriggeredAbilityImpl {
|
|||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
switch (event.getType()) {
|
||||
case ENTERS_THE_BATTLEFIELD:
|
||||
case ZONE_CHANGE:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD
|
||||
|| event.getType() == GameEvent.EventType.ZONE_CHANGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
switch (event.getType()) {
|
||||
case ENTERS_THE_BATTLEFIELD:
|
||||
if (game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD) {
|
||||
return event.getTargetId().equals(getSourceId());
|
||||
}
|
||||
break;
|
||||
return game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD
|
||||
&& event.getTargetId().equals(getSourceId());
|
||||
case ZONE_CHANGE:
|
||||
if (!usedFromExile
|
||||
&& game.getState().getZone(getSourceId()) == Zone.EXILED) {
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
if (zEvent.isDiesEvent()) {
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card != null
|
||||
&& game.getCard(event.getTargetId()) != null) {
|
||||
String key = new StringBuilder("Haunting_")
|
||||
.append(getSourceId().toString())
|
||||
.append(card.getZoneChangeCounter(game)
|
||||
+ (game.getPermanentOrLKIBattlefield(event.getTargetId()))
|
||||
.getZoneChangeCounter(game)).toString();
|
||||
Object object = game.getState().getValue(key);
|
||||
if (object instanceof FixedTarget) {
|
||||
FixedTarget target = (FixedTarget) object;
|
||||
if (target.getTarget() != null
|
||||
&& target.getTarget()
|
||||
.equals(event.getTargetId())) {
|
||||
usedFromExile = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (usedFromExile
|
||||
|| game.getState().getZone(getSourceId()) != Zone.EXILED) {
|
||||
return false;
|
||||
}
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
if (!zEvent.isDiesEvent()) {
|
||||
return false;
|
||||
}
|
||||
Card card = game.getCard(getSourceId());
|
||||
if (card == null
|
||||
|| game.getCard(event.getTargetId()) == null) {
|
||||
return false;
|
||||
}
|
||||
String key = new StringBuilder("Haunting_")
|
||||
.append(getSourceId().toString())
|
||||
.append(card.getZoneChangeCounter(game)
|
||||
+ (game.getPermanentOrLKIBattlefield(event.getTargetId()))
|
||||
.getZoneChangeCounter(game)).toString();
|
||||
Object object = game.getState().getValue(key);
|
||||
if (!(object instanceof FixedTarget)) {
|
||||
return false;
|
||||
}
|
||||
FixedTarget target = (FixedTarget) object;
|
||||
if (target.getTarget() != null
|
||||
&& target.getTarget()
|
||||
.equals(event.getTargetId())) {
|
||||
usedFromExile = true;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -134,7 +130,7 @@ class HauntExileAbility extends ZoneChangeTriggeredAbility {
|
|||
|
||||
}
|
||||
|
||||
public HauntExileAbility(final HauntExileAbility ability) {
|
||||
private HauntExileAbility(final HauntExileAbility ability) {
|
||||
super(ability);
|
||||
this.creatureHaunt = ability.creatureHaunt;
|
||||
}
|
||||
|
@ -171,12 +167,12 @@ class HauntExileAbility extends ZoneChangeTriggeredAbility {
|
|||
|
||||
class HauntEffect extends OneShotEffect {
|
||||
|
||||
public HauntEffect() {
|
||||
HauntEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "exile it haunting target creature";
|
||||
}
|
||||
|
||||
public HauntEffect(final HauntEffect effect) {
|
||||
private HauntEffect(final HauntEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
@ -187,27 +183,28 @@ class HauntEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
Card card = game.getCard(source.getSourceId());
|
||||
if (card != null) {
|
||||
Permanent hauntedCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
// haunting card will only be moved to exile, if
|
||||
if (hauntedCreature != null) {
|
||||
if (card.moveToExile(source.getSourceId(), "Haunting", source, game)) {
|
||||
// remember the haunted creature
|
||||
String key = new StringBuilder("Haunting_")
|
||||
.append(source.getSourceId().toString())
|
||||
.append(card.getZoneChangeCounter(game)
|
||||
+ hauntedCreature.getZoneChangeCounter(game)).toString(); // in case it is blinked
|
||||
game.getState().setValue(key, new FixedTarget(targetPointer.getFirst(game, source)));
|
||||
card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString(), game);
|
||||
hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString(), game);
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(new StringBuilder(card.getName()).append(" haunting ").append(hauntedCreature.getLogName()).toString());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (player == null || card == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
Permanent hauntedCreature = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
// haunting card will only be moved to exile, if
|
||||
if (hauntedCreature == null) {
|
||||
return false;
|
||||
}
|
||||
if (!player.moveCards(card, Zone.EXILED, source, game)) {
|
||||
return true;
|
||||
}
|
||||
// remember the haunted creature
|
||||
String key = new StringBuilder("Haunting_")
|
||||
.append(source.getSourceId().toString())
|
||||
.append(card.getZoneChangeCounter(game)
|
||||
+ hauntedCreature.getZoneChangeCounter(game)).toString(); // in case it is blinked
|
||||
game.getState().setValue(key, new FixedTarget(targetPointer.getFirst(game, source)));
|
||||
card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString(), game);
|
||||
hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString(), game);
|
||||
game.informPlayers(new StringBuilder(card.getName()).append(" haunting ").append(hauntedCreature.getLogName()).toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue