use of mage.game.command.CommandObject in project mage by magefree.
the class MaskwoodNexusEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// in Exile
for (Card card : game.getState().getExile().getAllCards(game)) {
if (card.isCreature(game) && card.isOwnedBy(controller.getId())) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// in Library (e.g. for Mystical Teachings)
for (Card card : controller.getLibrary().getCards(game)) {
if (card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// commander in command zone
for (CommandObject commandObject : game.getState().getCommand()) {
if (!(commandObject instanceof Commander)) {
continue;
}
Card card = game.getCard(((Commander) commandObject).getId());
if (card != null && card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell && stackObject.isControlledBy(source.getControllerId()) && stackObject.isCreature(game)) {
Card card = ((Spell) stackObject).getCard();
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
// creatures you control
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), source.getControllerId(), game);
for (Permanent creature : creatures) {
if (creature != null) {
creature.setIsAllCreatureTypes(game, true);
}
}
return true;
}
use of mage.game.command.CommandObject in project mage by magefree.
the class CardTestPlayerAPIImpl method assertCommandZoneCount.
@Override
public void assertCommandZoneCount(Player player, String commandZoneObjectName, int count) throws AssertionError {
// Assert.assertNotEquals("", commandZoneObjectName);
int actualCount = 0;
for (CommandObject commandObject : currentGame.getState().getCommand()) {
if (commandObject.getControllerId().equals(player.getId()) && isObjectHaveTargetNameOrAlias(player, commandObject, commandZoneObjectName)) {
actualCount++;
}
}
Assert.assertEquals("(Command Zone) Card counts are not equal (" + commandZoneObjectName + ')', count, actualCount);
}
use of mage.game.command.CommandObject in project mage by magefree.
the class PermanentImpl method doDamage.
/**
* @param damageAmount
* @param attackerId id of the permanent or player who make damage (source.getSourceId() in most cases)
* @param source
* @param game
* @param preventable
* @param combat
* @param markDamage If true, damage will be dealt later in applyDamage
* method, uses only in inner markDamage.
* @return
*/
private int doDamage(int damageAmount, UUID attackerId, Ability source, Game game, boolean preventable, boolean combat, boolean markDamage, List<UUID> appliedEffects) {
int damageDone = 0;
if (damageAmount < 1 || !canDamage(game.getObject(attackerId), game)) {
return 0;
}
DamageEvent event = new DamagePermanentEvent(objectId, attackerId, controllerId, damageAmount, preventable, combat);
event.setAppliedEffects(appliedEffects);
if (game.replaceEvent(event)) {
return 0;
}
int actualDamage = checkProtectionAbilities(event, attackerId, source, game);
if (actualDamage < 1) {
return 0;
}
int lethal = getLethalDamage(attackerId, game);
MageObject attacker = game.getObject(attackerId);
if (this.isCreature(game)) {
if (checkWither(event, attacker, game)) {
if (markDamage) {
// mark damage only
markDamage(CounterType.M1M1.createInstance(actualDamage), attacker, true);
} else {
Ability damageSourceAbility = null;
if (attacker instanceof Permanent) {
damageSourceAbility = ((Permanent) attacker).getSpellAbility();
}
// deal damage immediately
addCounters(CounterType.M1M1.createInstance(actualDamage), game.getControllerId(attackerId), damageSourceAbility, game);
}
} else {
this.damage = CardUtil.overflowInc(this.damage, actualDamage);
}
}
if (this.isPlaneswalker(game)) {
int loyalty = getCounters(game).getCount(CounterType.LOYALTY);
int countersToRemove = Math.min(actualDamage, loyalty);
if (attacker != null && markDamage) {
markDamage(CounterType.LOYALTY.createInstance(countersToRemove), attacker, false);
} else {
removeCounters(CounterType.LOYALTY.getName(), countersToRemove, source, game);
}
}
DamagedEvent damagedEvent = new DamagedPermanentEvent(this.getId(), attackerId, this.getControllerId(), actualDamage, combat);
damagedEvent.setExcess(actualDamage - lethal);
game.fireEvent(damagedEvent);
game.getState().addSimultaneousDamage(damagedEvent, game);
damageDone = actualDamage;
if (damageDone < 1) {
return 0;
}
UUID sourceControllerId = null;
Abilities sourceAbilities = null;
attacker = game.getPermanentOrLKIBattlefield(attackerId);
if (attacker == null) {
StackObject stackObject = game.getStack().getStackObject(attackerId);
if (stackObject != null) {
attacker = stackObject.getStackAbility().getSourceObject(game);
} else {
attacker = game.getObject(attackerId);
}
if (attacker instanceof Spell) {
sourceAbilities = ((Spell) attacker).getAbilities(game);
sourceControllerId = ((Spell) attacker).getControllerId();
} else if (attacker instanceof Card) {
sourceAbilities = ((Card) attacker).getAbilities(game);
sourceControllerId = ((Card) attacker).getOwnerId();
} else if (attacker instanceof CommandObject) {
sourceControllerId = ((CommandObject) attacker).getControllerId();
sourceAbilities = attacker.getAbilities();
} else {
attacker = null;
}
} else {
sourceAbilities = ((Permanent) attacker).getAbilities(game);
sourceControllerId = ((Permanent) attacker).getControllerId();
}
if (attacker != null && sourceAbilities != null) {
if (sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
if (markDamage) {
game.getPermanent(attackerId).markLifelink(damageDone);
} else {
Player player = game.getPlayer(sourceControllerId);
player.gainLife(damageDone, game, source);
}
}
if (sourceAbilities.containsKey(DeathtouchAbility.getInstance().getId())) {
deathtouched = true;
}
if (dealtDamageByThisTurn == null) {
dealtDamageByThisTurn = new HashSet<>();
}
// Unstable ability - Earl of Squirrel
if (sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
Player player = game.getPlayer(sourceControllerId);
new SquirrelToken().putOntoBattlefield(damageDone, game, source, player.getId());
}
dealtDamageByThisTurn.add(new MageObjectReference(attacker, game));
}
if (attacker == null) {
game.informPlayers(getLogName() + " gets " + damageDone + " damage");
} else {
game.informPlayers(attacker.getLogName() + " deals " + damageDone + " damage to " + getLogName());
}
return damageDone;
}
use of mage.game.command.CommandObject in project mage by magefree.
the class SwansOfBrynArgollEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
if (preventionEffectData.getPreventedDamage() > 0) {
boolean passed = false;
MageObject sourceOfDamage = game.getObject(event.getSourceId());
if (sourceOfDamage != null) {
Spell spell = game.getStack().getSpell(sourceOfDamage.getId());
Permanent permanent = game.getPermanentOrLKIBattlefield(sourceOfDamage.getId());
CommandObject emblem = (CommandObject) game.getEmblem(sourceOfDamage.getId());
if (spell != null) {
Player controllerOfSpell = game.getPlayer(spell.getControllerId());
if (controllerOfSpell != null) {
// original event is not a draw event, so skip it in params
controllerOfSpell.drawCards(preventionEffectData.getPreventedDamage(), source, game);
passed = true;
}
}
if (permanent != null) {
Player controllerOfPermanent = game.getPlayer(permanent.getControllerId());
if (controllerOfPermanent != null) {
// original event is not a draw event, so skip it in params
controllerOfPermanent.drawCards(preventionEffectData.getPreventedDamage(), source, game);
passed = true;
}
}
if (emblem != null) {
Player controllerOfEmblem = game.getPlayer(emblem.getControllerId());
if (controllerOfEmblem != null) {
// original event is not a draw event, so skip it in params
controllerOfEmblem.drawCards(preventionEffectData.getPreventedDamage(), source, game);
}
passed = true;
}
if (!passed) {
// Needed for cards that do damage from hand e.g. Gempalm Incinerator
Card cardSource = game.getCard(event.getSourceId());
if (cardSource != null) {
Player owner = game.getPlayer(cardSource.getOwnerId());
if (owner != null) {
// original event is not a draw event, so skip it in params
owner.drawCards(preventionEffectData.getPreventedDamage(), source, game);
}
}
}
}
}
return preventionEffectData.isReplaced();
}
use of mage.game.command.CommandObject in project mage by magefree.
the class PlayerImpl method doDamage.
private int doDamage(int damage, UUID attackerId, Ability source, Game game, boolean combatDamage, boolean preventable, List<UUID> appliedEffects) {
if (!this.isInGame()) {
return 0;
}
if (damage < 1) {
return 0;
}
if (!canDamage(game.getObject(attackerId), game)) {
MageObject sourceObject = game.getObject(attackerId);
game.informPlayers(damage + " damage " + (sourceObject == null ? "" : "from " + sourceObject.getLogName()) + " to " + getLogName() + (damage > 1 ? " were" : "was") + " prevented because of protection");
return 0;
}
DamageEvent event = new DamagePlayerEvent(playerId, attackerId, playerId, damage, preventable, combatDamage);
event.setAppliedEffects(appliedEffects);
if (game.replaceEvent(event)) {
return 0;
}
int actualDamage = event.getAmount();
if (actualDamage < 1) {
return 0;
}
UUID sourceControllerId = null;
Abilities sourceAbilities = null;
MageObject attacker = game.getPermanentOrLKIBattlefield(attackerId);
if (attacker == null) {
StackObject stackObject = game.getStack().getStackObject(attackerId);
if (stackObject != null) {
attacker = stackObject.getStackAbility().getSourceObject(game);
} else {
attacker = game.getObject(attackerId);
}
if (attacker instanceof Spell) {
sourceAbilities = ((Spell) attacker).getAbilities(game);
sourceControllerId = ((Spell) attacker).getControllerId();
} else if (attacker instanceof Card) {
sourceAbilities = ((Card) attacker).getAbilities(game);
sourceControllerId = ((Card) attacker).getOwnerId();
} else if (attacker instanceof CommandObject) {
sourceControllerId = ((CommandObject) attacker).getControllerId();
sourceAbilities = attacker.getAbilities();
}
} else {
sourceAbilities = ((Permanent) attacker).getAbilities(game);
sourceControllerId = ((Permanent) attacker).getControllerId();
}
if (event.isAsThoughInfect() || (sourceAbilities != null && sourceAbilities.containsKey(InfectAbility.getInstance().getId()))) {
addCounters(CounterType.POISON.createInstance(actualDamage), sourceControllerId, source, game);
} else {
GameEvent damageToLifeLossEvent = new GameEvent(GameEvent.EventType.DAMAGE_CAUSES_LIFE_LOSS, playerId, source, playerId, actualDamage, combatDamage);
if (!game.replaceEvent(damageToLifeLossEvent)) {
this.loseLife(damageToLifeLossEvent.getAmount(), game, source, combatDamage, attackerId);
}
}
if (sourceAbilities != null && sourceAbilities.containsKey(LifelinkAbility.getInstance().getId())) {
if (combatDamage) {
game.getPermanent(attackerId).markLifelink(actualDamage);
} else {
Player player = game.getPlayer(sourceControllerId);
player.gainLife(actualDamage, game, source);
}
}
// Unstable ability - Earl of Squirrel
if (sourceAbilities != null && sourceAbilities.containsKey(SquirrellinkAbility.getInstance().getId())) {
Player player = game.getPlayer(sourceControllerId);
new SquirrelToken().putOntoBattlefield(actualDamage, game, source, player.getId());
}
DamagedEvent damagedEvent = new DamagedPlayerEvent(playerId, attackerId, playerId, actualDamage, combatDamage);
game.fireEvent(damagedEvent);
game.getState().addSimultaneousDamage(damagedEvent, game);
return actualDamage;
}
Aggregations