2015-09-01 17:15:24 +02:00
|
|
|
--
|
|
|
|
-- Armor mod
|
|
|
|
-- By Kaadmy, for Pixture
|
|
|
|
--
|
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
local S = minetest.get_translator("armor")
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
armor = {}
|
|
|
|
|
2017-05-17 18:24:18 +02:00
|
|
|
-- Wear is wear per HP of damage taken
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
armor.materials = {
|
2017-05-17 18:24:18 +02:00
|
|
|
-- material craftitem description %
|
2019-08-28 20:59:56 +02:00
|
|
|
{"wood", "group:planks", { S("Wooden Helmet"), S("Wooden Chestplate"), S("Wooden Boots") }, 10},
|
|
|
|
{"steel", "default:ingot_steel", { S("Steel Helmet"), S("Steel Chestplate"), S("Steel Boots") }, 20},
|
|
|
|
{"chainmail", "armor:chainmail_sheet", { S("Chainmail Helmet"), S("Chainmail Chestplate"), S("Chainmail Boots") }, 30},
|
|
|
|
{"carbon_steel", "default:ingot_carbon_steel", { S("Carbon Steel Helmet"), S("Carbon Steel Chestplate"), S("Carbon Steel Boots") }, 40},
|
|
|
|
{"bronze", "default:ingot_bronze", { S("Bronze Helmet"), S("Bronze Chestplate"), S("Bronze Boots") }, 60},
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
-- Usable slots
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
armor.slots = {"helmet", "chestplate", "boots"}
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
-- Timer
|
|
|
|
|
|
|
|
local timer_interval = 1
|
|
|
|
local timer = 10
|
|
|
|
|
|
|
|
-- Formspec
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
local form_armor = default.ui.get_page("default:2part")
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
form_armor = form_armor .. "list[current_player;main;0.25,4.75;8,4;]"
|
|
|
|
form_armor = form_armor .. default.ui.get_hotbar_itemslot_bg(0.25, 4.75, 8, 1)
|
|
|
|
form_armor = form_armor .. default.ui.get_itemslot_bg(0.25, 5.75, 8, 3)
|
|
|
|
form_armor = form_armor .. "listring[current_player;main]"
|
2015-10-04 22:40:36 +02:00
|
|
|
|
2019-08-28 17:31:41 +02:00
|
|
|
form_armor = form_armor .. "label[3.25,1;"..minetest.formspec_escape(S("Helmet")).."]"
|
|
|
|
form_armor = form_armor .. "label[3.25,2;"..minetest.formspec_escape(S("Chestplate")).."]"
|
|
|
|
form_armor = form_armor .. "label[3.25,3;"..minetest.formspec_escape(S("Boots")).."]"
|
2017-05-16 05:57:30 +02:00
|
|
|
|
|
|
|
form_armor = form_armor .. "list[current_player;armor;2.25,0.75;1,3;]"
|
|
|
|
form_armor = form_armor .. "listring[current_player;armor]"
|
|
|
|
form_armor = form_armor .. default.ui.get_itemslot_bg(2.25, 0.75, 1, 3)
|
|
|
|
|
|
|
|
default.ui.register_page("armor:armor", form_armor)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
function armor.is_armor(itemname)
|
2017-05-12 04:29:55 +02:00
|
|
|
local item = minetest.registered_items[itemname]
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
if item ~= nil and item.groups ~= nil then
|
|
|
|
if item.groups.is_armor then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function armor.is_slot(itemname, slot)
|
|
|
|
local match = string.find(itemname, "armor:" .. slot .. "_")
|
|
|
|
local matchbool = false
|
|
|
|
if match ~= nil and match >= 1 then
|
|
|
|
matchbool = true
|
|
|
|
end
|
|
|
|
return matchbool
|
|
|
|
end
|
|
|
|
|
2015-10-17 01:36:39 +02:00
|
|
|
function armor.get_base_skin(player)
|
2017-05-12 04:29:55 +02:00
|
|
|
if minetest.get_modpath("player_skins") ~= nil then
|
2015-10-17 01:36:39 +02:00
|
|
|
return player_skins.get_skin(player:get_player_name())
|
|
|
|
else
|
|
|
|
return armor.player_skin
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
function armor.get_texture(player, base)
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
|
|
|
local image = base
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
for slot_index, slot in ipairs(armor.slots) do
|
|
|
|
local itemstack = inv:get_stack("armor", slot_index)
|
2015-09-01 17:15:24 +02:00
|
|
|
local itemname = itemstack:get_name()
|
2017-05-16 05:57:30 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if armor.is_armor(itemname) and armor.is_slot(itemname, slot) then
|
2017-05-12 04:29:55 +02:00
|
|
|
local item = minetest.registered_items[itemname]
|
2015-09-01 17:15:24 +02:00
|
|
|
local mat = armor.materials[item.groups.armor_material][1]
|
|
|
|
|
|
|
|
image = image .. "^armor_" .. slot .. "_" .. mat ..".png"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return image
|
|
|
|
end
|
|
|
|
|
|
|
|
function armor.get_groups(player)
|
|
|
|
local groups = {fleshy = 100}
|
|
|
|
|
|
|
|
local match_mat = nil
|
|
|
|
local match_amt = 0
|
|
|
|
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
2019-09-22 03:37:22 +02:00
|
|
|
local ach_ok = true
|
2017-05-16 05:57:30 +02:00
|
|
|
for slot_index, slot in ipairs(armor.slots) do
|
|
|
|
local itemstack = inv:get_stack("armor", slot_index)
|
2015-09-01 17:15:24 +02:00
|
|
|
local itemname = itemstack:get_name()
|
|
|
|
|
2019-09-22 03:37:22 +02:00
|
|
|
if itemstack:get_name() ~= "armor:"..slot.."_bronze" then
|
|
|
|
ach_ok = false
|
|
|
|
end
|
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if armor.is_armor(itemname) then
|
2017-05-12 04:29:55 +02:00
|
|
|
local item = minetest.registered_items[itemname]
|
2017-05-13 20:50:15 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
for mat_index, _ in ipairs(armor.materials) do
|
|
|
|
local mat = armor.materials[mat_index][1]
|
|
|
|
|
|
|
|
if mat_index == item.groups.armor_material then
|
|
|
|
groups.fleshy = groups.fleshy - item.groups.armor
|
|
|
|
if match_mat == nil then
|
|
|
|
match_mat = mat
|
|
|
|
end
|
2017-05-16 05:57:30 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
if mat == match_mat then
|
|
|
|
match_amt = match_amt + 1
|
|
|
|
end
|
2017-05-16 05:57:30 +02:00
|
|
|
|
2015-09-01 17:15:24 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-22 03:37:22 +02:00
|
|
|
if ach_ok then
|
|
|
|
achievements.trigger_achievement(player, "full_armor")
|
|
|
|
end
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
-- If full set of same armor material, then boost armor by 10%
|
|
|
|
|
|
|
|
if match_amt == #armor.slots then
|
2015-09-01 17:15:24 +02:00
|
|
|
groups.fleshy = groups.fleshy - 10
|
|
|
|
end
|
|
|
|
|
|
|
|
return groups
|
|
|
|
end
|
|
|
|
|
|
|
|
function armor.init(player)
|
|
|
|
local inv = player:get_inventory()
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
if inv:get_size("armor") ~= 3 then
|
|
|
|
inv:set_size("armor", 3)
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function armor.update(player)
|
|
|
|
local groups = armor.get_groups(player)
|
|
|
|
player:set_armor_groups({fleshy = groups.fleshy})
|
|
|
|
|
2015-10-17 01:36:39 +02:00
|
|
|
local image = armor.get_texture(player, armor.get_base_skin(player))
|
2015-09-01 17:15:24 +02:00
|
|
|
if image ~= default.player_get_textures(player)[1] then
|
|
|
|
default.player_set_textures(player, {image})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_newplayer(player)
|
|
|
|
armor.init(player)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function on_joinplayer(player)
|
|
|
|
armor.init(player)
|
|
|
|
end
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
local function on_globalstep(dtime)
|
|
|
|
timer = timer + dtime
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
if timer < timer_interval then
|
|
|
|
return
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
2017-05-16 05:57:30 +02:00
|
|
|
|
|
|
|
timer = 0
|
|
|
|
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
armor.update(player)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-17 18:24:18 +02:00
|
|
|
if minetest.get_modpath("drop_items_on_die") ~= nil then
|
|
|
|
drop_items_on_die.register_listname("armor")
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
minetest.register_on_newplayer(on_newplayer)
|
|
|
|
minetest.register_on_joinplayer(on_joinplayer)
|
|
|
|
|
|
|
|
minetest.register_globalstep(on_globalstep)
|
|
|
|
|
|
|
|
-- Chainmail
|
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2015-09-01 17:15:24 +02:00
|
|
|
"armor:chainmail_sheet",
|
|
|
|
{
|
2019-08-28 17:31:41 +02:00
|
|
|
description = S("Chainmail Sheet"),
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
inventory_image = "armor_chainmail.png",
|
2017-05-13 20:50:15 +02:00
|
|
|
wield_image = "armor_chainmail.png",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
stack_max = 20,
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
|
|
|
output = "armor:chainmail_sheet 3",
|
2017-05-16 05:57:30 +02:00
|
|
|
items = {
|
|
|
|
"default:ingot_steel 5",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- Armor pieces
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-17 17:57:14 +02:00
|
|
|
for mat_index, matdef in ipairs(armor.materials) do
|
|
|
|
local mat = matdef[1]
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-17 18:24:18 +02:00
|
|
|
local armor_def = math.floor(matdef[4] / #armor.slots)
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2019-08-28 20:59:56 +02:00
|
|
|
for s, slot in ipairs(armor.slots) do
|
2017-05-17 17:57:14 +02:00
|
|
|
|
2017-05-12 04:29:55 +02:00
|
|
|
minetest.register_craftitem(
|
2017-05-16 05:57:30 +02:00
|
|
|
"armor:" .. slot .. "_" .. mat,
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2019-08-28 20:59:56 +02:00
|
|
|
description = matdef[3][s],
|
2015-09-01 17:15:24 +02:00
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
inventory_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
|
|
|
wield_image = "armor_" .. slot .. "_" .. mat .. "_inventory.png",
|
2015-09-01 17:15:24 +02:00
|
|
|
|
|
|
|
groups = {
|
|
|
|
is_armor = 1,
|
|
|
|
armor = armor_def,
|
|
|
|
armor_material = mat_index
|
|
|
|
},
|
|
|
|
|
|
|
|
stack_max = 1,
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
2015-09-01 17:15:24 +02:00
|
|
|
end
|
|
|
|
|
2017-05-16 05:57:30 +02:00
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-16 05:57:30 +02:00
|
|
|
output = "armor:helmet_" .. mat,
|
|
|
|
items = {
|
2017-05-17 17:57:14 +02:00
|
|
|
matdef[2] .. " 5",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-16 05:57:30 +02:00
|
|
|
output = "armor:chestplate_" .. mat,
|
|
|
|
items = {
|
2017-05-17 17:57:14 +02:00
|
|
|
matdef[2] .. " 8",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
crafting.register_craft(
|
2015-09-01 17:15:24 +02:00
|
|
|
{
|
2017-05-16 05:57:30 +02:00
|
|
|
output = "armor:boots_" .. mat,
|
|
|
|
items = {
|
2017-05-17 17:57:14 +02:00
|
|
|
matdef[2] .. " 6",
|
2015-09-01 17:15:24 +02:00
|
|
|
}
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
2015-10-04 22:40:36 +02:00
|
|
|
end
|
2017-05-13 20:50:15 +02:00
|
|
|
|
2015-10-25 22:18:54 +01:00
|
|
|
-- Achievements
|
|
|
|
|
|
|
|
achievements.register_achievement(
|
|
|
|
"armored",
|
|
|
|
{
|
2019-09-26 18:35:14 +02:00
|
|
|
title = S("Armored"),
|
2019-09-02 14:54:29 +02:00
|
|
|
description = S("Craft a piece of armor."),
|
2015-10-25 22:18:54 +01:00
|
|
|
times = 1,
|
|
|
|
craftitem = "group:is_armor",
|
2017-05-16 05:57:30 +02:00
|
|
|
})
|
2015-10-25 22:18:54 +01:00
|
|
|
|
2019-09-22 03:37:22 +02:00
|
|
|
achievements.register_achievement(
|
|
|
|
"full_armor",
|
|
|
|
{
|
|
|
|
title = S("Skin of Bronze"),
|
|
|
|
description = S("Equip a full suit of bronze armor."),
|
|
|
|
times = 1,
|
|
|
|
})
|
|
|
|
|
2017-05-13 20:50:15 +02:00
|
|
|
default.log("mod:armor", "loaded")
|