In the BuffInterface class, method postTurn,
the program iterates over all buffs of an animal and when encountering an expired buff, removes that buff, using splice.
I do not know JS very well, but in other languages it is considered bad practice to mutate iterables while iterating over them, as this often has hard-to-predict consequences.
I thought for a long time, that this is the reason why poison sometimes bypasses taunt, but that is not the case. The code that causes that is in the battleUtil.postTurn method.
Suggestion: do not splice at all(!) in the postTurn method. Just reduce durations. Instead, at the end(!) of the postTurn method in battleUtil(!), remove all buffs with duration 0. But instead of using splice, rebuild the buff list, something like this (I don't know JS, so take it rather like pseudo code), or using some filter methods:
let newBuffList = new buffList();
for buff in animal.buffs {
____if (buff.duration > 0) { newBuffList.add(buff); }
}
animal.buffs = newBuffList
This would make sure that at the end of any turn, all buffs are simultaneously in effect and are also removed simultaneously.
Please note that:
Fixing this would have some serious side effects on the current battle system. For one, poison would both no longer be able to bypass taunt (as it currently does in turns 4/6/8/10/12/14/...), reducing the power of pdagger against taunts significantly (probably about 25-30%!!). I do not know whether flame from fstaff is affected the same way, but I guess that it is.
Further explanation how poison currently is blocked in turn 2, but not in turns 4/6/8/...:
the tank gets as a very first buff its taunt buff and after that it gets the poison buff. Order is important here.
in battleUtil.postTurn, buffs are resolved in reverse order: first poison is applied, then, during even rounds, taunt is removed.
in round 2, when the pdagger pet attacks again, the existing poison buff is not removed and replaced by a new buff, but its duration is extended. At turn end, poison hits first (because it is at the end of the list), then the taunt buff is removed from the animal's buff list completely, only poison (and other stuff) remains. In round 3, taunt is appended at the end of the buff list first, then pdagger hits and changes again the duration, but now the order is in reverse: first comes poison, then taunt. Thus, in round 4, first taunt is removed and then poison applies....