Skip to content

Commit

Permalink
Merge pull request #99 from cyb3rpsych0s1s/feat/tobacco
Browse files Browse the repository at this point in the history
Tobacco
  • Loading branch information
Roms1383 authored Feb 20, 2024
2 parents cddacba + 3c23160 commit dfa093f
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 35 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 6 additions & 2 deletions scripts/Addicted/Definitions.reds
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ enum Consumable {
BlackLace = 8,
CarryCapacityBooster = 9,
NeuroBlocker = 10,
Tobacco = 11
}

public static func Consumables() -> array<Consumable> {
Expand All @@ -380,7 +381,8 @@ public static func Consumables() -> array<Consumable> {
Consumable.StaminaBooster,
Consumable.BlackLace,
Consumable.CarryCapacityBooster,
Consumable.NeuroBlocker
Consumable.NeuroBlocker,
Consumable.Tobacco
];
}

Expand All @@ -397,6 +399,7 @@ enum Addiction {
Neuros = 2,
BlackLace = 3,
Alcohol = 4,
Tobacco = 5,
}

public static func Addictions() -> array<Addiction> {
Expand All @@ -405,7 +408,8 @@ public static func Addictions() -> array<Addiction> {
Addiction.Anabolics,
Addiction.Neuros,
Addiction.BlackLace,
Addiction.Alcohol
Addiction.Alcohol,
Addiction.Tobacco
];
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/Addicted/Helper.reds
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class Helper {
return [Consumable.BlackLace];
case Addiction.Alcohol:
return [Consumable.Alcohol];
case Addiction.Tobacco:
return [Consumable.Tobacco];
default:
break;
}
Expand Down
78 changes: 45 additions & 33 deletions scripts/Addicted/System.reds
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class AddictedSystem extends ScriptableSystem {
private let stimulantManager: ref<StimulantManager>;
private let blacklaceManager: ref<BlackLaceManager>;
private let alcoholManager: ref<AlcoholManager>;
private let tobaccoManager: ref<TobaccoManager>;
private persistent let consumptions: ref<Consumptions>;
public let restingSince: Float;
Expand All @@ -44,10 +45,44 @@ public class AddictedSystem extends ScriptableSystem {
private let updateSymtomsID: DelayID;
private let healingRechargeDurationModifier: ref<gameStatModifierData>;
private func RegisterListeners(player: ref<PlayerPuppet>) -> Void {
this.stimulantManager = new StimulantManager();
this.stimulantManager.Register(player);
this.blacklaceManager = new BlackLaceManager();
this.blacklaceManager.Register(player);
this.alcoholManager = new AlcoholManager();
this.alcoholManager.Register(player);
this.tobaccoManager = new TobaccoManager();
this.tobaccoManager.Register(player);
this.onoManager = new AudioManager();
this.onoManager.Register(player);
}
private func UnregisterListeners(player: ref<PlayerPuppet>) -> Void {
this.onoManager.Unregister(player);
this.onoManager = null;
this.stimulantManager.Unregister(player);
this.stimulantManager = null;
this.blacklaceManager.Unregister(player);
this.blacklaceManager = null;
this.alcoholManager.Unregister(player);
this.alcoholManager = null;
this.tobaccoManager.Unregister(player);
this.tobaccoManager = null;
}
private final func OnPlayerAttach(request: ref<PlayerAttachRequest>) -> Void {
let player: ref<PlayerPuppet> = GetPlayer(this.GetGameInstance());
if IsDefined(player) {
E(s"initialize system on player attach");
E(s"on player attach");
this.player = player;
this.delaySystem = GameInstance.GetDelaySystem(this.player.GetGame());
this.timeSystem = GameInstance.GetTimeSystem(this.player.GetGame());
Expand All @@ -57,22 +92,18 @@ public class AddictedSystem extends ScriptableSystem {
callback.system = this;
this.updateSymtomsID = this.delaySystem.DelayCallback(callback, 600., true);
this.stimulantManager = new StimulantManager();
this.stimulantManager.Register(this.player);
this.blacklaceManager = new BlackLaceManager();
this.blacklaceManager.Register(this.player);
this.alcoholManager = new AlcoholManager();
this.alcoholManager.Register(this.player);
this.onoManager = new AudioManager();
this.onoManager.Register(this.player);
this.RegisterListeners(this.player);
this.RefreshConfig();
} else { F(s"no player found!"); }
}
public final func OnPlayerDetach(player: ref<PlayerPuppet>) -> Void {
E(s"on player detach");
this.UnregisterListeners(this.player);
this.player = null;
}
private func OnAttach() -> Void {
E(s"on attach system");
this.callbackSystem = GameInstance.GetCallbackSystem();
Expand All @@ -87,33 +118,14 @@ public class AddictedSystem extends ScriptableSystem {
private func OnDetach() -> Void {
E(s"on detach system");
this.onoManager.Unregister(this.player);
this.onoManager = null;
this.stimulantManager.Unregister(this.player);
this.stimulantManager = null;
this.blacklaceManager.Unregister(this.player);
this.blacklaceManager = null;
this.UnregisterListeners(this.player);
OnAddictedPostDetach(this);
}
private func OnRestored(saveVersion: Int32, gameVersion: Int32) -> Void {
E(s"on restored system");
this.stimulantManager = new StimulantManager();
this.stimulantManager.Register(this.player);
this.blacklaceManager = new BlackLaceManager();
this.blacklaceManager.Register(this.player);
this.alcoholManager = new AlcoholManager();
this.alcoholManager.Register(this.player);
this.onoManager = new AudioManager();
this.onoManager.Register(this.player);
this.RegisterListeners(this.player);
}
private cb func OnPreSave(event: ref<GameSessionEvent>) {
Expand Down
14 changes: 14 additions & 0 deletions scripts/Addicted/helpers/Generic.reds
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class Generic {
if Generic.IsBlackLace(id) { return Consumable.BlackLace; }
if Generic.IsOxyBooster(id) { return Consumable.OxyBooster; }
if Generic.IsNeuroBlocker(id) { return Consumable.NeuroBlocker; }
if Generic.IsTobacco(id)
|| Generic.IsLighter(id) { return Consumable.Tobacco; }
return Consumable.Invalid;
}
Expand All @@ -35,6 +37,8 @@ public class Generic {
return Addiction.BlackLace;
case Consumable.Alcohol:
return Addiction.Alcohol;
case Consumable.Tobacco:
return Addiction.Tobacco;
default:
break;
}
Expand Down Expand Up @@ -111,6 +115,16 @@ public class Generic {
return StrContains(str, "Alcohol");
}
public static func IsTobacco(id: TweakDBID) -> Bool {
let str = TDBID.ToStringDEBUG(id);
return StrContains(str, "cigar");
}
public static func IsLighter(id: TweakDBID) -> Bool {
let str = TDBID.ToStringDEBUG(id);
return StrContains(str, "lighter");
}
public static func IsMaxDOC(id: TweakDBID) -> Bool {
let str = TDBID.ToStringDEBUG(id);
let suffix = StrAfterFirst(str, ".");
Expand Down
2 changes: 2 additions & 0 deletions scripts/Addicted/helpers/Translations.reds
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class Translations {
return [n"Mod-Addicted-Chemical-Dynorphin", n"Mod-Addicted-Chemical-Methadone"];
case Consumable.CarryCapacityBooster:
return [n"Mod-Addicted-Chemical-Testosterone", n"Mod-Addicted-Chemical-Oxandrin"];
case Consumable.Tobacco:
return [n"Mod-Addicted-Chemical-Nicotine"];
}
}
}
54 changes: 54 additions & 0 deletions scripts/Addicted/managers/TobaccoManager.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Addicted.Manager

import Addicted.System.AddictedSystem
import Addicted.Helper
import Addicted.Helpers.Generic
import Addicted.{Threshold, Addiction, Consumable}
import Addicted.Utils.E

public class CigaretteAttachment extends AttachmentSlotsScriptCallback {
public let owner: ref<PlayerPuppet>;
public func OnItemEquipped(slot: TweakDBID, item: ItemID) -> Void {
let system: ref<AddictedSystem>;
let threshold: Threshold;
let notable: Bool;
let severe: Bool;
let id: TweakDBID;
if Generic.IsTobacco(ItemID.GetTDBID(item))
|| Generic.IsLighter(ItemID.GetTDBID(item)) {
E(s"cigarette attachment");
system = AddictedSystem.GetInstance(this.owner.GetGame());
system.OnConsumeItem(item);
threshold = system.Threshold(Addiction.Tobacco);
notable = EnumInt(threshold) == EnumInt(Threshold.Notably);
severe = EnumInt(threshold) == EnumInt(Threshold.Severely);
if notable || severe {
if notable { id = t"BaseStatusEffect.ShortBreath"; }
else { id = t"BaseStatusEffect.BreathLess"; }
StatusEffectHelper.ApplyStatusEffect(this.owner, id, 0.2);
}
}
}
}

public class TobaccoManager extends IScriptable {
private let listener: ref<AttachmentSlotsScriptListener>;
public func Register(player: ref<PlayerPuppet>) -> Void {
let transactions: ref<TransactionSystem>;
if player != null && !IsDefined(this.listener) {
E(s"register tobacco manager");
transactions = GameInstance.GetTransactionSystem(player.GetGame());
let callback = new CigaretteAttachment();
callback.owner = player;
this.listener = transactions.RegisterAttachmentSlotListener(player, callback);
}
}
public func Unregister(player: ref<PlayerPuppet>) -> Void {
let transactions: ref<TransactionSystem>;
if player != null && IsDefined(this.listener) {
E(s"unregister tobacco manager");
transactions = GameInstance.GetTransactionSystem(player.GetGame());
transactions.UnregisterAttachmentSlotListener(player, this.listener);
}
}
}
Loading

0 comments on commit dfa093f

Please sign in to comment.