use of mage.MageObjectReference in project mage by magefree.
the class RadiantScrollwielderWatcher method checkSpell.
static boolean checkSpell(Card card, Ability source, Game game) {
if (card == null) {
return false;
}
RadiantScrollwielderWatcher watcher = game.getState().getWatcher(RadiantScrollwielderWatcher.class);
if (watcher == null) {
return false;
}
MageObjectReference mor = watcher.morMap.getOrDefault(new MageObjectReference(card, game), null);
return mor != null && mor.refersTo(source.getSourceObject(game), game);
}
use of mage.MageObjectReference in project mage by magefree.
the class SoulflayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
// one time abilities collect
if (objectReference == null || !objectReference.refersTo(permanent, game)) {
abilitiesToAdd = new HashSet<>();
this.objectReference = new MageObjectReference(permanent, game);
String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
Cards delvedCards = (Cards) game.getState().getValue(keyString);
if (delvedCards != null) {
for (Card card : delvedCards.getCards(game)) {
if (!card.isCreature(game)) {
continue;
}
for (Ability cardAbility : card.getAbilities(game)) {
if (cardAbility instanceof FlyingAbility) {
abilitiesToAdd.add(FlyingAbility.getInstance());
}
if (cardAbility instanceof FirstStrikeAbility) {
abilitiesToAdd.add(FirstStrikeAbility.getInstance());
}
if (cardAbility instanceof DoubleStrikeAbility) {
abilitiesToAdd.add(DoubleStrikeAbility.getInstance());
}
if (cardAbility instanceof DeathtouchAbility) {
abilitiesToAdd.add(DeathtouchAbility.getInstance());
}
if (cardAbility instanceof HasteAbility) {
abilitiesToAdd.add(HasteAbility.getInstance());
}
if (cardAbility instanceof HexproofBaseAbility) {
abilitiesToAdd.add(HexproofAbility.getInstance());
}
if (cardAbility instanceof IndestructibleAbility) {
abilitiesToAdd.add(IndestructibleAbility.getInstance());
}
if (cardAbility instanceof LifelinkAbility) {
abilitiesToAdd.add(LifelinkAbility.getInstance());
}
if (cardAbility instanceof ReachAbility) {
abilitiesToAdd.add(ReachAbility.getInstance());
}
if (cardAbility instanceof TrampleAbility) {
abilitiesToAdd.add(TrampleAbility.getInstance());
}
if (cardAbility instanceof VigilanceAbility) {
abilitiesToAdd.add(VigilanceAbility.getInstance());
}
}
}
}
}
// all time abilities apply
for (Ability ability : abilitiesToAdd) {
permanent.addAbility(ability, source.getSourceId(), game);
}
return true;
} else if (abilitiesToAdd != null) {
abilitiesToAdd = null;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class SparkOfCreativityPlayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
controller.moveCards(card, Zone.EXILED, source, game);
// You may have Spark of Creativity deal damage to that creature equal to the converted mana cost of the exiled card.
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null) {
int cmc = card.getManaCost().manaValue();
if (controller.chooseUse(outcome, "Let " + sourceObject.getLogName() + " deal " + cmc + " damage to " + targetCreature.getLogName() + '?', source, game)) {
targetCreature.damage(cmc, source.getSourceId(), source, game, false, true);
return true;
}
}
// If you don't, you may play that card until end of turn
game.addEffect(new SparkOfCreativityPlayEffect(new MageObjectReference(card, game)), source);
}
return true;
}
return false;
}
use of mage.MageObjectReference in project mage by magefree.
the class TakenoSamuraiGeneralEffect 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
Permanent permanent = it.next().getPermanent(game);
if (permanent != null) {
for (Ability ability : permanent.getAbilities()) {
if (ability instanceof BushidoAbility) {
int value = ((BushidoAbility) ability).getValue(source, game, this);
permanent.addPower(value);
permanent.addToughness(value);
}
}
} else {
// no longer on the battlefield, remove reference to object
it.remove();
}
}
} else {
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
if (!perm.getId().equals(source.getSourceId())) {
for (Ability ability : perm.getAbilities()) {
if (ability instanceof BushidoAbility) {
int value = ((BushidoAbility) ability).getValue(source, game, this);
perm.addPower(value);
perm.addToughness(value);
}
}
}
}
}
return true;
}
use of mage.MageObjectReference in project mage by magefree.
the class ThousandYearStormWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
MageObject object = game.getObject(event.getTargetId());
if (object != null && object.isInstantOrSorcery(game)) {
UUID playerId = event.getPlayerId();
List<MageObjectReference> spellsCast = spellsThisTurn.getOrDefault(playerId, new ArrayList<MageObjectReference>());
spellsCast.add(new MageObjectReference(object, game));
spellsThisTurn.put(playerId, spellsCast);
}
}
}
Aggregations