mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
PlayerControllerAi & AiController: move chooseSingleReplacementEffect into the brain part
also add logic for Lifegain replacement effects
This commit is contained in:
@@ -40,6 +40,8 @@ import forge.card.mana.ManaCost;
|
|||||||
import forge.deck.CardPool;
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
|
import forge.game.CardTraitBase;
|
||||||
|
import forge.game.CardTraitPredicates;
|
||||||
import forge.game.Direction;
|
import forge.game.Direction;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
@@ -1607,6 +1609,10 @@ public class AiController {
|
|||||||
return filterList(input, SpellAbilityPredicates.isApi(type));
|
return filterList(input, SpellAbilityPredicates.isApi(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private <T extends CardTraitBase> List<T> filterListByAiLogic(List<T> list, final String logic) {
|
||||||
|
return filterList(list, CardTraitPredicates.hasParam("AiLogic", logic));
|
||||||
|
}
|
||||||
|
|
||||||
public List<AbilitySub> chooseModeForAbility(SpellAbility sa, int min, int num, boolean allowRepeat) {
|
public List<AbilitySub> chooseModeForAbility(SpellAbility sa, int min, int num, boolean allowRepeat) {
|
||||||
if (simPicker != null) {
|
if (simPicker != null) {
|
||||||
return simPicker.chooseModeForAbility(sa, min, num, allowRepeat);
|
return simPicker.chooseModeForAbility(sa, min, num, allowRepeat);
|
||||||
@@ -1633,5 +1639,41 @@ public class AiController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> list,
|
||||||
|
Map<String, Object> runParams) {
|
||||||
|
// no need to choose anything
|
||||||
|
if (list.size() <= 1) {
|
||||||
|
return Iterables.getFirst(list, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (runParams.containsKey("Event")) {
|
||||||
|
// replace lifegain effects
|
||||||
|
if ("GainLife".equals(runParams.get("Event"))) {
|
||||||
|
List<ReplacementEffect> noGain = filterListByAiLogic(list, "NoLife");
|
||||||
|
List<ReplacementEffect> loseLife = filterListByAiLogic(list, "LoseLife");
|
||||||
|
List<ReplacementEffect> doubleLife = filterListByAiLogic(list, "DoubleLife");
|
||||||
|
List<ReplacementEffect> lichDraw = filterListByAiLogic(list, "LichDraw");
|
||||||
|
|
||||||
|
if (!noGain.isEmpty()) {
|
||||||
|
// no lifegain is better than lose life
|
||||||
|
return Iterables.getFirst(noGain, null);
|
||||||
|
} else if (!loseLife.isEmpty()) {
|
||||||
|
// lose life before double life to prevent lose double
|
||||||
|
return Iterables.getFirst(loseLife, null);
|
||||||
|
} else if (!lichDraw.isEmpty()) {
|
||||||
|
// lich draw before double life to prevent to draw to much
|
||||||
|
return Iterables.getFirst(lichDraw, null);
|
||||||
|
} else if (!doubleLife.isEmpty()) {
|
||||||
|
// other than that, do double life
|
||||||
|
return Iterables.getFirst(doubleLife, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AI logic for choosing which replacement effect to apply
|
||||||
|
// happens here.
|
||||||
|
return Iterables.getFirst(list, null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -603,9 +603,7 @@ public class PlayerControllerAi extends PlayerController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, Map<String, Object> runParams) {
|
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, Map<String, Object> runParams) {
|
||||||
// AI logic for choosing which replacement effect to apply
|
return brains.chooseSingleReplacementEffect(possibleReplacers, runParams);
|
||||||
// happens here.
|
|
||||||
return possibleReplacers.get(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user