more setup stuff for modular prosthetics
This commit is contained in:
@@ -6,19 +6,47 @@
|
||||
|
||||
---Equip a prosthesis transforming a normal item into a clothing item
|
||||
---@param part_name string
|
||||
---@param prosthesis_item any the prosthesis item
|
||||
---@param prosthesis_base_name string
|
||||
function TocEquipProsthesis(part_name, prosthesis_base_name)
|
||||
function TocEquipProsthesis(part_name, prosthesis_item, prosthesis_base_name)
|
||||
|
||||
-- TODO probably will have to move this from the TOC menu to classic equip to have dynamic durability
|
||||
|
||||
-- TODO We need to pass the original item so we can get its data!
|
||||
|
||||
local player = getPlayer()
|
||||
|
||||
local toc_data = player:getModData().TOC
|
||||
|
||||
|
||||
|
||||
local item_mod_data = prosthesis_item:getModData()
|
||||
|
||||
if item_mod_data.TOC == nil then
|
||||
GenerateEquippedProsthesis(prosthesis_item, "Test") -- TODO Change it with the limb
|
||||
item_mod_data = prosthesis_item:getModData() -- Updates it
|
||||
end
|
||||
|
||||
|
||||
--print("TOC: Test durability normal item " .. item_mod_data.TOC.durability)
|
||||
|
||||
|
||||
local prosthesis_name = TocFindCorrectClothingProsthesis(prosthesis_base_name, part_name)
|
||||
local added_prosthesis = player:getInventory():AddItem(prosthesis_name)
|
||||
|
||||
|
||||
-- Add parameters to added_prosthesis
|
||||
local added_prosthesis_mod_data = added_prosthesis:getModData()
|
||||
|
||||
added_prosthesis_mod_data.TOC = {
|
||||
durability = item_mod_data.TOC.durability,
|
||||
speed = item_mod_data.TOC.speed,
|
||||
}
|
||||
|
||||
|
||||
--print("TOC: Test durability new item " .. added_prosthesis_mod_data.TOC.durability)
|
||||
|
||||
|
||||
|
||||
if part_name ~= nil then
|
||||
|
||||
if added_prosthesis ~= nil then
|
||||
@@ -44,6 +72,8 @@ end
|
||||
function TocUnequipProsthesis(patient, part_name, equipped_prosthesis)
|
||||
|
||||
|
||||
-- TODO Pass the parameters generated from EquipProsthesis to the re-generated normal item
|
||||
|
||||
local toc_data = patient:getModData().TOC
|
||||
toc_data.Limbs[part_name].is_prosthesis_equipped = false
|
||||
|
||||
@@ -54,14 +84,21 @@ function TocUnequipProsthesis(patient, part_name, equipped_prosthesis)
|
||||
for _, prost_v in ipairs(GetProsthesisList()) do
|
||||
local prosthesis_name = string.match(equipped_prosthesis_full_type, prost_v)
|
||||
if prosthesis_name then
|
||||
patient:getInventory():AddItem("TOC." .. prosthesis_name)
|
||||
|
||||
-- Get mod data from equipped prosthesis so we can get its parameters
|
||||
local equipped_prosthesis_mod_data = equipped_prosthesis:getModData()
|
||||
|
||||
|
||||
local base_prosthesis_item = patient:getInventory():AddItem("TOC." .. prosthesis_name)
|
||||
local base_prosthesis_item_mod_data = base_prosthesis_item.getModData()
|
||||
base_prosthesis_item_mod_data.TOC = {
|
||||
durability = equipped_prosthesis_mod_data.TOC.durability,
|
||||
speed = equipped_prosthesis_mod_data.TOC.speed
|
||||
}
|
||||
|
||||
patient:setWornItem(equipped_prosthesis:getBodyLocation(), nil)
|
||||
patient:getInventory():Remove(equipped_prosthesis)
|
||||
toc_data.Limbs[part_name].equipped_prosthesis = nil
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -68,10 +68,11 @@ end
|
||||
ServerCommands.EquipProsthesis = function(arg)
|
||||
|
||||
-- part_name = arg[1]
|
||||
-- prosthesis = arg[2]
|
||||
|
||||
-- prosthesis_item = arg[2]
|
||||
-- prosthesis_name = arg[3]
|
||||
|
||||
local data = arg["toSend"]
|
||||
TocEquipProsthesis(data[1], data[2])
|
||||
TocEquipProsthesis(data[1], data[2], data[3])
|
||||
|
||||
end
|
||||
|
||||
@@ -199,12 +200,12 @@ function SendOperateLimb(player, part_name, surgeon_factor, use_oven)
|
||||
sendClientCommand("TOC", "SendServer", arg)
|
||||
end
|
||||
|
||||
function SendEquipProsthesis(player, part_name, prosthesis_base_name)
|
||||
function SendEquipProsthesis(player, part_name, item, prosthesis_base_name)
|
||||
local arg = {}
|
||||
arg["From"] = getPlayer():getOnlineID()
|
||||
arg["To"] = player:getOnlineID()
|
||||
arg["command"] = "EquipProsthesis"
|
||||
arg["toSend"] = { part_name, prosthesis_base_name}
|
||||
arg["toSend"] = { part_name, item, prosthesis_base_name}
|
||||
sendClientCommand("TOC", "SendServer", arg)
|
||||
end
|
||||
|
||||
|
||||
@@ -146,5 +146,7 @@ function TocTestItem()
|
||||
local found_item = player_inventory:FindAndReturn(item_name)
|
||||
|
||||
print(found_item:getID())
|
||||
|
||||
print("_______________")
|
||||
found_item:setID(12334)
|
||||
print(found_item:getID())
|
||||
end
|
||||
@@ -28,9 +28,11 @@ local TopStats = {
|
||||
|
||||
|
||||
|
||||
function GenerateEquippedProsthesis(prosthesis_item)
|
||||
function GenerateEquippedProsthesis(prosthesis_item, limb)
|
||||
-- TODO Durability should be decided from the clothing item xml. Same thing for disassembling stuff
|
||||
|
||||
-- TODO some stuff should be defined by the limb, like -10 if forearm in speed
|
||||
|
||||
local durability = 0
|
||||
local speed = 0
|
||||
|
||||
@@ -54,39 +56,36 @@ function GenerateEquippedProsthesis(prosthesis_item)
|
||||
end
|
||||
end
|
||||
|
||||
-- TODO This won't work since if we unequip it we would lose this stuff. We need to bind it to the item
|
||||
local prosthesis_table = {
|
||||
prost_id = prosthesis_item:getID(),
|
||||
prost_name = prosthesis_name,
|
||||
local item_mod_data = prosthesis_item:getModData()
|
||||
|
||||
--------------------
|
||||
-- TEST STUFF
|
||||
durability = 12
|
||||
speed = 51
|
||||
|
||||
-------------------
|
||||
|
||||
|
||||
item_mod_data.TOC = {
|
||||
durability = durability,
|
||||
speed = speed
|
||||
speed = speed,
|
||||
}
|
||||
|
||||
|
||||
return prosthesis_table
|
||||
end
|
||||
|
||||
local ProsthesisRecipe = {}
|
||||
--local ProsthesisRecipe = {}
|
||||
|
||||
|
||||
function ProsthesisRecipe.OnCreate.Hook(items, result, player, selectedItem)
|
||||
-- function ProsthesisRecipe.OnCreate.Hook(items, result, player, selectedItem)
|
||||
|
||||
-- Set mod data for item with durability and all that crap
|
||||
-- -- Set mod data for item with durability and all that crap
|
||||
|
||||
|
||||
-- when we equip a prosthesis, we're gonna pass these parameters to the newly generated clothing item
|
||||
-- -- when we equip a prosthesis, we're gonna pass these parameters to the newly generated clothing item
|
||||
|
||||
-- when we unequip it, we regen the normal item with the parameters from the clothing item
|
||||
-- -- when we unequip it, we regen the normal item with the parameters from the clothing item
|
||||
|
||||
|
||||
end
|
||||
-- end
|
||||
|
||||
|
||||
|
||||
|
||||
function DoWeReallyNeedThis()
|
||||
|
||||
-- We need a durability check... so in modData
|
||||
|
||||
--
|
||||
end
|
||||
@@ -3,6 +3,9 @@ require "TimedActions/ISBaseTimedAction"
|
||||
ISInstallProsthesis = ISBaseTimedAction:derive("ISInstallProsthesis");
|
||||
|
||||
function ISInstallProsthesis:isValid()
|
||||
|
||||
-- TODO add here conditions if the action can be performed or not, so if thing is in inventory
|
||||
-- TODO 'not sure about multiplayer, maybe an overriding check?
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -49,17 +52,19 @@ function ISInstallProsthesis:perform()
|
||||
return
|
||||
end
|
||||
|
||||
self.surgeon:getInventory():Remove(prosthesis_base_name) -- Removes the base item and substitute it with the part one
|
||||
|
||||
|
||||
if self.patient ~= self.surgeon and isClient() then
|
||||
|
||||
SendEquipProsthesis(self.patient, self.part_name, prosthesis_base_name)
|
||||
SendEquipProsthesis(self.patient, self.part_name, self.item, prosthesis_base_name)
|
||||
else
|
||||
TocEquipProsthesis(self.part_name, prosthesis_base_name)
|
||||
TocEquipProsthesis(self.part_name, self.item, prosthesis_base_name)
|
||||
|
||||
end
|
||||
|
||||
|
||||
self.surgeon:getInventory():Remove(prosthesis_base_name) -- Removes the base item after we transferred everything
|
||||
|
||||
-- needed to remove from queue / start next.
|
||||
ISBaseTimedAction.perform(self)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user