use of mage.game.stack.StackObject in project mage by magefree.
the class EntersBattlefieldEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
if (optional) {
Player controller = game.getPlayer(source.getControllerId());
MageObject object = game.getPermanentEntering(source.getSourceId());
if (object == null) {
object = game.getObject(source.getSourceId());
}
if (controller == null || object == null) {
return false;
}
if (!controller.chooseUse(outcome, "Use effect of " + object.getLogName() + '?', source, game)) {
return false;
}
}
Spell entersBySpell = game.getStack().getSpell(event.getSourceId());
if (entersBySpell == null) {
StackObject stackObject = (StackObject) game.getLastKnownInformation(event.getSourceId(), Zone.STACK);
if (stackObject instanceof Spell) {
entersBySpell = (Spell) stackObject;
}
}
for (Effect effect : baseEffects) {
if (effect instanceof ContinuousEffect) {
game.addEffect((ContinuousEffect) effect, source);
} else {
if (entersBySpell != null) {
effect.setValue(SOURCE_CAST_SPELL_ABILITY, entersBySpell.getSpellAbility());
}
effect.setValue("appliedEffects", event.getAppliedEffects());
effect.apply(game, source);
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class PlaneswalkerRedirectionEffect method getSourceControllerId.
private UUID getSourceControllerId(UUID sourceId, Game game) {
StackObject source = game.getStack().getStackObject(sourceId);
if (source != null) {
return source.getControllerId();
}
Permanent permanent = game.getBattlefield().getPermanent(sourceId);
if (permanent != null) {
return permanent.getControllerId();
}
// for effects like Deflecting Palm (could be wrong if card was played multiple times by different players)
return game.getContinuousEffects().getControllerOfSourceId(sourceId);
}
use of mage.game.stack.StackObject in project mage by magefree.
the class GainAbilitySpellsEffect 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) {
return false;
}
for (Card card : game.getExile().getAllCards(game)) {
if (card.isOwnedBy(source.getControllerId()) && filter.match(card, game)) {
game.getState().addOtherAbility(card, ability);
}
}
for (Card card : player.getLibrary().getCards(game)) {
if (filter.match(card, game)) {
game.getState().addOtherAbility(card, ability);
}
}
for (Card card : player.getHand().getCards(game)) {
if (filter.match(card, game)) {
game.getState().addOtherAbility(card, ability);
}
}
for (Card card : player.getGraveyard().getCards(game)) {
if (filter.match(card, game)) {
game.getState().addOtherAbility(card, ability);
}
}
// workaround to gain cost reduction abilities to commanders before cast (make it playable)
game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY).stream().filter(card -> filter.match(card, game)).forEach(card -> {
game.getState().addOtherAbility(card, ability);
});
for (StackObject stackObject : game.getStack()) {
if (!stackObject.isControlledBy(source.getControllerId())) {
continue;
}
Card card = game.getCard(stackObject.getSourceId());
if (card == null || !filter.match(stackObject, game)) {
continue;
}
game.getState().addOtherAbility(card, ability);
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class StormEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(getSourceId())) {
StackObject spell = game.getStack().getStackObject(getSourceId());
if (spell instanceof Spell) {
for (Effect effect : this.getEffects()) {
effect.setValue("StormSpell", spell);
effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
}
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class GameState method getValue.
public String getValue(boolean useHidden, Game game) {
StringBuilder sb = threadLocalBuilder.get();
sb.append(turn.getValue(turnNum));
sb.append(activePlayerId).append(priorityPlayerId).append(playerByOrderId);
for (Player player : players.values()) {
sb.append("player").append(player.isPassed()).append(player.getLife()).append("hand");
if (useHidden) {
sb.append(player.getHand().getValue(game));
} else {
sb.append(player.getHand().size());
}
sb.append("library").append(player.getLibrary().size());
sb.append("graveyard");
sb.append(player.getGraveyard().getValue(game));
}
sb.append("permanents");
List<String> perms = new ArrayList<>();
for (Permanent permanent : battlefield.getAllPermanents()) {
perms.add(permanent.getValue(this));
}
Collections.sort(perms);
sb.append(perms);
sb.append("spells");
for (StackObject spell : stack) {
sb.append(spell.getControllerId()).append(spell.getName());
sb.append(spell.getStackAbility().toString());
for (UUID modeId : spell.getStackAbility().getModes().getSelectedModes()) {
Mode mode = spell.getStackAbility().getModes().get(modeId);
if (!mode.getTargets().isEmpty()) {
sb.append("targets");
for (Target target : mode.getTargets()) {
sb.append(target.getTargets());
}
}
}
}
for (ExileZone zone : exile.getExileZones()) {
sb.append("exile").append(zone.getName()).append(zone.getValue(game));
}
sb.append("combat");
for (CombatGroup group : combat.getGroups()) {
sb.append(group.getDefenderId()).append(group.getAttackers()).append(group.getBlockers());
}
return sb.toString();
}
Aggregations