mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[KHM] fixed Orvar, the All-Form triggered ability not working correctly
This commit is contained in:
parent
25f929d70e
commit
ece9108695
3 changed files with 37 additions and 8 deletions
|
@ -1,6 +1,8 @@
|
|||
package mage.cards.o;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.MageItem;
|
||||
import mage.MageObjectReference;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.common.DiscardedByOpponentTriggeredAbility;
|
||||
|
@ -18,8 +20,10 @@ import mage.constants.SubType;
|
|||
import mage.constants.SuperType;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.filter.predicate.Predicate;
|
||||
import mage.filter.predicate.Predicates;
|
||||
import mage.filter.predicate.mageobject.MageObjectReferencePredicate;
|
||||
import mage.filter.predicate.permanent.PermanentIdPredicate;
|
||||
import mage.game.Controllable;
|
||||
import mage.game.Game;
|
||||
|
@ -85,6 +89,12 @@ enum OrvarTheAllFormCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Spell spell = (Spell) source.getEffects().get(0).getValue("spellCast");
|
||||
MageObjectReference mor;
|
||||
if (source.getSourceObjectZoneChangeCounter() == 0) {
|
||||
mor = new MageObjectReference(source.getSourceId(), game);
|
||||
} else {
|
||||
mor = new MageObjectReference(source);
|
||||
}
|
||||
return spell != null && spell
|
||||
.getSpellAbility()
|
||||
.getModes()
|
||||
|
@ -94,9 +104,9 @@ enum OrvarTheAllFormCondition implements Condition {
|
|||
.flatMap(Collection::stream)
|
||||
.map(Target::getTargets)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(uuid -> uuid != source.getSourceId())
|
||||
.map(game::getPermanent)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(p -> !mor.refersTo(p, game))
|
||||
.map(Controllable::getControllerId)
|
||||
.anyMatch(source::isControlledBy);
|
||||
}
|
||||
|
@ -121,7 +131,7 @@ class OrvarTheAllFormEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
Spell spell = (Spell) this.getValue("spellCast");
|
||||
if (spell == null) {
|
||||
if (player == null || spell == null) {
|
||||
return false;
|
||||
}
|
||||
List<Predicate<Permanent>> predicates = spell
|
||||
|
@ -133,18 +143,17 @@ class OrvarTheAllFormEffect extends OneShotEffect {
|
|||
.flatMap(Collection::stream)
|
||||
.map(Target::getTargets)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(uuid -> uuid != source.getSourceId())
|
||||
.map(game::getPermanent)
|
||||
.filter(Objects::nonNull)
|
||||
.map(Controllable::getControllerId)
|
||||
.filter(source::isControlledBy)
|
||||
.map(MageItem::getId)
|
||||
.map(PermanentIdPredicate::new)
|
||||
.collect(Collectors.toList());
|
||||
if (predicates.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
FilterPermanent filter = new FilterPermanent("a permanent targeted by this spell");
|
||||
FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
|
||||
filter.add(Predicates.or(predicates));
|
||||
filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
|
||||
TargetPermanent target = new TargetPermanent(filter);
|
||||
target.setNotTarget(true);
|
||||
player.choose(outcome, target, source.getSourceId(), game);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package mage;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
|
@ -52,6 +53,15 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
this.zoneChangeCounter = -1;
|
||||
}
|
||||
|
||||
public MageObjectReference(Ability source) {
|
||||
this(source, 0);
|
||||
}
|
||||
|
||||
public MageObjectReference(Ability source, int modifier) {
|
||||
this.sourceId = source.getSourceId();
|
||||
this.zoneChangeCounter = source.getSourceObjectZoneChangeCounter() + modifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sourceId can be null
|
||||
* @param game
|
||||
|
|
|
@ -31,8 +31,8 @@ public class ConditionalInterveningIfTriggeredAbility extends TriggeredAbilityIm
|
|||
*
|
||||
* @param ability
|
||||
* @param condition
|
||||
* @param text explicit rule text for the ability, if null or empty, the
|
||||
* rule text generated by the triggered ability itself is used.
|
||||
* @param text explicit rule text for the ability, if null or empty, the
|
||||
* rule text generated by the triggered ability itself is used.
|
||||
*/
|
||||
public ConditionalInterveningIfTriggeredAbility(TriggeredAbility ability, Condition condition, String text) {
|
||||
super(ability.getZone(), null);
|
||||
|
@ -112,4 +112,14 @@ public class ConditionalInterveningIfTriggeredAbility extends TriggeredAbilityIm
|
|||
public boolean isOptional() {
|
||||
return ability.isOptional();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceObjectZoneChangeCounter(int sourceObjectZoneChangeCounter) {
|
||||
ability.setSourceObjectZoneChangeCounter(sourceObjectZoneChangeCounter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceObjectZoneChangeCounter() {
|
||||
return ability.getSourceObjectZoneChangeCounter();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue