use of mage.MageObjectReference in project mage by magefree.
the class SwitchPowerToughnessAllEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (this.affectedObjectsSet) {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
// filter may not be used again, because object can have changed filter relevant attributes but still geets boost
Permanent creature = it.next().getPermanent(game);
if (creature != null) {
int power = creature.getPower().getValue();
creature.getPower().setValue(creature.getToughness().getValue());
creature.getToughness().setValue(power);
} else {
it.remove();
}
}
} else {
for (Permanent creature : game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
int power = creature.getPower().getValue();
creature.getPower().setValue(creature.getToughness().getValue());
creature.getToughness().setValue(power);
}
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class LoseAbilityAllEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (this.affectedObjectsSet) {
for (Iterator<MageObjectReference> it = affectedObjectList.iterator(); it.hasNext(); ) {
// filter may not be used again, because object can have changed filter relevant attributes but still geets boost
// LKI is neccessary for "dies triggered abilities" to work given to permanets (e.g. Showstopper)
Permanent perm = it.next().getPermanentOrLKIBattlefield(game);
if (perm != null) {
perm.removeAbilities(ability, source.getSourceId(), game);
} else {
it.remove();
if (affectedObjectList.isEmpty()) {
discard();
}
}
}
} else {
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
System.out.println(game.getTurn() + ", " + game.getPhase() + ": " + "remove from size " + perm.getAbilities().size());
perm.removeAbilities(ability, source.getSourceId(), game);
}
}
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class GainAbilityTargetEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (durationPhaseStep != null) {
durationPlayerId = source.getControllerId();
sameStep = true;
}
// must support dynamic targets from static ability and static targets from activated abilities
if (this.affectedObjectsSet) {
// target permanents (by default)
targetPointer.getTargets(game, source).stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> {
this.affectedObjectList.add(new MageObjectReference(permanent, game));
});
// target cards with linked permanents
if (this.useOnCard) {
targetPointer.getTargets(game, source).stream().map(game::getCard).filter(Objects::nonNull).forEach(card -> {
this.affectedObjectList.add(new MageObjectReference(card, game));
});
waitingCardPermanent = true;
if (this.affectedObjectList.size() > 1) {
throw new IllegalArgumentException("Gain ability can't target a multiple cards (unsupported)");
}
}
}
}
use of mage.MageObjectReference in project mage by magefree.
the class FireGiantsFuryMayPlayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent == null) {
return false;
}
game.addDelayedTriggeredAbility(new FireGiantsFuryDelayedTriggeredAbility(new MageObjectReference(permanent, game)), source);
return true;
}
use of mage.MageObjectReference 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;
}
Aggregations