mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
CopyPerm: rewoke and update with Populate
This commit is contained in:
@@ -4,6 +4,7 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.ai.*;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.*;
|
||||
import forge.game.card.CardPredicates.Presets;
|
||||
@@ -13,7 +14,9 @@ import forge.game.player.Player;
|
||||
import forge.game.player.PlayerActionConfirmMode;
|
||||
import forge.game.player.PlayerCollection;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CopyPermanentAi extends SpellAbilityAi {
|
||||
@@ -67,6 +70,12 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
||||
|
||||
@Override
|
||||
protected boolean doTriggerAINoCost(final Player aiPlayer, SpellAbility sa, boolean mandatory) {
|
||||
final Card host = sa.getHostCard();
|
||||
final Player activator = sa.getActivatingPlayer();
|
||||
final Game game = host.getGame();
|
||||
final String sourceName = ComputerUtilAbility.getAbilitySourceName(sa);
|
||||
|
||||
|
||||
// ////
|
||||
// Targeting
|
||||
if (sa.usesTargeting()) {
|
||||
@@ -81,7 +90,7 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
// Saheeli Rai + Felidar Guardian combo support
|
||||
if (sa.getHostCard().getName().equals("Saheeli Rai")) {
|
||||
if ("Saheeli Rai".equals(sourceName)) {
|
||||
CardCollection felidarGuardian = CardLists.filter(list, CardPredicates.nameEquals("Felidar Guardian"));
|
||||
if (felidarGuardian.size() > 0) {
|
||||
// can copy a Felidar Guardian and combo off, so let's do it
|
||||
@@ -131,6 +140,14 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
||||
list.remove(choice);
|
||||
sa.getTargets().add(choice);
|
||||
}
|
||||
} else if (sa.hasParam("Choices")) {
|
||||
// only check for options, does not select there
|
||||
CardCollectionView choices = game.getCardsIn(ZoneType.Battlefield);
|
||||
choices = CardLists.getValidCards(choices, sa.getParam("Choices"), activator, host);
|
||||
Collection<Card> betterChoices = getBetterOptions(aiPlayer, sa, choices, !mandatory);
|
||||
if (betterChoices.isEmpty()) {
|
||||
return mandatory;
|
||||
}
|
||||
} else {
|
||||
// if no targeting, it should always be ok
|
||||
}
|
||||
@@ -153,8 +170,20 @@ public class CopyPermanentAi extends SpellAbilityAi {
|
||||
@Override
|
||||
public Card chooseSingleCard(Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional, Player targetedPlayer) {
|
||||
// Select a card to attach to
|
||||
CardCollection betterOptions = getBetterOptions(ai, sa, options, isOptional);
|
||||
if (!betterOptions.isEmpty()) {
|
||||
options = betterOptions;
|
||||
}
|
||||
return ComputerUtilCard.getBestAI(options);
|
||||
}
|
||||
|
||||
private CardCollection getBetterOptions(Player ai, SpellAbility sa, Iterable<Card> options, boolean isOptional) {
|
||||
final Card host = sa.getHostCard();
|
||||
final Player ctrl = host.getController();
|
||||
final String filter = "Permanent.YouDontCtrl,Permanent.nonLegendary";
|
||||
// TODO add filter to not select Legendary from Other Player when ai already have a Legendary with that name
|
||||
return CardLists.getValidCards(options, filter.split(","), ctrl, host, sa);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Player chooseSinglePlayer(Player ai, SpellAbility sa, Iterable<Player> options) {
|
||||
|
||||
Reference in New Issue
Block a user