Merge pull request #121 from ZioPao/dev

v2.1.3
This commit is contained in:
Pao
2024-08-23 03:04:44 +02:00
committed by GitHub
8 changed files with 119 additions and 28 deletions

View File

@@ -1,4 +1,5 @@
local CommandsData = require("TOC/CommandsData") local CommandsData = require("TOC/CommandsData")
local ClientRelayCommands = require("TOC/ClientRelayCommands")
local StaticData = require("TOC/StaticData") local StaticData = require("TOC/StaticData")
local DataController = require("TOC/Controllers/DataController") local DataController = require("TOC/Controllers/DataController")
------------------- -------------------
@@ -7,7 +8,8 @@ local DataController = require("TOC/Controllers/DataController")
---@param context ISContextMenu ---@param context ISContextMenu
---@param worldobjects table ---@param worldobjects table
local function AddAdminTocOptions(playerNum, context, worldobjects) local function AddAdminTocOptions(playerNum, context, worldobjects)
if not isAdmin() then return end
if (isClient() and not isDebugEnabled()) or isAdmin() then return end
local players = {} local players = {}
for _, v in ipairs(worldobjects) do for _, v in ipairs(worldobjects) do
@@ -40,8 +42,13 @@ local function AddAdminTocOptions(playerNum, context, worldobjects)
context:addSubMenu(option, subMenu) context:addSubMenu(option, subMenu)
subMenu:addOption(getText("ContextMenu_Admin_ResetTOC"), nil, function() subMenu:addOption(getText("ContextMenu_Admin_ResetTOC"), nil, function()
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteInitialization, if isClient() then
{ patientNum = clickedPlayerNum }) sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayExecuteInitialization,
{ patientNum = clickedPlayerNum })
else
-- TODO ugly
ClientRelayCommands.ReceiveExecuteInitialization()
end
end) end)
-- Force amputation -- Force amputation
@@ -54,8 +61,14 @@ local function AddAdminTocOptions(playerNum, context, worldobjects)
local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName) local limbTranslatedName = getText("ContextMenu_Limb_" .. limbName)
forceAmpSubMenu:addOption(limbTranslatedName, nil, function() forceAmpSubMenu:addOption(limbTranslatedName, nil, function()
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayForcedAmputation, if isClient() then
sendClientCommand(CommandsData.modules.TOC_RELAY, CommandsData.server.Relay.RelayForcedAmputation,
{ patientNum = clickedPlayerNum, limbName = limbName }) { patientNum = clickedPlayerNum, limbName = limbName })
else
ClientRelayCommands.ReceiveExecuteAmputationAction({surgeonNum=clickedPlayerNum, limbName=limbName, damagePlayer=false})
-- todo ugly
end
end) end)
end end
end end

View File

@@ -72,3 +72,6 @@ local function OnServerRelayCommand(module, command, args)
end end
Events.OnServerCommand.Add(OnServerRelayCommand) Events.OnServerCommand.Add(OnServerRelayCommand)
-- TODO temporary
return ClientRelayCommands

View File

@@ -26,7 +26,7 @@ end
---Returns full name for the side, to be used with BodyLocations ---Returns full name for the side, to be used with BodyLocations
---@param side string ---@param side string
---@return string ---@return string?
function CommonMethods.GetSideFull(side) function CommonMethods.GetSideFull(side)
if side == 'R' then if side == 'R' then
return "Right" return "Right"

View File

@@ -32,8 +32,12 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
local time = og_ISBaseTimedAction_adjustMaxTime(self, maxTime) local time = og_ISBaseTimedAction_adjustMaxTime(self, maxTime)
-- Exceptions handling, if we find that parameter then we just use the original time -- Exceptions handling, if we find that parameter then we just use the original time
local queue = ISTimedActionQueue.getTimedActionQueue(getPlayer()) local actionsQueue = ISTimedActionQueue.getTimedActionQueue(getPlayer())
if queue and queue.current and queue.current.skipTOC then return time end
if actionsQueue and actionsQueue.current and actionsQueue.skipTOC then
--TOC_DEBUG.print("Should skip TOC stuff")
return time
end
-- Action is valid, check if we have any cut limb and then modify maxTime -- Action is valid, check if we have any cut limb and then modify maxTime
local dcInst = DataController.GetInstance() local dcInst = DataController.GetInstance()
@@ -57,6 +61,10 @@ function ISBaseTimedAction:adjustMaxTime(maxTime)
time = time * (StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[limbName] - perkLevelScaled) time = time * (StaticData.LIMBS_TIME_MULTIPLIER_IND_NUM[limbName] - perkLevelScaled)
end end
end end
if actionsQueue and actionsQueue.current then
TOC_DEBUG.print("OG Action: " .. tostring(actionsQueue.current.Type))
end
TOC_DEBUG.print("New time with amputations: " .. tostring(time))
return time return time
end end
@@ -74,7 +82,7 @@ function ISBaseTimedAction:perform()
if not dcInst:getIsAnyLimbCut() then return end if not dcInst:getIsAnyLimbCut() then return end
local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(LocalPlayerController.username) local amputatedLimbs = CachedDataHandler.GetAmputatedLimbs(LocalPlayerController.username)
local xp = self.maxTime/100 local xp = self.maxTime / 100
for k, _ in pairs(amputatedLimbs) do for k, _ in pairs(amputatedLimbs) do
local limbName = k local limbName = k
@@ -92,7 +100,6 @@ function ISBaseTimedAction:perform()
if dcInst:getIsProstEquipped(limbName) then if dcInst:getIsProstEquipped(limbName) then
LocalPlayerController.playerObj:getXp():AddXP(Perks["ProstFamiliarity"], xp) LocalPlayerController.playerObj:getXp():AddXP(Perks["ProstFamiliarity"], xp)
end end
end end
end end
end end
@@ -123,9 +130,7 @@ function ISEquipWeaponAction:isValid()
end end
---A recreation of the original method, but with amputations in mind ---A recreation of the original method, but with amputations in mind
---@param dcInst DataController function ISEquipWeaponAction:performWithAmputation()
function ISEquipWeaponAction:performWithAmputation(dcInst)
TOC_DEBUG.print("running ISEquipWeaponAction performWithAmputation") TOC_DEBUG.print("running ISEquipWeaponAction performWithAmputation")
local hand = nil local hand = nil
local otherHand = nil local otherHand = nil
@@ -204,12 +209,15 @@ local og_ISEquipWeaponAction_perform = ISEquipWeaponAction.perform
function ISEquipWeaponAction:perform() function ISEquipWeaponAction:perform()
og_ISEquipWeaponAction_perform(self) og_ISEquipWeaponAction_perform(self)
-- TODO Can we do it earlier?
--if self.character == getPlayer() then
local dcInst = DataController.GetInstance(self.character:getUsername()) local dcInst = DataController.GetInstance(self.character:getUsername())
-- Just check it any limb has been cut. If not, we can just return from here -- Just check it any limb has been cut. If not, we can just return from here
if dcInst:getIsAnyLimbCut() == true then if dcInst:getIsAnyLimbCut() then
self:performWithAmputation(dcInst) self:performWithAmputation()
end end
--end
end end
function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon, items, player) function ISInventoryPaneContextMenu.doEquipOption(context, playerObj, isWeapon, items, player)
@@ -269,6 +277,23 @@ function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test)
---@type ISContextMenu ---@type ISContextMenu
local ogContext = og_ISWorldObjectContextMenu_createMenu(player, worldobjects, x, y, test) local ogContext = og_ISWorldObjectContextMenu_createMenu(player, worldobjects, x, y, test)
-- The vanilla game doesn't count an item in the off hand as "equipped" for picking up glass. Let's fix that here
local brokenGlassOption = ogContext:getOptionFromName(getText("ContextMenu_RemoveBrokenGlass"))
if brokenGlassOption then
local playerObj = getSpecificPlayer(player)
if (CachedDataHandler.GetHandFeasibility(StaticData.SIDES_IND_STR.R) and playerObj:getPrimaryHandItem()) or
(CachedDataHandler.GetHandFeasibility(StaticData.SIDES_IND_STR.L) and playerObj:getSecondaryHandItem())
then
brokenGlassOption.notAvailable = false
brokenGlassOption.toolTip = nil -- This is active only when you can't do the action.
end
end
-- check if no hands, disable various interactions -- check if no hands, disable various interactions
if not CachedDataHandler.GetBothHandsFeasibility() then if not CachedDataHandler.GetBothHandsFeasibility() then
TOC_DEBUG.print("NO hands :((") TOC_DEBUG.print("NO hands :((")
@@ -283,7 +308,6 @@ function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test)
return ogContext return ogContext
end end
--* DISABLE WEARING CERTAIN ITEMS WHEN NO LIMB --* DISABLE WEARING CERTAIN ITEMS WHEN NO LIMB
local function CheckLimbFeasibility(limbName) local function CheckLimbFeasibility(limbName)

View File

@@ -123,7 +123,8 @@ function CachedDataHandler.CalculateHandFeasibility(limbName)
CachedDataHandler.handFeasibility[side] = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName) CachedDataHandler.handFeasibility[side] = not dcInst:getIsCut(limbName) or dcInst:getIsProstEquipped(limbName)
end end
---@param side string Either "L" or "R"
---@return boolean
function CachedDataHandler.GetHandFeasibility(side) function CachedDataHandler.GetHandFeasibility(side)
return CachedDataHandler.handFeasibility[side] return CachedDataHandler.handFeasibility[side]
end end

View File

@@ -6,7 +6,7 @@ require("TOC/Events")
---@class Main ---@class Main
local Main = { local Main = {
_version = "2.1.2" _version = "2.1.3"
} }
function Main.Start() function Main.Start()

View File

@@ -1,10 +1,60 @@
---@diagnostic disable: duplicate-set-field ---@diagnostic disable: duplicate-set-field
-- Bunch of actions shouldn't be modified by the adjusted time -- Bunch of actions shouldn't be modified by the adjusted time
-----------------------------------------------
---* Some actions have specific maxTime calculations and we must account for that
---ISAttachItemHotbar
---ISDetachItemHotbar
---ISEquipWeaponAction
---ISUnequipAction
--- We're forced to re-run this crap to fix it
---@param action ISBaseTimedAction
local function HandleSpeedSpecificAction(action)
action.skipTOC = true
action.animSpeed = action.maxTime / action:adjustMaxTime(action.maxTime)
action.maxTime = -1
end
local og_ISAttachItemHotbar_new = ISAttachItemHotbar.new
function ISAttachItemHotbar:new(character, item, slot, slotIndex, slotDef)
local action = og_ISAttachItemHotbar_new(self, character, item, slot, slotIndex, slotDef)
HandleSpeedSpecificAction(action)
return action
end
local og_ISDetachItemHotbar_new = ISDetachItemHotbar.new
function ISDetachItemHotbar:new(character, item)
local action = og_ISDetachItemHotbar_new(self, character, item)
HandleSpeedSpecificAction(action)
return action
end
local og_ISEquipWeaponAction_new = ISEquipWeaponAction.new
function ISEquipWeaponAction:new(character, item, time, primary, twoHands)
local action = og_ISEquipWeaponAction_new(self, character, item, time, primary, twoHands)
--TOC_DEBUG.print("Override ISEquipWeaponAction")
if not twoHands then
HandleSpeedSpecificAction(action)
end
return action
end
local og_ISUnequipAction_new = ISUnequipAction.new
function ISUnequipAction:new(character, item, time)
local action = og_ISUnequipAction_new(self, character, item, time)
HandleSpeedSpecificAction(action)
return action
end
------------------------------------------------------
--- Normal cases
local og_ISEatFoodAction_new = ISEatFoodAction.new local og_ISEatFoodAction_new = ISEatFoodAction.new
function ISEatFoodAction:new(character, item, percentage) function ISEatFoodAction:new(character, item, percentage)
local action = og_ISEatFoodAction_new(self, character, item, percentage) local action = og_ISEatFoodAction_new(self, character, item, percentage)
TOC_DEBUG.print("Override ISEatFoodAction") --TOC_DEBUG.print("Override ISEatFoodAction")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -12,7 +62,7 @@ end
local og_ISReadABook_new = ISReadABook.new local og_ISReadABook_new = ISReadABook.new
function ISReadABook:new(character, item, time) function ISReadABook:new(character, item, time)
local action = og_ISReadABook_new(self, character, item, time) local action = og_ISReadABook_new(self, character, item, time)
TOC_DEBUG.print("Override ISReadABook") --TOC_DEBUG.print("Override ISReadABook")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -20,7 +70,7 @@ end
local og_ISTakePillAction_new = ISTakePillAction.new local og_ISTakePillAction_new = ISTakePillAction.new
function ISTakePillAction:new(character, item, time) function ISTakePillAction:new(character, item, time)
local action = og_ISTakePillAction_new(self, character, item, time) local action = og_ISTakePillAction_new(self, character, item, time)
TOC_DEBUG.print("Override ISTakePillAction") --TOC_DEBUG.print("Override ISTakePillAction")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -28,7 +78,7 @@ end
local og_ISTakeWaterAction_new = ISTakeWaterAction.new local og_ISTakeWaterAction_new = ISTakeWaterAction.new
function ISTakeWaterAction:new(character, item, waterUnit, waterObject, time, oldItem) function ISTakeWaterAction:new(character, item, waterUnit, waterObject, time, oldItem)
local action = og_ISTakeWaterAction_new(self, character, item, waterUnit, waterObject, time, oldItem) local action = og_ISTakeWaterAction_new(self, character, item, waterUnit, waterObject, time, oldItem)
TOC_DEBUG.print("Override ISTakeWaterAction") --TOC_DEBUG.print("Override ISTakeWaterAction")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -36,7 +86,7 @@ end
local og_ISDrinkFromBottle_new = ISDrinkFromBottle.new local og_ISDrinkFromBottle_new = ISDrinkFromBottle.new
function ISDrinkFromBottle:new(character, item, uses) function ISDrinkFromBottle:new(character, item, uses)
local action = og_ISDrinkFromBottle_new(self, character, item, uses) local action = og_ISDrinkFromBottle_new(self, character, item, uses)
TOC_DEBUG.print("Override ISDrinkFromBottle") --TOC_DEBUG.print("Override ISDrinkFromBottle")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -44,7 +94,7 @@ end
local og_ISFinalizeDealAction_new = ISFinalizeDealAction.new local og_ISFinalizeDealAction_new = ISFinalizeDealAction.new
function ISFinalizeDealAction:new(player, otherPlayer, itemsToGive, itemsToReceive, time) function ISFinalizeDealAction:new(player, otherPlayer, itemsToGive, itemsToReceive, time)
local action = og_ISFinalizeDealAction_new(self, player, otherPlayer, itemsToGive, itemsToReceive, time) local action = og_ISFinalizeDealAction_new(self, player, otherPlayer, itemsToGive, itemsToReceive, time)
TOC_DEBUG.print("Override ISFinalizeDealAction") --TOC_DEBUG.print("Override ISFinalizeDealAction")
action.skipTOC = true action.skipTOC = true
return action return action
end end
@@ -52,7 +102,7 @@ end
local og_ISCampingInfoAction_new = ISCampingInfoAction.new local og_ISCampingInfoAction_new = ISCampingInfoAction.new
function ISCampingInfoAction:new(character, campfireObject, campfire) function ISCampingInfoAction:new(character, campfireObject, campfire)
local action = og_ISCampingInfoAction_new(self, character, campfireObject, campfire) local action = og_ISCampingInfoAction_new(self, character, campfireObject, campfire)
TOC_DEBUG.print("Override ISCampingInfoAction") --TOC_DEBUG.print("Override ISCampingInfoAction")
action.skipTOC = true action.skipTOC = true
return action return action
end end

View File

@@ -4,5 +4,5 @@ description=You've been bitten. You have only two choices.
id=TheOnlyCure id=TheOnlyCure
icon=icon.png icon=icon.png
url=https://github.com/ZioPao/The-Only-Cure url=https://github.com/ZioPao/The-Only-Cure
modversion=2.1.2 modversion=2.1.3
pzversion=41.65 pzversion=41.65