some more refactoring of ConditionalInterveningIfTriggeredAbility

This commit is contained in:
theelk801 2025-06-09 12:06:11 -04:00
parent c2daa00b74
commit a895ac9803
24 changed files with 217 additions and 291 deletions

View file

@ -33,6 +33,6 @@ public enum CovenCondition implements Condition {
@Override
public String toString() {
return "if you control three or more creatures with different powers";
return "you control three or more creatures with different powers";
}
}

View file

@ -2,29 +2,29 @@ package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.Optional;
/**
* Created by glerman on 20/6/15.
*/
public enum LastTimeCounterRemovedCondition implements Condition{
public enum LastTimeCounterRemovedCondition implements Condition {
instance;
instance;
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
@Override
public boolean apply(Game game, Ability source) {
return Optional
.ofNullable(source.getSourcePermanentOrLKI(game))
.map(permanent -> permanent.getCounters(game).getCount(CounterType.TIME))
.map(x -> x == 0)
.isPresent();
}
if (permanent != null) {
final int timeCounters = permanent.getCounters(game).getCount(CounterType.TIME);
return timeCounters == 0;
} else {
return false;
@Override
public String toString() {
return "it had no time counters on it";
}
}
}

View file

@ -1,4 +1,3 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
@ -10,22 +9,21 @@ import mage.watchers.common.CastSpellLastTurnWatcher;
* @author nantuko
*/
public enum TwoOrMoreSpellsWereCastLastTurnCondition implements Condition {
instance;
instance;
@Override
public boolean apply(Game game, Ability source) {
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
if(watcher == null){
return false;
}
// if any player cast more than two spells, return true
for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) {
if (count >= 2) {
return true;
}
}
// no one cast two or more spells last turn
return false;
return game
.getState()
.getWatcher(CastSpellLastTurnWatcher.class)
.getAmountOfSpellsCastOnPrevTurn()
.values()
.stream()
.anyMatch(x -> x >= 2);
}
@Override
public String toString() {
return "a player cast two or more spells last turn";
}
}