did an oopsie before, fixed uninstalling prosthesis

This commit is contained in:
Pao
2023-01-13 18:07:07 +01:00
parent 8429164c72
commit 416fcfb9a2
10 changed files with 305 additions and 127 deletions

View File

@@ -27,7 +27,7 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
for i,name in ipairs(protPartNames) do
if modData.TOC[name].is_cut then
if modData.TOC[name].has_prosthesis_equipped then
if modData.TOC[name].is_prosthesis_equipped then
maxTime = maxTime * modData.TOC[name].EquipFact --todo this is dumb
else
maxTime = maxTime * 2;
@@ -119,12 +119,12 @@ function ISEquipWeaponAction:perform()
if not self.item:isRequiresEquippedBothHands() then
if modData.TOC.RightHand.is_cut then
if modData.TOC.RightForearm.is_cut then
if not modData.TOC.RightForearm.has_prosthesis_equipped then
if not modData.TOC.RightForearm.is_prosthesis_equipped then
self.character:setPrimaryHandItem(nil);
self.character:setSecondaryHandItem(self.item);
end
else
if not modData.TOC.RightHand.has_prosthesis_equipped then
if not modData.TOC.RightHand.is_prosthesis_equipped then
self.character:setPrimaryHandItem(nil);
self.character:setSecondaryHandItem(self.item);
end
@@ -132,23 +132,23 @@ function ISEquipWeaponAction:perform()
end
if modData.TOC.LeftHand.is_cut then
if modData.TOC.LeftForearm.is_cut then
if not modData.TOC.LeftForearm.has_prosthesis_equipped then
if not modData.TOC.LeftForearm.is_prosthesis_equipped then
self.character:setPrimaryHandItem(self.item);
self.character:setSecondaryHandItem(nil);
end
else
if not modData.TOC.LeftHand.has_prosthesis_equipped then
if not modData.TOC.LeftHand.is_prosthesis_equipped then
self.character:setPrimaryHandItem(self.item);
self.character:setSecondaryHandItem(nil);
end
end
end
if (modData.TOC.RightHand.is_cut and not (modData.TOC.RightHand.has_prosthesis_equipped or modData.TOC.RightForearm.has_prosthesis_equipped)) and (modData.TOC.LeftHand.is_cut and not (modData.TOC.LeftHand.has_prosthesis_equipped or modData.TOC.LeftForearm.has_prosthesis_equipped)) then
if (modData.TOC.RightHand.is_cut and not (modData.TOC.RightHand.is_prosthesis_equipped or modData.TOC.RightForearm.is_prosthesis_equipped)) and (modData.TOC.LeftHand.is_cut and not (modData.TOC.LeftHand.is_prosthesis_equipped or modData.TOC.LeftForearm.is_prosthesis_equipped)) then
self.character:dropHandItems();
end
end
if self.item:isRequiresEquippedBothHands() and ((modData.TOC.RightHand.is_cut and not modData.TOC.RightHand.has_prosthesis_equipped) or (modData.TOC.RightForearm.is_cut and not modData.TOC.RightForearm.has_prosthesis_equipped) or (modData.TOC.LeftHand.is_cut and not modData.TOC.LeftHand.has_prosthesis_equipped) or (modData.TOC.LeftForearm.is_cut and not modData.TOC.LeftForearm.has_prosthesis_equipped)) then
if self.item:isRequiresEquippedBothHands() and ((modData.TOC.RightHand.is_cut and not modData.TOC.RightHand.is_prosthesis_equipped) or (modData.TOC.RightForearm.is_cut and not modData.TOC.RightForearm.is_prosthesis_equipped) or (modData.TOC.LeftHand.is_cut and not modData.TOC.LeftHand.is_prosthesis_equipped) or (modData.TOC.LeftForearm.is_cut and not modData.TOC.LeftForearm.is_prosthesis_equipped)) then
self.character:dropHandItems();
end

View File

@@ -23,11 +23,12 @@ end
function ISCutLimb:start()
if self.patient == self.surgeon then
self:setActionAnim("WearClothing") -- TODO Change it to a better animation
self:setAnimVariable("WearClothingLocation", "Jacket")
self:setActionAnim("SawLog") -- TODO Change it to a better animation
--self:setAnimVariable("WearClothingLocation", "Jacket")
else
self:setActionAnim("Loot")
self.patient:SetVariable("LootPosition", "Mid")
self:setActionAnim("SawLog")
-- TODO Point at patient
--self.patient:SetVariable("LootPosition", "Mid")
end
end

View File

@@ -0,0 +1,178 @@
require "TimedActions/ISBaseTimedAction"
ISInstallProsthesis = ISBaseTimedAction:derive("ISInstallProsthesis");
function ISInstallProsthesis:isValid()
return true
end
function ISInstallProsthesis:update()
self.item:setJobDelta(self:getJobDelta())
end
function ISInstallProsthesis:start()
self.item:setJobType("Install prosthesis")
self.item:setJobDelta(0.0)
self:setActionAnim("WearClothing")
self:setAnimVariable("WearClothingLocation", "Jacket")
end
function ISInstallProsthesis:stop()
ISBaseTimedAction.stop(self)
self.item:setJobDelta(0.0)
end
function ISInstallProsthesis:perform()
self.item:setJobDelta(0.0)
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
if self.bodyPart:getType() == BodyPartType.UpperArm_L or self.bodyPart:getType() == BodyPartType.UpperArm_R then
print("Can't equip prosthesis")
return
end
local prosthesis_table = {
WoodenHook = {
material_id = 1
},
MetalHook = {
material_id = 2
},
MetalHand = {
material_id = 3
}
}
print(self.item)
-- TODO make a parser or something I dont care
-- Check Item before doing any of this shit maybe
-- Assemble the correct name for the object
local prosthesis_name = self.item:getname() .. "_" .. Right .. "_" .. Forearm
-- for _, v in ipairs(GetLimbsBodyPartTypes()) do
-- if v ~= BodyPartType.UpperArm_L or v ~= BodyPartType.UpperArm_R then
-- if self.bodyPart:getType() == v then
-- --local item_name = "TOC."
-- --local weight = math.floor(self.item:getWeight() * 10 + 0.5) / 10 -- TODO why do we need this?
-- end
-- end
-- end
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.bodyPart:getType() == BodyPartType.Hand_R then
modData.TOC.RightHand.IsEquiped = true;
modData.TOC.RightHand.Equip_mat_id = mat_id;
modData.TOC.RightHand.EquipFact = find_protheseFact_TOC(self.cloth);
elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then
modData.TOC.RightForearm.IsEquiped = true;
modData.TOC.RightForearm.Equip_mat_id = mat_id;
modData.TOC.RightForearm.EquipFact = find_protheseFact_TOC(self.cloth);
elseif self.bodyPart:getType() == BodyPartType.Hand_L then
modData.TOC.LeftHand.IsEquiped = true;
modData.TOC.LeftHand.Equip_mat_id = mat_id;
modData.TOC.LeftHand.EquipFact = find_protheseFact_TOC(self.cloth);
elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then
modData.TOC.LeftForearm.IsEquiped = true;
modData.TOC.LeftForearm.Equip_mat_id = mat_id;
modData.TOC.LeftForearm.EquipFact = find_protheseFact_TOC(self.cloth);
end
self.character:getInventory():Remove(self.item);
self.character:setWornItem(self.cloth:getBodyLocation(), self.cloth);
end
self.character:transmitModData()
-- needed to remove from queue / start next.
ISBaseTimedAction.perform(self)
end
function ISInstallProsthesis:new(character, item, bodyPart)
local o = ISBaseTimedAction.new(self, character)
o.item = item
o.bodyPart = bodyPart
o.maxTime = 100
o.stopOnWalk = true
o.stopOnRun = true
o.cloth = nil
o.ignoreHandsWounds = false
o.fromHotbar = true -- just to disable hotbar:update() during the wearing
if o.character:isTimedActionInstant() then o.maxTime = 1 end
return o
end

View File

@@ -0,0 +1,94 @@
require "TimedActions/ISBaseTimedAction"
ISUninstallProsthesis = ISBaseTimedAction:derive("ISUninstallProsthesis");
function ISUninstallProsthesis:isValid()
return true;
end
function ISUninstallProsthesis:update()
self.item:setJobDelta(self:getJobDelta());
end
function ISUninstallProsthesis:start()
self.item:setJobType("Uninstall prothesis");
self.item:setJobDelta(0.0);
self:setActionAnim("WearClothing");
if self.item:IsClothing() then
self:setAnimVariable("WearClothingLocation", "Jacket")
elseif self.item:IsInventoryContainer() and self.item:canBeEquipped() ~= "" then
self:setAnimVariable("WearClothingLocation", "Jacket")
end
end
function ISUninstallProsthesis:stop()
ISBaseTimedAction.stop(self);
self.item:setJobDelta(0.0);
end
function ISUninstallProsthesis:perform()
self.item:getContainer():setDrawDirty(true)
self.item:setJobDelta(0.0)
if instanceof(self.item, "InventoryContainer") and self.item:canBeEquipped() ~= "" then
self.character:removeFromHands(self.item)
self.character:setWornItem(self.item:canBeEquipped(), self.item)
getPlayerInventory(self.character:getPlayerNum()):refreshBackpacks()
elseif self.item:getCategory() == "Clothing" then
if self.item:getBodyLocation() ~= "" then
self.character:setWornItem(self.item:getBodyLocation(), self.item)
end
end
local modData = self.character:getModData()
if self.bodyPart:getType() == BodyPartType.Hand_R then
modData.TOC.RightHand.is_prosthesis_equipped = false
modData.TOC.RightHand.prothesis_factor = 1
elseif self.bodyPart:getType() == BodyPartType.ForeArm_R then
modData.TOC.RightForearm.is_prosthesis_equipped = false
modData.TOC.RightForearm.prothesis_factor = 1
elseif self.bodyPart:getType() == BodyPartType.Hand_L then
modData.TOC.LeftHand.is_prosthesis_equipped = false
modData.TOC.LeftHand.prothesis_factor = 1
elseif self.bodyPart:getType() == BodyPartType.ForeArm_L then
modData.TOC.LeftForearm.is_prosthesis_equipped = false
modData.TOC.LeftForearm.prothesis_factor = 1
end
local weight = math.floor(self.item:getWeight() * 10 + 0.5)
if weight == 10 then
self.character:getInventory():AddItem("TOC.WoodenHook")
elseif weight == 5 then
self.character:getInventory():AddItem("TOC.MetalHook")
elseif weight == 3 then
self.character:getInventory():AddItem("TOC.MetalHand")
elseif weight == 20 then
self.character:getInventory():AddItem("TOC.WoodenHook")
elseif weight == 15 then
self.character:getInventory():AddItem("TOC.MetalHook")
elseif weight == 12 then
self.character:getInventory():AddItem("TOC.MetalHand")
end
self.character:setWornItem(self.item:getBodyLocation(), nil)
self.character:getInventory():Remove(self.item)
self.character:transmitModData()
-- needed to remove from queue / start next.
ISBaseTimedAction.perform(self);
end
function ISUninstallProsthesis:new(character, item, bodyPart)
local o = ISBaseTimedAction.new(self, character);
o.item = item;
o.character = character;
o.bodyPart = bodyPart;
o.maxTime = 100;
o.stopOnWalk = true;
o.stopOnRun = true;
o.ignoreHandsWounds = false;
o.fromHotbar = true; -- just to disable hotbar:update() during the wearing
if o.character:isTimedActionInstant() then o.maxTime = 1; end
return o;
end

View File

@@ -1,102 +0,0 @@
require "TimedActions/ISBaseTimedAction"
ISOperateArm = ISBaseTimedAction:derive("ISOperateArm");
function ISOperateArm:isValid()
return self.patientX == self.patient:getX() and self.patientY == self.patient:getY();
end
function ISOperateArm:waitToStart()
if self.patient == self.surgeon then
return false
end
self.surgeon:faceThisObject(self.patient)
return self.surgeon:shouldBeTurning()
end
function ISOperateArm:update()
if self.patient ~= self.surgeon then
self.surgeon:faceThisObject(self.patient)
end
end
function ISOperateArm:start()
self:setActionAnim("MedicalCheck");
if self.useOven then
self.sound = self.patient:getEmitter():playSound("Burn_sound")
self:forceComplete();
end
end
function ISOperateArm:findArgs()
local surgeonFact = self.surgeon:getPerkLevel(Perks.Doctor);
if self.useOven then
surgeonFact = surgeonFact + 100
else
if self.kit then
local weight = math.floor(self.kit:getWeight() * 10 + 0.5)
if weight == 1 then
surgeonFact = surgeonFact + 2
elseif weight == surgeonFact then
surgeonFact = surgeonFact + 4
elseif weight == 3 then
surgeonFact = surgeonFact + 6
end
end
if self.surgeon:getDescriptor():getProfession() == "surgeon" then surgeonFact = surgeonFact + 10 end
if self.surgeon:getDescriptor():getProfession() == "doctor" then surgeonFact = surgeonFact + 5 end
if self.surgeon:getDescriptor():getProfession() == "nurse" then surgeonFact = surgeonFact + 2 end
end
return surgeonFact, self.useOven;
end
function ISOperateArm:perform()
local surgeonFact, useOven = self:findArgs();
if self.patient ~= self.surgeon and isClient() then
SendOperateArm(self.patient, self.partName, surgeonFact, useOven)
else
OperateArm(self.partName, surgeonFact, useOven)
end
self.surgeon:getXp():AddXP(Perks.Doctor, 400)
-- FIXME Add a check for kit to prevent errors
if self.kit then
self.surgeon:getInventory():Remove(self.kit)
end
ISBaseTimedAction.perform(self)
end
function ISOperateArm:new(patient, surgeon, kit, partName, useOven)
local o = ISBaseTimedAction.new(self, patient);
o.partName = partName;
o.patient = patient;
o.character = surgeon; -- For anim
o.patientX = patient:getX();
o.patientY = patient:getY();
o.surgeon = surgeon;
o.kit = kit;
o.useOven = useOven
--o.UseOven = UseOven;
if useOven then
o.maxTime = 30
else
o.maxTime = 200 - (surgeon:getPerkLevel(Perks.Doctor) * 10)
end
o.stopOnWalk = true;
o.stopOnRun = true;
o.ignoreHandsWounds = false;
o.fromHotbar = true;
if o.patient:isTimedActionInstant()then
o.maxTime = 1
end
return o;
end