use of mage.game.stack.Spell in project mage by magefree.
the class SorcererClassWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = (Spell) getValue("spellCast");
if (spell == null) {
return false;
}
int count = SorcererClassWatcher.spellCount(source.getControllerId(), game);
if (count < 1) {
return false;
}
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
player.damage(count, spell.getId(), source, game);
}
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class StringOfDisappearancesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
Player affectedPlayer = game.getPlayer(permanent.getControllerId());
new ReturnToHandTargetEffect().apply(game, source);
if (affectedPlayer == null) {
return false;
}
if (!affectedPlayer.chooseUse(Outcome.Copy, "Pay {U}{U} to copy the spell?", source, game)) {
return true;
}
Cost cost = new ManaCostsImpl("{U}{U}");
if (!cost.pay(source, game, source, affectedPlayer.getId(), false, null)) {
return true;
}
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell == null) {
return true;
}
spell.createCopyOnStack(game, source, affectedPlayer.getId(), true);
return true;
}
use of mage.game.stack.Spell in project mage by magefree.
the class TemporalExtortionCounterSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null) {
for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null && player.chooseUse(outcome, "Pay half your life, rounded up to counter " + sourceObject.getIdName() + '?', source, game)) {
int amount = (int) Math.ceil(player.getLife() / 2f);
player.loseLife(amount, game, source, false);
game.informPlayers(player.getLogName() + " pays half their life, rounded up to counter " + sourceObject.getIdName() + '.');
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
game.getStack().counter(spell.getId(), source, game);
}
}
}
return true;
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class AbilityImpl method getMessageText.
protected String getMessageText(Game game) {
StringBuilder sb = threadLocalBuilder.get();
MageObject object = game.getObject(this.sourceId);
if (object != null) {
if (object instanceof StackAbility) {
Card card = game.getCard(((StackAbility) object).getSourceId());
if (card != null) {
sb.append(GameLog.getColoredObjectIdName(card));
} else {
sb.append(GameLog.getColoredObjectIdName(object));
}
} else if (object instanceof Spell) {
Spell spell = (Spell) object;
String castText = spell.getSpellCastText(game);
sb.append((castText.startsWith("Cast ") ? castText.substring(5) : castText));
if (spell.getFromZone() == Zone.GRAVEYARD) {
sb.append(" from graveyard");
}
sb.append(getOptionalTextSuffix(game, spell));
} else {
sb.append(GameLog.getColoredObjectIdName(object));
}
} else {
sb.append("unknown");
}
if (object instanceof Spell && ((Spell) object).getSpellAbilities().size() > 1) {
if (((Spell) object).getSpellAbility().getSpellAbilityType() == SpellAbilityType.SPLIT_FUSED) {
Spell spell = (Spell) object;
int i = 0;
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
i++;
String half;
if (i == 1) {
half = " left";
} else {
half = " right";
}
if (!spellAbility.getTargets().isEmpty()) {
sb.append(half).append(" half targeting ");
for (Target target : spellAbility.getTargets()) {
sb.append(target.getTargetedName(game));
}
}
}
} else {
Spell spell = (Spell) object;
int i = 0;
for (SpellAbility spellAbility : spell.getSpellAbilities()) {
i++;
if (i > 1) {
sb.append(" splicing ");
if (spellAbility.name.length() > 5 && spellAbility.name.startsWith("Cast ")) {
sb.append(spellAbility.name.substring(5));
} else {
sb.append(spellAbility.name);
}
}
sb.append(getTargetDescriptionForLog(spellAbility.getTargets(), game));
}
}
} else if (object instanceof Spell && ((Spell) object).getSpellAbility().getModes().size() > 1) {
Modes spellModes = ((Spell) object).getSpellAbility().getModes();
for (UUID selectedModeId : spellModes.getSelectedModes()) {
Mode selectedMode = spellModes.get(selectedModeId);
int item = 0;
for (Mode mode : spellModes.values()) {
item++;
if (mode.getId().equals(selectedMode.getId())) {
sb.append(" (mode ").append(item).append(')');
sb.append(getTargetDescriptionForLog(selectedMode.getTargets(), game));
break;
}
}
}
} else {
sb.append(getTargetDescriptionForLog(getTargets(), game));
}
return sb.toString();
}
use of mage.game.stack.Spell in project mage by magefree.
the class AdventureCastFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Spell spell = game.getStack().getSpell(source.getId());
if (spell != null) {
Card spellCard = spell.getCard();
if (spellCard instanceof AdventureCardSpell) {
UUID exileId = adventureExileId(controller.getId(), game);
game.getExile().createZone(exileId, "On an Adventure from " + controller.getName());
AdventureCardSpell adventureSpellCard = (AdventureCardSpell) spellCard;
Card parentCard = adventureSpellCard.getParentCard();
if (controller.moveCardsToExile(parentCard, source, game, true, exileId, "On an Adventure from " + controller.getName())) {
ContinuousEffect effect = new AdventureCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(parentCard, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
Aggregations