mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 22:12:03 -08:00
Refactored Target pointers. All tests pass now.
This commit is contained in:
parent
13f547f1a2
commit
12954eceee
138 changed files with 259 additions and 182 deletions
|
|
@ -40,7 +40,7 @@ import mage.abilities.effects.EntersBattlefieldEffect;
|
|||
public class EntersBattlefieldAbility extends StaticAbility<EntersBattlefieldAbility> {
|
||||
|
||||
public EntersBattlefieldAbility(Effect effect) {
|
||||
super(Zone.BATTLEFIELD, new EntersBattlefieldEffect(effect, ""));
|
||||
super(Zone.BATTLEFIELD, new EntersBattlefieldEffect(effect, null));
|
||||
}
|
||||
|
||||
public EntersBattlefieldAbility(Effect effect, String rule) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl<AuraReplacement
|
|||
if (sourceObject instanceof StackAbility) {
|
||||
StackAbility stackAbility = (StackAbility) sourceObject;
|
||||
if (!stackAbility.getEffects().isEmpty()) {
|
||||
targetId = stackAbility.getEffects().get(0).getTargetPointer().getFirst(stackAbility);
|
||||
targetId = stackAbility.getEffects().get(0).getTargetPointer().getFirst(game, stackAbility);
|
||||
}
|
||||
}
|
||||
if (targetId == null) {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class EntersBattlefieldEffect extends ReplacementEffectImpl<EntersBattlef
|
|||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
if (text.length() == 0)
|
||||
if (text == null || text.length() == 0)
|
||||
return "{this} enters the battlefield " + baseEffects.getText(mode);
|
||||
else
|
||||
return "{this} enters the battlefield " + text;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class CopyTargetSpellEffect extends OneShotEffect<CopyTargetSpellEffect>
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = game.getStack().getSpell(targetPointer.getFirst(source));
|
||||
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
|
||||
if (spell != null) {
|
||||
Spell copy = spell.copySpell();
|
||||
copy.setControllerId(source.getControllerId());
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class CounterUnlessPaysEffect extends OneShotEffect<CounterUnlessPaysEffe
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(source));
|
||||
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
|
||||
if (spell != null) {
|
||||
Player player = game.getPlayer(spell.getControllerId());
|
||||
if (player != null) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class CreateTokenTargetEffect extends OneShotEffect<CreateTokenTargetEffe
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int value = amount.calculate(game, source);
|
||||
token.putOntoBattlefield(value, game, source.getSourceId(), targetPointer.getFirst(source));
|
||||
token.putOntoBattlefield(value, game, source.getSourceId(), targetPointer.getFirst(game, source));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,12 +102,12 @@ public class DamageTargetEffect extends OneShotEffect<DamageTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
permanent.damage(amount.calculate(game, source), source.getSourceId(), game, preventable, false);
|
||||
return true;
|
||||
}
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.damage(amount.calculate(game, source), source.getSourceId(), game, false, preventable);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ public class DestroyTargetEffect extends OneShotEffect<DestroyTargetEffect> {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (targetPointer.getTargets(source).size() > 0) {
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
else if (targetPointer.getTargets(game, source).size() > 0) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
permanent.destroy(source.getId(), game, noRegen);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class DiscardTargetEffect extends OneShotEffect<DiscardTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
if (randomDiscard) {
|
||||
int maxAmount = Math.min(amount.calculate(game, source), player.getHand().size());
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class DrawCardTargetEffect extends OneShotEffect<DrawCardTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.drawCards(amount.calculate(game, source), game);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ public class ExileFromZoneTargetEffect extends OneShotEffect<ExileFromZoneTarget
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
Target target = null;
|
||||
switch (zone) {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public class ExileTargetEffect extends OneShotEffect<ExileTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
|
||||
if (exileId == null) {
|
||||
exileId = getId();
|
||||
|
|
@ -84,7 +84,7 @@ public class ExileTargetEffect extends OneShotEffect<ExileTargetEffect> {
|
|||
if (permanent != null) {
|
||||
return permanent.moveToExile(exileId, exileZone, source.getSourceId(), game);
|
||||
} else {
|
||||
Card card = game.getCard(targetPointer.getFirst(source));
|
||||
Card card = game.getCard(targetPointer.getFirst(game, source));
|
||||
if (card != null) {
|
||||
return card.moveToExile(exileId, exileZone, source.getSourceId(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,12 +66,12 @@ public class ExileTargetForSourceEffect extends OneShotEffect<ExileTargetForSour
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
UUID exileId = source.getSourceId();
|
||||
if (permanent != null) {
|
||||
return permanent.moveToExile(exileId, exileZone, source.getId(), game);
|
||||
} else {
|
||||
Card card = game.getCard(targetPointer.getFirst(source));
|
||||
Card card = game.getCard(targetPointer.getFirst(game, source));
|
||||
if (card != null) {
|
||||
return card.moveToExile(exileId, exileZone, source.getId(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class GainLifeTargetEffect extends OneShotEffect<GainLifeTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID playerId: targetPointer.getTargets(source)) {
|
||||
for (UUID playerId: targetPointer.getTargets(game, source)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
player.gainLife(life, game);
|
||||
|
|
|
|||
|
|
@ -59,11 +59,11 @@ public class ImprintTargetEffect extends OneShotEffect<ImprintTargetEffect> {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||
if (sourcePermanent != null) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
sourcePermanent.imprint(permanent.getId(), game);
|
||||
} else {
|
||||
Card card = game.getCard(targetPointer.getFirst(source));
|
||||
Card card = game.getCard(targetPointer.getFirst(game, source));
|
||||
if (card != null) {
|
||||
sourcePermanent.imprint(card.getId(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ public class LoseLifeControllerEffect extends OneShotEffect<LoseLifeControllerEf
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
MageObject targetCard = game.getLastKnownInformation(targetPointer.getFirst(source), Zone.BATTLEFIELD);
|
||||
MageObject targetCard = game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD);
|
||||
|
||||
if ( targetCard == null ) {
|
||||
MageObject obj = game.getObject(targetPointer.getFirst(source));
|
||||
MageObject obj = game.getObject(targetPointer.getFirst(game, source));
|
||||
if ( obj instanceof Card ) {
|
||||
targetCard = (Card)obj;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class LoseLifeTargetEffect extends OneShotEffect<LoseLifeTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.loseLife(amount.calculate(game, source), game);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class MayTapOrUntapTargetEffect extends OneShotEffect<MayTapOrUntapTarget
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (target != null && player != null) {
|
||||
if (target.isTapped()) {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class PutLibraryIntoGraveTargetEffect extends OneShotEffect<PutLibraryInt
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
// putting cards to grave shouldn't end the game, so getting minimun available
|
||||
int cardsCount = Math.min(amount.calculate(game, source), player.getLibrary().size());
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class PutOnLibraryTargetEffect extends OneShotEffect<PutOnLibraryTargetEf
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean result = false;
|
||||
for (UUID targetId : targetPointer.getTargets(source)) {
|
||||
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
||||
switch (game.getState().getZone(targetId)) {
|
||||
case BATTLEFIELD:
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class PutOntoBattlefieldTargetEffect extends OneShotEffect<PutOntoBattlef
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean result = false;
|
||||
for (UUID targetId : targetPointer.getTargets(source)) {
|
||||
for (UUID targetId : targetPointer.getTargets(game, source)) {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null) {
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl<RegenerateTar
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
//20110204 - 701.11
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (permanent != null && permanent.regenerate(this.getId(), game)) {
|
||||
this.used = true;
|
||||
return true;
|
||||
|
|
@ -76,7 +76,7 @@ public class RegenerateTargetEffect extends ReplacementEffectImpl<RegenerateTar
|
|||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
//20110204 - 701.11c - event.getAmount() is used to signal if regeneration is allowed
|
||||
if (event.getType() == EventType.DESTROY_PERMANENT && event.getAmount() == 0 && event.getTargetId().equals(targetPointer.getFirst(source)) && !this.used) {
|
||||
if (event.getType() == EventType.DESTROY_PERMANENT && event.getAmount() == 0 && event.getTargetId().equals(targetPointer.getFirst(game, source)) && !this.used) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class RemoveFromCombatTargetEffect extends OneShotEffect<RemoveFromCombat
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (permanent != null) {
|
||||
permanent.removeFromCombat(game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public class ReturnToBattlefieldUnderYourControlTargetEffect extends OneShotEffe
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Card card = game.getCard(targetPointer.getFirst(source));
|
||||
Card card = game.getCard(targetPointer.getFirst(game, source));
|
||||
if (card != null) {
|
||||
Zone currentZone = game.getState().getZone(card.getId());
|
||||
if (card.putOntoBattlefield(game, currentZone, source.getId(), source.getControllerId())) {
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class ReturnToHandTargetEffect extends OneShotEffect<ReturnToHandTargetEf
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean result = false;
|
||||
for (UUID id : targetPointer.getTargets(source)) {
|
||||
for (UUID id : targetPointer.getTargets(game, source)) {
|
||||
switch (game.getState().getZone(id)) {
|
||||
case BATTLEFIELD:
|
||||
Permanent permanent = game.getPermanent(id);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class SacrificeEffect extends OneShotEffect<SacrificeEffect>{
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
|
||||
if (player == null) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class SacrificeEquippedEffect extends OneShotEffect<SacrificeEquippedEffe
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Permanent equipment = game.getPermanent(source.getSourceId());
|
||||
if (equipment != null && equipment.getAttachedTo() != null) {
|
||||
UUID uuid = getTargetPointer().getFirst(source);
|
||||
UUID uuid = getTargetPointer().getFirst(game, source);
|
||||
Permanent permanent = game.getPermanent(uuid);
|
||||
if (permanent == null) {
|
||||
permanent = game.getPermanent(equipment.getAttachedTo());
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class SacrificeTargetEffect extends OneShotEffect<SacrificeTargetEffect>
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
permanent.sacrifice(source.getSourceId(), game);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ public class SkipNextPlayerUntapStepEffect extends OneShotEffect<SkipNextPlayerU
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (targetPointer != null) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
game.getState().getTurnMods().add(new TurnMod(player.getId(), PhaseStep.UNTAP));
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
|
|||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
if (targetPointer.getTargets(source).size() < 2) {
|
||||
if (targetPointer.getTargets(game, source).size() < 2) {
|
||||
used = true;
|
||||
} else {
|
||||
count++;
|
||||
|
|
@ -87,7 +87,7 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
|
|||
// not clear how to turn off the effect for more than one target
|
||||
// especially as some targets may leave the battlefield since the effect creation
|
||||
// so handling this in applies method is the only option for now for such cases
|
||||
if (count == targetPointer.getTargets(source).size()) {
|
||||
if (count == targetPointer.getTargets(game, source).size()) {
|
||||
// this won't work for targets disappeared before applies() return true
|
||||
used = true;
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ public class SkipNextUntapTargetEffect extends ReplacementEffectImpl<SkipNextUnt
|
|||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (game.getTurn().getStepType() == PhaseStep.UNTAP && event.getType() == EventType.UNTAP) {
|
||||
for (UUID target : targetPointer.getTargets(source)) {
|
||||
for (UUID target : targetPointer.getTargets(game, source)) {
|
||||
if (event.getTargetId().equals(target)) {
|
||||
if (!usedFor.contains(target)) {
|
||||
usedFor.add(target);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public class TapTargetEffect extends OneShotEffect<TapTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID target : targetPointer.getTargets(source)) {
|
||||
for (UUID target : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(target);
|
||||
if (permanent != null) {
|
||||
permanent.tap(game);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class UntapTargetEffect extends OneShotEffect<UntapTargetEffect> {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID target: targetPointer.getTargets(source)) {
|
||||
for (UUID target: targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(target);
|
||||
if (permanent != null) {
|
||||
permanent.untap(game);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class AddCardSubTypeTargetEffect extends ContinuousEffectImpl<AddCardSubT
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (target != null) {
|
||||
if (!target.hasSubtype(addedSubType)) {
|
||||
target.getSubtype().add(addedSubType);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public class AddCardTypeTargetEffect extends ContinuousEffectImpl<AddCardTypeTar
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(source));
|
||||
Permanent target = game.getPermanent(targetPointer.getFirst(game, source));
|
||||
if (target != null) {
|
||||
if (!target.getCardType().contains(addedCardType))
|
||||
target.getCardType().add(addedCardType);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class BecomesCreatureTargetEffect extends ContinuousEffectImpl<BecomesCre
|
|||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
boolean result = false;
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
switch (layer) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.abilities.effects.common.continious;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.Duration;
|
||||
import mage.Constants.Layer;
|
||||
import mage.Constants.Outcome;
|
||||
|
|
@ -41,6 +40,8 @@ import mage.game.Game;
|
|||
import mage.game.permanent.Permanent;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -88,12 +89,13 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
|
|||
power = new StaticValue(power.calculate(game, source));
|
||||
toughness = new StaticValue(toughness.calculate(game, source));
|
||||
}
|
||||
targetPointer.init(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent target = (Permanent) game.getPermanent(permanentId);
|
||||
if (target != null) {
|
||||
target.addPower(power.calculate(game, source));
|
||||
|
|
|
|||
|
|
@ -33,13 +33,13 @@ import mage.Constants.Layer;
|
|||
import mage.Constants.Outcome;
|
||||
import mage.Constants.SubLayer;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.target.Target;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Mode;
|
||||
import mage.target.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -65,10 +65,16 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl<GainAbilityTar
|
|||
return new GainAbilityTargetEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
targetPointer.init(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
permanent.addAbility(ability, game);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class LoseAllAbilitiesTargetEffect extends ContinuousEffectImpl {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID permanentId : targetPointer.getTargets(source)) {
|
||||
for (UUID permanentId : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(permanentId);
|
||||
if (permanent != null) {
|
||||
permanent.getAbilities().clear();
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class AddCountersTargetEffect extends OneShotEffect<AddCountersTargetEffe
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
int affectedTargets = 0;
|
||||
for (UUID uuid : targetPointer.getTargets(source)) {
|
||||
for (UUID uuid : targetPointer.getTargets(game, source)) {
|
||||
Permanent permanent = game.getPermanent(uuid);
|
||||
if (permanent != null) {
|
||||
if (counter != null) {
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class AddPoisonCounterTargetEffect extends OneShotEffect<AddPoisonCounter
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(targetPointer.getFirst(source));
|
||||
Player player = game.getPlayer(targetPointer.getFirst(game, source));
|
||||
if (player != null) {
|
||||
player.addCounters(CounterType.POISON.createInstance(amount), game);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1,33 +1,72 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class FirstTargetPointer implements TargetPointer {
|
||||
private static FirstTargetPointer instance = new FirstTargetPointer();
|
||||
|
||||
private Map<UUID, Integer> zoneChangeCounter = new HashMap<UUID, Integer>();
|
||||
|
||||
public static FirstTargetPointer getInstance() {
|
||||
return instance;
|
||||
return new FirstTargetPointer();
|
||||
}
|
||||
|
||||
public FirstTargetPointer() {
|
||||
}
|
||||
|
||||
public FirstTargetPointer(FirstTargetPointer firstTargetPointer) {
|
||||
this.zoneChangeCounter = new HashMap<UUID, Integer>();
|
||||
for (Map.Entry<UUID, Integer> entry : firstTargetPointer.zoneChangeCounter.entrySet()) {
|
||||
this.zoneChangeCounter.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getTargets(Ability source) {
|
||||
public void init(Game game, Ability source) {
|
||||
if (source.getTargets().size() > 0) {
|
||||
for (UUID target : source.getTargets().get(0).getTargets()) {
|
||||
Card card = game.getCard(target);
|
||||
if (card != null) {
|
||||
this.zoneChangeCounter.put(target, card.getZoneChangeCounter());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getTargets(Game game, Ability source) {
|
||||
ArrayList<UUID> target = new ArrayList<UUID>();
|
||||
if (source.getTargets().size() > 0)
|
||||
target.addAll(source.getTargets().get(0).getTargets());
|
||||
if (source.getTargets().size() > 0) {
|
||||
for (UUID targetId : source.getTargets().get(0).getTargets()) {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && zoneChangeCounter.containsKey(targetId)
|
||||
&& card.getZoneChangeCounter() != zoneChangeCounter.get(targetId)) {
|
||||
continue;
|
||||
}
|
||||
target.add(targetId);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getFirst(Ability source) {
|
||||
return source.getFirstTarget();
|
||||
public UUID getFirst(Game game, Ability source) {
|
||||
UUID targetId = source.getFirstTarget();
|
||||
if (zoneChangeCounter.containsKey(targetId)) {
|
||||
Card card = game.getCard(targetId);
|
||||
if (card != null && zoneChangeCounter.containsKey(targetId)
|
||||
&& card.getZoneChangeCounter() != zoneChangeCounter.get(targetId)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return targetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TargetPointer copy() {
|
||||
return instance;
|
||||
return new FirstTargetPointer(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -8,6 +10,7 @@ import java.util.UUID;
|
|||
|
||||
public class FixedTarget implements TargetPointer {
|
||||
private UUID target;
|
||||
private int zoneChangeCounter;
|
||||
|
||||
public FixedTarget(UUID target) {
|
||||
this.target = target;
|
||||
|
|
@ -15,17 +18,42 @@ public class FixedTarget implements TargetPointer {
|
|||
|
||||
public FixedTarget(final FixedTarget fixedTarget) {
|
||||
this.target = fixedTarget.target;
|
||||
this.zoneChangeCounter = fixedTarget.zoneChangeCounter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getTargets(Ability source) {
|
||||
public void init(Game game, Ability source) {
|
||||
Card card = game.getCard(target);
|
||||
if (card != null) {
|
||||
this.zoneChangeCounter = card.getZoneChangeCounter();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UUID> getTargets(Game game, Ability source) {
|
||||
// check target not changed zone
|
||||
if (this.zoneChangeCounter > 0) { // will be zero if not defined in init
|
||||
Card card = game.getCard(target);
|
||||
if (card != null && card.getZoneChangeCounter() != this.zoneChangeCounter) {
|
||||
return new ArrayList<UUID>(); // return empty
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<UUID> list = new ArrayList<UUID>(1);
|
||||
list.add(target);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getFirst(Ability source) {
|
||||
public UUID getFirst(Game game, Ability source) {
|
||||
// check target not changed zone
|
||||
if (this.zoneChangeCounter > 0) { // will be zero if not defined in init
|
||||
Card card = game.getCard(target);
|
||||
if (card != null && card.getZoneChangeCounter() != this.zoneChangeCounter) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
package mage.target.targetpointer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface TargetPointer extends Serializable {
|
||||
List<UUID> getTargets(Ability source);
|
||||
UUID getFirst(Ability source);
|
||||
void init(Game game, Ability source);
|
||||
List<UUID> getTargets(Game game, Ability source);
|
||||
UUID getFirst(Game game, Ability source);
|
||||
TargetPointer copy();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue