Slay the Spire: Enemy "Intent" State

Hello all.

I am currently working on a Card Battler using RPGMaker MV that has mechanics very similar to Slay the Spire. This includes the mechanic whereby the enemy's next action 'intent' is shown to allow the Player to plan accordingly.

While trying to introduce this mechanic into my own game, I came across Famicon80's post on the forum back in 2018 titled, "Show enemy's next move," where they were looking for assistance in re-creating the same mechanic.

Reading through the responses, I saw that both you and another user (Aloe Guvner) provided a way for the enemy 'intent' to appear as a state.


Code:
<After Eval>
var old = #
// Change # to the skill's required state
var newstate = [X, X, X];
// Replace the X's with state IDs, can have as many as you want here including duplicates
var index = Math.randomInt(newstate.length);
var choice = newstate[index]
if (user.isStateAffected(choice)) {
} else {
BattleManager._subject.removeState(old);
BattleManager._subject.addState(choice);
}
</After Eval>

<Custom Requirement>
var x = #
// Change # to the skill's required state
if (user.isStateAffected(x)) {
value = true;
} else {
value = false;
}
</Custom Requirement>


Guvner's addition to your code was for each new state be some pre-made array of state ID's unique to each enemy.


Code:
<After Eval>
var old = #
// Change # to the skill's required state
var newstate = $dataEnemies[user._enemyId].meta.states.split(',').map(function(n){return parseInt(n)});
// Reads the allowed state values from the enemy notetag
var index = Math.randomInt(newstate.length);
var choice = newstate[index]
if (user.isStateAffected(choice)) {
} else {
BattleManager._subject.removeState(old);
BattleManager._subject.addState(choice);
}
</After Eval>


I am struggling to get the code to work properly, likely due to my overall inexperience with using these types of codes in general.

Would anyone be willing to provide me some example screenshots of how to properly implement these codes (preferably including Guvner's addition) so that I can re-create it within my project?

Thanks for your time and any assistance anyone can offer in regards.



EDITS:
  • Removed the spoiler tags and used 'Code' tags as recommended by ATT_Turan.
  • Added (3) screenshots for my setup of the Skill, State, and Enemy note-tags in my attempt to follow the JSGreene and Guvner codes.

Slay the Spire Enemy Intent - Skill Notetag.jpg

Slay the Spire Enemy Intent - State Notetag.jpg

Slay the Spire Enemy Intent - Enemy Notetag.jpg
A tip: when you write/paste code, be sure to use the CODE tags (the </> on the edit bar). This preserves indenting and makes sure it isn't accidentally turned into BBCode. I know the bold spoilers are how JGreene posted it originally, but it's not a great idea 😉

I am struggling to get the code to work properly
Show us screenshots of what you have that isn't working. There are instructions for setting it up in the other thread, and...at least for myself, I'm happy to read your stuff over and correct it, but I'm not going to take the time to set up several entries in my database just to take pictures that might still confuse you 😀
Thank you for taking the time to respond ATT_Turan.

Screenshots are now included below. I also went back and added them to my original post, along with some new tags to the thread in case anyone else were to find this topic in the future and find some use in whatever solution is found.

I've also taken your recommendation and edited the original post to use 'Code' instead of the 'Spoiler' for the codes included.

Spoiler: Screenshot Skill/State/Enemy Notetags
Slay the Spire Enemy Intent - Skill Notetag.jpg

Slay the Spire Enemy Intent - State Notetag.jpg

Slay the Spire Enemy Intent - Enemy Notetag.jpg
Those are some deluxe screenshots! 😀

I don't understand why the code is using BattleManager._subject at the end of the After Eval instead of just user, but that shouldn't break anything. It's just strange. For that matter, I don't understand why the condition would be to have the state and do nothing, then do an else, instead of just checking to not have the state.

In the Custom Requirement in your skill, you failed to change isStateAffected(x) to isStateAffected(29)

It's a little hard to see because of how you resized and constructed your screenshots, but it looks like in your enemy setup there are spaces between the numbers listed in the notetag, which does not match the format in the instructions.

(it says <states:x,x,x> and you appear to have <states: 29, 30>)
It's a little hard to see because of how you resized and constructed your screenshots

Sorry, they turned out smaller than I intended. Included below are updated screenshots with your suggested edits that should be larger and easier to read.

In the Custom Requirement in your skill, you failed to change isStateAffected(x) to isStateAffected(29)

I've updated the code in the Skill Notetag accordingly (see the included screenshots in the Spoiler below), which now reads as:

Code:
<After Eval>
var old = 29
// Change # to the skill's required state
var newstate = $dataEnemies[user._enemyId].meta.states.split(',').map(function(n){return parseInt(n)});
// Reads the allowed state values from the enemy notetag
var index = Math.randomInt(newstate.length);
var choice = newstate[index]
if (user.isStateAffected(choice)) {
} else {
BattleManager._subject.removeState(old);
BattleManager._subject.addState(choice);
}
</After Eval>

<Custom Requirement>
var x = 29
// Change # to the skill's required state
if (user.isStateAffected(29)) {
value = true;
} else {
value = false;
}
</Custom Requirement>

it looks like in your enemy setup there are spaces between the numbers listed in the notetag, which does not match the format in the instructions.

(it says <states:x,x,x> and you appear to have <states: 29, 30>)

I've updated this Notetag (see the included screenshots in the Spoiler below) and removed the space between the '29' and '30,' which now reads as:

Code:
<states:29,30>

Unfortunately, even with both of these changes, it does not appear to be working as intended just yet. In the included screenshots you can see that the enemy has the 'Attack Intent' State (State ID 29), but his next action was 'Armor Up!' Skill (Skill ID 37). Ideally, what should have happened was that the action should have been 'Wild Swing' Skill (Skill ID 36), as that was what I am trying to setup in the Notetag for the 'Wild Swing' Skill to require the 'Attack Intent' State (State ID 29).

My only assumption is that I am somehow making an error in the code or setup of the Skill, State, or Enemy somewhere.

Spoiler: Updated Screenshots
UPDATED - Skill Notetag.jpg

UPDATED - Enemy Notetag.jpg

Battle - Attack Intent.jpg

Battle - Armor Up Skill.jpg
What does the skill entry for skill 37 Armor Up look like? Just because this state causes Wild Swing to meet its requirements won't prevent the enemy from using Armor Up unless you also give that one different requirements.

Just to put it out there, you might want to look at Yanfly's Battle A.I. Core. It might not have been written yet when the thread you found was made, and I think it might give you easier ways to implement this.

It also might not be easier for your usage, but it's free to check out.
What does the skill entry for skill 37 Armor Up look like?

Skill ID 37, Armor Up!, was built the same as Skill ID 36, Wild Swing, just with the difference in the State IDs (Armor Up! uses State ID 30, which is the Defend Intent State).

Code:
<After Eval>
var old = 30
// Change # to the skill's required state
var newstate = $dataEnemies[user._enemyId].meta.states.split(',').map(function(n){return parseInt(n)});
// Reads the allowed state values from the enemy notetag
var index = Math.randomInt(newstate.length);
var choice = newstate[index]
if (user.isStateAffected(choice)) {
} else {
BattleManager._subject.removeState(old);
BattleManager._subject.addState(choice);
}
</After Eval>

<Custom Requirement>
var x = 30
// Change # to the skill's required state
if (user.isStateAffected(30)) {
value = true;
} else {
value = false;
}
</Custom Requirement>

Just to put it out there, you might want to look at Yanfly's Battle A.I. Core.

I took a shot at it and added this 'AI Priority' to the Enemy Notetag, although it does not appear to work correctly but I would gladly appreciate any suggestions on how to fix it using this particular plugin.

Code:
<AI Priority>
State === State 29: Wild Swing, First
State === State 30: Armor Up!, User
</AI Priority>
...do you have the Yanfly Skill Core correctly installed? And all of the Yanfly plugins are in the correct order according to the Yanfly Engine Plugins list?

With that Custom Requirement tag checking for state 30, the battler shouldn't be able to use Armor Up with state 29 on (unless you're making a mistake and both states are on without you realizing).

You can check during the game by pressing F8, going to the Console tab, and typing in JavaScript commands. e.g. $gameTroop.members()[0].isStateAffected(30) will return true or false.
I took a shot at it and added this 'AI Priority' to the Enemy Notetag, although it does not appear to work correctly but I would gladly appreciate any suggestions on how to fix it using this particular plugin.

Code:
<AI Priority>
State === State 29: Wild Swing, First
State === State 30: Armor Up!, User
</AI Priority>
I would really not recommend trying to have all of this stuff going on at the same time - all of the code in the thread until now is basically a kind of hack around using this AI plugin.

However, if there is in fact an error with which state is actually on the battler at a given time, then the Battle A.I. checks would work identically to the code you already have.

Your syntax for the AI Priority appears to be correct.

Original thread: https://forums.rpgmakerweb.com/threads/slay-the-spire-enemy-intent-state.152232/