Skip to content

Instantly share code, notes, and snippets.

@SydMontague
Created October 28, 2021 13:44
Show Gist options
  • Save SydMontague/e527a24e9a1d1f7a2ea054d72e762ced to your computer and use it in GitHub Desktop.
Save SydMontague/e527a24e9a1d1f7a2ea054d72e762ced to your computer and use it in GitHub Desktop.
Digimon World damage formula
int calculateDamage(DigimonEntity *attacker,DigimonEntity *defender,int moveId)
{
byte factors [4];
int damage;
Special attackSpecial = MOVE_PARAM[moveId].special;
for (int i = 0; i < 3; i += 1) {
Special victimSpecial = DIGIMON_PARA[(defender->entity).type].special[i];
factors[i] = victimSpecial == 0xff ? 10 : TYPE_FACTORS[attackSpecial][victimSpecial];
}
int offense = (int)attacker->offense;
int defense = (int)defender->defense;
// counter
if (moveId == 0x2d)
defense = defense * 0.3;
int typeFactor = factors[0] + factors[1] + factors[2];
// regular attacks
if ((moveId < 0x3a) || (0x70 < moveId)) {
int offenseDifference = offense - defense;
// make sure diff isn't bigger than 500
if (500 < offenseDifference)
offenseDifference = 500;
if (offenseDifference < -500)
offenseDifference = -500;
int randomFactor = random(21);
damage = (((int)(typeFactor * (MOVE_PARAM[moveId].power + (offenseDifference * MOVE_PARAM[moveId].power) / 500)) / 30) * (randomFactor + 90)) / 100;
}
else {
// finisher
damage = (int)((offense + MOVE_PARAM[moveId].power) * typeFactor) / 0x1e;
}
// finisher
if ((0x39 < moveId) && (moveId < 0x71)) {
// when partner, take chargeup factor
if (attacker == ENTITY_TABLE.partner) {
int chargeupValue = (uint)*(byte *)&(COMBAT_DATA_PTR->player).finisherChargeup;
if (40 < chargeupValue)
damage = (int)(damage * chargeupValue) / 40;
}
// when NPC, take random factor
else {
int chargeupValue = random(101);
damage = (damage * (chargeupValue + 100)) / 100;
}
roll2 = random(21);
damage = (damage * (roll2 + 90)) / 100;
}
// verify boundaries
if (damage < 1)
damage = 1;
if (9999 < damage)
damage = 9999;
return damage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment