From ea735b47b04c4760ef9a301f494fa9aff1f812e0 Mon Sep 17 00:00:00 2001
From: Alphas00 <154434082+Alphas00@users.noreply.github.com>
Date: Tue, 10 Sep 2024 21:20:42 +0200
Subject: [PATCH] Permafat restored, cryo bug fix
Bug that caused cryopods to not teleport afk people fixed
Fixed issues regarding saving persistent fat or permanent weight while in another player's character
---
GainStation13/code/mechanics/fatness.dm | 35 ++++++++++++++++++
GainStation13/code/mechanics/permanent_fat.dm | 37 ++++++++++++++++++-
.../modules/client/preferences/preferences.dm | 2 +
.../reagents/chemistry/reagents/fermi_fat.dm | 5 ++-
code/__HELPERS/roundend.dm | 9 +++--
code/modules/client/preferences.dm | 11 +++++-
code/modules/client/preferences_savefile.dm | 4 ++
.../code/game/machinery/cryopod.dm | 7 ++--
8 files changed, 99 insertions(+), 11 deletions(-)
diff --git a/GainStation13/code/mechanics/fatness.dm b/GainStation13/code/mechanics/fatness.dm
index 00c9aa8a..7be44561 100644
--- a/GainStation13/code/mechanics/fatness.dm
+++ b/GainStation13/code/mechanics/fatness.dm
@@ -11,6 +11,8 @@ GLOBAL_LIST_INIT(uncapped_resize_areas, list(/area/bridge, /area/crew_quarters,
var/fat_hiders = list()
//The actual value a mob is at. Is equal to fatness if fat_hider is FALSE.
var/fatness_real = 0
+ //Permanent fatness, which sticks around between rounds
+ var/fatness_perma = 0
///At what rate does the parent mob gain weight? 1 = 100%
var/weight_gain_rate = 1
//At what rate does the parent mob lose weight? 1 = 100%
@@ -49,6 +51,7 @@ GLOBAL_LIST_INIT(uncapped_resize_areas, list(/area/bridge, /area/crew_quarters,
fatness = fatness_real //Make their current fatness their real fatness
hiders_apply() //Check and apply hiders
+ perma_apply() //Check and apply for permanent fat
xwg_resize() //Apply XWG
return TRUE
@@ -138,10 +141,42 @@ GLOBAL_LIST_INIT(uncapped_resize_areas, list(/area/bridge, /area/crew_quarters,
if(client?.prefs?.max_weight) //Check their prefs
fatness = min(fatness, (client?.prefs?.max_weight - 1)) //And make sure it's not above their preferred max
+/mob/living/carbon/proc/perma_apply()
+ if(fatness_perma > 0) //Check if we need to make calcs at all
+ fatness = fatness + fatness_perma //Add permanent fat to fatness
+ if(client?.prefs?.max_weight) //Check for max weight prefs
+ fatness = min(fatness, (client?.prefs?.max_weight - 1)) //Apply max weight prefs
+
+/mob/living/carbon/proc/adjust_perma(adjustment_amount, type_of_fattening = FATTENING_TYPE_ITEM)
+ if(!client)
+ return FALSE
+ if(!client.prefs.weight_gain_permanent)
+ return FALSE
+
+ if(!adjustment_amount || !type_of_fattening)
+ return FALSE
+
+ if(!HAS_TRAIT(src, TRAIT_UNIVERSAL_GAINER) && client?.prefs)
+ if(!check_weight_prefs(type_of_fattening))
+ return FALSE
+ var/amount_to_change = adjustment_amount
+
+ if(adjustment_amount > 0)
+ amount_to_change = amount_to_change * weight_gain_rate
+ else
+ amount_to_change = amount_to_change * weight_loss_rate
+
+ fatness_perma += amount_to_change
+ fatness_perma = max(fatness_perma, MINIMUM_FATNESS_LEVEL)
+
+ if(client?.prefs?.max_weight) // GS13
+ fatness_perma = min(fatness_perma, (client?.prefs?.max_weight - 1))
+
/mob/living/carbon/human/handle_breathing(times_fired)
. = ..()
fatness = fatness_real
hiders_apply()
+ perma_apply()
xwg_resize()
/mob/living/carbon/proc/xwg_resize()
diff --git a/GainStation13/code/mechanics/permanent_fat.dm b/GainStation13/code/mechanics/permanent_fat.dm
index ed926465..e07ec8f9 100644
--- a/GainStation13/code/mechanics/permanent_fat.dm
+++ b/GainStation13/code/mechanics/permanent_fat.dm
@@ -1,7 +1,36 @@
+/mob/living/carbon
+ var/savekey
+ var/ckeyslot
+
+/mob/living/carbon/proc/perma_fat_save(mob/living/carbon/character)
+ var/key = savekey
+ if(!key)
+ return FALSE
+ var/filename = "preferences.sav"
+ var/path = "data/player_saves/[key[1]]/[key]/[filename]"
+
+ var/savefile/S = new /savefile(path)
+ if(!path)
+ return FALSE
+
+ if(character.ckeyslot)
+ var/slot = character.ckeyslot
+ S.cd = "/character[slot]"
+
+ var/persi
+ S["weight_gain_persistent"] >> persi
+ if(persi)
+ WRITE_FILE(S["starting_weight"] , character.fatness_real)
+ var/perma
+ S["weight_gain_permanent"] >> perma
+ if(S["weight_gain_permanent"])
+ WRITE_FILE(S["permanent_fat"] , character.fatness_perma)
+
+/*
/datum/preferences/proc/perma_fat_save(character)
if(iscarbon(character))
var/mob/living/carbon/C = character
- if(!C.client.prefs.weight_gain_permanent)
+ if(!C.client.prefs.weight_gain_permanent && !C.client.prefs.weight_gain_persistent)
return FALSE
if(!path)
return 0
@@ -17,4 +46,8 @@
return 0
S.cd = "/character[default_slot]"
- WRITE_FILE(S["starting_weight"] , C.fatness_real)
+ if(C.client.prefs.weight_gain_persistent)
+ WRITE_FILE(S["starting_weight"] , C.fatness_real)
+ if(C.client.prefs.weight_gain_permanent)
+ WRITE_FILE(S["permanent_fat"] , C.fatness_perma)
+*/
diff --git a/GainStation13/code/modules/client/preferences/preferences.dm b/GainStation13/code/modules/client/preferences/preferences.dm
index 99a0f618..d6bfb035 100644
--- a/GainStation13/code/modules/client/preferences/preferences.dm
+++ b/GainStation13/code/modules/client/preferences/preferences.dm
@@ -19,6 +19,8 @@
var/blueberry_inflation = FALSE
///Extreme weight gain
var/weight_gain_extreme = FALSE
+ ///Persistant fatness
+ var/weight_gain_persistent = FALSE
///Permanent weight gain
var/weight_gain_permanent = FALSE
/// At what weight will you start to get stuck in airlocks?
diff --git a/GainStation13/code/modules/reagents/chemistry/reagents/fermi_fat.dm b/GainStation13/code/modules/reagents/chemistry/reagents/fermi_fat.dm
index e53e4692..2e496875 100644
--- a/GainStation13/code/modules/reagents/chemistry/reagents/fermi_fat.dm
+++ b/GainStation13/code/modules/reagents/chemistry/reagents/fermi_fat.dm
@@ -53,6 +53,7 @@
if(!iscarbon(M))
return..()
M.adjust_fatness(30, FATTENING_TYPE_CHEM)
+ M.adjust_perma(1, FATTENING_TYPE_CHEM)
..()
. = 1
@@ -62,6 +63,7 @@
return..()
var/mob/living/carbon/C = M
C.adjust_fatness(20, FATTENING_TYPE_CHEM)
+ C.adjust_perma(1, FATTENING_TYPE_CHEM)
..()
/datum/reagent/fermi_fat/overdose_start(mob/living/M)
@@ -179,7 +181,8 @@
/datum/reagent/fermi_slim/on_mob_life(mob/living/carbon/M)
if(!iscarbon(M))
return..()
- M.adjust_fatness(-50, FATTENING_TYPE_CHEM)
+ M.adjust_fatness(-50, FATTENING_TYPE_WEIGHT_LOSS)
+ M.adjust_perma(-5, FATTENING_TYPE_WEIGHT_LOSS)
..()
. = 1
diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm
index f3ca9244..9be186b8 100644
--- a/code/__HELPERS/roundend.dm
+++ b/code/__HELPERS/roundend.dm
@@ -6,10 +6,11 @@
//GS13 Process permanent fat
for(var/mob/m in GLOB.player_list)
- if(m.client.prefs)
- if(m.client.ckey)
- m.client.prefs.perma_fat_save(m)
-
+ if(iscarbon(m))
+ var/mob/living/carbon/C = m
+ if(C)
+ C.perma_fat_save(C)
+
gather_antag_data()
record_nuke_disk_location()
var/json_file = file("[GLOB.log_directory]/round_end_data.json")
diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm
index beb1b99d..e7d9d311 100644
--- a/code/modules/client/preferences.dm
+++ b/code/modules/client/preferences.dm
@@ -105,9 +105,11 @@ GLOBAL_LIST_EMPTY(preferences_datums)
//GS13
var/starting_weight = 0 //how thicc you wanna be at start
+ var/permanent_fat = 0 //If it isn't the consequences of your own actions
var/wg_rate = 0.5
var/wl_rate = 0.5
var/voice = "human"
+ var/ckeyslot
//HS13 jobs
var/sillyroles = TRUE //for clown and mime
@@ -1076,7 +1078,8 @@ GLOBAL_LIST_EMPTY(preferences_datums)
dat += "This preference functions similar to the one before but allows for items with more drastic effects. Do not enable this if you aren't okay with more drastic things happening to your character.
"
dat += "Extreme Fatness Vulnerability:[extreme_fatness_vulnerable == TRUE ? "Enabled" : "Disabled"]
"
dat += "Extreme Weight Gain (Sprite Size scales with weight):[weight_gain_extreme == TRUE ? "Enabled" : "Disabled"]
"
- dat += "Weight Gain Permanent (endround/cryo weight becomes your new start weight):[weight_gain_permanent == TRUE ? "Enabled" : "Disabled"]
"
+ dat += "Persistent Fat (endround/cryo weight becomes your new start weight):[weight_gain_persistent == TRUE ? "Enabled" : "Disabled"]
"
+ dat += "Permanent Weight (hard to remove and persistent weight):[weight_gain_permanent == TRUE ? "Enabled" : "Disabled"]
"
dat += "