use of mage.abilities.costs.Cost in project mage by magefree.
the class OozeFluxCreateTokenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int xValue = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveVariableCountersTargetCost) {
xValue = ((RemoveVariableCountersTargetCost) cost).getAmount();
break;
}
}
Token tokenCopy = token.copy();
tokenCopy.getAbilities().newId();
tokenCopy.getPower().modifyBaseValue(xValue);
tokenCopy.getToughness().modifyBaseValue(xValue);
tokenCopy.putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class OozeToken method apply.
@Override
public boolean apply(Game game, Ability source) {
int value = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
value = ((SacrificeTargetCost) cost).getPermanents().get(0).getPower().getValue();
}
}
Token token = new OozeToken(value);
// neccessary if token has ability like DevourAbility()
token.getAbilities().newId();
token.putOntoBattlefield(1, game, source, source.getControllerId());
return true;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class RohgahhOfKherKeepEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player == null) {
return false;
}
Cost cost = new ManaCostsImpl("{R}{R}{R}");
if (!cost.canPay(source, source, player.getId(), game) || !player.chooseUse(Outcome.Benefit, "Pay {R}{R}{R}?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
TargetOpponent target = new TargetOpponent();
Player opponent = null;
if (target.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
opponent = game.getPlayer(target.getFirstTarget());
}
new TapAllEffect(filter).apply(game, source);
if (permanent != null) {
permanent.tap(source, game);
}
if (opponent != null) {
new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
if (permanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class VodalianWarMachineWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
if (event.getSourceId() != null) {
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
if (sourcePermanent != null) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility != null) {
Ability ability = stackAbility.getStackAbility();
if (ability != null) {
for (Cost cost : ability.getCosts()) {
if (cost instanceof TapTargetCost && cost.isPaid()) {
TapTargetCost tapCost = (TapTargetCost) cost;
if (tapCost.getTarget().isChosen()) {
MageObjectReference mor = new MageObjectReference(sourcePermanent.getId(), sourcePermanent.getZoneChangeCounter(game), game);
Set<MageObjectReference> toAdd;
if (tappedMerfolkIds.get(mor) == null) {
toAdd = new HashSet<>();
} else {
toAdd = tappedMerfolkIds.get(mor);
}
for (UUID targetId : tapCost.getTarget().getTargets()) {
toAdd.add(new MageObjectReference(targetId, game));
}
tappedMerfolkIds.put(mor, toAdd);
break;
}
}
}
}
}
}
}
}
}
use of mage.abilities.costs.Cost in project mage by magefree.
the class WithdrawEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
effect.apply(game, source);
Permanent secondCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (secondCreature != null) {
Player creatureController = game.getPlayer(secondCreature.getControllerId());
if (creatureController != null) {
Cost cost = ManaUtil.createManaCost(1, false);
if (creatureController.chooseUse(Outcome.Benefit, "Pay {1}? (Otherwise " + secondCreature.getName() + " will be returned to its owner's hand)", source, game)) {
cost.pay(source, game, source, creatureController.getId(), false);
}
if (!cost.isPaid()) {
creatureController.moveCards(secondCreature, Zone.HAND, source, game);
}
}
}
return true;
}
Aggregations