use of mage.MageObject in project mage by magefree.
the class BingoCount method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
if (spell.getManaValue() > 9) {
return true;
}
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
// Map<number, amount of counters>
Map<Integer, Integer> chipCounters = new HashMap<>();
if (game.getState().getValue(mageObject.getId() + "_chip") != null) {
chipCounters.putAll((Map<Integer, Integer>) game.getState().getValue(mageObject.getId() + "_chip"));
}
chipCounters.putIfAbsent(spell.getManaValue(), 0);
chipCounters.put(spell.getManaValue(), chipCounters.get(spell.getManaValue()) + 1);
game.getState().setValue(mageObject.getId() + "_chip", chipCounters);
if (mageObject instanceof Permanent) {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Map.Entry<Integer, Integer> entry : chipCounters.entrySet()) {
i++;
sb.append(entry.getKey());
if (i < chipCounters.size()) {
sb.append(", ");
}
}
((Permanent) mageObject).addInfo("chip counters", CardUtil.addToolTipMarkTags("Chip counters at: " + sb), game);
new AddCountersSourceEffect(CounterType.CHIP.createInstance()).apply(game, source);
}
return true;
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class BreyasApprenticeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || sourceObject == null) {
return false;
}
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
game.addEffect(new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.UntilEndOfYourNextTurn).setTargetPointer(new FixedTarget(card, game)), source);
return true;
}
use of mage.MageObject in project mage by magefree.
the class CemeteryProtectorTriggeredAbility method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetCardInGraveyard target = new TargetCardInGraveyard();
target.setNotTarget(true);
controller.choose(outcome, target, source.getSourceId(), game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
MageObject sourceObject = source.getSourceObject(game);
String exileName = sourceObject == null ? null : sourceObject.getIdName();
return controller.moveCardsToExile(card, source, game, true, exileId, exileName);
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class CerebralEruptionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
if (player != null && sourceObject != null && player.getLibrary().hasCards()) {
Card card = player.getLibrary().getFromTop(game);
Cards cards = new CardsImpl(card);
player.revealCards(sourceObject.getIdName(), cards, game);
game.getState().setValue(source.getSourceId().toString(), card);
int damage = card.getManaValue();
player.damage(damage, source.getSourceId(), source, game);
for (Permanent perm : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, player.getId(), game)) {
perm.damage(damage, source.getSourceId(), source, game, false, true);
}
if (card.isLand(game)) {
Card spellCard = game.getStack().getSpell(source.getSourceId()).getCard();
if (spellCard != null) {
player.moveCards(spellCard, Zone.HAND, source, game);
}
}
return true;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class CephalidShrineEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
MageObject mageObject = game.getObject(sourceId);
if (spell != null && mageObject != null) {
game.getState().setValue("cephalidShrine" + mageObject, spell);
return true;
}
return false;
}
Aggregations