use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class OfferingCostReductionEffect method applies.
@Override
public boolean applies(UUID sourceId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (sourceId.equals(source.getSourceId())) {
Card card = game.getCard(sourceId);
if (card == null || !card.isOwnedBy(source.getControllerId())) {
return false;
}
// because can activate is always called twice, result from first call will be used
Object object = game.getState().getValue("offering_" + card.getId());
if (object != null && object.equals(true)) {
Object alreadyConfirmed = game.getState().getValue("offering_ok_" + card.getId());
game.getState().setValue("offering_" + card.getId(), null);
game.getState().setValue("offering_ok_" + card.getId(), null);
return alreadyConfirmed != null;
} else {
// first call -> remove previous Ids
game.getState().setValue("offering_Id_" + card.getId(), null);
}
if (game.getBattlefield().count(((OfferingAbility) source).getFilter(), source.getSourceId(), source.getControllerId(), game) > 0) {
if (game.inCheckPlayableState()) {
return true;
}
FilterControlledCreaturePermanent filter = ((OfferingAbility) source).getFilter();
Card spellToCast = game.getCard(source.getSourceId());
if (spellToCast == null) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Offer a " + filter.getMessage() + " to cast " + spellToCast.getName() + '?', source, game)) {
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
player.chooseTarget(Outcome.Sacrifice, target, source, game);
if (!target.isChosen()) {
return false;
}
game.getState().setValue("offering_" + card.getId(), true);
Permanent offer = game.getPermanent(target.getFirstTarget());
if (offer != null) {
UUID activationId = UUID.randomUUID();
OfferingCostReductionEffect effect = new OfferingCostReductionEffect(activationId);
effect.setTargetPointer(new FixedTarget(offer, game));
game.addEffect(effect, source);
game.getState().setValue("offering_ok_" + card.getId(), true);
game.getState().setValue("offering_Id_" + card.getId(), activationId);
game.informPlayers(player.getLogName() + " announces to offer " + offer.getLogName() + " to cast " + // No id name to prevent to offer hand card knowledge after cancel casting
GameLog.getColoredObjectName(spellToCast));
return true;
}
} else {
game.getState().setValue("offering_" + card.getId(), true);
}
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class HauntEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch(event.getType()) {
case ENTERS_THE_BATTLEFIELD:
return game.getState().getZone(getSourceId()) == Zone.BATTLEFIELD && event.getTargetId().equals(getSourceId());
case ZONE_CHANGE:
if (usedFromExile || game.getState().getZone(getSourceId()) != Zone.EXILED) {
return false;
}
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
if (!zEvent.isDiesEvent()) {
return false;
}
Card card = game.getCard(getSourceId());
if (card == null || game.getCard(event.getTargetId()) == null) {
return false;
}
String key = new StringBuilder("Haunting_").append(getSourceId().toString()).append(card.getZoneChangeCounter(game) + (game.getPermanentOrLKIBattlefield(event.getTargetId())).getZoneChangeCounter(game)).toString();
Object object = game.getState().getValue(key);
if (!(object instanceof FixedTarget)) {
return false;
}
FixedTarget target = (FixedTarget) object;
if (target.getTarget() != null && target.getTarget().equals(event.getTargetId())) {
usedFromExile = true;
return true;
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class HauntEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getSourceId());
if (player == null || card == null) {
return false;
}
Permanent hauntedCreature = game.getPermanent(targetPointer.getFirst(game, source));
// haunting card will only be moved to exile, if
if (hauntedCreature == null) {
return false;
}
if (!player.moveCards(card, Zone.EXILED, source, game)) {
return true;
}
// remember the haunted creature
String key = new StringBuilder("Haunting_").append(source.getSourceId().toString()).append(card.getZoneChangeCounter(game) + hauntedCreature.getZoneChangeCounter(game)).toString();
game.getState().setValue(key, new FixedTarget(targetPointer.getFirst(game, source), game));
card.addInfo("hauntinfo", new StringBuilder("Haunting ").append(hauntedCreature.getLogName()).toString(), game);
hauntedCreature.addInfo("hauntinfo", new StringBuilder("Haunted by ").append(card.getLogName()).toString(), game);
game.informPlayers(new StringBuilder(card.getName()).append(" haunting ").append(hauntedCreature.getLogName()).toString());
return true;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class AchHansRunEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
FilterCard nameFilter = new FilterCard();
nameFilter.add(new NamePredicate(cardName));
TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
if (!controller.searchLibrary(target, source, game)) {
return false;
}
Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent creature = game.getPermanent(card.getId());
if (creature == null) {
return false;
}
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(creature, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class AminatousAuguryCastFromExileEffect 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) {
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, 8), source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
ExileZone auguryExileZone = game.getExile().getExileZone(source.getSourceId());
if (auguryExileZone == null) {
return true;
}
Cards cardsToCast = new CardsImpl();
cardsToCast.addAll(auguryExileZone.getCards(game));
// put a land card from among them onto the battlefield
TargetCard target = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_LAND_A);
if (cardsToCast.count(StaticFilters.FILTER_CARD_LAND, game) > 0) {
if (controller.chooseUse(Outcome.PutLandInPlay, "Put a land from among the exiled cards into play?", source, game)) {
if (controller.choose(Outcome.PutLandInPlay, cardsToCast, target, game)) {
Card card = cardsToCast.get(target.getFirstTarget(), game);
if (card != null) {
cardsToCast.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
}
for (Card card : cardsToCast.getCards(StaticFilters.FILTER_CARD_NON_LAND, game)) {
AminatousAuguryCastFromExileEffect effect = new AminatousAuguryCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
}
}
return false;
}
Aggregations