From 8ee853997c000e463fa73e65ffb0fad1a7af1e0d Mon Sep 17 00:00:00 2001 From: Roms1383 Date: Wed, 3 Jan 2024 16:45:38 +0700 Subject: [PATCH] :necktie: improve logic for rest rested stays the same, but only refreshed grants a minor decrease once a day --- scripts/Addicted/System.reds | 56 ++++++++++++++++++++-------- scripts/Addicted/helpers/Effect.reds | 1 + 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/scripts/Addicted/System.reds b/scripts/Addicted/System.reds index 40ad36df..9fd7ed7d 100644 --- a/scripts/Addicted/System.reds +++ b/scripts/Addicted/System.reds @@ -28,6 +28,7 @@ public class AddictedSystem extends ScriptableSystem { private persistent let consumptions: ref; public let restingSince: Float; + private persistent let lastEnergized: Float; private persistent let hasBiomonitorEquipped: Bool; private persistent let hasDetoxifierEquipped: Bool; @@ -203,12 +204,16 @@ public class AddictedSystem extends ScriptableSystem { } public func OnRested(id: TweakDBID) -> Void { - let sleep = Effect.IsSleep(id); + if Effect.IsSleep(id) { this.OnSlept(); } + else if Effect.IsRefreshed(id) { this.OnRefreshed(); } + } + + private func OnSlept() -> Void { let now = this.timeSystem.GetGameTimeStamp(); let duration = now - this.restingSince; let minimum = 60. * 60. * 6.; // 6h let light = duration < minimum; - if sleep && light { + if light { E(s"not enough sleep ! no wean off"); return; } @@ -222,28 +227,21 @@ public class AddictedSystem extends ScriptableSystem { let under_influence = false; if this.IsHard() { under_influence = this.SleptUnderInfluence(id) && !this.hasDetoxifierEquipped; - if sleep && under_influence + if under_influence { E(s"slept under influence, no weaning off for \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); } } - if consumption.current > 0 { - // energized and refreshed are not affected - if !sleep || !under_influence { + if !under_influence { + if consumption.current > 0 { let current = consumption.current; let next = Max(current - Helper.Resilience(id) - this.player.CyberwareImmunity(), 0); consumption.current = next; - if sleep { - E(s"slept well, weaning off \(ToString(current)) -> \(ToString(next)) for \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); - } - else - { - E(s"energized or refreshed, weaning off \(ToString(current)) -> \(ToString(next)) for \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); - } + E(s"slept well, weaning off \(ToString(current)) -> \(ToString(next)) for \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); + } else { + this.consumptions.Remove(id); + E(s"clean again from \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); } - } else { - this.consumptions.Remove(id); - E(s"clean again from \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); } } @@ -252,6 +250,32 @@ public class AddictedSystem extends ScriptableSystem { this.delaySystem.DelayCallbackNextFrame(callback); } + private func OnRefreshed() -> Void { + let now = this.timeSystem.GetGameTimeStamp(); + let duration = now - this.lastEnergized; + let minimum = 60. * 60. * 24.; // 24h + let less_than_a_day = duration < minimum; + this.lastEnergized = now; + if less_than_a_day { + E(s"refreshed bonus only applies once a day"); + return; + } + + let size = this.consumptions.Size(); + if size == 0 { return; } + let ids = this.consumptions.Items(); + let consumption: ref; + for id in ids { + consumption = this.consumptions.Get(id) as Consumption; + if consumption.current > 0 { + let current = consumption.current; + let next = Max(current - 1, 0); + consumption.current = next; + E(s"well refreshed, weaning slightly off \(ToString(current)) -> \(ToString(next)) for \(TDBID.ToStringDEBUG(ItemID.GetTDBID(id)))"); + } + } + } + public func ShrinkDoses() -> Void { let consumption: ref; let doses: array; diff --git a/scripts/Addicted/helpers/Effect.reds b/scripts/Addicted/helpers/Effect.reds index 5d831960..ed9425c4 100644 --- a/scripts/Addicted/helpers/Effect.reds +++ b/scripts/Addicted/helpers/Effect.reds @@ -19,6 +19,7 @@ public class Effect { } public static func IsSleep(id: TweakDBID) -> Bool { return Equals(id, t"HousingStatusEffect.Rested"); } + public static func IsRefreshed(id: TweakDBID) -> Bool { return Equals(id, t"HousingStatusEffect.Refreshed"); } public static func IsInstant(record: ref) -> Bool { if record.IsA(n"gamedataStatusEffect_Record") {