use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class HeraldOfLeshracLeavesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (playerId.equals(source.getControllerId())) {
continue;
}
FilterPermanent filter = new FilterLandPermanent();
filter.add(new OwnerIdPredicate(playerId));
filter.add(new ControllerIdPredicate(source.getControllerId()));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, playerId);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class KaronaFalseGodEffect 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)) {
sourcePermanent.untap(game);
game.informPlayers(newController.getLogName() + " untaps " + sourceObject.getIdName());
// 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("KaronaFalseGodSourceId");
UUID controllerId = (UUID) effect.getValue("KaronaFalseGodControllerId");
if (source.getSourceId().equals(checkId) && newController.getId().equals(controllerId)) {
effect.discard();
}
}
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, newController.getId());
effect.setValue("KaronaFalseGodSourceId", source.getSourceId());
effect.setValue("KaronaFalseGodControllerId", 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 PreacherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && sourcePermanent != null && targetPermanent != null) {
SourceTappedCondition sourceTappedCondition = SourceTappedCondition.TAPPED;
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom), sourceTappedCondition, "Gain control of target creature of an opponent's choice that they control for as long as {this} remains tapped");
effect.setTargetPointer(new FixedTarget(targetPermanent.getId(), game));
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class SokenzanRenegadeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null && sourcePermanent != null) {
int max = Integer.MIN_VALUE;
Player newController = null;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getHand().size() > max) {
max = player.getHand().size();
newController = player;
}
}
}
if (newController != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, newController.getId());
effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), game));
game.addEffect(effect, source);
if (!source.isControlledBy(newController.getId())) {
game.informPlayers(newController.getLogName() + " got control of " + sourcePermanent.getLogName());
}
return true;
}
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class TheWretchedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent theWretched = source.getSourcePermanentIfItStillExists(game);
if (theWretched == null || theWretched.isRemovedFromCombat() || !theWretched.isAttacking() || !source.isControlledBy(theWretched.getControllerId())) {
return false;
}
// Check if control of source has changed since ability triggered????? (does it work is it neccessary???)
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (!combatGroup.getAttackers().contains(source.getSourceId())) {
continue;
}
for (UUID creatureId : combatGroup.getBlockers()) {
Permanent blocker = game.getPermanent(creatureId);
if (blocker == null || blocker.getBlocking() <= 0) {
continue;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.WhileControlled, source.getControllerId());
effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
Aggregations