Some more changes concerning ThoughtAsEffects.

This commit is contained in:
LevelX2 2014-08-09 11:48:40 +02:00
parent d1a8678086
commit 2ca945fabf
45 changed files with 3306 additions and 206 deletions

View file

@ -34,7 +34,6 @@ import mage.abilities.condition.FixedCondition;
import mage.abilities.effects.AsThoughEffect;
import mage.abilities.effects.AsThoughEffectImpl;
import mage.constants.Duration;
import mage.constants.EffectType;
import mage.game.Game;
/**
@ -100,17 +99,17 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (lockedInCondition && !(condition instanceof FixedCondition)) {
condition = new FixedCondition(condition.apply(game, source));
}
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
return effect.applies(sourceId, source,game);
return effect.applies(sourceId, source, affectedControllerId, game);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.applies(sourceId, source, game);
return otherwiseEffect.applies(sourceId, source, affectedControllerId, game);
}
return false;
}

View file

@ -40,7 +40,7 @@ import mage.game.Game;
public interface AsThoughEffect extends ContinuousEffect {
boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game);
boolean applies(UUID sourceId, Ability source, Game game);
boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game);
AsThoughEffectType getAsThoughEffectType();
@Override

View file

@ -57,7 +57,7 @@ public abstract class AsThoughEffectImpl extends ContinuousEffectImpl implements
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game) {
return applies(sourceId, source, game);
return applies(sourceId, source, affectedAbility.getControllerId(), game);
}
@Override

View file

@ -440,7 +440,7 @@ public class ContinuousEffects implements Serializable {
for (Ability ability : abilities) {
if (controllerId.equals(ability.getControllerId())) {
if (affectedAbility == null) {
if (effect.applies(objectId, ability, game)) {
if (effect.applies(objectId, ability, controllerId, game)) {
return true;
}
} else {

View file

@ -72,7 +72,7 @@ public class CanAttackAsThoughtItDidntHaveDefenderAllEffect extends AsThoughEffe
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && filter.match(permanent, game)) {
return true;

View file

@ -62,7 +62,7 @@ public class CanAttackAsThoughtItDidntHaveDefenderEffect extends AsThoughEffectI
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
return sourceId.equals(source.getSourceId());
}

View file

@ -77,7 +77,7 @@ public class CastAsThoughItHadFlashEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
Card card = game.getCard(sourceId);
if (card != null && filter.match(card, game) && card.getSpellAbility().isInUseableZone(game, card, false)) {
if (anyPlayer) {

View file

@ -73,7 +73,7 @@ public class PlayTheTopCardEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
Card card = game.getCard(sourceId);
if (card != null && filter.match(card, game)) {
Player player = game.getPlayer(card.getOwnerId());

View file

@ -179,7 +179,7 @@ class HideawayLookAtFaceDownCardEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
Card card = game.getCard(sourceId);
if (card != null && game.getState().getZone(sourceId) == Zone.EXILED) {
Card sourceCard = game.getCard(source.getSourceId());

View file

@ -100,7 +100,7 @@ class MadnessPlayEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (sourceId.equals(source.getSourceId())) {
Card card = game.getCard(source.getSourceId());
if (card != null && card.getOwnerId().equals(source.getControllerId()) && game.getState().getZone(source.getSourceId()) == Zone.EXILED) {

View file

@ -130,7 +130,7 @@ class OfferingAsThoughEffect extends AsThoughEffectImpl {
}
@Override
public boolean applies(UUID sourceId, Ability source, Game game) {
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
return false;
}

View file

@ -479,4 +479,13 @@ public interface Player extends MageItem, Copyable<Player> {
* Free resources on match end
*/
void cleanUpOnMatchEnd();
/**
* If the next cast spell has the set sourceId, the spell will
* be cast without mana.
*
* @param sourceId the source that can be cast without mana
*/
void setCastSourceIdWithoutMana(UUID sourceId);
UUID getCastSourceIdWithoutMana();
}

View file

@ -163,6 +163,9 @@ public abstract class PlayerImpl implements Player, Serializable {
// They neither expire immediately nor last indefinitely.
protected boolean reachedNextTurnAfterLeaving = false;
// indicates that a sourceId will be cast without paying mana
protected UUID castSourceIdWithoutMana;
protected UserData userData;
/**
@ -247,6 +250,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.passedAllTurns = player.passedAllTurns;
this.priorityTimeLeft = player.getPriorityTimeLeft();
this.reachedNextTurnAfterLeaving = player.reachedNextTurnAfterLeaving;
this.castSourceIdWithoutMana = player.castSourceIdWithoutMana;
}
@Override
@ -303,6 +308,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.passed = player.isPassed();
this.priorityTimeLeft = player.getPriorityTimeLeft();
this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving();
this.castSourceIdWithoutMana = player.getCastSourceIdWithoutMana();
}
@Override
@ -354,7 +360,8 @@ public abstract class PlayerImpl implements Player, Serializable {
this.topCardRevealed = false;
this.setLife(game.getLife(), game);
this.setReachedNextTurnAfterLeaving(false);
game.getState().getWatchers().add(new BloodthirstWatcher(playerId));
game.getState().getWatchers().add(new BloodthirstWatcher(playerId));
this.castSourceIdWithoutMana = null;
}
/**
* called before apply effects
@ -375,6 +382,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.canPlayCardsFromGraveyard = false;
this.topCardRevealed = false;
this.alternativeSourceCosts.clear();
this.castSourceIdWithoutMana = null;
}
@Override
@ -734,6 +742,15 @@ public abstract class PlayerImpl implements Player, Serializable {
return true;
}
@Override
public void setCastSourceIdWithoutMana(UUID sourceId) {
castSourceIdWithoutMana = sourceId;
}
public UUID getCastSourceIdWithoutMana() {
return castSourceIdWithoutMana;
}
@Override
public boolean cast(SpellAbility ability, Game game, boolean noMana) {
@ -751,6 +768,11 @@ public abstract class PlayerImpl implements Player, Serializable {
Zone fromZone = game.getState().getZone(card.getId());
card.cast(game, fromZone, ability, playerId);
Spell spell = game.getStack().getSpell(ability.getId());
// some effects set sourceId to cast without paying mana costs
if (ability.getSourceId().equals(getCastSourceIdWithoutMana())) {
noMana = true;
}
setCastSourceIdWithoutMana(null);
if (spell.activate(game, noMana)) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
event.setZone(fromZone);