Battle AI Core Extension

By DreamX


Description


This is an extension for Battle A.I. Core by Yanfly. At the present, it allows for custom target conditions when use eval. For example, you can require that target must be of a certain class, have a certain weapon, have a certain id or anything else. As long as you know a little javascript, you can apply extra target conditions.


How To Use


Right click the script link and save as a .js file. Must be under Yanfly plugins.


* ============================================================================
* How To Use
* ============================================================================
* Use AIManager.targetCondition("x") when using an eval condition.
* Examples:
* AIManager.targetCondition("target.name() === \"Harold\"")
* AIManager.targetCondition("target.actorId() === 2")
*
* If you're using quotes in your condition, you need to escape them with \
* like I did for Harold (\"Harold\")
*
* Example of a whole ai pattern:
* <AI Priority>
* Eval user.name() === 'Bat' && AIManager.targetCondition("target.name() === \"Harold\""): Skill 25, Highest HP%
* </AI Priority>
* ============================================================================
* Terms Of Use
* ============================================================================
* Free to use and modify for commercial and noncommercial games, with credit.
* Please remember credit Yanfly as this is an extension of their Ai Core plugin.
* ============================================================================
* Credits & Thanks
* ============================================================================
* DreamX
* Thanks to Yanfly for the plugin this is an extension of.


Script
hp% param <= 50%: SKILL 5, Lowest HP%  (skill 5 is heal 1 ally)


to my understanding, if 1 ally has <=50% health, then cast heal on lowest health ally.


tested - proven it.


now what if say a monster has some form of affinity rage (sees one of the troop is below 50%) and so he uses a strong special attack in attempt to quickly win the fight.


the problem i face when trying to create it is that the special attack, attacks party member(s) whereas the troop members health is below 50%


using


hp% param <= 50%: SKILL 6, Lowest HP%  (skill 6 is rage attack 1 enemy)


this would look for a party member's hp to be below 50% then attack the lowest hp party member.


if i change the rage attack to 1 ally, the monster will attack the lowest hp troop member when a troop is below 50% hp.


so, is there a plugin that allows to check troops health then rage attack a party member?
I made an extension for this extension. The extension checks if EVERY alive target member is fulfilling the condition. (I use it a lot. For example, my skill "Multi guardian angel" has a 75% chance to give an ally the state "guardian angel". The Condition is: if not a single alive ally has the state "guardian angel", use the skill "Multi guardian angel")

extension for the extension (u need to copy pasta this at the bottom of the extension plugin, but above "})();" ):


JavaScript:
 AIManager.groupCondition = function (condition) {                //eine Funktion
        var group = this.getActionGroup();                            // group = Verbündete des ziels + ziel
        var validTargets = [];                                        // array von validen Zielen
        for (var i = 0; i < group.length; ++i) {                    // loop der für group.length durchläuft
            var target = group[i];                                    // target = group[i]
            if (!target)                                            // wenn es kein ziel gibt, dann nächster loop
                continue;                      
            if (eval(condition)) {                                    // wenn eigene condition zutrifft, dann wird valides ziel hinzugefügt
                validTargets.push(target);
            }
        }
        if (validTargets.length < target.friendsUnit().aliveMembers().length) {        // Wenn nicht jedes lebendige gruppenmitglied die condition erfüllt, dann return false.
            return false;
        }
        this.setProperTarget(validTargets);                            // ansonsten valide ziele registrieren.
        return true;
    };

Original thread: https://forums.rpgmakerweb.com/threads/battle-ai-core-extension.61403/