mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
48 lines
1.6 KiB
Java
48 lines
1.6 KiB
Java
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package mage.abilities.condition.common;
|
|
|
|
import mage.MageObjectReference;
|
|
import mage.abilities.Ability;
|
|
import mage.abilities.condition.Condition;
|
|
import mage.game.Game;
|
|
import mage.game.permanent.Permanent;
|
|
import mage.watchers.common.AttackedOrBlockedThisCombatWatcher;
|
|
|
|
/**
|
|
*
|
|
* @author LevelX2
|
|
*/
|
|
public enum AttackedOrBlockedThisCombatSourceCondition implements Condition {
|
|
|
|
instance;
|
|
|
|
@Override
|
|
public boolean apply(Game game, Ability source) {
|
|
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
|
|
if (sourceObject != null) {
|
|
AttackedOrBlockedThisCombatWatcher watcher = (AttackedOrBlockedThisCombatWatcher) game.getState().getWatchers().get(AttackedOrBlockedThisCombatWatcher.class.getName());
|
|
if (watcher != null) {
|
|
for (MageObjectReference mor : watcher.getAttackedThisTurnCreatures()) {
|
|
if (mor.refersTo(sourceObject, game)) {
|
|
return true;
|
|
}
|
|
}
|
|
for (MageObjectReference mor : watcher.getBlockedThisTurnCreatures()) {
|
|
if (mor.refersTo(sourceObject, game)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "{this} attacked or blocked this combat";
|
|
}
|
|
}
|