Fix misc stuff (#234)

This commit is contained in:
tool4ever
2022-05-03 17:54:24 +02:00
committed by GitHub
parent cb6f28c741
commit 2198947c53
6 changed files with 21 additions and 17 deletions

View File

@@ -329,9 +329,6 @@ public class ComputerUtil {
}
AbilityUtils.resolve(sa);
// destroys creatures if they have lethal damage, etc..
//game.getAction().checkStateEffects();
}
}
@@ -827,7 +824,7 @@ public class ComputerUtil {
}
}
if ("DesecrationDemon".equals(source.getParam("AILogic"))) {
if ("DesecrationDemon".equals(logic)) {
sacThreshold = SpecialCardAi.DesecrationDemon.getSacThreshold();
} else if (considerSacThreshold != -1) {
sacThreshold = considerSacThreshold;
@@ -1227,12 +1224,12 @@ public class ComputerUtil {
final Game game = sa.getActivatingPlayer().getGame();
final PhaseHandler ph = game.getPhaseHandler();
return (sa.getHostCard().isCreature()
return sa.getHostCard().isCreature()
&& sa.getPayCosts().hasTapCost()
&& (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
&& !ph.getNextTurn().equals(sa.getActivatingPlayer()))
&& !sa.getHostCard().hasSVar("EndOfTurnLeavePlay")
&& !sa.hasParam("ActivationPhases"));
&& !sa.hasParam("ActivationPhases");
}
//returns true if it's better to wait until blockers are declared).
@@ -2601,8 +2598,7 @@ public class ComputerUtil {
}
public static CardCollection getSafeTargets(final Player ai, SpellAbility sa, CardCollectionView validCards) {
CardCollection safeCards = new CardCollection(validCards);
safeCards = CardLists.filter(safeCards, new Predicate<Card>() {
CardCollection safeCards = CardLists.filter(validCards, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
if (c.getController() == ai) {
@@ -2615,8 +2611,7 @@ public class ComputerUtil {
}
public static Card getKilledByTargeting(final SpellAbility sa, CardCollectionView validCards) {
CardCollection killables = new CardCollection(validCards);
killables = CardLists.filter(killables, new Predicate<Card>() {
CardCollection killables = CardLists.filter(validCards, new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.getController() != sa.getActivatingPlayer() && c.getSVar("Targeting").equals("Dies");

View File

@@ -5,6 +5,7 @@ import java.util.Map;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard;
import forge.ai.SpellAbilityAi;
import forge.game.card.Card;
@@ -20,6 +21,7 @@ public class MutateAi extends SpellAbilityAi {
@Override
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
CardCollectionView mutateTgts = CardLists.getTargetableCards(aiPlayer.getCreaturesInPlay(), sa);
mutateTgts = ComputerUtil.getSafeTargets(aiPlayer, sa, mutateTgts);
// Filter out some abilities that are useless
// TODO: add other stuff useless for Mutate here

View File

@@ -133,6 +133,10 @@ public class UntapAi extends SpellAbilityAi {
CardCollection list = CardLists.getTargetableCards(targetController.getCardsIn(ZoneType.Battlefield), sa);
if (!sa.isCurse()) {
list = ComputerUtil.getSafeTargets(ai, sa, list);
}
if (list.isEmpty()) {
return false;
}
@@ -262,9 +266,7 @@ public class UntapAi extends SpellAbilityAi {
private boolean untapTargetList(final Card source, final TargetRestrictions tgt, final SpellAbility sa, final boolean mandatory,
final CardCollection tapList) {
for (final Card c : sa.getTargets().getTargetCards()) {
tapList.remove(c);
}
tapList.removeAll(sa.getTargets().getTargetCards());
if (tapList.isEmpty()) {
return false;

View File

@@ -899,12 +899,12 @@ public class Cost implements Serializable {
part.getType().equals(other.getType()) &&
StringUtils.isNumeric(part.getAmount()) &&
StringUtils.isNumeric(other.getAmount())) {
String amount = String.valueOf(Integer.parseInt(part.getAmount()) + Integer.parseInt(other.getAmount()));
String amount = String.valueOf(part.convertAmount() + other.convertAmount());
if (part instanceof CostPutCounter) { // path for Carth & Cumulative Upkeep
if (other instanceof CostPutCounter && ((CostPutCounter)other).getCounter().equals(((CostPutCounter) part).getCounter())) {
costParts.add(new CostPutCounter(amount, ((CostPutCounter) part).getCounter(), part.getType(), part.getTypeDescription()));
} else if (other instanceof CostRemoveCounter && ((CostRemoveCounter)other).counter.is(CounterEnumType.LOYALTY)) {
Integer counters = Integer.parseInt(other.getAmount()) - Integer.parseInt(part.getAmount());
Integer counters = other.convertAmount() - part.convertAmount();
// the cost can turn positive if multiple Carth raise it
if (counters < 0) {
costParts.add(new CostPutCounter(String.valueOf(counters *-1), CounterType.get(CounterEnumType.LOYALTY), part.getType(), part.getTypeDescription()));

View File

@@ -92,9 +92,9 @@ public class DeckController<T extends DeckBase> {
public void loadDeck(Deck deck, boolean substituteCurrentDeck) {
boolean isStored;
boolean isInfinite = view.getCatalogManager().isInfinite();
Deck currentDeck = view.getHumanDeck();
if (isInfinite) {
Deck currentDeck = view.getHumanDeck();
if (substituteCurrentDeck || currentDeck.isEmpty()) {
newModel();
isStored = false;
@@ -109,6 +109,8 @@ public class DeckController<T extends DeckBase> {
isStored = false;
}
// not the same as before
Deck currentDeck = view.getHumanDeck();
for (DeckSection section: EnumSet.allOf(DeckSection.class)) {
if (view.isSectionImportable(section)) {
CardPool sectionCards = currentDeck.getOrCreate(section);

View File

@@ -1345,6 +1345,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
}
// pre sort
Collections.sort(types);
// create sorted list from map from least to most frequent
List<Entry<String, Integer>> sortedList = Lists.newArrayList(typesInDeck.entrySet());
Collections.sort(sortedList, new Comparator<Entry<String, Integer>>() {