Add armor set and armor set bonus setting (#41)

- Add settingtypes of:
  -  armor_set_elements
  - armor_set_multiplier
- Add check to armor.registration_armor for "_materialname", print msg to debug if not found
- Complete change to how an armor set is calculated
- Set elements linked to settingtypes no longer hard linked to num armor.elements
- Set multiplier linked to settingtypes no longer hard coded
- Readme.MD updated:
  - Addition of the 2 new settingtypes
  - Addition of "Armor Material" topic
This commit is contained in:
Sirrobzeroone 2021-01-12 01:34:28 +11:00 committed by GitHub
parent a3cba570c4
commit e7abacc94e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 121 additions and 39 deletions

@ -1,27 +1,28 @@
# [mod] Visible Player Armor [3d_armor] # [mod] Visible Player Armor [3d_armor]
| | | | | | | | | |
|--|--|--|--| |--|--|--|--|
|-[Overview](#overview) |||-[API](#api)| |-[Overview](#overview) |||-[API](#api)
|-[Armor Configuration](#armor-configuration) |||- - [3d_Armor Item Storage](#3d_armor-item-storage) |-[Armor Configuration](#armor-configuration) |||- - [3d_Armor Item Storage](#3d_armor-item-storage)
|- - [disable_specific_materials](#to-disable-individual-armor-materials) |||- - [Armor Registration](#armor-registration) |- - [disable_specific_materials](#to-disable-individual-armor-materials) |||- - [Armor Registration](#armor-registration)
|- - [armor_init_delay](#initialization-glitches-when-a-player-first-joins) |||- - [Registering Armor Groups](#registering-armor-groups) |- - [armor_init_delay](#initialization-glitches-when-a-player-first-joins) |||- - [Registering Armor Groups](#registering-armor-groups)
|- - [armor_init_times](#number-of-initialization-attempts) |||- - [Groups used by 3d_Armor](#groups-used-by-3d_armor) |- - [armor_init_times](#number-of-initialization-attempts) |||- - [Groups used by 3d_Armor](#groups-used-by-3d_armor)
|- - [armor_bones_delay](#armor-not-in-bones-due-to-server-lag) |||- - - [Elements](#elements) |- - [armor_bones_delay](#armor-not-in-bones-due-to-server-lag) |||- - - [Elements](#elements)
|- - [armor_update_time](#how-often-player-armor-items-are-updated) |||- - - [Attributes](#attributes) |- - [armor_update_time](#how-often-player-armor-items-are-updated) |||- - - [Attributes](#attributes)
|- - [armor_drop](#drop-armor-when-a-player-dies) |||- - - [Physics](#physics) |- - [armor_drop](#drop-armor-when-a-player-dies) |||- - - [Physics](#physics)
|- - [armor_destroy](#destroy-armor-when-a-player-dies) |||- - - [Durability](#durability) |- - [armor_destroy](#destroy-armor-when-a-player-dies) |||- - - [Durability](#durability)
|- - [armor_level_multiplier](#armor-level-multiplyer) |||- - [Armour Functions](#armour-functions) |- - [armor_level_multiplier](#armor-level-multiplyer) |||- - - [Armor Material](#armor-material)
|- - [armor_heal_multiplier](#armor-healing-multiplyer) |||- - - [armor:set_player_armor](#armor-set_player_armor) |- - [armor_heal_multiplier](#armor-healing-multiplyer) |||- - [Armour Functions](#armor-functions)
|- - [armor_water_protect](#enable-water-protection) |||- - - [armor:punch](#armor-punch) |- - [armor_set_elements](#allows-the-customisation-of-armor-set) |||- - - [armor:set_player_armor](#armor-set_player_armor)
|- - [armor_fire_protect](#enable-fire-protection) |||- - - [armor:damage](#armor-damage) |- - [armor_set_bonus](#armor-set-bonus-multiplier) |||- - - [armor:punch](#armor-punch)
|- - [armor_punch_damage](#enable-punch-damage-effects) |||- - - [armor:remove_all](#armor-remove_all) |- - [armor_water_protect](#enable-water-protection) |||- - - [armor:damage](#armor-damage)
|- - [armor_migrate_old_inventory](#migration-of-old-armor-inventories) |||- - - [armor:equip](#armor-equip) |- - [armor_fire_protect](#enable-fire-protection) |||- - - [armor:remove_all](#armor-remove_all)
|- - [wieldview_update_time](#how-often-player-wield-items-are-updated) |||- - - [armor:unequip](#armor-unequip) |- - [armor_punch_damage](#enable-punch-damage-effects) |||- - - [armor:equip](#armor-equip)
| - [Credits](#credits) |||- - - [armor:update_skin](#armor-update_skin) |- - [armor_migrate_old_inventory](#migration-of-old-armor-inventories) |||- - - [armor:unequip](#armor-unequip)
| |||- - [Callbacks](#Callbacks) |- - [wieldview_update_time](#how-often-player-wield-items-are-updated) |||- - - [armor:update_skin](#armor-update_skin)
| |||- - - [Item callbacks](#item-callbacks) |-[Credits](#credits) |||- - [Callbacks](#Callbacks)
| |||- - - [Global callbacks](#global-callbacks) | |||- - - [Item callbacks](#item-callbacks)
| |||- - - [Global callbacks](#global-callbacks)
# Overview # Overview
@ -39,7 +40,7 @@ Overall level is boosted by 10% when wearing a full matching set.
# Armor Configuration # Armor Configuration
Override the following default settings by adding them to your ***minetest.conf*** file. Change the following default settings by going to Main Menu>>Settings(Tab)>>All Settings(Button)>>Mods>>minetest-3d_Armor>>3d_Armor
### To disable individual armor materials ### To disable individual armor materials
**set the below to false** **set the below to false**
@ -94,6 +95,17 @@ Override the following default settings by adding them to your ***minetest.conf*
**eg: armor_heal_multiplier = 0 will disable healing altogether.** **eg: armor_heal_multiplier = 0 will disable healing altogether.**
armor_heal_multiplier = 1 armor_heal_multiplier = 1
### Allows the customisation of armor set
**Shields already configured as need to be worn to complete an armor set**
**These names come from [Element names](#groups-used-by-3d_armor), the second half of the element name only is used eg armor_head is head**
armor_set_elements = head torso legs feet shield
### Armor set bonus multiplier
**Set to 1 to disable set bonus**
armor_set_multiplier = 1.1
### Enable water protection ### Enable water protection
**periodically restores breath when activated** **periodically restores breath when activated**
@ -174,7 +186,7 @@ Wrapper function for `minetest.register_tool`, which enables the easy registrati
preview = "mod_name_leather_chestplate_preview.png", preview = "mod_name_leather_chestplate_preview.png",
groups = {armor_torso=1, armor_heal=0, armor_use=2000, flammable=1}, groups = {armor_torso=1, armor_heal=0, armor_use=2000, flammable=1},
armor_groups = {fleshy=10}, armor_groups = {fleshy=10},
damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1} damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}
}) })
*See ***armor.lua*** under **3d_armor>>3d_armor** for further examples* *See ***armor.lua*** under **3d_armor>>3d_armor** for further examples*
@ -254,13 +266,9 @@ Adding Elements is more complex but the below code can be used to add new elemen
if minetest.global_exists("armor") and armor.elements then if minetest.global_exists("armor") and armor.elements then
table.insert(armor.elements, "hands") table.insert(armor.elements, "hands")
local mult = armor.config.level_multiplier or 1
armor.config.level_multiplier = mult * 0.5
end end
**1st line** not strictly needed but checks that the global table "armor" and subtable "elements" exists **1st line** not strictly needed but checks that the global table "armor" and subtable "elements" exists
**2nd line** adds a new value to the armor.elements table called "hands" **2nd line** adds a new value to the armor.elements table called "hands"
**3rd line** in this case will be set to one ***note: need more detail here***
**4th line** simply sets the multiplier, by setting 0.5 smaller armor becomes less effective and larger more effective. good values are between 0.1 and 1 in increments of 0.1.
See ***init.lua*** under **3d_armor>>shields** for a further example See ***init.lua*** under **3d_armor>>shields** for a further example
@ -350,7 +358,41 @@ Durability is determined by the value assigned to the group ***armor_use***. The
All diamond armor items have an ***armor_use=200***; All diamond armor items have an ***armor_use=200***;
65535/2000 = 327.6 (327) 65535/2000 = 327.6 (327)
After 327 uses(hits) the armor item will break. After 327 uses(hits) the armor item will break.
### Armor Material
The material the armor is made from is defined by adding the material to the end of registered armor item name. It is very important the material is the last item in the registered item name and it is preceeded by an "_" eg "_materialname".
The material name is what 3d_armor uses to determine if a player is wearing a set of armor. To recieve the set bonus all items worn must be made of the same material.
So to get a set bonus under the default set settings the players armor items listed below must be made of the same material:
* head - Helmet
* torso - Chestplate
* legs - Leggings
* feet - Boots
* shield - Shields
If all of the above were made of material "wood" the player would recieve an ***armor_set_bonus*** of armor_level * 1.1, essentially +10%
**Example One**
armor:register_armor("3d_armor:helmet_bronze", {
description = S("Bronze Helmet"),
inventory_image = "3d_armor_inv_helmet_bronze.png",
groups = {armor_head=1, armor_heal=6, armor_use=400, physics_speed=-0.01, physics_gravity=0.01},
armor_groups = {fleshy=10},
damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2},
})
**Example Two**
armor:register_armor("new_mod:helmet_spartan_bronze", {
description = S("Spartan Helmet"),
inventory_image = "new_mod_inv_helmet_spartan_bronze.png",
groups = {armor_head=1, armor_heal=6, armor_use=350, physics_speed=-0.01, physics_gravity=0.01},
armor_groups = {fleshy=12},
damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2},
})
***Note: At the moment an armor item can only be made of one material***
## Armor Functions ## Armor Functions

@ -95,6 +95,8 @@ armor.config = {
material_gold = true, material_gold = true,
material_mithril = true, material_mithril = true,
material_crystal = true, material_crystal = true,
set_elements = "head torso legs feet shield",
set_multiplier = 1.1,
water_protect = true, water_protect = true,
fire_protect = minetest.get_modpath("ethereal") ~= nil, fire_protect = minetest.get_modpath("ethereal") ~= nil,
fire_protect_torch = minetest.get_modpath("ethereal") ~= nil, fire_protect_torch = minetest.get_modpath("ethereal") ~= nil,
@ -117,6 +119,14 @@ armor.register_armor = function(self, name, def)
end end
return armor:equip(player, itemstack) return armor:equip(player, itemstack)
end end
-- The below is a very basic check to try and see if a material name exists as part
-- of the item name. However this check is very simple and just checks theres "_something"
-- at the end of the item name and logging an error to debug if not.
local check_mat_exists = string.match(name, "%:.+_(.+)$")
if check_mat_exists == nil then
minetest.log("warning:[3d_armor] Registered armor "..name..
" does not have \"_material\" specified at the end of the item registration name")
end
minetest.register_tool(name, def) minetest.register_tool(name, def)
end end
@ -197,7 +207,6 @@ armor.set_player_armor = function(self, player)
end end
local state = 0 local state = 0
local count = 0 local count = 0
local material = {count=1}
local preview = armor:get_preview(name) local preview = armor:get_preview(name)
local texture = "3d_armor_trans.png" local texture = "3d_armor_trans.png"
local physics = {} local physics = {}
@ -205,6 +214,9 @@ armor.set_player_armor = function(self, player)
local levels = {} local levels = {}
local groups = {} local groups = {}
local change = {} local change = {}
local set_worn = {}
local armor_multi = 0
local worn_armor = armor:get_weared_armor_elements(player)
for _, phys in pairs(self.physics) do for _, phys in pairs(self.physics) do
physics[phys] = 1 physics[phys] = 1
end end
@ -258,21 +270,38 @@ armor.set_player_armor = function(self, player)
local value = def.groups["armor_"..attr] or 0 local value = def.groups["armor_"..attr] or 0
attributes[attr] = attributes[attr] + value attributes[attr] = attributes[attr] + value
end end
local mat = string.match(item, "%:.+_(.+)$") end
if material.name then end
if material.name == mat then -- The following code compares player worn armor items against requirements
material.count = material.count + 1 -- of which armor pieces are needed to be worn to meet set bonus requirements
for loc,item in pairs(worn_armor) do
local item_mat = string.match(item, "%:.+_(.+)$")
local worn_key = item_mat or "unknown"
-- Perform location checks to ensure the armor is worn correctly
for k,set_loc in pairs(armor.config.set_elements)do
if set_loc == loc then
if set_worn[worn_key] == nil then
set_worn[worn_key] = 0
set_worn[worn_key] = set_worn[worn_key] + 1
else
set_worn[worn_key] = set_worn[worn_key] + 1
end end
else
material.name = mat
end end
end end
end end
-- Apply the armor multiplier only if the player is wearing a full set of armor
for mat_name,arm_piece_num in pairs(set_worn) do
if arm_piece_num == #armor.config.set_elements then
armor_multi = armor.config.set_multiplier
end
end
for group, level in pairs(levels) do for group, level in pairs(levels) do
if level > 0 then if level > 0 then
level = level * armor.config.level_multiplier level = level * armor.config.level_multiplier
if material.name and material.count == #self.elements then if armor_multi ~= 0 then
level = level * 1.1 level = level * armor.config.set_multiplier
end end
end end
local base = self.registered_groups[group] local base = self.registered_groups[group]

@ -48,6 +48,8 @@ for name, config in pairs(armor.config) do
local setting = minetest.settings:get("armor_"..name) local setting = minetest.settings:get("armor_"..name)
if type(config) == "number" then if type(config) == "number" then
setting = tonumber(setting) setting = tonumber(setting)
elseif type(config) == "string" then
setting = tostring(setting)
elseif type(config) == "boolean" then elseif type(config) == "boolean" then
setting = minetest.settings:get_bool("armor_"..name) setting = minetest.settings:get_bool("armor_"..name)
end end
@ -62,6 +64,10 @@ for material, _ in pairs(armor.materials) do
end end
end end
-- Convert set_elements to a Lua table splitting on blank spaces
local t_set_elements = armor.config.set_elements
armor.config.set_elements = string.split(t_set_elements, " ")
-- Remove torch damage if fire_protect_torch == false -- Remove torch damage if fire_protect_torch == false
if armor.config.fire_protect_torch == false and armor.config.fire_protect == true then if armor.config.fire_protect_torch == false and armor.config.fire_protect == true then
for k,v in pairs(armor.fire_nodes) do for k,v in pairs(armor.fire_nodes) do

@ -1,4 +1,3 @@
[3d_armor] [3d_armor]
armor_material_wood (Enable wood armor) bool true armor_material_wood (Enable wood armor) bool true
@ -38,6 +37,12 @@ armor_level_multiplier (Armor effectiveness multiplier) float 1
# eg: armor_heal_multiplier = 0 will disable healing altogether. # eg: armor_heal_multiplier = 0 will disable healing altogether.
armor_heal_multiplier (Armor healing multiplier) float 1 armor_heal_multiplier (Armor healing multiplier) float 1
# Armor set item names, remove or add items to include them or remove them from whats considered an Armor set.
armor_set_elements (Armor set items) string head torso legs feet shield
# Bonus multiplier when wearing armor set, set to the same as armor_level_multiplier to disable
armor_set_multiplier (Armor Set Bonus multiplier) float 1.1
# Enable water protection (periodically restores breath when activated). # Enable water protection (periodically restores breath when activated).
armor_water_protect (Enable water protection) bool true armor_water_protect (Enable water protection) bool true