Add AI for Rousing Refrain

This commit is contained in:
tool4EvEr
2021-10-05 20:12:52 +02:00
parent 27b0fb3247
commit 8ea9eb6118
7 changed files with 22 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
package forge.ai.ability;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -25,6 +26,7 @@ public class CharmAi extends SpellAbilityAi {
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
final Card source = sa.getHostCard();
List<AbilitySub> choices = CharmEffect.makePossibleOptions(sa);
Collections.shuffle(choices);
final int num;
final int min;

View File

@@ -114,7 +114,7 @@ public class ManaEffectAi extends SpellAbilityAi {
}
// Dark Ritual and other similar instants/sorceries that add mana to mana pool
private boolean doManaRitualLogic(Player ai, SpellAbility sa) {
public static boolean doManaRitualLogic(Player ai, SpellAbility sa) {
final Card host = sa.getHostCard();
final String logic = sa.getParamOrDefault("AILogic", "");
@@ -123,7 +123,7 @@ public class ManaEffectAi extends SpellAbilityAi {
int manaReceived = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(host, sa.getParam("Amount"), sa) : 1;
manaReceived *= sa.getParam("Produced").split(" ").length;
int selfCost = sa.getPayCosts().getCostMana() != null ? sa.getPayCosts().getCostMana().getMana().getCMC() : 0;
int selfCost = sa.getRootAbility().getPayCosts().getCostMana() != null ? sa.getRootAbility().getPayCosts().getCostMana().getMana().getCMC() : 0;
String produced = sa.getParam("Produced");
byte producedColor = produced.equals("Any") ? MagicColor.ALL_COLORS : MagicColor.fromName(produced);

View File

@@ -34,6 +34,8 @@ import forge.game.phase.PhaseHandler;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode;
import forge.game.player.PlayerCollection;
import forge.game.player.PlayerPredicates;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions;
import forge.game.staticability.StaticAbility;
@@ -510,6 +512,15 @@ public class PumpAi extends PumpAiBase {
}
return false;
} else if ("ManaRitual".equals(sa.getParam("AILogic"))) {
PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa));
if (targetableOpps.isEmpty()) {
return false;
}
Player mostCards = targetableOpps.max(PlayerPredicates.compareByZoneSize(ZoneType.Hand));
sa.resetTargets();
sa.getTargets().add(mostCards);
return mandatory || ManaEffectAi.doManaRitualLogic(ai, sa.getSubAbility());
}
if (isFight) {

View File

@@ -3201,7 +3201,7 @@ public class CardFactoryUtil {
return true;
}
return this.getHostCard().getOwner().canCastSorcery() || this.getHostCard().getFirstSpellAbility().withFlash(this.getHostCard(), this.getActivatingPlayer());
return this.getHostCard().getFirstSpellAbility().canCastTiming(this.getHostCard(), this.getActivatingPlayer());
}
@Override

View File

@@ -2341,7 +2341,6 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
public boolean canCastTiming(Player activator) {
return canCastTiming(getHostCard(), activator);
}
public boolean canCastTiming(Card host, Player activator) {
// for companion
if (this instanceof AbilityStatic && getRestrictions().isSorcerySpeed() && !activator.canCastSorcery()) {
@@ -2360,7 +2359,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
// spells per default are sorcerySpeed
if (isSpell()) {
return false;
} else if (isActivatedAbility()) {
}
if (isActivatedAbility()) {
// Activated Abillties are instant speed per default
return !getRestrictions().isSorcerySpeed();
}

View File

@@ -2,7 +2,7 @@ Name:Jeska's Will
ManaCost:2 R
Types:Sorcery
A:SP$ Charm | Cost$ 2 R | MinCharmNum$ 1 | CharmNum$ X | Choices$ DBHandTarget,DBExile | AdditionalDescription$ If you control a commander as you cast this spell, you may choose both.
SVar:DBHandTarget:DB$ Pump | ValidTgts$ Opponent | SubAbility$ DBMana | SpellDescription$ Add {R} for each card in target opponent's hand.
SVar:DBHandTarget:DB$ Pump | ValidTgts$ Opponent | SubAbility$ DBMana | AILogic$ ManaRitual | SpellDescription$ Add {R} for each card in target opponent's hand.
SVar:DBMana:DB$ Mana | Produced$ R | Amount$ Z | StackDescription$ None
SVar:DBExile:DB$ Dig | Defined$ You | DigNum$ 3 | ChangeNum$ All | DestinationZone$ Exile | RememberChanged$ True | SubAbility$ DBEffect | SpellDescription$ Exile the top three cards of your library. You may play them this turn.
SVar:DBEffect:DB$ Effect | RememberObjects$ RememberedCard | StaticAbilities$ Play | SubAbility$ DBCleanup | ForgetOnMoved$ Exile

View File

@@ -2,8 +2,8 @@ Name:Rousing Refrain
ManaCost:3 R R
Types:Sorcery
K:Suspend:3:1 R
A:SP$ Pump | Cost$ 3 R R | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | SubAbility$ DBMana | StackDescription$ None | SpellDescription$ Add {R} for each card in target opponent's hand.
SVar:DBMana:DB$ Mana | Produced$ R | Amount$ Z | PersistentMana$ True | StackDescription$ None | SubAbility$ DBChange |SpellDescription$ Until end of turn, you don't lose this mana as steps and phases end.
A:SP$ Pump | Cost$ 3 R R | ValidTgts$ Opponent | TgtPrompt$ Select target opponent | SubAbility$ DBMana | AILogic$ ManaRitual | StackDescription$ SpellDescription | SpellDescription$ Add {R} for each card in target opponent's hand.
SVar:DBMana:DB$ Mana | Produced$ R | Amount$ Z | PersistentMana$ True | SubAbility$ DBChange | StackDescription$ SpellDescription | SpellDescription$ Until end of turn, you don't lose this mana as steps and phases end.
SVar:Z:TargetedPlayer$CardsInHand
SVar:DBChange:DB$ ChangeZone | Origin$ Stack | Destination$ Exile | WithCountersType$ TIME | WithCountersAmount$ 3 | SpellDescription$ Exile CARDNAME with three time counters on it.
Oracle:Add {R} for each card in target opponent's hand. Until end of turn, you don't lose this mana as steps and phases end. Exile Rousing Refrain with three time counters on it.\nSuspend 3—{1}{R} (Rather than cast this card from your hand, you may pay {1}{R} and exile it with three time counters on it. At the beginning of your upkeep, remove a time counter. When the last is removed, cast it without paying its mana cost.)