My counter system is actually quite in-depth
each entity, thanks to passives/weapons/etc, has a list of "counter" skills that they have at their disposal.
Each of these are then set to what I called a "counter distance" meaning, this is as far as that skill can be used to counter.
It then determines the distance between attacker, and victim.
It then works like this
Say my character has 3 counter abilities active:
Auto-Potion, Smash, Fire Ball
Auto-Potion has a Counter Distance of 20
Smash is 1
Fire Ball is 7
If the enemy is 6 cells away, the valid skills are then
Fire Ball and Auto-Potion.
Because the entity has 2 VALID counters, it randomly chooses one of them.
Then that counter skill is used.
The problem then became:
What if I had auto-potion.
Well, using the standard counter system, the victim would try to cast auto-potion on the enemy, which didn't work too well,
This led me into using 2 branches (before adding several more counter types:
Code:
if(this.checkCounter(skillId) === "Offensive")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Offensive Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Defensive Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(entity.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
What this then meant was, If the skill was an offensive counter (like fireball, or smash) then it would set the "cursor" to the attacking entity,
Otherwise, since it is a defensive counter, it sets the cursor to the victim. This means that now, instead of "attacking" the oriiginal attacker with auto-potion, the victim would use it on itself.
This will make absolutely no sense to many of you, but this should be the entirety of my counter system, not including all the additions I made to YEP_Counter_Control
Spoiler: Counters
Code:
BattleManagerTBS.processCounterAttack = function (targets, subject, action) {
console.log("____________________");
console.log(action);
console.log("____________________");
if (!action) return;
targets.forEach(function (entity) {
if (entity) {
var dist = LeUtilities.distanceBetweenCells(subject.getCell(), entity.getCell());
//if (dist <= 1 && Math.random() < action.itemCnt(entity.battler())) {
//var skill = $dataSkills[entity.battler().attackSkillId()];
entity.battler().makeCounterSkills();
if(entity.battler().counterSkills() && entity.battler()._counters<entity.battler().counterTotal() && Math.random() < action.itemCnt(entity.battler()) )
{
var valid = true;
var defC = $dataSkills[1];
if(entity.battler().isActor())
{defC = $dataSkills[$dataActors[entity.battler().actorId()].defaultCounter];}
else
{defC = $dataSkills[1];}
var skills = this.getBestCounter(entity.battler().counterSkills(),dist,defC);
console.log("skills");
console.log(skills);
console.log("Default skill");
console.log(defC);
if(!skills.indexOf(defC)){skills.push(defC);}
//Test
//skills = [1,1880];
//get random skill if user has multiple counter skills
if(skills.length <=0)
{return;}
var skillId = skills[Math.floor(Math.random()*skills.length)].id;
var sDist = this.checkCounterDistance(skillId);
var skill = $dataSkills[skillId];
console.log(skill);
subject.battler().clearResult();
entity.lookAt(subject.getCell());
//Check Counter Type
if(this.checkCounter(skillId) === "Invalid" || dist > sDist || !valid)
{
}
else if(this.checkCounter(skillId) === "Offensive")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Offensive Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else if(this.checkCounter(skillId) === "Support")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Support Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else if(this.checkCounter(skillId) === "Elemental")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Elemental Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else if(this.checkCounter(skillId) === "Physical")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Physical Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else if(this.checkCounter(skillId) === "Magical")
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Magical Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(subject.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
else
{
var popup = $dataSkills[skillId].meta["Counter Type Display"];
var cName = $dataSkills[skillId].meta["Counter Name"];
if(!popup) popup = "Defensive Counter";
entity.addTextPopup(popup);
if(!cName) cName = skill.name;
entity.addTextPopup(cName);
entity.startSequence("counter");
this.setCursorCell(entity.getCell());
this.forceAction(skill, entity);
entity.battler()._counters+=1;
}
}//Won't do anything if user has no Counter Skills
//}
}
}.bind(this));
};
BattleManagerTBS.checkCounterDistance = function (skillId) {
console.log(skillId);
var CDist = 1;
if ($dataSkills[skillId].meta["Counter Distance"])
CDist = $dataSkills[skillId].meta["Counter Distance"];
if(CDist)
{
return Number(CDist);
}
else
{
return 0;
}
};
BattleManagerTBS.getBestCounter = function (counterSkills, cntDistance, defCounter)
{
counterSkills.push(defCounter);
console.log("counter skills");
console.log(counterSkills);
var goodSkills = [];
var bestSkills = [];
counterSkills.forEach(function(skill)
{
console.log(skill);
console.log(skill.id);
//Skills with counter range 0 should be treated as permanent counters - able to counter all (auto-potion for example)
if(BattleManagerTBS.checkCounter(skill.id) == "Invalid" || BattleManagerTBS.checkCounterDistance(skill.id)==0)
{
}
else if(BattleManagerTBS.checkCounterDistance(skill.id)==cntDistance)
{
//console.log("best skill")
//console.log(skill)
bestSkills.push(skill);
}
else if(BattleManagerTBS.checkCounterDistance(skill.id)>=cntDistance && BattleManagerTBS.checkCounterDistance(skill.id)>0 && BattleManagerTBS.checkCounter(skill.id))
{
//console.log("good skill")
//console.log(skill)
goodSkills.push(skill);
}
else
{
//console.log("bad skill")
console.log(skill)
}
});
if(bestSkills.length>=1)
{
console.log(bestSkills);
return bestSkills;//[Math.floor(Math.random()*bestSkills.length)].id;
}
else if(goodSkills.length>=1)
{
console.log(goodSkills);
return goodSkills;//[Math.floor(Math.random()*goodSkills.length)].id;
}
else
return [];//null;
};
BattleManagerTBS.checkCounter = function (skillId) {
var defensiveSkills = [1880];
var cType = $dataSkills[skillId].meta["Counter Type"];
if(!cType) cType = "Counter" ;
var n = defensiveSkills.indexOf(skillId);
var eva = $dataSkills[skillId].counterConditionEval;
if(eva)
{
// If the skill has an eval, this will make sure the skill is valid.
// Example: If the skill is "Auto-Potion" it will make sure the player has enough potions.
// To give enemies Auto-Potion, make sure to create a duplicate skill without the eval.
if(!eval(eva)){return "Invalid";}
}
if (n>=0 || cType =="Defensive")
{
return "Defensive";
}
else if(cType =="Support")
return "Support";
else if(cType =="Elemental")
return "Elemental";
else if(cType =="Physical")
return "Physical";
else if(cType =="Magical")
return "Magical";
return "Offensive";
};
BattleManagerTBS.getCounterType = function (skillId) {
var type = $dataSkills[skillId];
};
Here's my Changelog For basically everything I added to LeTBS.js, not including various other plugins.
Spoiler: Changelog
# - 0.77.PHX
# * ===========
# * Positioning
# * ===========
# * Added support for variable-based actor cells
# * Added support for switch-based actor cells
# * Added support for leader-based actor cells (Party Leader auto-positioning
# * Added support for neutral positioning cells that can be used by enemies or actors
# * Added custom color for neutral positioning
# * Added logic to determine of all player entities are placed in the pre-positioning phase.
# * If this is the case, the battle is immediately started, eliminating the need for the player
# to "Confirm" they are ready. Eliminates a bug where you could "Cancel" on a pre-placed unit.
# Causing the game to crash.
# * ===========
# * Scope Select
# * ===========
# * Added support for Scope_Select if Actor is afflicted with a specific State
# * Added support for Scope_Select if Enemy Unit is afflicted with a specific State
# * Added support for Scope_Select if A Team Member is afflicted with a specific State
# * Added support for Scope_Select if An Enemy Team Member (enemies if player, player if enemies0
# * is afflicted with a specific State
# * Added support for Scope_Select if Actor Knows a specific Skill
# * Added support for Scope_Select if Enemy Knows a specific Skill
# * ===========
# * Turn Order
# * ===========
# * Added support for "Redrawing" the Turn Order
# * If enabled, the turn order will be determined at the end of every turn.
# * This allows for skills that raise a unit's agility to have a better advantage
# The next turn.
#
# * Added support for Initiative Battle System:
# ** Allows the configuring of
# *** Bonus Initiative for non-movement / remaining move points
# *** Non-Action - Not attacking/using skills/items/ect.
# *** Default Initiative cost - Initiative cost per turn
# * ===========
# * Turn Order
# * ===========
# * [Order Types]
# * Type 0
# * Fair Order - Alternates between Ally and Enemy. Ally and Enemy order is
# * based on agility. [Ally1, Enemy1, Ally2, Enemy2....etc]
# *
# * Type 1
# * Simple Order - Takes all ally/enemy together and sorts indiscriminately based on
# * agility. Can Cause unfair turn order if either side is faster in general
# * ex. [Ally1, Ally2, Enemy1, Enemy3, Enemy2, Ally3]
# *
# * Type 2 (Also known as Pre-emptive Strike)
# * Actor First - Sorts Actors and Enemies by Agility order respectively
# * (Orders Actor List by AGI. and Enemy List by AGI.
# * Then Combines the Two Lists. Results in order like the following:
# * [Ally3, Ally1, Ally2, Enemy1, Enemy3, Enemy2]
# *
# * Type 3 (Also known as Surprise Attack)
# * Enemy First - Sorts Actors and Enemies by Agility order respectively
# * (Orders Actor List by AGI. and Enemy List by AGI.
# * Then Combines the Two Lists. Results in order like the following:
# * [Enemy1 ,Enemy3, Enemy2,Ally3, Ally1, Ally2]
# *
# * Reverse
# *
# * Type 4
# * Fair Order - Alternates between Ally and Enemy. Ally and Enemy order is
# * based on agility. [Ally1, Enemy1, Ally2, Enemy2....etc] Slowest Acts First
# *
# * Type 5
# * Simple Order - Takes all ally/enemy together and sorts indiscriminately based on
# * agility. Can Cause unfair turn order if either side is faster in general
# * ex. [Ally1, Ally2, Enemy1, Enemy3, Enemy2, Ally3] Slowest Acts First
# *
# * Type 6
# * Actor First - Sorts Actors and Enemies by Agility order respectively
# * (Orders Actor List by AGI. and Enemy List by AGI.
# * Then Combines the Two Lists. Results in order like the following:
# * [Ally3, Ally1, Ally2, Enemy1, Enemy3, Enemy2] Slowest Acts First
# *
# * Type 7
# * Enemy First - Sorts Actors and Enemies by Agility order respectively
# * (Orders Actor List by AGI. and Enemy List by AGI.
# * Then Combines the Two Lists. Results in order like the following:
# * [Enemy1 ,Enemy3, Enemy2,Ally3, Ally1, Ally2] Slowest Acts First
# *
# * Special
# * Type 8
# * Initiative Order - Currently uses the Actor's initial move points and agility to determine level of initiative.
# * the higher the player's initiative, the higher in the order they go.
# * After a turn ends, bonuses can be set for:
# * Non-Action (No attack / item / skill / etc
# * Remaining Movepoints (ie: used 3 of 5 movepoints - results in 2 bonus initiative)
# * Pre-Set initiative cost deducted on turn end (default of 10). When an actor or enemy
# * has 0 or fewer initiative points, they are removed from the turn order, and must wait
# * until the initiative order is re-structured (all units finished using all initiative)
# * ===========
# * Counter System
# * ===========
# * Repaired Counter System for 0.77
# * Added support for Yanfly Counter Control
# * Added support for Counter Conditions, Counter Distance
# * Counter is selected by determining "Best Counters"
#
# * First, the skill's Counter Conditions are checked.
# ** If no counter condition is set, it is evaluated as true -
# ** otherwise it evaluates the counter condition. If false, it
# it does not add the skill to any array, if true, proceed to next step.
# * Second, it checks Counter distance (If unavailable, assumes "0") of all Counter Skills
# for the "countering" entity.
# * If Counter Distance = Distance between attacker and the entity that counters
# or the Counter Distance = 0, then that counter skill is added to the "Best" counters
# * If Counter Distance is greater than or equal to the distance between the two entities,
# then it is considered a "good" or otherwise "valid" counter.
# * If the "Best" counters has a length > 0 then it is returned, otherwise, it checks if
# the "Good" counters array has a length of > 0, if so, that one is returned.
# * If neither array has elements, it returns an empty array, and the character does NOT counter.
#
# * After the Counter SKills array is determined, it randomly selects one.
# * This counter is then checked to see what "Type" of counter it is.
# * Using an array of "Defensive Counters" (Will later be updated to use a notetag) it checks if the skill
# selected is a Defensive Counter and returns such, otherwise it returns "Offensive".
# ** CheckCounter is also used by getBestCounter(), which uses it to determine if the counter is Invalid
# ** Here, it is simply used to determine if it is defensive or offensive.
#
# * If the skill is defensive, the cursor is set to the countering entity, and the action is performed.
# ** A popup will display with "Defensive Counter" and "Skill Name"
# * If the skill is offensive, the cursor is set to the entity to BE countered, and the action is performed.
# ** A popup will display with "Offensive Counter" and "Skill Name"
# *** Will add support later for other counter types such as:
# **** Support Counter
# **** Magic Counter
# **** Physical Counter
# **** Elemental Counters
# ***** Fire,Ice,Thunder,Water,Wind,Earth,Light,Dark
#
# ****TO-DO****
# * Check if counters affect allies.
# * Add notetag to prevent ally counters
# * Add notetag to allow ally counters
# * Add notetag for specialiszed counters
# ** Nearest Enemy
# ** Nearest Ally
# ** ETC
# - 0.77.PHX.02
# * Added support for "exclude_free_cells" in the AOE. previously
# * this boolean did exist, but there was never a function to filter
# * out cells without an entity in it. This also greatly reduces lag
# * when selecting skills with 20+ range.
# *
# * Fixed "Charm" System.
# * Lecode used isAlly and isEnemy to determine which side the enemy/
# * target was on, rather than using isAlly to determine if the target
# * was an actual Ally of the user.
# *
# * This resulted in crazy situations where the ally and enemy arrays
# * for a confused user were identical, resulting in the AI getting confused.
# * Any confused AI will continue to beat up their own allies, until the
# * confusion wears off, the user dies, or all their allies are dead.
# *
# * In these cases, the user will then proceed to attack the actual enemy.
# * I believe that if the confused enemy has healing skills, he will heal
# * and/or resurrect their teammates. This can cause even more hilarious
# * situations where an enemy kills/revives/kills again their teammates.
# *
In addition to all of this, I also have 3 other plugins for general Utility, and my region and terrain plugins,
Combine those with the changes to LeTBS.js, and the yanfly plugins, I estimate I have added around 4,000 lines of code minimum to my project.