mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
- TokenAi to use default checkAiLogic()
- Updated FightAi to use new canPlay()
This commit is contained in:
@@ -23,33 +23,34 @@ import java.util.Random;
|
|||||||
|
|
||||||
public class FightAi extends SpellAbilityAi {
|
public class FightAi extends SpellAbilityAi {
|
||||||
@Override
|
@Override
|
||||||
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
||||||
sa.resetTargets();
|
|
||||||
final Card source = sa.getHostCard();
|
|
||||||
|
|
||||||
CardCollectionView aiCreatures = ai.getCreaturesInPlay();
|
|
||||||
aiCreatures = CardLists.getTargetableCards(aiCreatures, sa);
|
|
||||||
aiCreatures = ComputerUtil.getSafeTargets(ai, sa, aiCreatures);
|
|
||||||
|
|
||||||
List<Card> humCreatures = ai.getOpponent().getCreaturesInPlay();
|
|
||||||
humCreatures = CardLists.getTargetableCards(humCreatures, sa);
|
|
||||||
|
|
||||||
final Random r = MyRandom.getRandom();
|
|
||||||
if (r.nextFloat() > Math.pow(.6667, sa.getActivationsThisTurn())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (sa.hasParam("FightWithToughness")) {
|
if (sa.hasParam("FightWithToughness")) {
|
||||||
// TODO: add ailogic
|
// TODO: add ailogic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return super.checkAiLogic(ai, sa, aiLogic);
|
||||||
|
}
|
||||||
|
|
||||||
//assumes the triggered card belongs to the ai
|
@Override
|
||||||
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
|
sa.resetTargets();
|
||||||
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
|
// Get creature lists
|
||||||
|
CardCollectionView aiCreatures = ai.getCreaturesInPlay();
|
||||||
|
aiCreatures = CardLists.getTargetableCards(aiCreatures, sa);
|
||||||
|
aiCreatures = ComputerUtil.getSafeTargets(ai, sa, aiCreatures);
|
||||||
|
List<Card> humCreatures = ai.getOpponent().getCreaturesInPlay();
|
||||||
|
humCreatures = CardLists.getTargetableCards(humCreatures, sa);
|
||||||
|
|
||||||
|
// assumes the triggered card belongs to the ai
|
||||||
if (sa.hasParam("Defined")) {
|
if (sa.hasParam("Defined")) {
|
||||||
Card fighter1 = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa).get(0);
|
Card fighter1 = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa).get(0);
|
||||||
for (Card humanCreature : humCreatures) {
|
for (Card humanCreature : humCreatures) {
|
||||||
if (ComputerUtilCombat.getDamageToKill(humanCreature) <= fighter1.getNetPower()
|
if (ComputerUtilCombat.getDamageToKill(humanCreature) <= fighter1.getNetPower()
|
||||||
&& humanCreature.getNetPower() < ComputerUtilCombat.getDamageToKill(fighter1)) {
|
&& humanCreature.getNetPower() < ComputerUtilCombat.getDamageToKill(fighter1)) {
|
||||||
// todo: check min/max targets; see if we picked the best matchup
|
// todo: check min/max targets; see if we picked the best
|
||||||
|
// matchup
|
||||||
sa.getTargets().add(humanCreature);
|
sa.getTargets().add(humanCreature);
|
||||||
return true;
|
return true;
|
||||||
} else if (humanCreature.getSVar("Targeting").equals("Dies")) {
|
} else if (humanCreature.getSVar("Targeting").equals("Dies")) {
|
||||||
@@ -65,7 +66,8 @@ public class FightAi extends SpellAbilityAi {
|
|||||||
for (Card aiCreature : aiCreatures) {
|
for (Card aiCreature : aiCreatures) {
|
||||||
if (ComputerUtilCombat.getDamageToKill(humanCreature) <= aiCreature.getNetPower()
|
if (ComputerUtilCombat.getDamageToKill(humanCreature) <= aiCreature.getNetPower()
|
||||||
&& humanCreature.getNetPower() < ComputerUtilCombat.getDamageToKill(aiCreature)) {
|
&& humanCreature.getNetPower() < ComputerUtilCombat.getDamageToKill(aiCreature)) {
|
||||||
// todo: check min/max targets; see if we picked the best matchup
|
// todo: check min/max targets; see if we picked the
|
||||||
|
// best matchup
|
||||||
sa.getTargets().add(humanCreature);
|
sa.getTargets().add(humanCreature);
|
||||||
sa.getTargets().add(aiCreature);
|
sa.getTargets().add(aiCreature);
|
||||||
return true;
|
return true;
|
||||||
@@ -84,13 +86,13 @@ public class FightAi extends SpellAbilityAi {
|
|||||||
if (creature1.equals(creature2)) {
|
if (creature1.equals(creature2)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sa.hasParam("TargetsWithoutSameCreatureType")
|
if (sa.hasParam("TargetsWithoutSameCreatureType") && creature1.sharesCreatureTypeWith(creature2)) {
|
||||||
&& creature1.sharesCreatureTypeWith(creature2)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ComputerUtilCombat.getDamageToKill(creature1) <= creature2.getNetPower()
|
if (ComputerUtilCombat.getDamageToKill(creature1) <= creature2.getNetPower()
|
||||||
&& creature1.getNetPower() >= ComputerUtilCombat.getDamageToKill(creature2)) {
|
&& creature1.getNetPower() >= ComputerUtilCombat.getDamageToKill(creature2)) {
|
||||||
// todo: check min/max targets; see if we picked the best matchup
|
// todo: check min/max targets; see if we picked the best
|
||||||
|
// matchup
|
||||||
sa.getTargets().add(creature1);
|
sa.getTargets().add(creature1);
|
||||||
sa.getTargets().add(creature2);
|
sa.getTargets().add(creature2);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -80,14 +80,6 @@ public class TokenAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
|
|
||||||
if (aiLogic.equals("Never")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkPhaseRestrictions(final Player ai, final SpellAbility sa, final PhaseHandler ph) {
|
protected boolean checkPhaseRestrictions(final Player ai, final SpellAbility sa, final PhaseHandler ph) {
|
||||||
readParameters(sa); // remember to call this somewhere!
|
readParameters(sa); // remember to call this somewhere!
|
||||||
|
|||||||
Reference in New Issue
Block a user