This commit is contained in:
jeffwadsworth 2021-02-11 09:36:45 -06:00
parent 1d137526a8
commit 78bae348e8
3 changed files with 111 additions and 4 deletions

View file

@ -17,6 +17,9 @@ import mage.target.targetadjustment.TargetAdjuster;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
/**
* @author LevelX2
@ -74,7 +77,41 @@ class CurseOfTheSwineEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Cards creaturesToExile = new CardsImpl();
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Permanent creature = game.getPermanent(targetId);
if (creature != null) {
creaturesToExile.add(creature);
}
}
// move creatures to exile all at once
controller.moveCards(creaturesToExile, Zone.EXILED, source, game);
// Count all creatures actually exiled and add them to the player's count
for (Card card : creaturesToExile.getCards(game)) {
Permanent lkiP = game.getPermanentOrLKIBattlefield(card.getId());
if (lkiP != null
&& game.getState().getZone(lkiP.getId()) == Zone.EXILED) {
playersWithTargets.put(lkiP.getControllerId(),
playersWithTargets.getOrDefault(lkiP.getControllerId(), 0) + 1);
}
}
Boar2Token swineToken = new Boar2Token();
for (Map.Entry<UUID, Integer> exiledByController : playersWithTargets.entrySet()) {
swineToken.putOntoBattlefield(exiledByController.getValue(), game, source, exiledByController.getKey());
}
return true;
}
return false;
}
}
/*
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Permanent creature = game.getPermanent(targetId);
@ -91,7 +128,8 @@ class CurseOfTheSwineEffect extends OneShotEffect {
}
return true;
}
return false;
}
}
*/

View file

@ -121,6 +121,7 @@ class RanarTheEverWatchfulTriggeredAbility extends TriggeredAbilityImpl {
if (zEvent != null
&& Zone.HAND == zEvent.getFromZone()
&& Zone.EXILED == zEvent.getToZone()
&& zEvent.getPlayerId() == controllerId
&& zEvent.getCards() != null) {
for (Card card : zEvent.getCards()) {
if (card != null) {
@ -135,6 +136,7 @@ class RanarTheEverWatchfulTriggeredAbility extends TriggeredAbilityImpl {
if (zEvent != null
&& Zone.BATTLEFIELD == zEvent.getFromZone()
&& Zone.EXILED == zEvent.getToZone()
&& zEvent.getPlayerId() == controllerId
&& zEvent.getCards() != null) {
return true;

View file

@ -18,6 +18,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import mage.abilities.SpellAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.target.Target;
public abstract class TokenImpl extends MageObjectImpl implements Token {
@ -180,7 +187,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
if (event.getAmount() > tokenSlots) {
game.informPlayers(
"The token limit per player is " + MAX_TOKENS_PER_GAME + ", " + controller.getName()
+ " will only create " + tokenSlots + " tokens."
+ " will only create " + tokenSlots + " tokens."
);
}
event.setAmount(Math.min(event.getAmount(), tokenSlots));
@ -249,6 +256,66 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
game.addSimultaneousEvent(new CreatedTokenEvent(source, (PermanentToken) permanent));
}
// handle auras coming into the battlefield
// code refactored from CopyPermanentEffect
if (permanent.getSubtype().contains(SubType.AURA)) {
Outcome auraOutcome = Outcome.BoostCreature;
Target auraTarget = null;
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
for (Ability ability : permanent.getAbilities()) {
if (!(ability instanceof SpellAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
for (Effect effect : ability.getEffects()) {
if (!(effect instanceof AttachEffect)) {
continue;
}
if (permanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = permanent.getSpellAbility().getTargets().get(0);
}
}
}
// enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
if (auraTarget == null) {
for (Ability ability : permanent.getAbilities()) {
if (!(ability instanceof EnchantAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
if (ability.getTargets().size() > 0) { // Animate Dead don't have targets
auraTarget = ability.getTargets().get(0);
}
}
}
// if this is a copy of a copy, the copy's target has been copied and needs to be cleared
if (auraTarget == null) {
break;
}
// clear selected target
if (auraTarget.getFirstTarget() != null) {
auraTarget.remove(auraTarget.getFirstTarget());
}
// select new target
auraTarget.setNotTarget(true);
if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
break;
}
UUID targetId = auraTarget.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) {
targetPermanent.addAttachment(permanent.getId(), source, game);
} else if (targetPlayer != null) {
targetPlayer.addAttachment(permanent.getId(), source, game);
}
}
// end of aura code : just remove this line if everything works out well
// must attack
if (attacking && game.getCombat() != null && game.getActivePlayerId().equals(permanent.getControllerId())) {
game.getCombat().addAttackingCreature(permanent.getId(), game, attackedPlayer);