use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ExpropriateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// Outcome.Detriment - AI will gain control all the time (Money choice)
// TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
vote.doVotes(source, game);
// extra turn
int timeCount = vote.getVoteCount(true);
for (int i = 0; i < timeCount; i++) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
}
// gain control
if (vote.getVoteCount(false) < 1) {
return true;
}
List<Permanent> toSteal = new ArrayList<>();
for (UUID playerId : vote.getVotedFor(false)) {
int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
FilterPermanent filter = new FilterPermanent();
filter.add(new ControllerIdPredicate(playerId));
moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
if (moneyCount == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(moneyCount, filter);
target.setNotTarget(true);
player.choose(Outcome.GainControl, target, source.getSourceId(), game);
target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
}
game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
return true;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ExertInfluenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && sourceObject != null) {
int colors = new ColorsOfManaSpentToCastCount().calculate(game, source, this);
if (targetCreature.getPower().getValue() <= colors) {
game.addEffect(new GainControlTargetEffect(Duration.Custom, true), source);
}
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class InsurrectionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
ContinuousEffect gainControl = new GainControlTargetEffect(Duration.EndOfTurn);
ContinuousEffect gainHaste = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
for (Permanent creature : game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game)) {
creature.untap(game);
gainControl.setTargetPointer(new FixedTarget(creature.getId(), game));
gainHaste.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(gainControl, source);
game.addEffect(gainHaste, source);
result = true;
}
return result;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ChangeCreatureTypeTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true);
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
effect = new ChangeCreatureTypeTargetEffect(null, SubType.VAMPIRE, Duration.Custom);
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.abilities.effects.common.continuous.GainControlTargetEffect in project mage by magefree.
the class ConfiscationCoupEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
new GetEnergyCountersControllerEffect(4).apply(game, source);
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetPermanent != null) {
Cost cost = new PayEnergyCost(targetPermanent.getManaCost().manaValue());
if (cost.canPay(source, source, source.getControllerId(), game)) {
int manaValue = targetPermanent.getManaCost().manaValue();
StringBuilder energy = new StringBuilder(manaValue);
for (int i = 0; i < manaValue; i++) {
energy.append("{E}");
}
if (controller.chooseUse(outcome, "Pay " + energy + " to get control of " + targetPermanent.getLogName() + '?', source, game)) {
if (cost.pay(source, game, source, source.getControllerId(), true)) {
ContinuousEffect controllEffect = new GainControlTargetEffect(Duration.Custom);
controllEffect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(controllEffect, source);
}
}
}
}
return true;
}
return false;
}
Aggregations