Improves in some effects:

* ConditionalAsThoughEffect - improved support with target effects (see comments from e6e802033b);
* TargetCardInLibrary - added additional checks on wrong usage (must be used inside effects only, not as ability's target);
* PlayFromNotOwnHandZone - fixed wrong playable mark on battlefield's permanents (AI related too);
This commit is contained in:
Oleg Agafonov 2021-09-17 21:21:37 +04:00
parent aed6a4ac3d
commit 021a2d251c
8 changed files with 173 additions and 3 deletions

View file

@ -26,7 +26,9 @@ import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetCard;
import mage.target.Targets;
import mage.target.common.TargetCardInLibrary;
import mage.target.targetadjustment.TargetAdjuster;
import mage.util.CardUtil;
import mage.util.GameLog;
@ -881,6 +883,12 @@ public abstract class AbilityImpl implements Ability {
@Override
public void addTarget(Target target) {
// verify check
if (target instanceof TargetCardInLibrary
|| (target instanceof TargetCard && target.getZone().equals(Zone.LIBRARY))) {
throw new IllegalArgumentException("Wrong usage of TargetCardInLibrary - you must use it with SearchLibrary only");
}
if (target != null) {
getTargets().add(target);
}

View file

@ -65,6 +65,19 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
return false;
}
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
conditionState = condition.apply(game, source);
if (conditionState) {
effect.setTargetPointer(this.targetPointer);
return effect.applies(sourceId, affectedAbility, source, game, playerId);
} else if (otherwiseEffect != null) {
otherwiseEffect.setTargetPointer(this.targetPointer);
return otherwiseEffect.applies(sourceId, affectedAbility, source, game, playerId);
}
return false;
}
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
conditionState = condition.apply(game, source);

View file

@ -15,6 +15,7 @@ public interface AsThoughEffect extends ContinuousEffect {
* Apply to ONE affected ability from the object (sourceId)
* <p>
* Warning, if you don't need ability to check then ignore it (by default it calls full object check)
* Warning, if you use conditional effect then you must override both applies methods to support different types
*
* @param sourceId
* @param affectedAbility ability to check (example: check if spell ability can be cast from non hand)

View file

@ -85,6 +85,8 @@ public class PlayFromNotOwnHandZoneTargetEffect extends AsThoughEffectImpl {
if (affectedAbility == null) {
// ContinuousEffects.asThough already checks affectedAbility, so that error must never be called here
// PLAY_FROM_NOT_OWN_HAND_ZONE must applies to affectedAbility only
// If you see it then parent conditional effect must override both applies methods to support different
// AsThough effect types in one conditional effect
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}

View file

@ -3794,8 +3794,8 @@ public abstract class PlayerImpl implements Player, Serializable {
}
ApprovingObject approvingObject;
if (isPlaySpell || isPlayLand) {
// play hand from non hand zone
if ((isPlaySpell || isPlayLand) && (fromZone != Zone.BATTLEFIELD)) {
// play hand from non hand zone (except battlefield - you can't play already played permanents)
approvingObject = game.getContinuousEffects().asThough(object.getId(),
AsThoughEffectType.PLAY_FROM_NOT_OWN_HAND_ZONE, ability, this.getId(), game);
} else {

View file

@ -19,6 +19,9 @@ import java.util.List;
import java.util.UUID;
/**
*
* Can be used with SearchLibrary only. User hasn't access to libs.
*
* @author BetaSteward_at_googlemail.com
*/
public class TargetCardInLibrary extends TargetCard {