use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class RiskyMoveCreatureGainControlEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Player newController = game.getPlayer(getTargetPointer().getFirst(game, source));
if (newController != null && controller != null && sourceObject != null && sourceObject.equals(sourcePermanent)) {
// remove old control effects of the same player
for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (effect instanceof GainControlTargetEffect) {
UUID checkId = (UUID) effect.getValue("RiskyMoveSourceId");
UUID controllerId = (UUID) effect.getValue("RiskyMoveControllerId");
if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) {
effect.discard();
}
}
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, true, newController.getId());
effect.setValue("RiskyMoveSourceId", source.getSourceId());
effect.setValue("RiskyMoveControllerId", newController.getId());
effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
effect.setText("and gains control of it");
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ScrambleverseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
PlayerList players = game.getState().getPlayersInRange(source.getControllerId(), game);
int count = players.size();
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, players.get(RandomUtil.nextInt(count)));
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
permanent.untap(game);
}
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class SuddenSubstitutionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getSpell(source.getTargets().get(0).getFirstTarget());
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (spell == null || creature == null) {
return false;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, spell.getControllerId());
effect.setTargetPointer(new FixedTarget(creature, game));
spell.setControllerId(creature.getControllerId());
spell.chooseNewTargets(game, creature.getControllerId());
game.addEffect(effect, source);
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class FrenziedFugueTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
this.getEffects().clear();
boolean result;
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
result = event.getTargetId().equals(this.getSourceId());
} else {
result = event.getPlayerId().equals(this.getControllerId());
}
if (result) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
Effect effect = new GainControlTargetEffect(Duration.EndOfTurn, true);
effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
this.getEffects().add(effect);
effect = new UntapTargetEffect();
effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
this.getEffects().add(effect);
effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(enchantment.getAttachedTo(), game));
this.getEffects().add(effect);
} else {
result = false;
}
}
return result;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class GhazbanOgreEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
Player newController = null;
int lowLife = Integer.MIN_VALUE;
boolean tie = false;
for (UUID playerID : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerID);
if (player != null) {
if (player.getLife() > lowLife) {
lowLife = player.getLife();
newController = player;
tie = false;
} else if (player.getLife() == lowLife) {
tie = true;
}
}
}
if (!controller.equals(newController) && !tie && newController != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newController.getId());
effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
Aggregations