1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-03 01:08:59 -09:00

removed unnecessary lastAddedToken method from TokenImpl, reworked Warren Weirding

This commit is contained in:
Evan Kranzler 2022-03-31 20:12:09 -04:00
parent 676c3a8bb4
commit a581d55160
7 changed files with 31 additions and 69 deletions
Mage.Sets/src/mage/cards
Mage/src/main/java/mage

View file

@ -69,7 +69,7 @@ class GripOfPhyresisEffect extends CreateTokenEffect {
if (controller != null && equipment != null) {
if (super.apply(game, source)) {
Permanent germ = game.getPermanent(this.getLastAddedTokenId());
Permanent germ = game.getPermanent(this.getLastAddedTokenIds().stream().findFirst().orElse(null));
if (germ != null) {
germ.addAttachment(equipment.getId(), source, game);
return true;

View file

@ -1,13 +1,7 @@
package mage.cards.w;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
@ -16,17 +10,18 @@ import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.GoblinRogueToken;
import mage.game.permanent.token.Token;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.TargetPlayer;
import mage.target.common.TargetControlledPermanent;
import mage.target.targetpointer.FixedTarget;
import mage.target.targetpointer.FixedTargets;
import java.util.UUID;
/**
* @author LevelX2
@ -37,7 +32,6 @@ public final class WarrenWeirding extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.TRIBAL, CardType.SORCERY}, "{1}{B}");
this.subtype.add(SubType.GOBLIN);
// Target player sacrifices a creature. If a Goblin is sacrificed this way, that player creates two 1/1 black Goblin Rogue creature tokens, and those tokens gain haste until end of turn.
this.getSpellAbility().addEffect(new WarrenWeirdingEffect());
this.getSpellAbility().addTarget(new TargetPlayer());
@ -63,7 +57,8 @@ class WarrenWeirdingEffect extends OneShotEffect {
WarrenWeirdingEffect() {
super(Outcome.Sacrifice);
staticText = "Target player sacrifices a creature. If a Goblin is sacrificed this way, that player creates two 1/1 black Goblin Rogue creature tokens, and those tokens gain haste until end of turn";
staticText = "Target player sacrifices a creature. If a Goblin is sacrificed this way, that player " +
"creates two 1/1 black Goblin Rogue creature tokens, and those tokens gain haste until end of turn";
}
WarrenWeirdingEffect(WarrenWeirdingEffect effect) {
@ -73,45 +68,30 @@ class WarrenWeirdingEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player == null) {
if (player == null || game.getBattlefield().count(
StaticFilters.FILTER_CONTROLLED_CREATURE, player.getId(), source, game
) < 1) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
//A spell or ability could have removed the only legal target this player
//had, if thats the case this ability should fizzle.
if (target.canChoose(player.getId(), source, game)) {
player.choose(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
if (filterGoblin.match(permanent, game)) {
for (int i = 0; i < 2; i++) {
Token token = new GoblinRogueToken();
Effect effect = new CreateTokenTargetEffect(token);
effect.setTargetPointer(new FixedTarget(player.getId()));
if (effect.apply(game, source)) {
Permanent tokenPermanent = game.getPermanent(token.getLastAddedToken());
if (tokenPermanent != null) {
ContinuousEffect hasteEffect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
hasteEffect.setTargetPointer(new FixedTarget(tokenPermanent.getId()));
game.addEffect(hasteEffect, source);
}
}
}
}
}
return true;
TargetPermanent target = new TargetPermanent(StaticFilters.FILTER_CONTROLLED_CREATURE);
target.setNotTarget(true);
player.choose(outcome, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null || !permanent.sacrifice(source, game)) {
return false;
}
return false;
if (permanent.hasSubtype(SubType.GOBLIN, game)) {
Token token = new GoblinRogueToken();
token.putOntoBattlefield(2, game, source, player.getId());
game.addEffect(new GainAbilityTargetEffect(
HasteAbility.getInstance(), Duration.EndOfTurn
).setTargetPointer(new FixedTargets(token, game)), source);
}
return true;
}
@Override
public WarrenWeirdingEffect copy() {
return new WarrenWeirdingEffect(this);
}
}

View file

@ -6,7 +6,6 @@ import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
/**
*
* @author weirddan455
*/
public class CreateTokenAttachSourceEffect extends CreateTokenEffect {
@ -28,7 +27,7 @@ public class CreateTokenAttachSourceEffect extends CreateTokenEffect {
@Override
public boolean apply(Game game, Ability source) {
super.apply(game, source);
Permanent token = game.getPermanent(this.getLastAddedTokenId());
Permanent token = game.getPermanent(this.getLastAddedTokenIds().stream().findFirst().orElse(null));
if (token != null) {
token.addAttachment(source.getSourceId(), source, game);
return true;

View file

@ -24,11 +24,10 @@ import java.util.UUID;
*/
public class CreateTokenEffect extends OneShotEffect {
private Token token;
private DynamicValue amount;
private boolean tapped;
private boolean attacking;
private UUID lastAddedTokenId;
private final Token token;
private final DynamicValue amount;
private final boolean tapped;
private final boolean attacking;
private List<UUID> lastAddedTokenIds = new ArrayList<>();
public CreateTokenEffect(Token token) {
@ -62,7 +61,6 @@ public class CreateTokenEffect extends OneShotEffect {
this.token = effect.token.copy();
this.tapped = effect.tapped;
this.attacking = effect.attacking;
this.lastAddedTokenId = effect.lastAddedTokenId;
this.lastAddedTokenIds.addAll(effect.lastAddedTokenIds);
}
@ -75,16 +73,11 @@ public class CreateTokenEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
int value = amount.calculate(game, source, this);
token.putOntoBattlefield(value, game, source, source.getControllerId(), tapped, attacking);
this.lastAddedTokenId = token.getLastAddedToken();
this.lastAddedTokenIds = token.getLastAddedTokenIds();
return true;
}
public UUID getLastAddedTokenId() {
return lastAddedTokenId;
}
public List<UUID> getLastAddedTokenIds() {
return lastAddedTokenIds;
}

View file

@ -21,8 +21,6 @@ public interface Token extends MageObject {
String getDescription();
UUID getLastAddedToken();
List<UUID> getLastAddedTokenIds();
void addAbility(Ability ability);

View file

@ -30,7 +30,6 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
protected String description;
private final ArrayList<UUID> lastAddedTokenIds = new ArrayList<>();
private UUID lastAddedTokenId;
private int tokenType;
private String originalCardNumber;
private String originalExpansionSetCode;
@ -76,7 +75,6 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
super(token);
this.description = token.description;
this.tokenType = token.tokenType;
this.lastAddedTokenId = token.lastAddedTokenId;
this.lastAddedTokenIds.addAll(token.lastAddedTokenIds);
this.originalCardNumber = token.originalCardNumber;
this.originalExpansionSetCode = token.originalExpansionSetCode;
@ -113,11 +111,6 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
return description;
}
@Override
public UUID getLastAddedToken() {
return lastAddedTokenId;
}
@Override
public List<UUID> getLastAddedTokenIds() {
return new ArrayList<>(lastAddedTokenIds);
@ -301,7 +294,6 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
// keep tokens ids
if (token instanceof TokenImpl) {
((TokenImpl) token).lastAddedTokenIds.add(permanent.getId());
((TokenImpl) token).lastAddedTokenId = permanent.getId();
}
// created token events

View file

@ -273,7 +273,7 @@ public class Spell extends StackObjectImpl implements Card {
CardUtil.copyTo(token).from(card, game, this);
// The token that a resolving copy of a spell becomes isnt said to have been created. (2020-09-25)
if (token.putOntoBattlefield(1, game, ability, getControllerId(), false, false, null, false)) {
permId = token.getLastAddedToken();
permId = token.getLastAddedTokenIds().stream().findFirst().orElse(null);
flag = true;
} else {
permId = null;