From 9c18c99c3791267534b56f338dbf7684e2e80aff Mon Sep 17 00:00:00 2001 From: Werner <1331699+Arrow768@users.noreply.github.com> Date: Sat, 6 Jan 2024 16:16:25 +0100 Subject: [PATCH] Death Stats Fix (#18100) * Death Stats Fix Changes how the coordinates for the death stats are stored. -> One column for x,y,z instead of all mashed into one column * Add missing GLOB * convert indentation * Rebase to latest master * Adds the attackers char id aswell. * Slight reformatting and add constraint * Fix indentation * Adds another check --------- Co-authored-by: Werner --- SQL/migrate-2023/V007__death_table_fix.sql | 9 ++++ code/controllers/subsystems/statistics.dm | 53 +++++++++++--------- html/changelogs/arrow768-death-stats-fix.yml | 41 +++++++++++++++ 3 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 SQL/migrate-2023/V007__death_table_fix.sql create mode 100644 html/changelogs/arrow768-death-stats-fix.yml diff --git a/SQL/migrate-2023/V007__death_table_fix.sql b/SQL/migrate-2023/V007__death_table_fix.sql new file mode 100644 index 00000000000..0b239c4235a --- /dev/null +++ b/SQL/migrate-2023/V007__death_table_fix.sql @@ -0,0 +1,9 @@ +-- +-- Adds a column for single coordinate instead of mashing them into one column +-- +ALTER TABLE `ss13_death` + ADD COLUMN `loc_x` INT NULL AFTER `oxyloss`, + ADD COLUMN `loc_y` INT NULL AFTER `loc_x`, + ADD COLUMN `loc_z` INT NULL AFTER `loc_y`, + ADD COLUMN `lachar_id` INT NULL DEFAULT NULL AFTER `lackey`, + ADD CONSTRAINT `FK_ss13_death_ss13_characters_lachar_id` FOREIGN KEY (`lachar_id`) REFERENCES `ss13_characters` (`id`) ON UPDATE CASCADE ON DELETE CASCADE; diff --git a/code/controllers/subsystems/statistics.dm b/code/controllers/subsystems/statistics.dm index 8ffe4fa1726..5688c3a8fae 100644 --- a/code/controllers/subsystems/statistics.dm +++ b/code/controllers/subsystems/statistics.dm @@ -241,36 +241,41 @@ GENERAL_PROTECT_DATUM(/datum/controller/subsystem/statistics) return if(!istype(H, /mob/living/carbon/human) && !istype(H, /mob/living/silicon/robot)) return - if(!H.key || !H.mind) - return var/area/placeofdeath = get_area(H) var/podname = placeofdeath ? "[placeofdeath]" : "Unknown area" if(!establish_db_connection(GLOB.dbcon)) log_game("SQL ERROR during death reporting. Failed to connect.") - else - var/DBQuery/query = GLOB.dbcon.NewQuery("INSERT INTO ss13_death (name, ckey, char_id, job, special, pod, tod, laname, lackey, gender, bruteloss, fireloss, brainloss, oxyloss, coord) VALUES \ - (:name:, :ckey:, :char_id:, :job:, :special:, :pod:, :tod:, :laname:, :lackey:, :gender:, :bruteloss:, :fireloss:, :brainloss:, :oxyloss:, :coord:')") - if(!query.Execute(list( - "name"=H.real_name, - "ckey"=H.ckey, - "char_id"=H.character_id, - "job"=H?.mind.assigned_role, - "special"=H?.mind.special_role, - "pod"=podname, - "tod"=time2text(world.realtime, "YYYY-MM-DD hh:mm:ss"), - "laname"=H?.lastattacker?.real_name, - "lackey"=H?.lastattacker?.ckey, - "gender"=H.gender, - "bruteloss"=H.getBruteLoss(), - "fireloss"=H.getFireLoss(), - "brainloss"=H.getBrainLoss(), - "oxyloss"=H.getOxyLoss(), - "coord"="[H.x], [H.y], [H.z]") - )) - var/err = query.ErrorMsg() - log_game("SQL ERROR during death reporting. Error : \[[err]\]\n") + return + + //Prepare location data + var/turf/T = get_turf(H) + + var/DBQuery/query = GLOB.dbcon.NewQuery("INSERT INTO ss13_death (name, ckey, char_id, job, special, pod, tod, laname, lackey, lachar_id, gender, bruteloss, fireloss, brainloss, oxyloss, loc_x, loc_y, loc_z) VALUES \ + (:name:, :ckey:, :char_id:, :job:, :special:, :pod:, :tod:, :laname:, :lackey:, :lachar_id:, :gender:, :bruteloss:, :fireloss:, :brainloss:, :oxyloss:, :loc_x:, :loc_y:, :loc_z:)") + if(!query.Execute(list( + "name"=H.real_name, + "ckey"=H.ckey, + "char_id"=H.character_id, + "job"=H?.mind?.assigned_role, + "special"=H?.mind?.special_role, + "pod"=podname, + "tod"=time2text(world.realtime, "YYYY-MM-DD hh:mm:ss"), + "laname"=H?.lastattacker?.real_name, + "lackey"=H?.lastattacker?.ckey, + "lachar_id"=H?.lastattacker?.character_id, + "gender"=H.gender, + "bruteloss"=H.getBruteLoss(), + "fireloss"=H.getFireLoss(), + "brainloss"=H.getBrainLoss(), + "oxyloss"=H.getOxyLoss(), + "loc_x"=T?.x, + "loc_y"=T?.y, + "loc_z"=T?.z) + )) + var/err = query.ErrorMsg() + log_game("SQL ERROR during death reporting. Error : \[[err]\]\n") /datum/controller/subsystem/statistics/proc/IncrementSimpleStat(stat) . = TRUE diff --git a/html/changelogs/arrow768-death-stats-fix.yml b/html/changelogs/arrow768-death-stats-fix.yml new file mode 100644 index 00000000000..50439606842 --- /dev/null +++ b/html/changelogs/arrow768-death-stats-fix.yml @@ -0,0 +1,41 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +# admin +# backend +# security +# refactor +################################# + +# Your name. +author: arrow768 + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - backend: "Changes how the coordinates for the death stats are stored."