Refactor Nano Suit
This commit is contained in:
@@ -15,62 +15,66 @@
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
local S=minetest.get_translator("industrialtest")
|
||||
industrialtest.NanoSuit=table.copy(industrialtest.ElectricArmor)
|
||||
industrialtest.internal.unpackTableInto(industrialtest.NanoSuit,{
|
||||
name="industrialtest:nano",
|
||||
elements={
|
||||
{
|
||||
name="helmet",
|
||||
description=S("Nano Helmet"),
|
||||
element="head",
|
||||
inventoryImage="industrialtest_nano_helmet_inv.png",
|
||||
texture="industrialtest_nano_helmet.png"
|
||||
},
|
||||
{
|
||||
name="bodyarmor",
|
||||
description=S("Nano Bodyarmor"),
|
||||
element="torso",
|
||||
inventoryImage="industrialtest_nano_bodyarmor_inv.png",
|
||||
texture="industrialtest_nano_bodyarmor.png"
|
||||
},
|
||||
{
|
||||
name="leggings",
|
||||
description=S("Nano Leggings"),
|
||||
element="legs",
|
||||
inventoryImage="industrialtest_nano_leggings_inv.png",
|
||||
texture="industrialtest_nano_leggings.png"
|
||||
},
|
||||
{
|
||||
name="boots",
|
||||
description=S("Nano Boots"),
|
||||
element="feet",
|
||||
inventoryImage="industrialtest_nano_boots_inv.png",
|
||||
texture={
|
||||
"industrialtest_nano_boots.png",
|
||||
"industrialtest_mcl_nano_boots.png"
|
||||
}
|
||||
}
|
||||
},
|
||||
capacity=1000000,
|
||||
flow=industrialtest.api.evPowerFlow
|
||||
})
|
||||
|
||||
local function registerNanoSuitPart(config)
|
||||
local groups={
|
||||
_industrialtest_nanoSuit=1
|
||||
}
|
||||
if config.element=="head" then
|
||||
groups.armor_head=1
|
||||
elseif config.element=="torso" then
|
||||
groups.armor_torso=1
|
||||
elseif config.element=="legs" then
|
||||
groups.armor_legs=1
|
||||
elseif config.element=="feet" then
|
||||
groups.armor_feet=1
|
||||
end
|
||||
if industrialtest.mtgAvailable then
|
||||
groups.armor_heal=0
|
||||
armor:register_armor("industrialtest:"..config.name,{
|
||||
description=config.displayName,
|
||||
inventory_image="industrialtest_"..config.name.."_inv.png",
|
||||
groups=groups,
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=1000000,
|
||||
_industrialtest_powerFlow=industrialtest.api.evPowerFlow,
|
||||
_industrialtest_damageReduction=config.damageReduction,
|
||||
industrialtest_powerPerDamage=5000
|
||||
})
|
||||
elseif industrialtest.mclAvailable then
|
||||
groups.armor=1
|
||||
groups.non_combat_armor=1
|
||||
minetest.register_tool("industrialtest:"..config.name,{
|
||||
description=config.displayName,
|
||||
inventory_image="industrialtest_"..config.name.."_inv.png",
|
||||
groups=groups,
|
||||
sounds={
|
||||
_mcl_armor_equip="mcl_armor_equip_iron",
|
||||
_mcl_armor_unequip="mcl_armor_unequip_iron"
|
||||
},
|
||||
on_place=mcl_armor.equip_on_use,
|
||||
on_secondary_use=mcl_armor.equip_on_use,
|
||||
_mcl_armor_element=config.element,
|
||||
_mcl_armor_texture=(config.element=="feet" and "industrialtest_mcl_" or "industrialtest_")..config.name..".png",
|
||||
_industrialtest_powerStorage=true,
|
||||
_industrialtest_powerCapacity=1000000,
|
||||
_industrialtest_powerFlow=industrialtest.api.evPowerFlow,
|
||||
_industrialtest_damageReduction=config.damageReduction,
|
||||
_industrialtest_powerPerDamage=5000
|
||||
})
|
||||
function industrialtest.NanoSuit.getReducedDamageForItem(self,itemstack)
|
||||
local def=itemstack:get_definition()
|
||||
if def.groups.armor_head then
|
||||
return 0.12
|
||||
elseif def.groups.armor_torso then
|
||||
return 0.32
|
||||
elseif def.groups.armor_legs then
|
||||
return 0.3
|
||||
elseif def.groups.armor_feet then
|
||||
return 0.24
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
registerNanoSuitPart({
|
||||
name="nano_helmet",
|
||||
displayName=S("Nano Helmet"),
|
||||
element="head",
|
||||
damageReduction=0.12
|
||||
})
|
||||
function industrialtest.NanoSuit.getPowerPerDamageForItem(self,itemstack)
|
||||
return 5000
|
||||
end
|
||||
|
||||
industrialtest.NanoSuit:register()
|
||||
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:nano_helmet",
|
||||
@@ -80,12 +84,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
registerNanoSuitPart({
|
||||
name="nano_bodyarmor",
|
||||
displayName=S("Nano Bodyarmor"),
|
||||
element="torso",
|
||||
damageReduction=0.32
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:nano_bodyarmor",
|
||||
@@ -96,12 +94,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
registerNanoSuitPart({
|
||||
name="nano_leggings",
|
||||
displayName=S("Nano Leggings"),
|
||||
element="legs",
|
||||
damageReduction=0.3
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:nano_leggings",
|
||||
@@ -112,12 +104,6 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
registerNanoSuitPart({
|
||||
name="nano_boots",
|
||||
displayName=S("Nano Boots"),
|
||||
element="feet",
|
||||
damageReduction=0.24
|
||||
})
|
||||
minetest.register_craft({
|
||||
type="shaped",
|
||||
output="industrialtest:nano_boots",
|
||||
@@ -126,41 +112,3 @@ minetest.register_craft({
|
||||
{"industrialtest:carbon_plate","industrialtest:energy_crystal","industrialtest:carbon_plate"}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_player_hpchange(function(player,hpChange)
|
||||
if hpChange>0 or not player:is_player() then
|
||||
return hpChange
|
||||
end
|
||||
|
||||
local inv
|
||||
if industrialtest.mtgAvailable then
|
||||
_,inv=armor:get_valid_player(player,"")
|
||||
if not inv then
|
||||
return hpChange
|
||||
end
|
||||
elseif industrialtest.mclAvailable then
|
||||
inv=player:get_inventory()
|
||||
end
|
||||
|
||||
local armorList=inv:get_list("armor")
|
||||
assert(armorList)
|
||||
local result=hpChange
|
||||
for i=1,#armorList do
|
||||
local stack=armorList[i]
|
||||
local def=stack:get_definition()
|
||||
if def.groups and def.groups._industrialtest_nanoSuit then
|
||||
local meta=stack:get_meta()
|
||||
local targetReducedDamage=math.floor(math.abs(hpChange)*def._industrialtest_damageReduction)
|
||||
local requiredPower=targetReducedDamage*def._industrialtest_powerPerDamage
|
||||
local availablePower=math.min(meta:get_int("industrialtest.powerAmount"),requiredPower)
|
||||
local reducedDamage=math.floor(availablePower/def._industrialtest_powerPerDamage)
|
||||
if reducedDamage>0 then
|
||||
result=result+reducedDamage
|
||||
industrialtest.api.addPowerToItem(stack,-reducedDamage*def._industrialtest_powerPerDamage)
|
||||
inv:set_stack("armor",i,stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
end,true)
|
||||
|
||||
Reference in New Issue
Block a user