legacy.lua 733 B

1234567891011121314151617181920212223242526272829303132
  1. -- Localize for performance.
  2. local math_floor = math.floor
  3. local armor_org_func = armor.set_player_armor
  4. local function get_armor_lvl(def)
  5. -- items/protection based display
  6. local lvl = def.level or 0
  7. local max = 51.975 -- full mithril armor + mithril shield
  8. -- TODO: is there a sane way to read out max values?
  9. local ret = lvl / max
  10. if ret > 1 then
  11. ret = 1
  12. end
  13. return math_floor(tonumber(20 * (ret)))
  14. end
  15. function armor.set_player_armor(self, player)
  16. armor_org_func(self, player)
  17. local name = player:get_player_name()
  18. local def = self.def
  19. local armor_lvl = 0
  20. if def[name] and def[name].level then
  21. armor_lvl = get_armor_lvl(def[name])
  22. end
  23. hud.change_item(player, "armor", {number = armor_lvl, max = 20})
  24. end