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); 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(); sacThreshold = SpecialCardAi.DesecrationDemon.getSacThreshold();
} else if (considerSacThreshold != -1) { } else if (considerSacThreshold != -1) {
sacThreshold = considerSacThreshold; sacThreshold = considerSacThreshold;
@@ -1227,12 +1224,12 @@ public class ComputerUtil {
final Game game = sa.getActivatingPlayer().getGame(); final Game game = sa.getActivatingPlayer().getGame();
final PhaseHandler ph = game.getPhaseHandler(); final PhaseHandler ph = game.getPhaseHandler();
return (sa.getHostCard().isCreature() return sa.getHostCard().isCreature()
&& sa.getPayCosts().hasTapCost() && sa.getPayCosts().hasTapCost()
&& (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS) && (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS)
&& !ph.getNextTurn().equals(sa.getActivatingPlayer())) && !ph.getNextTurn().equals(sa.getActivatingPlayer()))
&& !sa.getHostCard().hasSVar("EndOfTurnLeavePlay") && !sa.getHostCard().hasSVar("EndOfTurnLeavePlay")
&& !sa.hasParam("ActivationPhases")); && !sa.hasParam("ActivationPhases");
} }
//returns true if it's better to wait until blockers are declared). //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) { public static CardCollection getSafeTargets(final Player ai, SpellAbility sa, CardCollectionView validCards) {
CardCollection safeCards = new CardCollection(validCards); CardCollection safeCards = CardLists.filter(validCards, new Predicate<Card>() {
safeCards = CardLists.filter(safeCards, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
if (c.getController() == ai) { if (c.getController() == ai) {
@@ -2615,8 +2611,7 @@ public class ComputerUtil {
} }
public static Card getKilledByTargeting(final SpellAbility sa, CardCollectionView validCards) { public static Card getKilledByTargeting(final SpellAbility sa, CardCollectionView validCards) {
CardCollection killables = new CardCollection(validCards); CardCollection killables = CardLists.filter(validCards, new Predicate<Card>() {
killables = CardLists.filter(killables, new Predicate<Card>() {
@Override @Override
public boolean apply(final Card c) { public boolean apply(final Card c) {
return c.getController() != sa.getActivatingPlayer() && c.getSVar("Targeting").equals("Dies"); 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.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
import forge.game.card.Card; import forge.game.card.Card;
@@ -20,6 +21,7 @@ public class MutateAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) { protected boolean canPlayAI(Player aiPlayer, SpellAbility sa) {
CardCollectionView mutateTgts = CardLists.getTargetableCards(aiPlayer.getCreaturesInPlay(), sa); CardCollectionView mutateTgts = CardLists.getTargetableCards(aiPlayer.getCreaturesInPlay(), sa);
mutateTgts = ComputerUtil.getSafeTargets(aiPlayer, sa, mutateTgts);
// Filter out some abilities that are useless // Filter out some abilities that are useless
// TODO: add other stuff useless for Mutate here // 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); CardCollection list = CardLists.getTargetableCards(targetController.getCardsIn(ZoneType.Battlefield), sa);
if (!sa.isCurse()) {
list = ComputerUtil.getSafeTargets(ai, sa, list);
}
if (list.isEmpty()) { if (list.isEmpty()) {
return false; 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, private boolean untapTargetList(final Card source, final TargetRestrictions tgt, final SpellAbility sa, final boolean mandatory,
final CardCollection tapList) { final CardCollection tapList) {
for (final Card c : sa.getTargets().getTargetCards()) { tapList.removeAll(sa.getTargets().getTargetCards());
tapList.remove(c);
}
if (tapList.isEmpty()) { if (tapList.isEmpty()) {
return false; return false;

View File

@@ -899,12 +899,12 @@ public class Cost implements Serializable {
part.getType().equals(other.getType()) && part.getType().equals(other.getType()) &&
StringUtils.isNumeric(part.getAmount()) && StringUtils.isNumeric(part.getAmount()) &&
StringUtils.isNumeric(other.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 (part instanceof CostPutCounter) { // path for Carth & Cumulative Upkeep
if (other instanceof CostPutCounter && ((CostPutCounter)other).getCounter().equals(((CostPutCounter) part).getCounter())) { if (other instanceof CostPutCounter && ((CostPutCounter)other).getCounter().equals(((CostPutCounter) part).getCounter())) {
costParts.add(new CostPutCounter(amount, ((CostPutCounter) part).getCounter(), part.getType(), part.getTypeDescription())); costParts.add(new CostPutCounter(amount, ((CostPutCounter) part).getCounter(), part.getType(), part.getTypeDescription()));
} else if (other instanceof CostRemoveCounter && ((CostRemoveCounter)other).counter.is(CounterEnumType.LOYALTY)) { } 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 // the cost can turn positive if multiple Carth raise it
if (counters < 0) { if (counters < 0) {
costParts.add(new CostPutCounter(String.valueOf(counters *-1), CounterType.get(CounterEnumType.LOYALTY), part.getType(), part.getTypeDescription())); 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) { public void loadDeck(Deck deck, boolean substituteCurrentDeck) {
boolean isStored; boolean isStored;
boolean isInfinite = view.getCatalogManager().isInfinite(); boolean isInfinite = view.getCatalogManager().isInfinite();
Deck currentDeck = view.getHumanDeck();
if (isInfinite) { if (isInfinite) {
Deck currentDeck = view.getHumanDeck();
if (substituteCurrentDeck || currentDeck.isEmpty()) { if (substituteCurrentDeck || currentDeck.isEmpty()) {
newModel(); newModel();
isStored = false; isStored = false;
@@ -109,6 +109,8 @@ public class DeckController<T extends DeckBase> {
isStored = false; isStored = false;
} }
// not the same as before
Deck currentDeck = view.getHumanDeck();
for (DeckSection section: EnumSet.allOf(DeckSection.class)) { for (DeckSection section: EnumSet.allOf(DeckSection.class)) {
if (view.isSectionImportable(section)) { if (view.isSectionImportable(section)) {
CardPool sectionCards = currentDeck.getOrCreate(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 // create sorted list from map from least to most frequent
List<Entry<String, Integer>> sortedList = Lists.newArrayList(typesInDeck.entrySet()); List<Entry<String, Integer>> sortedList = Lists.newArrayList(typesInDeck.entrySet());
Collections.sort(sortedList, new Comparator<Entry<String, Integer>>() { Collections.sort(sortedList, new Comparator<Entry<String, Integer>>() {