###############
# Damage Calc #
###############
{
local previous_hp = 0
function AnnounceDamage()
local current_hp, max_hp = you.hp()
-- Skip on game initialization
if previous_hp == 0 then
previous_hp = current_hp
return
end
-- Calculate HP difference
local hp_difference = previous_hp - current_hp
-- Only show message if damage was taken
if hp_difference > 0 then
-- Damage taken
if current_hp <= (max_hp * 0.30) then
crawl.mpr("You take " .. hp_difference .. " damage! (" .. current_hp .. "/" .. max_hp .. " HP)")
elseif current_hp <= (max_hp * 0.50) then
crawl.mpr("You take " .. hp_difference .. " damage. (" .. current_hp .. "/" .. max_hp .. " HP)")
elseif current_hp <= (max_hp * 0.70) then
crawl.mpr("You take " .. hp_difference .. " damage. (" .. current_hp .. "/" .. max_hp .. " HP)")
else
crawl.mpr("You take " .. hp_difference .. " damage. (" .. current_hp .. "/" .. max_hp .. " HP)")
you.event("turn", on_turn)
end
-- Massive damage warning
if hp_difference > (max_hp * 0.20) then
crawl.mpr("** MASSIVE DAMAGE! **")
end
end
-- Update tracking variable
previous_hp = current_hp
end
}