use of mage.game.stack.StackAbility in project mage by magefree.
the class ComputerPlayer6 method resolve.
protected void resolve(SimulationNode2 node, int depth, Game game) {
StackObject stackObject = game.getStack().getFirst();
if (stackObject instanceof StackAbility) {
// AI hint for search effects (calc all possible cards for best score)
SearchEffect effect = getSearchEffect((StackAbility) stackObject);
if (effect != null && stackObject.getControllerId().equals(playerId)) {
Target target = effect.getTarget();
if (!target.doneChosing()) {
for (UUID targetId : target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game)) {
Game sim = game.copy();
StackAbility newAbility = (StackAbility) stackObject.copy();
SearchEffect newEffect = getSearchEffect(newAbility);
newEffect.getTarget().addTarget(targetId, newAbility, sim);
sim.getStack().push(newAbility);
SimulationNode2 newNode = new SimulationNode2(node, sim, depth, stackObject.getControllerId());
node.children.add(newNode);
newNode.getTargets().add(targetId);
logger.trace("Sim search -- node#: " + SimulationNode2.getCount() + " for player: " + sim.getPlayer(stackObject.getControllerId()).getName());
}
return;
}
}
}
stackObject.resolve(game);
if (stackObject instanceof StackAbility) {
game.getStack().remove(stackObject, game);
}
game.applyEffects();
game.getPlayers().resetPassed();
game.getPlayerList().setCurrent(game.getActivePlayerId());
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class LithoformEngineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (stackAbility != null) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null && sourcePermanent != null) {
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
}
return false;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class StrionicResonatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (stackAbility == null) {
return false;
}
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
use of mage.game.stack.StackAbility 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.StackAbility in project mage by magefree.
the class IllusionistsBracersTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent equipment = game.getPermanent(this.getSourceId());
if (equipment == null || !equipment.isAttachedTo(event.getSourceId())) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
this.getEffects().setValue("stackAbility", stackAbility);
return true;
}
Aggregations