mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
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:
parent
aed6a4ac3d
commit
021a2d251c
8 changed files with 173 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue