Missed a few things

This commit is contained in:
Pao
2023-01-18 03:11:54 +01:00
parent 5b3e10c0db
commit a795a01c19
9 changed files with 85 additions and 76 deletions

View File

@@ -10,17 +10,17 @@ function CheckIfCanBeCut(part_name)
end
function CheckIfProsthesisAlreadyInstalled(toc_data, part_name)
function CheckIfProsthesisAlreadyInstalled(part_data, part_name)
local r = "Right"
local l = "Left"
if string.find(part_name, r) then
return (toc_data[r .. "Hand"].is_prosthesis_equipped or toc_data[r .. "Forearm"].is_prosthesis_equipped)
return (part_data[r .. "_Hand"].is_prosthesis_equipped or part_data[r .. "_LowerArm"].is_prosthesis_equipped)
elseif string.find(part_name, l) then
return (toc_data[l .. "Hand"].is_prosthesis_equipped or toc_data[l .. "Forearm"].is_prosthesis_equipped)
return (part_data[l .. "_Hand"].is_prosthesis_equipped or part_data[l .. "_LowerArm"].is_prosthesis_equipped)
end
@@ -30,9 +30,9 @@ end
function CheckIfCanBeOperated(part_name)
local toc_data = getPlayer():getModData().TOC
local part_data = getPlayer():getModData().TOC.Limbs
return toc_data[part_name].is_operated == false and toc_data[part_name].is_amputation_shown
return part_data[part_name].is_operated == false and part_data[part_name].is_amputation_shown
end

View File

@@ -28,7 +28,7 @@ function GetAcceptingProsthesisBodyPartTypes()
end
-- TODO Change name
-- TODO This is just convoluted. Do not use this
function FindTocDataPartNameFromBodyPartType(toc_limbs_data, bodyPartType)
if bodyPartType == BodyPartType.Hand_R then return toc_limbs_data.Right_Hand
elseif bodyPartType == BodyPartType.ForeArm_R then return toc_limbs_data.Right_LowerArm

View File

@@ -66,21 +66,21 @@ TocContextMenus.CreateOperateWithOvenMenu = function(player, context, worldObjec
-- TODO Add a way to move the player towards the oven
local toc_data = player_obj:getModData().TOC
local part_data = player_obj:getModData().TOC.Limbs
local is_main_menu_already_created = false
--local props = v:getSprite() and v:getSprite():getProperties() or nil
for k_stove, v_stove in pairs(worldObjects) do
for _, v_stove in pairs(worldObjects) do
if instanceof(v_stove, "IsoStove") and (player_obj:HasTrait("Brave") or player_obj:getPerkLevel(Perks.Strength) >= 6) then
-- Check temperature
if v_stove:getCurrentTemperature() > 250 then
for k_bodypart, v_bodypart in ipairs(GetBodyParts()) do
if toc_data[v_bodypart].is_cut and toc_data[v_bodypart].is_amputation_shown and not toc_data[v_bodypart].is_operated then
for _, v_bodypart in ipairs(GetBodyParts()) do
if part_data[v_bodypart].is_cut and part_data[v_bodypart].is_amputation_shown and not part_data[v_bodypart].is_operated then
local subMenu = context:getNew(context);
if is_main_menu_already_created == false then
@@ -125,16 +125,15 @@ end
TocContextMenus.FillCutAndOperateMenus = function(local_player, clicked_player, world_objects, cut_menu, operate_menu)
local local_toc_data = local_player:getModData().TOC
local local_part_data = local_player:getModData().TOC.Limbs
for _, v in ipairs(GetBodyParts()) do
if local_player == clicked_player then -- Local player
if CheckIfCanBeCut(v) and not CheckIfProsthesisAlreadyInstalled(local_toc_data, v) then
if CheckIfCanBeCut(v) and not CheckIfProsthesisAlreadyInstalled(local_part_data, v) then
cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Cut", local_player, local_player)
--cut_menu:addOption(getText('UI_ContextMenu_' .. v), _, TocCutLocal, local_player, local_player, v)
elseif CheckIfCanBeOperated(v) then
operate_menu:addOption(getText('UI_ContextMenu_' .. v), _, TryTocAction, v, "Operate", local_player, local_player)
end

View File

@@ -1,7 +1,7 @@
-- CutLimb
-- TODO if TheONlyCure. triggers an errors
function CheckIfStillInfected(toc_data)
if toc_data == nil then
function CheckIfStillInfected(part_data)
if part_data == nil then
return
end
-- Check ALL body part types to check if the player is still gonna die
@@ -9,12 +9,12 @@ function CheckIfStillInfected(toc_data)
for _, v in ipairs(GetBodyParts()) do
if toc_data[v].is_infected then
if part_data[v].is_infected then
check = true
end
end
if toc_data.is_other_bodypart_infected then
if part_data.is_other_bodypart_infected then
check = true
end
@@ -40,14 +40,14 @@ end
-- OperateLimb
function SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven)
function SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven)
--for _, v in ipairs(GetBodyParts()) do
local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(part_name))
FixSingleBodyPartType(body_part_type, use_oven)
for _, v in ipairs(toc_data[part_name].depends_on) do
for _, v in ipairs(part_data[part_name].depends_on) do
local depended_body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(v))
FixSingleBodyPartType(depended_body_part_type, use_oven)

View File

@@ -60,9 +60,9 @@ local function GetImageName(part_name, toc_data)
end
-- If foreaerm equip, change hand
if part_name == "Right_Hand" and toc_data["Right_LowerArm"].is_prosthesis_equipped then
if part_name == "Right_Hand" and toc_data.Limbs["Right_LowerArm"].is_prosthesis_equipped then
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
elseif part_name == "Left_Hand" and toc_data["Left_LowerArm"].is_prosthesis_equipped then
elseif part_name == "Left_Hand" and toc_data.Limbs["Left_LowerArm"].is_prosthesis_equipped then
name = "media/ui/TOC/" .. part_name .. "/Hook.png"
end
return name

View File

@@ -1,5 +1,7 @@
-- Makes the player drop an item if they don't have a limb or haven't equipped a prosthesis
function TheOnlyCure.TryDropItem(player, toc_data)
-- TODO this is old, was used in the update thing
if TheOnlyCure.CheckIfCanPickUpItem(toc_data, Right, Hand, Forearm) and player:getPrimaryHandItem() ~= nil then
if player:getPrimaryHandItem():getName() ~= "Bare Hands" then
player:dropHandItems()
@@ -18,6 +20,8 @@ end
-- Helper for DropItem
function TheOnlyCure.CheckIfCanPickUpItem(toc_data, side, limb, secondary_limb)
-- TODO we can use this when uninstall prost or when cutting
local full_primary_limb = side .. limb
local full_secondary_limb = side .. secondary_limb
@@ -33,10 +37,13 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
local body_damage = player:getBodyDamage()
for _, v in ipairs(GetLimbsBodyPartTypes()) do
local toc_bodypart = FindTocDataPartNameFromBodyPartType(toc_data.Limbs, v)
if body_damage:getBodyPart(v):bitten() and toc_bodypart ~= nil then
if toc_bodypart.is_cut == false then
toc_bodypart.is_infected = true
local part_name = FindTocBodyPartNameFromBodyPartType(v)
local part_data = toc_data.Limbs[part_name]
if body_damage:getBodyPart(v):bitten() and part_data ~= nil then
if part_data.is_cut == false then
part_data.is_infected = true
player:transmitModData()
end
@@ -45,14 +52,14 @@ function TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
for _, v in ipairs(GetOtherBodyPartTypes()) do
if body_damage:getBodyPart(v):bitten() then
toc_data.is_other_bodypart_infected = true -- Even one is enough, stop cycling if we find it
toc_data.Limbs.is_other_bodypart_infected = true -- Even one is enough, stop cycling if we find it
player:transmitModData()
break
end
end
end
function TheOnlyCure.UpdatePlayerHealth(player, toc_data)
function TheOnlyCure.UpdatePlayerHealth(player, part_data)
local body_damage = player:getBodyDamage()
@@ -60,8 +67,8 @@ function TheOnlyCure.UpdatePlayerHealth(player, toc_data)
if player:HasTrait("Insensitive") then body_damage:setPainReduction(49) end
for i, part_name in pairs(GetBodyParts()) do
if toc_data[part_name].is_cut then
TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
if part_data[part_name].is_cut then
TheOnlyCure.HealSpecificPart(part_data, part_name, player)
end
end
@@ -72,7 +79,7 @@ function TheOnlyCure.UpdatePlayerHealth(player, toc_data)
end
--Helper function for UpdatePlayerHealth
function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
function TheOnlyCure.HealSpecificPart(part_data, part_name, player)
local body_damage = player:getBodyDamage()
@@ -98,7 +105,7 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
-- Set max health
if toc_data[part_name].is_cicatrized and body_part_type:getHealth() > 80 then
if part_data[part_name].is_cicatrized and body_part_type:getHealth() > 80 then
body_part_type:SetHealth(80)
elseif body_part_type:getHealth() > 40 then
body_part_type:SetHealth(40)
@@ -114,7 +121,11 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
-- Check if we can heal the infection
if body_part_type:bitten() then
body_part_type:SetBitten(false)
if not toc_data[part_name].is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(toc_data, part_name) then
local is_other_bodypart_infected = player:getModData().TOC.Limbs.is_other_bodypart_infected
if not is_other_bodypart_infected and not TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name) then
body_part_type:setInfected(false)
body_part_type:setInfectionMortalityDuration(-1)
body_part_type:setInfectionTime(-1)
@@ -138,9 +149,9 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
if body_part_type:getFractureTime()>0 then body_part_type:setFractureTime(0) end
-- Cicatrization check
if toc_data[part_name].is_cut and not toc_data[part_name].is_cicatrized then
if toc_data[part_name].cicatrization_time < 0 then
toc_data[part_name].is_cicatrized = true
if part_data[part_name].is_cut and not part_data[part_name].is_cicatrized then
if part_data[part_name].cicatrization_time < 0 then
part_data[part_name].is_cicatrized = true
-- TODO make this random if the player gets it or not
--FIXME they're gonna stack!!!!
@@ -158,9 +169,9 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
end
-- Phantom Pain
if toc_data[part_name].is_amputation_shown and ZombRand(1, 100) < 10 then
if part_data[part_name].is_amputation_shown and ZombRand(1, 100) < 10 then
local added_pain
if toc_data[part_name].is_cauterized then added_pain = 60 else added_pain = 30 end
if part_data[part_name].is_cauterized then added_pain = 60 else added_pain = 30 end
body_part_type:setAdditionalPain(ZombRand(1, added_pain))
end
@@ -170,14 +181,14 @@ function TheOnlyCure.HealSpecificPart(toc_data, part_name, player)
end
--Helper function for UpdatePlayerHealth
function TheOnlyCure.CheckIfOtherLimbsAreInfected(toc_data, part_name)
function TheOnlyCure.CheckIfOtherLimbsAreInfected(part_data, part_name)
local body_parts = GetBodyParts()
body_parts[part_name] = nil
for _,v in pairs(body_parts) do
if toc_data[v].is_infected then
if part_data[v].is_infected then
return true
end
end
@@ -200,7 +211,7 @@ function TheOnlyCure.UpdateEveryOneMinute()
if toc_data ~= nil then
--TheOnlyCure.TryDropItem(player, toc_data) -- TODO this must be set only in the cut\equipping function, not here
TheOnlyCure.CheckIfPlayerIsInfected(player, toc_data)
TheOnlyCure.UpdatePlayerHealth(player, toc_data)
TheOnlyCure.UpdatePlayerHealth(player, toc_data.Limbs)
end
end

View File

@@ -20,7 +20,9 @@ function TheOnlyCure.InitTheOnlyCure(_, player)
mod_data.TOC = {
Limbs = {},
Limbs = {
is_other_bodypart_infected = false
},
Prosthesis = {},
Generic = {},
}
@@ -159,6 +161,7 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
-- TODO Check if this works in MP through MENU UI
local player = getPlayer()
local toc_data = player:getModData().TOC
local part_data = toc_data.Limbs
local body_part_type = player:getBodyDamage():getBodyPart(TocGetBodyPartTypeFromBodyPart(part_name))
local stats = player:getStats();
@@ -184,19 +187,19 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
-- Remove object in hand
-- TODO do this
if toc_data[part_name].is_cut == false then
toc_data[part_name].is_cut = true
toc_data[part_name].is_amputation_shown = true
toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_base_time - surgeon_factor * 50
if part_data[part_name].is_cut == false then
part_data[part_name].is_cut = true
part_data[part_name].is_amputation_shown = true
part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50
-- Heal the infection here
local body_damage = player:getBodyDamage()
if toc_data[part_name].is_infected and body_damage.getInfectionLevel() < 20 then
toc_data[part_name].is_infected = false
if part_data[part_name].is_infected and body_damage.getInfectionLevel() < 20 then
part_data[part_name].is_infected = false
body_part_type:SetBitten(false)
-- Second check, let's see if there is any other infected limb.
if CheckIfStillInfected(toc_data) == false then
if CheckIfStillInfected(part_data) == false then
CureInfection(body_damage)
getPlayer():Say("I'm gonna be fine")
else
@@ -205,10 +208,10 @@ function TheOnlyCure.CutLimb(part_name, surgeon_factor, bandage_table, painkille
end
-- Cut the depended part
for _, depended_v in pairs(toc_data[part_name].depends_on) do
toc_data[depended_v].is_cut = true
toc_data[depended_v].is_amputation_shown = false -- TODO why was it true before?
toc_data[depended_v].cicatrization_time = toc_data[part_name].cicatrization_base_time - surgeon_factor * 50
for _, depended_v in pairs(part_data[part_name].depends_on) do
part_data[depended_v].is_cut = true
part_data[depended_v].is_amputation_shown = false -- TODO why was it true before?
part_data[depended_v].cicatrization_time = part_data[part_name].cicatrization_base_time - surgeon_factor * 50
end
--Equip model for amputation
@@ -226,7 +229,7 @@ end
function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven)
local player = getPlayer()
local toc_data = player:getModData().TOC
local part_data = player:getModData().TOC.Limbs
if use_oven then
local stats = player:getStats()
@@ -234,20 +237,20 @@ function TheOnlyCure.OperateLimb(part_name, surgeon_factor, use_oven)
stats:setStress(100)
end
if toc_data[part_name].is_operated == false and toc_data[part_name].is_cut == true then
toc_data[part_name].is_operated = true
toc_data[part_name].cicatrization_time = toc_data[part_name].cicatrization_time - (surgeon_factor * 200)
if use_oven then toc_data[part_name].is_cauterized = true end
for _, depended_v in pairs(toc_data[part_name].depends_on) do
toc_data[depended_v].is_operated = true
toc_data[depended_v].cicatrization_time = toc_data[depended_v].cicatrization_time - (surgeon_factor * 200)
if use_oven then toc_data[depended_v].is_cauterized = true end -- TODO does this make sense?
if part_data[part_name].is_operated == false and part_data[part_name].is_cut == true then
part_data[part_name].is_operated = true
part_data[part_name].cicatrization_time = part_data[part_name].cicatrization_time - (surgeon_factor * 200)
if use_oven then part_data[part_name].is_cauterized = true end
for _, depended_v in pairs(part_data[part_name].depends_on) do
part_data[depended_v].is_operated = true
part_data[depended_v].cicatrization_time = part_data[depended_v].cicatrization_time - (surgeon_factor * 200)
if use_oven then part_data[depended_v].is_cauterized = true end -- TODO does this make sense?
end
end
SetBodyPartsStatusAfterOperation(player, toc_data, part_name, use_oven)
SetBodyPartsStatusAfterOperation(player, part_data, part_name, use_oven)
player:transmitModData()
end

View File

@@ -56,9 +56,6 @@ function ISUninstallProsthesis:perform()
print("Found prost in " .. part_name)
if part_name then
toc_data.Limbs[part_name].is_prosthesis_equipped = false
--toc_data.Limbs[part_name].prosthesis_factor = 1 -- TODO This is wrong
--local side = string.gsub(part_name, "Hand" or "Forearm", "")
local item_full_type = self.item:getFullType()
print("Searching for " .. item_full_type)
for _, prost_v in ipairs(GetProsthesisList()) do

View File

@@ -11,7 +11,7 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
local original_max_time = og_ISEquipTimedActionAdjustMaxTime(self, maxTime) -- TODO will it work?
local modified_max_time = original_max_time
local toc_data = getPlayer():getModData().TOC
local part_data = getPlayer():getModData().TOC.Limbs
local burn_factor = 1.3
-- To make it faster, let's have everything already written in another func
@@ -21,17 +21,16 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
-- TODO this gets awfully slow really quick, doesn't even make much sense.
for _, part_name in ipairs(all_body_parts) do
if toc_data.Limbs[part_name].is_cut then
if part_data[part_name].is_cut then
if toc_data.Limbs[part_name].is_prosthesis_equipped then
modified_max_time = modified_max_time * toc_data.Limbs[part_name].equipped_prosthesis.prosthesis_factor
if part_data[part_name].is_prosthesis_equipped then
modified_max_time = modified_max_time * part_data[part_name].equipped_prosthesis.prosthesis_factor
else
modified_max_time = modified_max_time * 2
end
if toc_data.Limbs[part_name].is_cauterized then
if part_data[part_name].is_cauterized then
modified_max_time = modified_max_time * burn_factor
end
@@ -61,18 +60,18 @@ local og_ISEquipWeaponActionPerform = ISEquipWeaponAction.perform
function ISEquipWeaponAction:perform()
og_ISEquipWeaponActionPerform(self)
local toc_data = self.character:getModData().TOC
local part_data = self.character:getModData().TOC.Limbs
local can_be_held = {}
for _, side in ipairs ({"Left", "Right"}) do
can_be_held[side] = true
if toc_data[side .. "Hand"].is_cut then
if toc_data[side .. "Forearm"].is_cut then
if not toc_data[side .. "Forearm"].is_prosthesis_equipped then
if part_data[side .. "_Hand"].is_cut then
if part_data[side .. "_LowerArm"].is_cut then
if not part_data[side .. "_LowerArm"].is_prosthesis_equipped then
can_be_held[side] = false
end
elseif not toc_data[side .. "Hand"].is_prosthesis_equipped then
elseif not part_data[side .. "_Hand"].is_prosthesis_equipped then
can_be_held[side] = false
end
end