use of mage.game.stack.StackObject in project mage by magefree.
the class GuileReplacementEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Spell counteredSpell = game.getStack().getSpell(event.getTargetId());
StackObject counteringObject = game.getStack().getStackObject(event.getSourceId());
return counteredSpell != null && counteringObject != null && counteringObject.isControlledBy(source.getControllerId());
}
use of mage.game.stack.StackObject in project mage by magefree.
the class HopeOfGhirapurCombatDamageWatcher method playerGotCombatDamage.
/**
* Checks if the current object has damaged the player during the current
* turn.
*
* @param objectId
* @param playerId
* @return
*/
public boolean playerGotCombatDamage(UUID objectId, UUID playerId, Game game) {
StackObject stackObject = game.getState().getStack().getStackObject(objectId);
MageObjectReference mor;
if (stackObject instanceof StackAbility) {
// This is neccessary because the source object was sacrificed as cost and the correct zone change counter for target calid check can only be get from stack
mor = new MageObjectReference(objectId, ((StackAbility) stackObject).getSourceObjectZoneChangeCounter(), game);
} else {
mor = new MageObjectReference(objectId, game);
}
if (combatDamagedPlayers.containsKey(mor)) {
return combatDamagedPlayers.get(mor).contains(playerId);
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SpellSyphonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
int amount = controller.getHand().size();
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, false);
if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class TeferisResponseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = source.getFirstTarget();
StackObject stackObject = game.getStack().getStackObject(targetId);
if (targetId != null && game.getStack().counter(targetId, source, game)) {
UUID permanentId = stackObject.getSourceId();
if (permanentId != null) {
Permanent usedPermanent = game.getPermanent(permanentId);
if (usedPermanent != null) {
usedPermanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class UnpredictableCycloneReplacementEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!event.getPlayerId().equals(source.getControllerId())) {
return false;
}
Player player = game.getPlayer(event.getPlayerId());
// event.getSourceId() will be null for default draws (non effects)
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (player == null || stackObject == null || stackObject.getStackAbility() == null || !(stackObject.getStackAbility() instanceof CyclingAbility)) {
return false;
}
Card sourceCard = game.getCard(stackObject.getSourceId());
return sourceCard != null && !sourceCard.isLand(game);
}
Aggregations