Added check to remove wrist watches when amputating
This commit is contained in:
@@ -114,17 +114,17 @@ function JCIO.DamagePlayerDuringAmputation(patient, partName)
|
||||
end
|
||||
|
||||
local function FindTourniquetInWornItems(patient, side)
|
||||
local worn_items = patient:getWornItems()
|
||||
|
||||
for i = 1, worn_items:size() - 1 do -- Maybe wornItems:size()-1
|
||||
local item = worn_items:get(i):getItem()
|
||||
local item_full_type = item:getFullType()
|
||||
if string.find(item_full_type, "Surgery_" .. side .. "_Tourniquet") then
|
||||
local checkString = "Surgery_" .. side .. "_Tourniquet"
|
||||
local item = JCIO_Common.FindItemInWornItems(patient, checkString)
|
||||
return item
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
local function FindWristWatchInWornItems(patient, side)
|
||||
local checkString = "Watch_" .. side
|
||||
local item = JCIO_Common.FindItemInWornItems(patient, checkString)
|
||||
return item
|
||||
|
||||
end
|
||||
----------------------------------------------------------------------------------
|
||||
@@ -159,6 +159,7 @@ JCIO.CutLimb = function(partName, surgeonFactor, bandageTable, painkillerTable)
|
||||
local adjacentBodyPart = player:getBodyDamage():getBodyPart(JCIO_Common.GetAdjacentBodyPartFromPartName(partName))
|
||||
|
||||
local stats = player:getStats()
|
||||
local side = JCIO_Common.GetSideFromPartName(partName)
|
||||
|
||||
|
||||
|
||||
@@ -167,7 +168,7 @@ JCIO.CutLimb = function(partName, surgeonFactor, bandageTable, painkillerTable)
|
||||
SetParametersForMissingLimb(bodyPart, false)
|
||||
|
||||
-- Use a tourniquet if available
|
||||
local tourniquetItem = FindTourniquetInWornItems(player, JCIO_Common.GetSideFromPartName(partName))
|
||||
local tourniquetItem = FindTourniquetInWornItems(player, side)
|
||||
|
||||
local baseDamageValue = 100
|
||||
|
||||
@@ -177,9 +178,20 @@ JCIO.CutLimb = function(partName, surgeonFactor, bandageTable, painkillerTable)
|
||||
if partName == "Left_UpperArm" or partName == "Right_UpperArm" then
|
||||
player:removeWornItem(tourniquetItem)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- Removes wrist watches in case they're amputating the same side where they equipped it
|
||||
local wristWatchItem = FindWristWatchInWornItems(player, side)
|
||||
|
||||
if wristWatchItem ~= nil then
|
||||
player:removeWornItem(wristWatchItem)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Set damage, stress, and low endurance after amputation
|
||||
adjacentBodyPart:AddDamage(baseDamageValue - surgeonFactor)
|
||||
adjacentBodyPart:setAdditionalPain(baseDamageValue - surgeonFactor)
|
||||
|
||||
@@ -274,3 +274,18 @@ JCIO_Common.GetCanBeHeldTable = function(limbs_data)
|
||||
|
||||
end
|
||||
-------------------------------
|
||||
|
||||
JCIO_Common.FindItemInWornItems = function(player, checkString)
|
||||
local wornItems = player:getWornItems()
|
||||
|
||||
for i = 1, wornItems:size() - 1 do -- Maybe wornItems:size()-1
|
||||
local item = wornItems:get(i):getItem()
|
||||
local itemFullType = item:getFullType()
|
||||
if string.find(itemFullType, checkString) then
|
||||
return item
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
|
||||
end
|
||||
@@ -4,6 +4,9 @@ require "TimedActions/ISUnequipAction"
|
||||
require "ISUI/ISInventoryPaneContextMenu"
|
||||
|
||||
|
||||
|
||||
-- TODO 1) Add exceptions for watches
|
||||
|
||||
local og_ISBaseTimedActionAdjustMaxTime = ISBaseTimedAction.adjustMaxTime
|
||||
function ISBaseTimedAction:adjustMaxTime(maxTime)
|
||||
|
||||
@@ -184,29 +187,33 @@ function ISInventoryPaneContextMenu.dropItem(item, player)
|
||||
|
||||
end
|
||||
|
||||
-- Make the player unable to equip a tourniquet on an already fully amputated limb
|
||||
-- Make the player unable to equip a tourniquet or watches on an already fully amputated limb
|
||||
local og_ISWearClothingIsValid = ISWearClothing.isValid
|
||||
function ISWearClothing:isValid()
|
||||
local base_check = og_ISWearClothingIsValid(self)
|
||||
--return self.character:getInventory():contains(self.item);
|
||||
|
||||
local item_full_type = self.item:getFullType()
|
||||
|
||||
-- TODO Sides
|
||||
local limbs_data = self.character:getModData().JCIO.limbs
|
||||
local baseCheck = og_ISWearClothingIsValid(self)
|
||||
local itemFullType = self.item:getFullType()
|
||||
local limbsData = self.character:getModData().JCIO.limbs
|
||||
local itemsToBeChecked = {
|
||||
"Surgery_%1_Tourniquet", -- 1
|
||||
"Watch_%1" -- 2
|
||||
}
|
||||
|
||||
for _, side in pairs(JCIO.sideNames) do
|
||||
if string.find(item_full_type, "Test_Tourniquet_" .. side) then
|
||||
if limbs_data[side .. "_UpperArm"].isCut then
|
||||
for indexItem, itemName in pairs(itemsToBeChecked) do
|
||||
local formattedItemName = string.format(itemName, side)
|
||||
|
||||
if string.find(itemFullType, formattedItemName) then
|
||||
if indexItem == 1 and limbsData[side .. "_UpperArm"].isCut then
|
||||
return false
|
||||
elseif indexItem == 2 and limbsData[side .. "_Hand"].isCut then
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return base_check
|
||||
return baseCheck
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user