legacy.lua 671 B

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