use of mage.target.Targets in project mage by magefree.
the class SeismicWaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Targets targets = source.getTargets();
if (targets.size() < 2) {
return false;
}
UUID firstTarget = targets.get(0).getFirstTarget();
if (firstTarget != null) {
Permanent targetPermanent = game.getPermanent(firstTarget);
if (targetPermanent != null) {
targetPermanent.damage(2, source, game);
} else {
Player targetPlayer = game.getPlayer(firstTarget);
if (targetPlayer != null) {
targetPlayer.damage(2, source, game);
}
}
}
Target targetOpponent = targets.get(1);
UUID opponentId = targetOpponent.getFirstTarget();
if (opponentId != null && targetOpponent.isLegal(source, game)) {
// Needs this check in case opponent gets hexproof at instant speed
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, opponentId, game)) {
permanent.damage(1, source, game);
}
}
return true;
}
use of mage.target.Targets in project mage by magefree.
the class RicochetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Targets targets = new Targets();
Ability sourceAbility = spell.getSpellAbility();
for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
Mode mode = sourceAbility.getModes().get(modeId);
targets.addAll(mode.getTargets());
}
if (targets.size() != 1 || targets.get(0).getTargets().size() != 1) {
return false;
}
Map<Player, Integer> playerRolls = new HashMap<>();
for (UUID playerId : game.getPlayerList().copy()) {
Player player = game.getPlayer(playerId);
if (player != null) {
playerRolls.put(player, 7);
}
}
do {
for (Player player : playerRolls.keySet()) {
// bad outcome - ai must choose lowest value
playerRolls.put(player, player.rollDice(Outcome.Detriment, source, game, 6));
}
int minValueInMap = Collections.min(playerRolls.values());
for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {
if (mapEntry.getValue() > minValueInMap) {
playerRolls.remove(mapEntry.getKey());
}
}
} while (playerRolls.size() > 1);
if (playerRolls.size() == 1) {
Player loser = (Player) playerRolls.keySet().toArray()[0];
UUID loserId = loser.getId();
Target target = targets.get(0);
if (target.getFirstTarget().equals(loserId)) {
return true;
}
String oldTargetName = null;
if (target.canTarget(spell.getControllerId(), loserId, sourceAbility, game)) {
Player oldPlayer = game.getPlayer(targets.getFirstTarget());
if (oldPlayer != null) {
oldTargetName = oldPlayer.getLogName();
}
target.clearChosen();
target.addTarget(loserId, sourceAbility, game);
}
MageObject sourceObject = game.getObject(source.getSourceId());
if (oldTargetName != null && sourceObject != null) {
game.informPlayers(sourceObject.getLogName() + ": Changed target of " + spell.getLogName() + " from " + oldTargetName + " to " + loser.getLogName());
}
}
return true;
}
return false;
}
use of mage.target.Targets in project mage by magefree.
the class SpellskiteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (stackObject != null && sourceObject != null) {
Targets targets = new Targets();
Ability sourceAbility;
String oldTargetName = null;
if (stackObject instanceof Spell) {
Spell spell = (Spell) stackObject;
sourceAbility = spell.getSpellAbility();
} else if (stackObject instanceof StackAbility) {
StackAbility stackAbility = (StackAbility) stackObject;
sourceAbility = stackAbility;
} else {
return false;
}
for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
Mode mode = sourceAbility.getModes().get(modeId);
targets.addAll(mode.getTargets());
}
boolean twoTimesTarget = false;
if (targets.size() == 1 && targets.get(0).getTargets().size() == 1) {
Target target = targets.get(0);
if (target.getFirstTarget().equals(source.getSourceId())) {
// Target was already the same source, so no change / target event to create
return true;
}
if (target.canTarget(stackObject.getControllerId(), source.getSourceId(), sourceAbility, game)) {
oldTargetName = getTargetName(targets.getFirstTarget(), game);
target.clearChosen();
// The source is still the spell on the stack
target.addTarget(source.getSourceId(), stackObject.getStackAbility(), game);
}
} else {
// needed for targeted source's with multiple targets
Player controller = game.getPlayer(source.getControllerId());
boolean validTargets = false;
do {
for (Target target : targets) {
if (target.getTargets().contains(source.getSourceId())) {
// You can't change a traget to Spellskite, if Spellskite is already targeted by this target
continue;
}
for (UUID targetId : target.getTargets()) {
String name = getTargetName(targetId, game);
if (target.canTarget(stackObject.getControllerId(), source.getSourceId(), sourceAbility, game)) {
validTargets = true;
if (name != null && controller.chooseUse(Outcome.Neutral, "Change target from " + name + " to " + sourceObject.getLogName() + '?', source, game)) {
oldTargetName = getTargetName(targetId, game);
int damageAmount = target.getTargetAmount(targetId);
target.remove(targetId);
// The source is still the spell on the stack
// add the source permanent id and set the damage if any
target.addTarget(source.getSourceId(), stackObject.getStackAbility(), game);
target.setTargetAmount(source.getSourceId(), damageAmount, game);
break;
}
}
}
if (oldTargetName != null) {
break;
}
}
if (oldTargetName == null) {
game.informPlayer(controller, "You have to select at least one target to change to " + sourceObject.getIdName() + '!');
}
} while (validTargets && oldTargetName == null);
}
if (oldTargetName != null) {
game.informPlayers(sourceObject.getLogName() + ": Changed target of " + stackObject.getLogName() + " from " + oldTargetName + " to " + sourceObject.getLogName());
} else if (twoTimesTarget) {
game.informPlayers(sourceObject.getLogName() + ": Target not changed to " + sourceObject.getLogName() + " because its not valid to target it twice for " + stackObject.getLogName());
} else {
game.informPlayers(sourceObject.getLogName() + ": Target not changed to " + sourceObject.getLogName() + " because its no valid target for " + stackObject.getLogName());
}
return true;
}
return false;
}
use of mage.target.Targets in project mage by magefree.
the class CompositeCost method getTargets.
@Override
public Targets getTargets() {
Targets result = new Targets();
result.addAll(firstCost.getTargets());
result.addAll(secondCost.getTargets());
return result;
}
use of mage.target.Targets in project mage by magefree.
the class YoseiTheMorningStarTapEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Targets targets = source.getTargets();
Target target1 = targets.get(1);
for (UUID target : target1.getTargets()) {
Permanent permanent = game.getPermanent(target);
if (permanent != null) {
permanent.tap(source, game);
} else {
return false;
}
}
return true;
}
Aggregations