For reference purposes, here is the default engine Damage_Logic code.
$stat_diff = $attacker.stat["attack"] - $defender.stat["defense"];
if $stat_diff <= 0 then
$damage = random(0, 1);
elseif $weapon == null then
$damage = $stat_diff + random(-1, 1);
else
$damage = $stat_diff + random(-1, 1) + random($weapon.min_damage, $weapon.max_damage);
end;
if $damage < 0 then
$damage = 0;
end;
return $damage;
To use,
make a script file with the name "damage_logic" in your project and paste the above code inside.
This will allow you to edit and set how your project calculates damage.
EXPLANATION
To explain how this script calculates damage by default:
it starts by subtracting the defenders "defense" stat value from the attackers "attack" stat value
(found in the character's voxel model properties).
- If the sum of that subtraction is 0 or less, then it makes damage a random result of either 0 or 1.
- if the sum of that subtraction is greater than 0, it then checks for a weapon.
- if not equipped. then
- damage is the difference sum plus a random number between [-1 - 1]
- if equipped then
- damage is the difference sum, plus a random number between [-1 - 1] and then a random number between the equipped weapons min/max damage property
(found in item editor)
Lastly:
[if damage calculated is below 0]
then it forces it to return a value of 0....
otherwise, it returns the calculated damage from the above math.
Example 1:
Player Attack stat: 5
Goblin defense stat: 2
5 - 2 = 3 [stat diff]
Player has no weapon, so damage will be stat diff + random(-1, 1).... lets say it chose 1.
Damage will then be returned as 4 (3 + 1)
Example 2:
Player Attack stat: 5
Skeleton defense stat: 3
5 - 3 = 2 [stat diff]
Player has a sword equipped with a min damage of 2 and a max damage of 7.
damage will be calculated as stat diff, + random (-1, 1), + random number between 2 - 7.
Lets say the first random number was -1,
which in that case will further deduct from the stat diff,
and then the random number for the weapon damage was 5.
Damage will then be returned as 6 ( 2 + -1 + 5)
Hopefully that helps break down how the damage_logic works by default,
You can of course alter these values to adjust how the damage functions in your own projects.