From 291411e847ca1ea8e452f95efc86efe253f37fa8 Mon Sep 17 00:00:00 2001 From: TRT <> Date: Wed, 10 Apr 2024 09:29:51 +0200 Subject: [PATCH] Support AI assisting --- .../src/main/java/forge/ai/AiController.java | 16 ++++++++-------- .../main/java/forge/ai/PlayerControllerAi.java | 12 +++++++++--- .../java/forge/player/PlayerControllerHuman.java | 2 -- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index 44c5cf23e6f..f5a7ff663af 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -1897,27 +1897,27 @@ public class AiController { PlayerCollection allies = player.getAllies(); - if (allies.size() > 0) { - // AI has allies, don't help out anyone but allies. - if (!allies.contains(activator)) { - return 0; - } - } else { + if (allies.isEmpty()) { // AI only has opponents. // TODO: Maybe help out someone if it seems good for us, but who knows how you calculate that. // Probably needs some specific AI here. // If the spell is a creature, probably don't help. // If spell is a instant/sorcery, help based on the situation return 0; + } else { + // AI has allies, don't help out anyone but allies. + if (!allies.contains(activator)) { + return 0; + } } // AI has decided to help. Now let's figure out how much they can help - int mana = ComputerUtilMana.getAvailableManaEstimate(player, false); + int mana = ComputerUtilMana.getAvailableManaEstimate(player, true); // TODO We should make a logical guess here, but for now just uh yknow randomly decide? // What do I want to play next? Can I still pay for that and have mana left over to help? // Is the spell I'm helping cast better for me than the thing I would cast? - if (MyRandom.getRandom().nextInt(100) < 80) { + if (MyRandom.percentTrue(80)) { return 0; } diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index 535b6c0ffc5..e1aab6af645 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -188,11 +188,17 @@ public class PlayerControllerAi extends PlayerController { public boolean helpPayForAssistSpell(ManaCostBeingPaid cost, SpellAbility sa, int max, int requested) { int toPay = getAi().attemptToAssist(sa, max, requested); - // TODO Figure out how to pay toPay amount if (toPay == 0) { - //return true; + return true; + } else { + ManaCost manaCost = ManaCost.get(toPay); + ManaCostBeingPaid assistCost = new ManaCostBeingPaid(manaCost); + if (ComputerUtilMana.canPayManaCost(assistCost, sa, player, false)) { + ComputerUtilMana.payManaCost(assistCost, sa, player, false); + cost.decreaseGenericMana(toPay); + return true; + } } - return true; } diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index 1ac9e7b31b6..3d7f5a4f0c5 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -616,13 +616,11 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont InputPayMana inpPayment = new InputPayManaOfCostPayment(this, assistCost, sa, this.getPlayer(), null, true); inpPayment.setMessagePrefix("Paying for assist - "); inpPayment.showAndWait(); - // Once you pay, loop in the paid SAs and add them to cost if (inpPayment.isPaid()) { // Apply payments from assistCost to cost // If cost is canceled, how do we make sure mana gets undone? - final List paidAbs = sa.getPayingManaAbilities(); cost.decreaseGenericMana(willPay); return true; } else if (sa.getHostCard().getGame().EXPERIMENTAL_RESTORE_SNAPSHOT) {