2013-03-15 21:27:58 +01:00
|
|
|
|
|
|
|
armor_api = {
|
|
|
|
player_hp = {},
|
2013-04-11 21:56:35 +02:00
|
|
|
fleshy_max = 20
|
2013-03-15 21:27:58 +01:00
|
|
|
}
|
|
|
|
|
2013-04-11 21:56:35 +02:00
|
|
|
armor_api.get_armor_textures = function(self, player)
|
2013-03-15 21:27:58 +01:00
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
2013-04-11 21:56:35 +02:00
|
|
|
local textures = {}
|
2013-03-15 21:27:58 +01:00
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
for _,v in ipairs({"head", "torso", "legs"}) do
|
|
|
|
local stack = player_inv:get_stack("armor_"..v, 1)
|
2013-04-11 21:56:35 +02:00
|
|
|
if stack:get_definition().groups["armor_"..v] then
|
|
|
|
local item = stack:get_name()
|
|
|
|
textures[v] = item:gsub("%:", "_")..".png"
|
2013-03-15 21:27:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local stack = player_inv:get_stack("armor_shield", 1)
|
2013-04-11 21:56:35 +02:00
|
|
|
if stack:get_definition().groups["armor_shield"] then
|
|
|
|
local item = stack:get_name()
|
|
|
|
textures["shield"] = minetest.registered_items[item].inventory_image
|
|
|
|
end
|
|
|
|
return textures
|
|
|
|
end
|
|
|
|
|
|
|
|
armor_api.set_player_armor = function(self, player)
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_level = 0
|
|
|
|
for _,v in ipairs({"head", "torso", "legs", "shield"}) do
|
|
|
|
local stack = player_inv:get_stack("armor_"..v, 1)
|
|
|
|
local armor = stack:get_definition().groups["armor_"..v] or 0
|
|
|
|
armor_level = armor_level + armor
|
2013-03-15 21:27:58 +01:00
|
|
|
end
|
2013-04-11 21:56:35 +02:00
|
|
|
local armor_groups = {fleshy=100}
|
|
|
|
if armor_level > 0 then
|
|
|
|
armor_groups.level = math.floor(armor_level / 20)
|
|
|
|
armor_groups.fleshy = 100 - armor_level
|
2013-03-26 22:02:48 +01:00
|
|
|
end
|
2013-03-15 21:27:58 +01:00
|
|
|
player:set_armor_groups(armor_groups)
|
2013-04-11 21:56:35 +02:00
|
|
|
uniskins:update_player_visuals(player)
|
2013-03-15 21:27:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
armor_api.update_armor = function(self, player)
|
|
|
|
if not player then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local hp = player:get_hp()
|
2013-03-17 20:34:12 +01:00
|
|
|
if hp == nil or hp == 0 or hp == self.player_hp[name] then
|
2013-03-15 21:27:58 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if self.player_hp[name] > hp then
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
local armor_inv = minetest.get_inventory({type="detached", name=name.."_outfit"})
|
|
|
|
if armor_inv == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local heal_max = 0
|
|
|
|
for _,v in ipairs({"head", "torso", "legs", "shield"}) do
|
|
|
|
local stack = armor_inv:get_stack("armor_"..v, 1)
|
2013-03-17 20:34:12 +01:00
|
|
|
if stack:get_count() > 0 then
|
|
|
|
local use = stack:get_definition().groups["armor_use"] or 0
|
|
|
|
local heal = stack:get_definition().groups["armor_heal"] or 0
|
|
|
|
local item = stack:get_name()
|
|
|
|
stack:add_wear(use)
|
|
|
|
armor_inv:set_stack("armor_"..v, 1, stack)
|
|
|
|
player_inv:set_stack("armor_"..v, 1, stack)
|
|
|
|
if stack:get_count() == 0 then
|
|
|
|
local desc = minetest.registered_items[item].description
|
|
|
|
if desc then
|
|
|
|
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
|
|
|
|
end
|
2013-04-11 21:56:35 +02:00
|
|
|
self:set_player_armor(player)
|
2013-03-17 20:34:12 +01:00
|
|
|
end
|
|
|
|
heal_max = heal_max + heal
|
2013-03-15 21:27:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if heal_max > math.random(100) then
|
|
|
|
player:set_hp(self.player_hp[name])
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.player_hp[name] = hp
|
|
|
|
end
|
|
|
|
|