Skip to content

Commit

Permalink
Refactoring: lottarmor: no globalstep, use `register_on_punchplayer…
Browse files Browse the repository at this point in the history
…()` for check healing on hit. Relates to lord-server#339, lord-server#1012.
  • Loading branch information
alek13 committed Jul 28, 2024
1 parent 0fef3db commit a39361f
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions mods/lord/lottarmor/armor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ local math_random, math_floor, string_match, ipairs
= math.random, math.floor, string.match, ipairs


local ARMOR_UPDATE_TIME = 1

--- @type table<number,string>|string[]
local PHYSICS_TYPES = { "jump", "speed", "gravity" }
--- @type table<number,string>|string[]
Expand Down Expand Up @@ -125,28 +123,15 @@ local function get_armor_healing_chance(player)
end
end

local handle_armor_heal = function(player)
local handle_armor_healing = function(player)
local name = player:get_player_name()
if not name then
return
end
if not name then return end

local hp = player:get_hp() or 0
if hp <= 0 or hp == armor.player_hp[name] then
local armor_healing_chance = get_armor_healing_chance(player)
if math_random(100) < armor_healing_chance then
player:set_hp(armor.player_hp[name])
return
end
if armor.player_hp[name] > hp then -- only on punch


local armor_healing_chance = get_armor_healing_chance(player)
if math_random(100) < armor_healing_chance then
player:set_hp(armor.player_hp[name])
return
end


end
armor.player_hp[name] = hp
end


Expand All @@ -169,4 +154,4 @@ equipment.on_load(equipment.Kind.ARMOR, function(player, kind, event, slot, item
end)


minetest.foreach_player_every(ARMOR_UPDATE_TIME, handle_armor_heal)
minetest.register_on_punchplayer(handle_armor_healing)

0 comments on commit a39361f

Please sign in to comment.