Refactor Quantum Suit

This commit is contained in:
mrkubax10 2025-04-25 10:42:33 +02:00
parent 5b32382422
commit 230c9803ea

View File

@ -16,62 +16,213 @@
local S=minetest.get_translator("industrialtest")
local quantumSuit={}
quantumSuit.helmetBreathRefillOpPower=1000
quantumSuit.leggingsSpeedOpPower=125
quantumSuit.leggingsSpeedMaxVel=4
quantumSuit.bootsJumpOpPower=50
quantumSuit.bootsFallDamageReductionOpPower=900
industrialtest.QuantumArmorBase=table.copy(industrialtest.ElectricGearTool)
industrialtest.internal.unpackTableInto(industrialtest.QuantumArmorBase,{
flow=industrialtest.api.ivPowerFlow,
capacity=10000000
})
local playerPositions={}
local playerLeggingsSpeedEnabled={}
local playerBootsJumpEnabled={}
function industrialtest.QuantumArmorBase.createDefintionTable(self)
local def=industrialtest.ElectricGearTool.createDefintionTable(self)
def.groups._industrialtest_electricArmor=1
return def
end
local function registerQuantumSuitPart(config)
config.groups=config.groups or {}
config.groups._industrialtest_nanoSuit=1
if config.element=="head" then
config.groups.armor_head=1
elseif config.element=="torso" then
config.groups.armor_torso=1
elseif config.element=="legs" then
config.groups.armor_legs=1
elseif config.element=="feet" then
config.groups.armor_feet=1
function industrialtest.QuantumArmorBase.getPowerPerDamageForItem(self,itemstack)
return 30
end
industrialtest.QuantumHelmet=table.copy(industrialtest.QuantumArmorBase)
industrialtest.internal.unpackTableInto(industrialtest.QuantumHelmet,{
name="industrialtest:quantum_helmet",
description=S("Quantum Helmet"),
inventoryImage="industrialtest_quantum_helmet_inv.png",
part="head",
modelImage="industrialtest_quantum_helmet.png",
_breathRefillOpPower=1000
})
local quantumHelmetUpdateDelta=0
function industrialtest.QuantumHelmet.update(self,player,inv,itemstack,dtime)
quantumHelmetUpdateDelta=quantumHelmetUpdateDelta+dtime
if quantumHelmetUpdateDelta<industrialtest.updateDelay then
return false
end
local definition={
description=config.displayName,
inventory_image="industrialtest_"..config.name.."_inv.png",
groups=config.groups,
_industrialtest_powerStorage=true,
_industrialtest_powerCapacity=10000000,
_industrialtest_powerFlow=industrialtest.api.ivPowerFlow,
_industrialtest_damageReduction=config.damageReduction,
_industrialtest_powerPerDamage=30
}
if config.customKeys then
for k,v in pairs(config.customKeys) do
definition[k]=v
quantumHelmetUpdateDelta=0
if player:get_breath()<10 then
local meta=itemstack:get_meta()
local refilled=math.min(9-player:get_breath(),math.floor(meta:get_int("industrialtest.powerAmount")/self._breathRefillOpPower))
if refilled>0 then
player:set_breath(player:get_breath()+refilled)
industrialtest.api.addPowerToItem(itemstack,-refilled*self._breathRefillOpPower)
return true
end
end
if industrialtest.mtgAvailable then
definition.groups.armor_heal=0
armor:register_armor("industrialtest:"..config.name,definition)
elseif industrialtest.mclAvailable then
definition.groups.armor=1
definition.groups.non_combat_armor=1
definition.sounds={
_mcl_armor_equip="mcl_armor_equip_iron",
_mcl_armor_unequip="mcl_armor_unequip_iron"
}
definition.on_place=mcl_armor.equip_on_use
definition.on_secondary_use=mcl_armor.equip_on_use
definition._mcl_armor_element=config.element
definition._mcl_armor_texture=(config.element=="feet" and "industrialtest_mcl_" or "industrialtest_")..config.name..".png"
minetest.register_tool("industrialtest:"..config.name,definition)
end
return false
end
function industrialtest.QuantumHelmet.getReducedDamageForItem(self,itemstack)
return 0.15
end
industrialtest.QuantumHelmet:register()
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_helmet",
recipe={
{"industrialtest:reinforced_glass","industrialtest:nano_helmet","industrialtest:reinforced_glass"},
{"industrialtest:iridium_plate","industrialtest:lapotron_crystal","industrialtest:iridium_plate"},
{"industrialtest:advanced_electronic_circuit","industrialtest:empty_cell","industrialtest:advanced_electronic_circuit"}
}
})
industrialtest.QuantumBodyarmor=table.copy(industrialtest.QuantumArmorBase)
industrialtest.internal.unpackTableInto(industrialtest.QuantumBodyarmor,{
name="industrialtest:quantum_bodyarmor",
description=S("Quantum Bodyarmor"),
inventoryImage="industrialtest_quantum_bodyarmor_inv.png",
part="torso",
modelImage="industrialtest_quantum_bodyarmor.png",
update=industrialtest.JetpackBase.update,
addYVelocityClamped=industrialtest.JetpackBase.addYVelocityClamped,
tryFly=industrialtest.ElectricJetpack.tryFly
})
function industrialtest.QuantumBodyarmor.getReducedDamageForItem(self,itemstack)
return 0.4
end
industrialtest.QuantumBodyarmor:register()
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_bodyarmor",
recipe={
{"industrialtest:advanced_alloy","industrialtest:nano_bodyarmor","industrialtest:advanced_alloy"},
{"industrialtest:iridium_plate","industrialtest:lapotron_crystal","industrialtest:iridium_plate"},
{"industrialtest:iridium_plate","industrialtest:electric_jetpack","industrialtest:iridium_plate"}
}
})
industrialtest.QuantumLeggings=table.copy(industrialtest.QuantumArmorBase)
industrialtest.internal.unpackTableInto(industrialtest.QuantumLeggings,{
name="industrialtest:quantum_leggings",
description=S("Quantum Leggings"),
inventoryImage="industrialtest_quantum_leggings_inv.png",
part="legs",
modelImage="industrialtest_quantum_leggings.png",
_speedOpPower=125,
_speedMaxVel=4
})
local leggingsSpeedEnabled={}
local playerPositions={}
function industrialtest.QuantumLeggings.update(self,player,inv,itemstack,dtime)
local control=player:get_player_control()
local playerName=player:get_player_name()
if leggingsSpeedEnabled[playerName] then
if control.up and control.aux1 then
local meta=itemstack:get_meta()
local requiredPower=vector.distance(player:get_pos(),playerPositions[playerName])*self._speedOpPower
if meta:get_int("industrialtest.powerAmount")>=requiredPower then
industrialtest.api.addPowerToItem(itemstack,-requiredPower)
playerPositions[playerName]=player:get_pos()
return true
end
end
player:set_physics_override({
speed=1
})
leggingsSpeedEnabled[playerName]=false
elseif control.up and control.aux1 then
local meta=itemstack:get_meta()
local requiredPower=vector.distance(player:get_pos(),playerPositions[playerName])*self._speedOpPower
if meta:get_int("industrialtest.powerAmount")>=requiredPower then
player:set_physics_override({
speed=self._speedMaxVel
})
leggingsSpeedEnabled[playerName]=true
end
end
playerPositions[playerName]=player:get_pos()
return false
end
function industrialtest.QuantumLeggings.getReducedDamageForItem(self,itemstack)
return 0.3
end
industrialtest.QuantumLeggings:register()
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_leggings",
recipe={
{"industrialtest:machine_block","industrialtest:lapotron_crystal","industrialtest:machine_block"},
{"industrialtest:iridium_plate","industrialtest:nano_leggings","industrialtest:iridium_plate"},
{industrialtest.elementKeys.yellowDust,"",industrialtest.elementKeys.yellowDust}
}
})
industrialtest.QuantumBoots=table.copy(industrialtest.QuantumArmorBase)
industrialtest.internal.unpackTableInto(industrialtest.QuantumBoots,{
name="industrialtest:quantum_boots",
description=S("Quantum Boots"),
inventoryImage="industrialtest_quantum_boots_inv.png",
part="feet",
modelImage=(industrialtest.mclAvailable and "industrialtest_mcl_quantum_leggings.png" or "industrialtest_quantum_leggings.png"),
_jumpOpPower=50,
_jumpPower=2,
_fallDamageReductionOpPower=900,
})
local bootsJumpEnabled={}
function industrialtest.QuantumBoots.update(self,player,inv,itemstack,dtime)
local control=player:get_player_control()
local playerName=player:get_player_name()
if bootsJumpEnabled[playerName] then
local shouldStopJump=not control.aux1
if control.jump and control.aux1 then
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=self._jumpOpPower then
industrialtest.api.addPowerToItem(itemstack,-self._jumpOpPower)
return true
end
end
player:set_physics_override({
jump=1
})
bootsJumpEnabled[playerName]=false
elseif control.aux1 then
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=self._jumpOpPower then
player:set_physics_override({
jump=self._jumpPower
})
bootsJumpEnabled[playerName]=true
end
end
return false
end
function industrialtest.QuantumBoots.getReducedDamageForItem(self,itemstack)
return 0.15
end
industrialtest.QuantumBoots:register()
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_boots",
recipe={
{"industrialtest:iridium_plate","industrialtest:nano_boots","industrialtest:iridium_plate"},
{industrialtest.elementKeys.ironBoots,"industrialtest:lapotron_crystal",industrialtest.elementKeys.ironBoots}
}
})
local function findInPlayerArmorList(player,itemname)
local inv
if industrialtest.mclAvailable then
@ -87,174 +238,6 @@ local function findInPlayerArmorList(player,itemname)
end
end
quantumSuit.tryFly=function(itemstack)
local meta=itemstack:get_meta()
if meta:get_int("industrialtest.powerAmount")<10 then
return false
end
industrialtest.api.addPowerToItem(itemstack,-10)
return true
end
registerQuantumSuitPart({
name="quantum_helmet",
displayName=S("Quantum Helmet"),
element="head",
damageReduction=0.15
})
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_helmet",
recipe={
{"industrialtest:reinforced_glass","industrialtest:nano_helmet","industrialtest:reinforced_glass"},
{"industrialtest:iridium_plate","industrialtest:lapotron_crystal","industrialtest:iridium_plate"},
{"industrialtest:advanced_electronic_circuit","industrialtest:empty_cell","industrialtest:advanced_electronic_circuit"}
}
})
registerQuantumSuitPart({
name="quantum_bodyarmor",
displayName=S("Quantum Bodyarmor"),
element="torso",
damageReduction=0.4,
groups={
_industrialtest_jetpack=1
},
customKeys={
_industrialtest_tryFly=quantumSuit.tryFly
}
})
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_bodyarmor",
recipe={
{"industrialtest:advanced_alloy","industrialtest:nano_bodyarmor","industrialtest:advanced_alloy"},
{"industrialtest:iridium_plate","industrialtest:lapotron_crystal","industrialtest:iridium_plate"},
{"industrialtest:iridium_plate","industrialtest:electric_jetpack","industrialtest:iridium_plate"}
}
})
registerQuantumSuitPart({
name="quantum_leggings",
displayName=S("Quantum Leggings"),
element="legs",
damageReduction=0.30
})
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_leggings",
recipe={
{"industrialtest:machine_block","industrialtest:lapotron_crystal","industrialtest:machine_block"},
{"industrialtest:iridium_plate","industrialtest:nano_leggings","industrialtest:iridium_plate"},
{industrialtest.elementKeys.yellowDust,"",industrialtest.elementKeys.yellowDust}
}
})
registerQuantumSuitPart({
name="quantum_boots",
displayName=S("Quantum Boots"),
element="feet",
damageReduction=0.15
})
minetest.register_craft({
type="shaped",
output="industrialtest:quantum_boots",
recipe={
{"industrialtest:iridium_plate","industrialtest:nano_boots","industrialtest:iridium_plate"},
{industrialtest.elementKeys.ironBoots,"industrialtest:lapotron_crystal",industrialtest.elementKeys.ironBoots}
}
})
minetest.register_globalstep(function(dtime)
local players=minetest.get_connected_players()
for _,player in ipairs(players) do
local control=player:get_player_control()
local playerName=player:get_player_name()
if playerLeggingsSpeedEnabled[playerName] then
local shouldStopSpeed=true
if control.up and control.aux1 then
local index,stack,inv=findInPlayerArmorList(player,"industrialtest:quantum_leggings")
if index and stack and inv then
local meta=stack:get_meta()
local requiredPower=vector.distance(player:get_pos(),playerPositions[playerName])*quantumSuit.leggingsSpeedOpPower
if meta:get_int("industrialtest.powerAmount")>=requiredPower then
industrialtest.api.addPowerToItem(stack,-requiredPower)
inv:set_stack("armor",index,stack)
shouldStopSpeed=false
end
end
end
if shouldStopSpeed then
player:set_physics_override({
speed=1
})
playerLeggingsSpeedEnabled[playerName]=false
end
elseif control.up and control.aux1 then
local index,stack,inv=findInPlayerArmorList(player,"industrialtest:quantum_leggings")
if index and stack and inv then
local meta=stack:get_meta()
local requiredPower=vector.distance(player:get_pos(),playerPositions[playerName])*quantumSuit.leggingsSpeedOpPower
if meta:get_int("industrialtest.powerAmount")>=requiredPower then
player:set_physics_override({
speed=quantumSuit.leggingsSpeedMaxVel
})
playerLeggingsSpeedEnabled[playerName]=true
end
end
end
if playerBootsJumpEnabled[playerName] then
local shouldStopJump=not control.aux1
if control.jump and control.aux1 then
local index,stack,inv=findInPlayerArmorList(player,"industrialtest:quantum_boots")
if index and stack and inv then
local meta=stack:get_meta()
if meta:get_int("industrialtest.powerAmount")>=quantumSuit.bootsJumpOpPower then
industrialtest.api.addPowerToItem(stack,-quantumSuit.bootsJumpOpPower)
inv:set_stack("armor",index,stack)
shouldStopJump=false
end
end
end
if shouldStopJump then
player:set_physics_override({
jump=1
})
playerBootsJumpEnabled[playerName]=false
end
elseif control.aux1 then
local index,stack,inv=findInPlayerArmorList(player,"industrialtest:quantum_boots")
if index and stack and inv then
local meta=stack:get_meta()
local requiredPower=vector.distance(player:get_pos(),playerPositions[playerName])*quantumSuit.leggingsSpeedOpPower
if meta:get_int("industrialtest.powerAmount")>=quantumSuit.bootsJumpOpPower then
player:set_physics_override({
jump=2
})
playerBootsJumpEnabled[playerName]=true
end
end
end
if player:get_breath()<10 then
local index,stack,inv=findInPlayerArmorList(player,"industrialtest:quantum_helmet")
if index and stack and inv then
local meta=stack:get_meta()
local refilled=math.min(9-player:get_breath(),math.floor(meta:get_int("industrialtest.powerAmount")/quantumSuit.helmetBreathRefillOpPower))
if refilled>0 then
player:set_breath(player:get_breath()+refilled)
industrialtest.api.addPowerToItem(stack,-refilled*quantumSuit.helmetBreathRefillOpPower)
inv:set_stack("armor",index,stack)
end
end
end
playerPositions[playerName]=player:get_pos()
end
end)
minetest.register_on_player_hpchange(function(player,hpChange,reason)
if reason.type~="fall" then
return hpChange
@ -267,8 +250,8 @@ minetest.register_on_player_hpchange(function(player,hpChange,reason)
local damage=math.abs(hpChange)
local meta=stack:get_meta()
local reducedDamage=math.min(damage,math.floor(meta:get_int("industrialtest.powerAmount")/(damage*quantumSuit.bootsFallDamageReductionOpPower)))
industrialtest.api.addPowerToItem(stack,-reducedDamage*quantumSuit.bootsFallDamageReductionOpPower)
local reducedDamage=math.min(damage,math.floor(meta:get_int("industrialtest.powerAmount")/(damage*industrialtest.QuantumBoots._fallDamageReductionOpPower)))
industrialtest.api.addPowerToItem(stack,-reducedDamage*industrialtest.QuantumBoots._fallDamageReductionOpPower)
inv:set_stack("armor",index,stack)
return hpChange+reducedDamage