mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
- Added two new AI functions containsUsefulKeyword and isUsefulKeyword, to be used by AF Pump and Attach. WIP.
This commit is contained in:
@@ -1951,4 +1951,42 @@ public class ComputerUtil {
|
||||
}
|
||||
return prevented;
|
||||
}
|
||||
|
||||
public static boolean containsUsefulKeyword(final ArrayList<String> keywords, Card card) {
|
||||
for (final String keyword : keywords) {
|
||||
if (isUsefulKeyword(keyword, card)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isUsefulKeyword(final String keyword, Card card) {
|
||||
if (keyword.equals("Defender") || keyword.endsWith("CARDNAME can't attack.")) {
|
||||
if (card.getController().isComputer()
|
||||
|| AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer())
|
||||
|| !CombatUtil.canAttack(card)
|
||||
|| card.getNetCombatDamage() <= 0) {
|
||||
return false;
|
||||
}
|
||||
} else if (keyword.contains("CARDNAME can't block.")) {
|
||||
if (card.getController().isComputer()
|
||||
|| AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())
|
||||
|| !CombatUtil.canBlock(card)) {
|
||||
return false;
|
||||
}
|
||||
} else if (keyword.endsWith("This card doesn't untap during your next untap step.")) {
|
||||
if (AllZone.getPhaseHandler().isBefore(Constant.Phase.MAIN2)
|
||||
|| AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())) {
|
||||
return false;
|
||||
}
|
||||
} else if (keyword.endsWith("CARDNAME attacks each turn if able.")) {
|
||||
if (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer())
|
||||
|| !CombatUtil.canAttack(card)
|
||||
|| !CombatUtil.canBeBlocked(card)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,12 +713,12 @@ public class AbilityFactoryAttach {
|
||||
if (!keywords.isEmpty()) {
|
||||
// Don't give Can't Attack or Defender to cards that can't do these
|
||||
// things to begin with
|
||||
if (keywords.contains("CARDNAME can't attack") || keywords.contains("Defender")
|
||||
if (keywords.contains("CARDNAME can't attack.") || keywords.contains("Defender")
|
||||
|| keywords.contains("CARDNAME attacks each turn if able.")) {
|
||||
prefList = prefList.filter(new CardListFilter() {
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
return !(c.hasKeyword("CARDNAME can't attack") || c.hasKeyword("Defender"));
|
||||
return !(c.hasKeyword("CARDNAME can't attack.") || c.hasKeyword("Defender"));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -897,11 +897,10 @@ public class AbilityFactoryAttach {
|
||||
|
||||
if (abCost != null) {
|
||||
// No Aura spells have Additional Costs
|
||||
|
||||
}
|
||||
|
||||
// prevent run-away activations - first time will always return true
|
||||
boolean chance = r.nextFloat() <= .6667;
|
||||
boolean chance = r.nextFloat() <= .9;
|
||||
|
||||
// Attach spells always have a target
|
||||
final Target tgt = sa.getTarget();
|
||||
@@ -929,8 +928,6 @@ public class AbilityFactoryAttach {
|
||||
return false;
|
||||
}
|
||||
|
||||
chance &= r.nextFloat() <= .9;
|
||||
|
||||
return chance;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,28 +380,14 @@ public class AbilityFactoryPump {
|
||||
}); // leaves all creatures that will be destroyed
|
||||
} // -X/-X end
|
||||
else if (!list.isEmpty()) {
|
||||
String[] kwPump = { "none" };
|
||||
if (!this.keywords.get(0).equals("none")) {
|
||||
kwPump = this.keywords.toArray(new String[this.keywords.size()]);
|
||||
}
|
||||
final String[] keywords = kwPump;
|
||||
final ArrayList<String> keywords = this.keywords;
|
||||
final boolean addsKeywords = this.keywords.size() > 0;
|
||||
|
||||
if (addsKeywords) {
|
||||
if (!this.containsCombatRelevantKeyword(this.keywords)
|
||||
&& AllZone.getPhaseHandler().isBefore(Constant.Phase.MAIN2)) {
|
||||
list.clear(); // this keyword is not combat relevenat
|
||||
} else if (this.keywords.get(0).equals("HIDDEN CARDNAME attacks each turn if able.")
|
||||
&& AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer())) {
|
||||
list.clear();
|
||||
}
|
||||
|
||||
list = list.filter(new CardListFilter() {
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
return !c.hasAnyKeyword(keywords); // don't add
|
||||
// duplicate
|
||||
// negative keywords
|
||||
return ComputerUtil.containsUsefulKeyword(keywords, c);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -540,14 +526,10 @@ public class AbilityFactoryPump {
|
||||
if (card.getController().isComputer()) {
|
||||
return false;
|
||||
}
|
||||
if (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getComputerPlayer())
|
||||
&& this.keywords.contains("Defender")) {
|
||||
return false;
|
||||
}
|
||||
if (AllZone.getPhaseHandler().isPlayerTurn(AllZone.getHumanPlayer())
|
||||
&& this.keywords.contains("HIDDEN CARDNAME can't block.")) {
|
||||
if (!ComputerUtil.containsUsefulKeyword(this.keywords, card)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (r.nextFloat() <= Math.pow(.6667, activations));
|
||||
}
|
||||
if (((card.getNetDefense() + defense) > 0) && (!card.hasAnyKeyword(this.keywords))) {
|
||||
|
||||
Reference in New Issue
Block a user