Rewrote a bit of ISUninstallProsthesis

This commit is contained in:
Pao
2023-01-15 16:25:43 +01:00
parent eeb7076c13
commit 4d5e20d1fd
4 changed files with 74 additions and 105 deletions

View File

@@ -1,5 +1,7 @@
function GetKitInInventory(surgeon) function GetKitInInventory(surgeon)
local playerInv = surgeon:getInventory(); local playerInv = surgeon:getInventory();
local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit') local item = playerInv:getItemFromType('TOC.Real_surgeon_kit') or playerInv:getItemFromType('TOC.Surgeon_kit') or playerInv:getItemFromType('TOC.Improvised_surgeon_kit')

View File

@@ -23,110 +23,38 @@ function ISInstallProsthesis:stop()
end end
function ISInstallProsthesis:perform() function ISInstallProsthesis:perform()
local prosthesis_base_name = self.item:getType()
self.item:setJobDelta(0.0) self.item:setJobDelta(0.0)
local toc_data = self.character:getModData().TOC
local part_name = TocGetPartNameFromBodyPartType(self.bodyPart:getType())
local modData = self.character:getModData()
--local toc_data = self.character:getModData().TOC
local lor = 0 -- LEFT OR RIGHT
local foh = 0 -- FOREARM OR HAND
-- Check if can be performed. This shouldn't be necessary, but just to be sure -- Check if can be performed. This shouldn't be necessary, but just to be sure
if self.bodyPart:getType() == BodyPartType.UpperArm_L or self.bodyPart:getType() == BodyPartType.UpperArm_R then if self.bodyPart:getType() == BodyPartType.UpperArm_L or self.bodyPart:getType() == BodyPartType.UpperArm_R then
print("Can't equip prosthesis") print("Can't equip prosthesis")
return return
end end
local prosthesis_name =TocFindCorrectClothingProsthesis(self.item:getType(), part_name)
local prosthesis_table = { self.cloth = self.character:getInventory():AddItem(prosthesis_name)
WoodenHook = {
material_id = 1
},
MetalHook = {
material_id = 2
},
MetalHand = {
material_id = 3
}
}
if self.bodyPart:getType() == BodyPartType.Hand_R then lor = 1; foh = 1
elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then lor = 1; foh = 2
elseif self.bodyPart:getType() == BodyPartType.Hand_L then lor = 0; foh = 1
elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then lor = 0; foh = 2
end
local mat_id = 0
local weight = math.floor(self.item:getWeight() * 10 + 0.5) / 10
if weight == 1 and foh == 1 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_right_noHand");
mat_id = 1;
else
self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_left_noHand");
mat_id = 1;
end
elseif weight == 0.5 and foh == 1 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_right_noHand");
mat_id = 2;
else
self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_left_noHand");
mat_id = 2;
end
elseif weight == 0.3 and foh == 1 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_right_noHand");
mat_id = 3;
else
self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_left_noHand");
mat_id = 3;
end
elseif weight == 1 and foh == 2 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_right_noForearm");
mat_id = 1;
else
self.cloth = self.character:getInventory():AddItem("TOC.WoodenHook_left_noForearm");
mat_id = 1;
end
elseif weight == 0.5 and foh == 2 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_right_noForearm");
mat_id = 2;
else
self.cloth = self.character:getInventory():AddItem("TOC.MetalHook_left_noForearm");
mat_id = 2;
end
elseif weight == 0.3 and foh == 2 then
if lor == 1 then
self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_right_noForearm");
mat_id = 3;
else
self.cloth = self.character:getInventory():AddItem("TOC.MetalHand_left_noForearm");
mat_id = 3;
end
end
if self.cloth ~= nil then if self.cloth ~= nil then
if self.bodyPart:getType() == BodyPartType.Hand_R then
modData.TOC.RightHand.is_prosthesis_equipped = true;
modData.TOC.RightHand.prosthesis_factor = find_protheseFact_TOC(self.cloth); if part_name then
elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then toc_data[part_name].is_prosthesis_equipped = true
modData.TOC.RightForearm.is_prosthesis_equipped = true; toc_data[part_name].prosthesis_factor = TocFindProsthesisFactorFromItem(self.cloth)
modData.TOC.RightForearm.prosthesis_factor = find_protheseFact_TOC(self.cloth);
elseif self.bodyPart:getType() == BodyPartType.Hand_L then self.character:getInventory():Remove(self.item)
modData.TOC.LeftHand.is_prosthesis_equipped = true; self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth)
modData.TOC.LeftHand.prosthesis_factor = find_protheseFact_TOC(self.cloth);
elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then
modData.TOC.LeftForearm.is_prosthesis_equipped = true;
modData.TOC.LeftForearm.prosthesis_factor = find_protheseFact_TOC(self.cloth);
end end
self.character:getInventory():Remove(self.item);
self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth);
end end
self.character:transmitModData() self.character:transmitModData()

View File

@@ -57,11 +57,10 @@ function ISUninstallProsthesis:perform()
toc_data[part_name].is_prosthesis_equipped = false toc_data[part_name].is_prosthesis_equipped = false
toc_data[part_name].prosthesis_factor = 1 toc_data[part_name].prosthesis_factor = 1
local side = string.gsub(part_name, "Hand" or "Forearm", "") --local side = string.gsub(part_name, "Hand" or "Forearm", "")
local prosthesis_list = {"TOC.WoodenHook", "TOC.MetalHook", "TOC.MetalHand"}
for _, prost_v in ipairs(prosthesis_list) do for _, prost_v in ipairs(GetProsthesisList()) do
local prosthesis_name = string.match(self.item:getName(), prost_v) local prosthesis_name = string.match(self.item:getName(), prost_v)
if prosthesis_name then if prosthesis_name then

View File

@@ -3,6 +3,11 @@ function GetBodyParts()
return bodyparts return bodyparts
end end
function GetProsthesisList()
return {"TOC.WoodenHook", "TOC.MetalHook", "TOC.MetalHand"}
end
function GetLimbsBodyPartTypes() function GetLimbsBodyPartTypes()
return {BodyPartType.Hand_R, BodyPartType.ForeArm_R, BodyPartType.UpperArm_R, return {BodyPartType.Hand_R, BodyPartType.ForeArm_R, BodyPartType.UpperArm_R,
@@ -54,7 +59,18 @@ function FindTocItemWorn(part_name, patient)
end end
function TocGetPartNameFromBodyPartType(body_part)
if body_part == BodyPartType.Hand_R then return "RightHand"
elseif body_part == BodyPartType.ForeArm_R then return "RightForearm"
elseif body_part == BodyPartType.UpperArm_R then return "RightArm"
elseif body_part == BodyPartType.Hand_L then return "LeftHand"
elseif body_part == BodyPartType.ForeArm_L then return "LeftForearm"
elseif body_part == BodyPartType.UpperArm_L then return "LeftArm"
else return nil
end
end
@@ -106,17 +122,8 @@ function TocFindAmputatedClothingFromPartName(part_name)
end end
function TocFindProsthesisFactorFromItem(item)
function find_protheseID_TOC(item)
local itemType = item:getType()
if string.find(itemType, "WoodenHook") then return 1
elseif string.find(itemType, "MetalHook") then return 2
elseif string.find(itemType, "MetalHand") then return 3
else return 0
end
end
function find_protheseFact_TOC(item)
local itemType = item:getType() local itemType = item:getType()
if string.find(itemType, "WoodenHook") and string.find(itemType, "noHand") then return 1.5 if string.find(itemType, "WoodenHook") and string.find(itemType, "noHand") then return 1.5
elseif string.find(itemType, "WoodenHook") and string.find(itemType, "noForearm") then return 1.65 elseif string.find(itemType, "WoodenHook") and string.find(itemType, "noForearm") then return 1.65
@@ -125,4 +132,37 @@ function find_protheseFact_TOC(item)
elseif string.find(itemType, "MetalHand") and string.find(itemType, "noHand") then return 1.1 elseif string.find(itemType, "MetalHand") and string.find(itemType, "noHand") then return 1.1
elseif string.find(itemType, "MetalHand") and string.find(itemType, "noForearm") then return 1.25 elseif string.find(itemType, "MetalHand") and string.find(itemType, "noForearm") then return 1.25
end end
end
function TocFindCorrectClothingProsthesis(item_name, part_name)
-- for _, v in ipairs(GetProsthesisList()) do
-- if string.find(item, v)
-- end
local lowered_part_name = string.lower(part_name)
local side = string.match(lowered_part_name, "left")
if side == nil then
side = "right"
end
local limb = string.match(part_name, "Hand")
if limb == nil then
limb = "Forearm"
end
-- Just to accomodate this horrendous naming scheme, let's have Hand or Forearm again... Jesus dude
-- if limb then
-- limb = limb:gsub("^%l", string.upper)
-- end
local correct_name = "TOC." .. item_name .. "_" .. side .. "_no" .. limb
return correct_name
end end