Target Core: Prime Numbers and Lowest/Highest Attributes

Hello all! I am making a class based off the Arithmetician class from Final Fantasy Tactics. I had a couple questions regarding target conditions:

1) What tags would allow a skill to target any unit with a level that is a prime number? (i.e., 2, 3, 5, 7, 11, 13, 17, 19, 23, etc).

2) I suspect this one is more challenging... I want to create the following spells:

- Warp: Increases the Agility of the unit(s) with lowest Agility by 25%.
- Dilate: Decreases the Agility of the unit(s) with the highest Agility by 25%.

How would I create a condition that hits the target(s) with the lowest parameters for a specific stat, if at all possible?
I guess an inefficient way would be to simply list all the prime levels outright, up to your game's level cap. Not the most elegant solution, but at least it'd work.
I think it'd be quicker (more "efficient") to list all primes below max level, rather than applying the Sieve every time you use the skill. 😅

Link to Yanfly's Target Core plugin, for reference:
Suggested <Custom Target Eval> notetags, based on the example on that page (untested):
  1. Target all alive opponents with prime-numbered level (assuming max level is 99):
    JavaScript:
    var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
    foes.aliveMembers().forEach(function(m) {
      if (primes.contains(m.level)) {
        targets.push(m);
      }
    });
    Note that if you want actors to use this skill, you'll need some kind of plugin to add levels to enemies.

  2. Target lowest-AGI alive ally:
    JavaScript:
    var v = 10000;      // min value tracker
    var x = friends.aliveMembers().reduce(function(a, c, n) {
      if (c.agi < v) {  // new min value?
        v = c.agi;      // update min value
        return n;       // store current index
      }
      return a;         // retain index
    }, 0);  // start with index 0
    targets.push(friends.aliveMembers()[x]);
    Target highest-AGI alive opponent:
    JavaScript:
    var v = -1;         // max value tracker
    var x = foes.aliveMembers().reduce(function(a, c, n) {
      if (c.agi > v) {  // new max value?
        v = c.agi;      // update max value
        return n;       // store current index
      }
      return a;         // retain index
    }, 0);  // start with index 0
    targets.push(foes.aliveMembers()[x]);
Hope those work as planned and/or give you enough to work with to figure things out~ 🙏

In case you're interested, here's a link to some technical info on that "reduce" thing I've used:
I think it'd be quicker (more "efficient") to list all primes below max level, rather than applying the Sieve every time you use the skill. 😅
Thank you so much! These all appear to be working. 🙂 Do you know if there is a way to make it cycle through all the targets on the battlefield, instead of just friends. or foes. ? I tried using battlers. and members. but didn't have any luck.
Thank you so much! These all appear to be working. 🙂 Do you know if there is a way to make it cycle through all the targets on the battlefield, instead of just friends. or foes. ? I tried using battlers. and members. but didn't have any luck.
Instead of just friends or foes you could try friends.concat(foes) (or vice-versa), e.g.
JavaScript:
var primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97];
foes.concat(friends).aliveMembers().forEach(function(m) {
  if (primes.contains(m.level)) {
    targets.push(m);
  }
});
concat just merges arrays, details here~

Original thread: https://forums.rpgmakerweb.com/threads/target-core-prime-numbers-and-lowest-highest-attributes.122795/