Skip to content

Commit

Permalink
improved data updating
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Oct 10, 2023
1 parent 2f81fdb commit 60cb90a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 22 deletions.
12 changes: 8 additions & 4 deletions gamemodes/terrortown/gamemode/client/cl_search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,21 @@ function SEARCHSCRN:Show(data)
and not bodysearch.IsConfirmed(data.ragOwner)
and not clientRD.isPolicingRole and not clientRD.isPublicRole
then
local searchMode = bodysearch.GetInspectConfirmMode()

self:MakeInfoItem(contentAreaScroll, "policingrole_confirm_disabled", {
text = {
title = {
body = "search_title_policingrole_confirm_disabled",
params = nil
},
text = {{
body = "search_policingrole_confirm_disabled_" .. GetConVar("ttt2_inspect_confirm_mode"):GetString(),
body = "search_policingrole_confirm_disabled_" .. tostring(searchMode),
params = nil
}}
},
colorBox = roles.DETECTIVE.ltcolor
}, 62)
}, (searchMode == 1) and 62 or 78)
end

-- POPULATE WITH INFORMATION
Expand Down Expand Up @@ -291,12 +293,14 @@ function SEARCHSCRN:Show(data)
end
buttonConfirm:SetParams({credits = data.credits})
buttonConfirm:SetIcon(Material("vgui/ttt/icon_credits_transparent"))
buttonConfirm:SetSize(self.sizes.widthButtonCredits, self.sizes.heightButton)
buttonConfirm:SetPos(self.sizes.widthMainArea - self.sizes.widthButtonCredits, self.sizes.padding + 1)
else
buttonConfirm:SetText("search_confirm_forbidden")
buttonConfirm:SetEnabled(false)
buttonConfirm:SetSize(self.sizes.widthButton, self.sizes.heightButton)
buttonConfirm:SetPos(self.sizes.widthMainArea - self.sizes.widthButton, self.sizes.padding + 1)
end
buttonConfirm:SetSize(self.sizes.widthButtonCredits, self.sizes.heightButton)
buttonConfirm:SetPos(self.sizes.widthMainArea - self.sizes.widthButtonCredits, self.sizes.padding + 1)
elseif data.credits > 0 and playerCanTakeCredits then
if data.credits == 1 then
buttonConfirm:SetText("search_confirm_credit")
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/client/vgui/cl_sb_row.lua
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function PANEL:UpdatePlayerData()
self.tag:SetText(ptag and GetTranslation(ptag.txt) or "")
self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)

self.sresult:SetVisible(ply.bodySearchResult and ply.bodySearchResult.isPublicPolicingSearch)
self.sresult:SetVisible(ply.bodySearchResult and ply.bodySearchResult.base.isPublicPolicingSearch)

-- more blue if a detective searched them
if ply.bodySearchResult and (LocalPlayer():GetSubRoleData().isPolicingRole or not ply.bodySearchResult.show) then
Expand Down
2 changes: 1 addition & 1 deletion gamemodes/terrortown/gamemode/server/sv_corpse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function CORPSE.ShowSearch(ply, rag, isCovert, isLongRange)
local sData = bodysearch.AssimilateSceneData(ply, rag, isCovert, isLongRange)

-- only in mode 0 everyone can confirm by pressing E
if bodysearch.GetInspectConfirmMode() == 0 or sData.isPublicPolicingSearch then
if bodysearch.GetInspectConfirmMode() == 0 or sData.base.isPublicPolicingSearch then
-- only give credits if body is also confirmed
if not isCovert then
bodysearch.GiveFoundCredits(ply, rag, isLongRange, sData.searchUID)
Expand Down
46 changes: 32 additions & 14 deletions lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,23 @@ if SERVER then
function bodysearch.AssimilateSceneData(inspector, rag, isCovert, isLongRange)

Check failure on line 130 in lua/ttt2/libraries/bodysearch.lua

View workflow job for this annotation

GitHub Actions / doc-check

Missing essential param --> "Missing '@realm' in function 'bodysearch.AssimilateSceneData'"

Check failure on line 130 in lua/ttt2/libraries/bodysearch.lua

View workflow job for this annotation

GitHub Actions / doc-check

Param mismatch --> "In 'function' datastructure ('function bodysearch.AssimilateSceneData(inspector, rag, isCovert, isLongRange)'), detected params (0): " "Expected Params (4): " "- 'inspector'" "- 'rag'" "- 'isCovert'" "- 'isLongRange'"
local sData = {}
local inspectorRoleData = inspector:GetSubRoleData()
local isPublicPolicingSearch = inspector:IsActive() and inspectorRoleData.isPolicingRole and inspectorRoleData.isPublicRole

-- hot-reloads can break the data, therefore we have to sanitize it
rag.scene = rag.scene or {}

-- data that is available to everyone
sData.searchUID = mathFloor(rag:EntIndex() + (rag.time or 0))
sData.inspector = inspector
sData.base = {}
sData.base.inspector = inspector
sData.base.isPublicPolicingSearch = isPublicPolicingSearch and not isCovert

sData.playerModel = rag.scene.plyModel or ""
sData.credits = CORPSE.GetCredits(rag, 0)
sData.ragOwner = player.GetBySteamID64(rag.sid64)
sData.isPublicPolicingSearch = inspector:IsActive() and inspectorRoleData.isPolicingRole and inspectorRoleData.isPublicRole and not isCovert
sData.credits = CORPSE.GetCredits(rag, 0)
sData.searchUID = mathFloor(rag:EntIndex() + (rag.time or 0))

-- if a non-public or non-policing role tries to search a body in mode 2, nothing happens
if cvInspectConfirmMode:GetInt() == 2 and not sData.isPublicPolicingSearch and not inspector:IsSpec() then
if cvInspectConfirmMode:GetInt() == 2 and not isPublicPolicingSearch and not inspector:IsSpec() then
return sData
end

Expand Down Expand Up @@ -244,7 +247,7 @@ if CLIENT then
-- @realm shared
hook.Run("TTTBodySearchEquipment", searchStreamData, eq)

searchStreamData.show = LocalPlayer() == searchStreamData.inspector
searchStreamData.show = LocalPlayer() == searchStreamData.base.inspector

if searchStreamData.show then
-- if there is more elaborate data already available
Expand All @@ -257,7 +260,7 @@ if CLIENT then
end

-- add this hack here to keep compatibility to the old scoreboard
searchStreamData.show_sb = searchStreamData.show or searchStreamData.isPublicPolicingSearch
searchStreamData.show_sb = searchStreamData.show or searchStreamData.base.isPublicPolicingSearch

-- cache search result in rag.bodySearchResult, e.g. useful for scoreboard
bodysearch.StoreSearchResult(searchStreamData)
Expand Down Expand Up @@ -770,20 +773,35 @@ if CLIENT then
local ply = sData.ragOwner
local rag = sData.rag

-- do not store if searching player (client) is spectator
if LocalPlayer():IsSpec() then return end

-- if the currently stored search result is by a public policing role, it should be kept
-- it can be overwritten by another public policing role though
if ply.bodySearchResult and ply.bodySearchResult.isPublicPolicingSearch
and not sData.isPublicPolicingSearch
then return end
-- data can still be updated, but the original base is kept
local oldBase
if ply.bodySearchResult and ply.bodySearchResult.base and ply.bodySearchResult.base.isPublicPolicingSearch
and not sData.base.isPublicPolicingSearch
then
oldBase = sData.base
end

-- do not store if searching player (client) is spectator
if LocalPlayer():IsSpec() then return end
-- merge new data into old data
-- this is useful if a player had good data on a body from another source
-- and now gets updated info on it as it now only replaces the newly added
-- entries
local newData = ply.bodySearchResult or {}
table.Merge(newData, sData)

-- keep the original finder info if previously searched by public policing role
newData.base = oldBase or newData.base

ply.bodySearchResult = sData
ply.bodySearchResult = newData

-- also store data in the ragdoll for targetID
if not IsValid(rag) then return end
rag.bodySearchResult = sData

rag.bodySearchResult = newData
end

function bodysearch.PlayerHasDetailedSearchResult(ply)
Expand Down
4 changes: 2 additions & 2 deletions lua/ttt2/libraries/targetid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ function targetid.HUDDrawTargetIDRagdolls(tData)
tData:SetSubtitle(ParT("corpse_hint_spec", key_params))
elseif bodysearch.GetInspectConfirmMode() == 2 and not roleDataClient.isPolicingRole and not roleDataClient.isPublicRole then
-- a detective added search results, this should change the targetID
if ent.bodySearchResult and ent.bodySearchResult.isPublicPolicingSearch then
if ent.bodySearchResult and ent.bodySearchResult.base and ent.bodySearchResult.base.isPublicPolicingSearch then
tData:SetSubtitle(ParT("corpse_hint_public_policing_searched", key_params))
else
tData:SetSubtitle(ParT("corpse_hint_no_inspect", key_params))
Expand Down Expand Up @@ -528,7 +528,7 @@ function targetid.HUDDrawTargetIDRagdolls(tData)
end

-- add info if searched by detectives
if ent.bodySearchResult and ent.bodySearchResult.isPublicPolicingSearch then
if ent.bodySearchResult and ent.bodySearchResult.base and ent.bodySearchResult.base.isPublicPolicingSearch then
tData:AddDescriptionLine(
TryT("corpse_searched_by_detective"),
roles.DETECTIVE.ltcolor,
Expand Down

0 comments on commit 60cb90a

Please sign in to comment.