use of mage.game.events.ManaEvent in project mage by magefree.
the class CumulativeUpkeepEffect 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 && permanent != null) {
int ageCounter = permanent.getCounters(game).getCount(CounterType.AGE);
if (cumulativeCost instanceof ManaCost) {
ManaCostsImpl totalCost = new ManaCostsImpl<>();
for (int i = 0; i < ageCounter; i++) {
totalCost.add((ManaCost) cumulativeCost.copy());
}
if (player.chooseUse(Outcome.Benefit, "Pay " + totalCost.getText() + '?', source, game)) {
totalCost.clearPaid();
if (totalCost.payOrRollback(source, game, source, source.getControllerId())) {
game.fireEvent(new ManaEvent(EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), totalCost.getUsedManaToPay()));
return true;
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
if (source.getControllerId().equals(permanent.getControllerId())) {
// Permanent can only be sacrificed if you still control it
permanent.sacrifice(source, game);
}
return true;
} else {
CostsImpl<Cost> totalCost = new CostsImpl<>();
for (int i = 0; i < ageCounter; i++) {
totalCost.add(cumulativeCost.copy());
}
if (player.chooseUse(Outcome.Benefit, totalCost.getText() + '?', source, game)) {
totalCost.clearPaid();
int bookmark = game.bookmarkState();
if (totalCost.pay(source, game, source, source.getControllerId(), false, null)) {
game.fireEvent(new GameEvent(GameEvent.EventType.PAID_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
return true;
} else {
player.restoreState(bookmark, source.getRule(), game);
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.DIDNT_PAY_CUMULATIVE_UPKEEP, permanent.getId(), source, player.getId(), ageCounter, false));
permanent.sacrifice(source, game);
return true;
}
}
return false;
}
use of mage.game.events.ManaEvent in project mage by magefree.
the class ContaminationReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaEvent manaEvent = (ManaEvent) event;
Mana mana = manaEvent.getMana();
mana.setToMana(Mana.BlackMana(1));
return false;
}
use of mage.game.events.ManaEvent in project mage by magefree.
the class DeepWaterReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaEvent manaEvent = (ManaEvent) event;
Mana mana = manaEvent.getMana();
mana.setToMana(Mana.BlueMana(mana.count()));
return false;
}
use of mage.game.events.ManaEvent in project mage by magefree.
the class InfernalDarknessReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
ManaEvent manaEvent = (ManaEvent) event;
Mana mana = manaEvent.getMana();
mana.setToMana(Mana.BlackMana(mana.count()));
return false;
}
use of mage.game.events.ManaEvent in project mage by magefree.
the class ManaPool method addMana.
public void addMana(Mana manaToAdd, Game game, Ability source, boolean dontLoseUntilEOT) {
if (manaToAdd != null) {
Mana mana = manaToAdd.copy();
if (!game.replaceEvent(new ManaEvent(EventType.ADD_MANA, source.getId(), source, playerId, mana))) {
if (mana instanceof ConditionalMana) {
ConditionalMana conditionalMana = (ConditionalMana) mana;
ManaPoolItem item = new ManaPoolItem(conditionalMana, source.getSourceObject(game), conditionalMana.getManaProducerOriginalId() != null ? conditionalMana.getManaProducerOriginalId() : source.getOriginalId());
if (dontLoseUntilEOT) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
} else {
ManaPoolItem item = new ManaPoolItem(mana.getRed(), mana.getGreen(), mana.getBlue(), mana.getWhite(), mana.getBlack(), mana.getGeneric() + mana.getColorless(), source.getSourceObject(game), source.getOriginalId(), mana.getFlag());
if (dontLoseUntilEOT) {
item.setDuration(Duration.EndOfTurn);
}
this.manaItems.add(item);
}
ManaEvent manaEvent = new ManaEvent(EventType.MANA_ADDED, source.getId(), source, playerId, mana);
manaEvent.setData(mana.toString());
game.fireEvent(manaEvent);
}
}
}
Aggregations