use of mage.game.permanent.Permanent in project mage by magefree.
the class AuraFinesseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent aura = game.getPermanent(source.getFirstTarget());
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (aura != null && creature != null) {
Permanent oldCreature = game.getPermanent(aura.getAttachedTo());
if (oldCreature != null && !oldCreature.equals(creature)) {
Target auraTarget = aura.getSpellAbility().getTargets().get(0);
if (!auraTarget.canTarget(creature.getId(), game)) {
game.informPlayers(aura.getLogName() + " was not attched to " + creature.getLogName() + " because it's no legal target for the aura");
} else if (oldCreature.removeAttachment(aura.getId(), source, game)) {
game.informPlayers(aura.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + creature.getLogName());
creature.addAttachment(aura.getId(), source, game);
}
}
}
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class MoveTargetAuraEffect method apply.
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
Permanent potentialAttachment = input.getObject();
for (TargetAddress addr : TargetAddress.walk(aura)) {
Target target = addr.getTarget(aura);
Filter filter = target.getFilter();
return filter.match(potentialAttachment, game);
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class AureliasFuryDamagedByWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
AureliasFuryDamagedByWatcher watcher = game.getState().getWatcher(AureliasFuryDamagedByWatcher.class, source.getSourceId());
if (watcher != null) {
for (UUID creatureId : watcher.getDamagedCreatures()) {
Permanent permanent = game.getPermanent(creatureId);
if (permanent != null) {
permanent.tap(source, game);
}
}
for (UUID playerId : watcher.getDamagedPlayers()) {
ContinuousEffect effect = new AureliasFuryCantCastEffect();
effect.setTargetPointer(new FixedTarget(playerId));
game.addEffect(effect, source);
}
watcher.reset();
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BattlefieldThaumaturgeSpellsCostReductionEffect method apply.
@Override
public boolean apply(Game game, Ability source, Ability abilityToModify) {
int reduceAmount = 0;
if (game.inCheckPlayableState()) {
// checking state (search max possible targets)
reduceAmount = getMaxPossibleTargetCreatures(abilityToModify, game);
} else {
// real cast check
Set<UUID> creaturesTargeted = new HashSet<>();
for (Target target : abilityToModify.getAllSelectedTargets()) {
if (target.isNotTarget()) {
continue;
}
for (UUID uuid : target.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null && permanent.isCreature(game)) {
creaturesTargeted.add(permanent.getId());
}
}
}
reduceAmount = creaturesTargeted.size();
}
CardUtil.reduceCost(abilityToModify, reduceAmount);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BattlefieldThaumaturgeSpellsCostReductionEffect method getMaxPossibleTargetCreatures.
private int getMaxPossibleTargetCreatures(Ability ability, Game game) {
// checks only one mode, so it can be wrong in rare use cases with multi-modes (example: mode one gives +2 and mode two gives another +1 -- total +3)
int maxAmount = 0;
for (Mode mode : ability.getModes().values()) {
for (Target target : mode.getTargets()) {
if (target.isNotTarget()) {
continue;
}
Set<UUID> possibleList = target.possibleTargets(ability.getSourceId(), ability.getControllerId(), game);
possibleList.removeIf(id -> {
Permanent permanent = game.getPermanent(id);
return permanent == null || !permanent.isCreature(game);
});
int possibleAmount = Math.min(possibleList.size(), target.getMaxNumberOfTargets());
maxAmount = Math.max(maxAmount, possibleAmount);
}
}
return maxAmount;
}
Aggregations