use of mage.game.command.Plane in project mage by magefree.
the class DrawCardsActivePlayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_ACADEMY_AT_TOLARIA_WEST)) {
return false;
}
Player player = game.getPlayer(game.getActivePlayerId());
if (player != null) {
player.drawCards(amount.calculate(game, source, this), source, game);
return true;
}
return false;
}
use of mage.game.command.Plane in project mage by magefree.
the class FeedingGroundsEffect method applies.
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_FEEDING_GROUNDS)) {
return false;
}
Spell spell = (Spell) game.getStack().getStackObject(abilityToModify.getId());
if (spell != null) {
return filter.match(spell, game) && selectedByRuntimeData(spell, source, game);
} else {
// used at least for flashback ability because Flashback ability doesn't use stack
Card sourceCard = game.getCard(abilityToModify.getSourceId());
return filter.match(sourceCard, game) && selectedByRuntimeData(sourceCard, source, game);
}
}
return false;
}
use of mage.game.command.Plane in project mage by magefree.
the class RollPlanarDieEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && mageObject != null) {
PlanarDieRollResult planarRoll = controller.rollPlanarDie(outcome, source, game);
if (planarRoll == PlanarDieRollResult.CHAOS_ROLL && chaosEffects != null && chaosTargets != null) {
for (int i = 0; i < chaosTargets.size(); i++) {
Target target = chaosTargets.get(i);
if (target != null) {
target.clearChosen();
}
}
for (int i = 0; i < chaosEffects.size(); i++) {
Effect effect = chaosEffects.get(i);
Target target = null;
if (chaosTargets.size() > i) {
target = chaosTargets.get(i);
}
boolean done = false;
while (controller.canRespond() && effect != null && !done) {
if (target != null && !target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target, source, game);
source.addTarget(target);
}
if (target != null) {
effect.setTargetPointer(new FixedTarget(target.getFirstTarget()));
}
try {
effect.apply(game, source);
} catch (UnsupportedOperationException exception) {
}
if (effect instanceof ContinuousEffect) {
game.addEffect((ContinuousEffect) effect, source);
}
done = true;
}
}
} else if (planarRoll == PlanarDieRollResult.PLANAR_ROLL) {
// Steps: 1) Remove the last plane and set its effects to discarded
for (CommandObject cobject : game.getState().getCommand()) {
if (cobject instanceof Plane) {
if (cobject.getAbilities() != null) {
for (Ability ability : cobject.getAbilities()) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof ContinuousEffect) {
((ContinuousEffect) effect).discard();
}
}
}
}
game.getState().removeTriggersOfSourceId(cobject.getId());
game.getState().getCommand().remove(cobject);
break;
}
}
// 2) Choose a new random plane we haven't been to, or reset if we've been everywhere
List<String> planesVisited = game.getState().getSeenPlanes();
if (game.getState().getSeenPlanes() != null) {
if (planesVisited.size() == Planes.values().length) {
game.getState().resetSeenPlanes();
}
}
boolean foundNextPlane = false;
while (!foundNextPlane) {
Plane plane = Plane.createRandomPlane();
try {
if (plane != null && !planesVisited.contains(plane.getName())) {
foundNextPlane = true;
plane.setControllerId(controller.getId());
game.addPlane(plane, null, controller.getId());
}
} catch (Exception ex) {
}
}
}
return true;
}
return false;
}
use of mage.game.command.Plane in project mage by magefree.
the class UndercityReachesTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Plane cPlane = game.getState().getCurrentPlane();
if (cPlane == null) {
return false;
}
if (!cPlane.getPlaneType().equals(Planes.PLANE_UNDERCITY_REACHES)) {
return false;
}
if (((DamagedPlayerEvent) event).isCombatDamage()) {
Permanent creature = game.getPermanent(event.getSourceId());
if (creature != null) {
Effect effect = new DrawCardTargetEffect(StaticValue.get(1), true, false);
effect.setTargetPointer(new FixedTarget(creature.getControllerId()));
effect.apply(game, this);
return true;
}
}
return false;
}
use of mage.game.command.Plane in project mage by magefree.
the class AbilityImpl method isInUseableZone.
/**
* @param game
* @param source
* @return
*/
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
if (!this.hasSourceObjectAbility(game, source, event)) {
return false;
}
if (zone == Zone.COMMAND) {
if (this.getSourceId() == null) {
// commander effects
return true;
}
MageObject object = game.getObject(this.getSourceId());
// emblem/planes are always actual
if (object instanceof Emblem || object instanceof Dungeon || object instanceof Plane) {
return true;
}
}
UUID parameterSourceId;
// so will use the sourceId of the object itself that came as a parameter if it is not null
if (this instanceof MageSingleton && source != null) {
parameterSourceId = source.getId();
} else {
parameterSourceId = getSourceId();
}
// check against shortLKI for effects that move multiple object at the same time (e.g. destroy all)
if (game.getShortLivingLKI(getSourceId(), getZone())) {
return true;
}
// check against current state
Zone test = game.getState().getZone(parameterSourceId);
return zone.match(test);
}
Aggregations