Some clean up fix

This commit is contained in:
tool4EvEr
2022-03-10 08:22:55 +01:00
parent 1217c61736
commit 94d0802528
7 changed files with 21 additions and 33 deletions

View File

@@ -987,10 +987,7 @@ public class PlayerControllerAi extends PlayerController {
} }
final String logic = sa.getParam("AILogic"); final String logic = sa.getParam("AILogic");
if (logic == null || logic.equals("MostProminentHumanCreatures")) { if (logic == null || logic.equals("MostProminentHumanCreatures")) {
CardCollection list = new CardCollection(); CardCollection list = player.getOpponents().getCreaturesInPlay();
for (Player opp : player.getOpponents()) {
list.addAll(opp.getCreaturesInPlay());
}
if (list.isEmpty()) { if (list.isEmpty()) {
list = CardLists.filterControlledBy(getGame().getCardsInGame(), player.getOpponents()); list = CardLists.filterControlledBy(getGame().getCardsInGame(), player.getOpponents());
} }

View File

@@ -138,7 +138,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
return true; return true;
} else { } else {
// search targetable Opponents // search targetable Opponents
final PlayerCollection oppList = new PlayerCollection(Iterables.filter(ai.getOpponents(), PlayerPredicates.isTargetableBy(sa))); final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
if (oppList.isEmpty()) { if (oppList.isEmpty()) {
return false; return false;
@@ -162,8 +162,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
// if human creatures are more valuable // if human creatures are more valuable
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
// search targetable Opponents // search targetable Opponents
final PlayerCollection oppList = new PlayerCollection(Iterables.filter(ai.getOpponents(), final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
PlayerPredicates.isTargetableBy(sa)));
if (oppList.isEmpty()) { if (oppList.isEmpty()) {
return false; return false;
@@ -386,8 +385,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) { if (origin.equals(ZoneType.Hand) || origin.equals(ZoneType.Library)) {
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
// search targetable Opponents // search targetable Opponents
final PlayerCollection oppList = new PlayerCollection(Iterables.filter(ai.getOpponents(), final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
PlayerPredicates.isTargetableBy(sa)));
if (oppList.isEmpty()) { if (oppList.isEmpty()) {
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) { if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {
@@ -432,8 +430,7 @@ public class ChangeZoneAllAi extends SpellAbilityAi {
} else if (origin.equals(ZoneType.Graveyard)) { } else if (origin.equals(ZoneType.Graveyard)) {
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
// search targetable Opponents // search targetable Opponents
final PlayerCollection oppList = new PlayerCollection(Iterables.filter(ai.getOpponents(), final PlayerCollection oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
PlayerPredicates.isTargetableBy(sa)));
if (oppList.isEmpty()) { if (oppList.isEmpty()) {
if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) { if (mandatory && !sa.isTargetNumberValid() && sa.canTarget(ai)) {

View File

@@ -7,7 +7,6 @@ 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 com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.ai.AiAttackController; import forge.ai.AiAttackController;
import forge.ai.ComputerUtilAbility; import forge.ai.ComputerUtilAbility;
@@ -42,8 +41,7 @@ public class ChooseCardAi extends SpellAbilityAi {
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
sa.resetTargets(); sa.resetTargets();
// search targetable Opponents // search targetable Opponents
final List<Player> oppList = Lists.newArrayList(Iterables.filter( final List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
ai.getOpponents(), PlayerPredicates.isTargetableBy(sa)));
if (oppList.isEmpty()) { if (oppList.isEmpty()) {
return false; return false;

View File

@@ -7,7 +7,6 @@ import java.util.Set;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.ai.AiCardMemory; import forge.ai.AiCardMemory;
import forge.ai.ComputerUtilAbility; import forge.ai.ComputerUtilAbility;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
@@ -111,10 +110,8 @@ public class ChooseTypeAi extends SpellAbilityAi {
boolean isCurse = sa.isCurse(); boolean isCurse = sa.isCurse();
if (sa.usesTargeting()) { if (sa.usesTargeting()) {
final List<Player> oppList = Lists.newArrayList(Iterables.filter( final List<Player> oppList = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
ai.getOpponents(), PlayerPredicates.isTargetableBy(sa))); final List<Player> alliesList = ai.getAllies().filter(PlayerPredicates.isTargetableBy(sa));
final List<Player> alliesList = Lists.newArrayList(Iterables.filter(
ai.getAllies(), PlayerPredicates.isTargetableBy(sa)));
sa.resetTargets(); sa.resetTargets();

View File

@@ -146,13 +146,12 @@ public class ProtectAi extends SpellAbilityAi {
String s = aiAtk.toProtectAttacker(sa); String s = aiAtk.toProtectAttacker(sa);
if (s == null) { if (s == null) {
return false; return false;
} else {
Player opponent = ai.getWeakestOpponent();
Combat combat = ai.getGame().getCombat();
int dmg = ComputerUtilCombat.damageIfUnblocked(c, opponent, combat, true);
float ratio = 1.0f * dmg / opponent.getLife();
return MyRandom.getRandom().nextFloat() < ratio;
} }
Player opponent = ai.getWeakestOpponent();
Combat combat = ai.getGame().getCombat();
int dmg = ComputerUtilCombat.damageIfUnblocked(c, opponent, combat, true);
float ratio = 1.0f * dmg / opponent.getLife();
return MyRandom.getRandom().nextFloat() < ratio;
} }
return false; return false;
} }
@@ -227,7 +226,7 @@ public class ProtectAi extends SpellAbilityAi {
} }
if (list.isEmpty()) { if (list.isEmpty()) {
return mandatory && protectMandatoryTarget(ai, sa, mandatory); return mandatory && protectMandatoryTarget(ai, sa);
} }
while (sa.canAddMoreTarget()) { while (sa.canAddMoreTarget()) {
@@ -237,7 +236,7 @@ public class ProtectAi extends SpellAbilityAi {
if (list.isEmpty()) { if (list.isEmpty()) {
if ((sa.getTargets().size() < tgt.getMinTargets(source, sa)) || sa.getTargets().size() == 0) { if ((sa.getTargets().size() < tgt.getMinTargets(source, sa)) || sa.getTargets().size() == 0) {
if (mandatory) { if (mandatory) {
return protectMandatoryTarget(ai, sa, mandatory); return protectMandatoryTarget(ai, sa);
} }
sa.resetTargets(); sa.resetTargets();
@@ -256,7 +255,7 @@ public class ProtectAi extends SpellAbilityAi {
return true; return true;
} // protectTgtAI() } // protectTgtAI()
private static boolean protectMandatoryTarget(final Player ai, final SpellAbility sa, final boolean mandatory) { private static boolean protectMandatoryTarget(final Player ai, final SpellAbility sa) {
final Game game = ai.getGame(); final Game game = ai.getGame();
final TargetRestrictions tgt = sa.getTargetRestrictions(); final TargetRestrictions tgt = sa.getTargetRestrictions();
@@ -294,7 +293,7 @@ public class ProtectAi extends SpellAbilityAi {
break; break;
} }
Card c = ComputerUtilCard.getBestAI(list); Card c = ComputerUtilCard.getBestAI(pref);
pref.remove(c); pref.remove(c);
sa.getTargets().add(c); sa.getTargets().add(c);
} }
@@ -304,7 +303,7 @@ public class ProtectAi extends SpellAbilityAi {
break; break;
} }
Card c = ComputerUtilCard.getBestAI(list); Card c = ComputerUtilCard.getBestAI(pref2);
pref2.remove(c); pref2.remove(c);
sa.getTargets().add(c); sa.getTargets().add(c);
} }

View File

@@ -540,7 +540,7 @@ public class PumpAi extends PumpAiBase {
// Filter AI-specific targets if provided // Filter AI-specific targets if provided
list = ComputerUtil.filterAITgts(sa, ai, list, true); list = ComputerUtil.filterAITgts(sa, ai, list, true);
if (list.isEmpty() || ComputerUtil.activateForCost(sa, ai)) { if (list.isEmpty() && (mandatory || ComputerUtil.activateForCost(sa, ai))) {
return pumpMandatoryTarget(ai, sa); return pumpMandatoryTarget(ai, sa);
} }

View File

@@ -34,8 +34,8 @@ public class DigEffect extends SpellAbilityEffect {
final Card host = sa.getHostCard(); final Card host = sa.getHostCard();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
final int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa); final int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
final int numToChange = (sa.hasParam("ChangeNum") ? final String toChange = sa.getParamOrDefault("ChangeNum", "1");
AbilityUtils.calculateAmount(host, sa.getParam("ChangeNum"), sa) : 1); final int numToChange = toChange.startsWith("All") ? numToDig : AbilityUtils.calculateAmount(host, sa.getParam("ChangeNum"), sa);
final List<Player> tgtPlayers = getTargetPlayers(sa); final List<Player> tgtPlayers = getTargetPlayers(sa);
String verb = " looks at "; String verb = " looks at ";