use of mage.abilities.Ability in project mage by magefree.
the class RickSteadfastLeaderGainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Object choice = game.getState().getValue(source.getSourceId() + "_rick");
if (!(choice instanceof String)) {
return false;
}
Ability ability1 = null;
Ability ability2 = null;
switch(((String) choice)) {
case "First strike and vigilance":
ability1 = FirstStrikeAbility.getInstance();
ability2 = VigilanceAbility.getInstance();
break;
case "First strike and lifelink":
ability1 = FirstStrikeAbility.getInstance();
ability2 = LifelinkAbility.getInstance();
break;
case "Vigilance and lifelink":
ability1 = VigilanceAbility.getInstance();
ability2 = LifelinkAbility.getInstance();
break;
default:
return false;
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent == null) {
continue;
}
permanent.addAbility(ability1, source.getSourceId(), game);
permanent.addAbility(ability2, source.getSourceId(), game);
}
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class RicochetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
Targets targets = new Targets();
Ability sourceAbility = spell.getSpellAbility();
for (UUID modeId : sourceAbility.getModes().getSelectedModes()) {
Mode mode = sourceAbility.getModes().get(modeId);
targets.addAll(mode.getTargets());
}
if (targets.size() != 1 || targets.get(0).getTargets().size() != 1) {
return false;
}
Map<Player, Integer> playerRolls = new HashMap<>();
for (UUID playerId : game.getPlayerList().copy()) {
Player player = game.getPlayer(playerId);
if (player != null) {
playerRolls.put(player, 7);
}
}
do {
for (Player player : playerRolls.keySet()) {
// bad outcome - ai must choose lowest value
playerRolls.put(player, player.rollDice(Outcome.Detriment, source, game, 6));
}
int minValueInMap = Collections.min(playerRolls.values());
for (Map.Entry<Player, Integer> mapEntry : new HashSet<>(playerRolls.entrySet())) {
if (mapEntry.getValue() > minValueInMap) {
playerRolls.remove(mapEntry.getKey());
}
}
} while (playerRolls.size() > 1);
if (playerRolls.size() == 1) {
Player loser = (Player) playerRolls.keySet().toArray()[0];
UUID loserId = loser.getId();
Target target = targets.get(0);
if (target.getFirstTarget().equals(loserId)) {
return true;
}
String oldTargetName = null;
if (target.canTarget(spell.getControllerId(), loserId, sourceAbility, game)) {
Player oldPlayer = game.getPlayer(targets.getFirstTarget());
if (oldPlayer != null) {
oldTargetName = oldPlayer.getLogName();
}
target.clearChosen();
target.addTarget(loserId, sourceAbility, game);
}
MageObject sourceObject = game.getObject(source.getSourceId());
if (oldTargetName != null && sourceObject != null) {
game.informPlayers(sourceObject.getLogName() + ": Changed target of " + spell.getLogName() + " from " + oldTargetName + " to " + loser.getLogName());
}
}
return true;
}
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class SchemingSymmetryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
source.getTargets().get(0).getTargets().stream().map(playerId -> game.getPlayer(playerId)).filter(player -> player != null).forEach(player -> {
TargetCardInLibrary targetCard = new TargetCardInLibrary();
if (player.searchLibrary(targetCard, source, game)) {
Cards cards = new CardsImpl();
cards.add(targetCard.getFirstTarget());
player.shuffleLibrary(source, game);
player.putCardsOnTopOfLibrary(cards, game, source, false);
}
});
return true;
}
use of mage.abilities.Ability in project mage by magefree.
the class ShowOfConfidenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = (Spell) getValue("spellCast");
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (spell == null || watcher == null) {
return false;
}
int copies = watcher.getSpellsCastThisTurn(source.getControllerId()).stream().filter(Objects::nonNull).filter(spell1 -> spell1.isInstantOrSorcery(game)).filter(s -> !s.getSourceId().equals(source.getSourceId()) || s.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()).mapToInt(x -> 1).sum();
if (copies > 0) {
spell.createCopyOnStack(game, source, source.getControllerId(), true, copies);
}
return true;
}
use of mage.abilities.Ability 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;
}
Aggregations