Possible underflow (?) in battle criticals
Brought to you by:
bgamez23
Originally created by: pazkero
Describe the bug
In battle.c:4654 critical is defined as
short cri = sstatus->cri;
A few lines later, the following problematic calculation is done:
#ifndef RENEWAL
//The official equation is *2, but that only applies when sd's do critical.
//Therefore, we use the old value 3 on cases when an sd gets attacked by a mob
cri -= tstatus->luk*(!sd&&tsd?3:2);
#else
cri -= status->get_lv(target) / 15 + 2 * status_get_luk(target);
#endif
Both are using "luck" stat, which is an uint16. See status.h:1059, when struct status_data is declared:
uint16 str, agi, vit, int_, dex, luk;
This means that critical can underflow (?) here.
Because luck can go up to 65535, a monster could (in both modes) have at least 131070 crit def.
So the critical must accept at least -131070 (an int32 should do the trick)
To Reproduce
Expected behavior
Modified monster should not receive crits, instead of always receiving crits.
System specs (please complete the following information):
Plugins used or source modifications
Evol Plugin (does not interfere)