use of mage.game.permanent.Permanent in project mage by magefree.
the class HaukensInsightWatcher method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (affectedControllerId.equals(source.getControllerId()) && game.isActivePlayer(source.getControllerId())) {
Player controller = game.getPlayer(source.getControllerId());
HaukensInsightWatcher watcher = game.getState().getWatcher(HaukensInsightWatcher.class);
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (controller != null && watcher != null && sourceObject != null && !watcher.isAbilityUsed(new MageObjectReference(sourceObject, game))) {
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()));
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null && exileZone.contains(CardUtil.getMainCardId(game, objectId))) {
allowCardToPlayWithoutMana(objectId, source, affectedControllerId, game);
return true;
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HeartPiercerManticoreSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Target target = new TargetControlledCreaturePermanent(1, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
if (!controller.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
if (toSacrifice == null) {
return false;
}
int power = toSacrifice.getPower().getValue();
if (!toSacrifice.sacrifice(source, game)) {
return false;
}
ReflexiveTriggeredAbility trigger = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, "{this} deals damage equal to that creature's power to any target.");
trigger.addTarget(new TargetAnyTarget());
game.fireReflexiveTriggeredAbility(trigger, source);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HeartlessActEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
int toRemove = 3;
int removed = 0;
String[] counterNames = permanent.getCounters(game).keySet().toArray(new String[0]);
for (String counterName : counterNames) {
if (controller.chooseUse(Outcome.Neutral, "Remove " + counterName + " counters?", source, game)) {
if (permanent.getCounters(game).get(counterName).getCount() == 1 || (toRemove - removed == 1)) {
permanent.removeCounters(counterName, 1, source, game);
removed++;
} else {
int amount = controller.getAmount(1, Math.min(permanent.getCounters(game).get(counterName).getCount(), toRemove - removed), "How many?", game);
if (amount > 0) {
removed += amount;
permanent.removeCounters(counterName, amount, source, game);
}
}
}
if (removed >= toRemove) {
break;
}
}
game.addEffect(new BoostSourceEffect(removed, 0, Duration.EndOfTurn), source);
return true;
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HauntingWindTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent == null || !permanent.isArtifact(game)) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null) {
return false;
}
String abilityText = stackAbility.getRule(true);
if (abilityText.contains("{T}:") || abilityText.contains("{T},") || abilityText.contains("{T} or")) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getControllerId(), game));
}
return true;
}
if (event.getType() == GameEvent.EventType.TAPPED) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent == null || !permanent.isArtifact(game)) {
return false;
}
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(permanent.getControllerId(), game));
}
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HawkinsNationalLaboratoryWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SACRIFICED_PERMANENT) {
return;
}
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (permanent == null || !permanent.hasSubtype(SubType.CLUE, game)) {
return;
}
playerMap.compute(event.getPlayerId(), CardUtil::setOrIncrementValue);
}
Aggregations