diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1691f22 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.png filter=lfs diff=lfs merge=lfs -text +*.jpg filter=lfs diff=lfs merge=lfs -text diff --git a/media/eddiesReceivedMultiplier_header.png b/media/eddiesReceivedMultiplier_header.png new file mode 100644 index 0000000..5243525 --- /dev/null +++ b/media/eddiesReceivedMultiplier_header.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:963fc8fbb0a46423bef01c2bcdf7ce905c8c7381899f597ffb5d46f1b489b9a0 +size 81080 diff --git a/media/erm_menu_showcase.jpg b/media/erm_menu_showcase.jpg new file mode 100644 index 0000000..585414a --- /dev/null +++ b/media/erm_menu_showcase.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b5240e124aaa27478d28dad37fb2ee04174c6caa49f60dccee6bac5391bd8705 +size 92098 diff --git a/src/r6/scripts/EddiesReceivedMult/erm_base.reds b/src/r6/scripts/EddiesReceivedMult/erm_base.reds index 946c879..47073bd 100644 --- a/src/r6/scripts/EddiesReceivedMult/erm_base.reds +++ b/src/r6/scripts/EddiesReceivedMult/erm_base.reds @@ -1,100 +1,125 @@ -// Eddies Received Multiplier by pMarK -// v1.1 - -module EddiesReceivedMult.Base - -public class EddiesReceivedMult { - private let multiplier: Float; - private let player: wref; - private let transactionSystem: ref; - private let blackboard: ref; - private let flag: Bool; - private let debugMode: Bool; - - public func Setup(player: wref) -> Void { - this.player = player; - this.transactionSystem = GameInstance.GetTransactionSystem(player.GetGame()); - this.blackboard = GameInstance.GetBlackboardSystem(player.GetGame()).Get(GetAllBlackboardDefs().UI_Notifications); - this.SetupSettings(); - } - - protected func SetupSettings() -> Void { - // ------ Settings Start ------ - - this.debugMode = false; // Show debug message every time the player receives eddies. - this.multiplier = 1.0; - - // ------ Settings End ------ - } - - public func DeltaEddies(itemDataQuantity: Int32, currentQuantity: Int32) -> Void { - let originalValue: Int32; - let newTotalValue: Int32; - let delta: Int32; - let msg: String; - let multValue: Float = this.GetMultiplier(); - - if this.ShouldDeltaEddies(multValue) { - originalValue = itemDataQuantity - currentQuantity; - newTotalValue = Cast(Cast(originalValue) * multValue); - delta = newTotalValue - originalValue; - - if originalValue == 0 { - // For some reason the game invokes 0 eddies received events. - // I noticed this when fighting enemies with bounties. At every kill a 0 eddie event is consumed. - // You actually get the total money when the fight is over. - return; - } - - if delta < 0 { - this.transactionSystem.RemoveItem(this.player, MarketSystem.Money(), -delta); - } - else { - this.transactionSystem.GiveItem(this.player, MarketSystem.Money(), delta); - - this.flag = true; - } - - if this.GetShowDebugMsg() { - msg = "Original value: " + originalValue + "\\n" + "New total: " + newTotalValue + "\\n" + "Delta: " + delta + "\\n" + "Multiplier: " + Cast(multValue * 100.0) + "%"; - - this.ShowMessage(msg); - } +module ERM.Base +import ERM.Settings.ERMSettings +import ERM.Settings.Menu + +public class ERMSystem extends ScriptableSystem { + private let player: ref; + private let transactionSystem: ref; + private let ermCallback: ref; + private let inventoryListener: ref; + private let lastRequestHandled: Bool; + private let settings: ref; + + private func OnPlayerAttach(request: ref) -> Void { + this.player = GameInstance.GetPlayerSystem(request.owner.GetGame()).GetLocalPlayerMainGameObject() as PlayerPuppet; + this.transactionSystem = GameInstance.GetTransactionSystem(this.GetGameInstance()); + + this.ermCallback = new ERMCallback(); + this.ermCallback.ermSys = this; + this.inventoryListener = this.transactionSystem.RegisterInventoryListener(this.player, this.ermCallback); + + this.settings = GetSettings(); + this.settings.Setup(); + + // this.Log("::OnPlayerAttach"); } - else { - this.flag = false; + + private func OnPlayerDetach(request: ref) -> Void { + this.transactionSystem.UnregisterInventoryListener(this.player, this.inventoryListener); + this.inventoryListener = null; + + // this.Log("::OnPlayerDetach"); } - } - protected func GetIsEnabled() -> Bool { - return true; - } + public func OnEddiesChanged(request: ref) -> Void { + let delta: Int32; + let multiplier: Float; + + // this.Log("::OnEddiesChanged"); + + if !this.settings.GetIsEnabled() { + // this.Log("ERM is disabled."); + + return; + } + + if request.diffAmount < 1 { + // this.Log("diffAmount was 0 or negative. Ignoring..."); + + return; + } + + if !this.lastRequestHandled { + multiplier = this.settings.GetMultiplier(); + + if multiplier < 0.1 { + multiplier = 1.0; + + // this.Log("Multiplier < 0.1, defaulting to 1.0"); + } + + if Equals(multiplier, 1.0) { + // this.Log("Multiplier == 1.0, no delta..."); + + return; + } + + delta = Cast(Cast(request.diffAmount) * multiplier) - request.diffAmount; - protected func GetMultiplier() -> Float { - return this.multiplier; - } + if delta > 0 { + this.transactionSystem.GiveItem(this.player, MarketSystem.Money(), delta); + } + else { + this.transactionSystem.RemoveItem(this.player, MarketSystem.Money(), -delta); + } - protected func GetShowDebugMsg() -> Bool { - return this.debugMode; - } + if this.settings.GetShowExtraEddiesMsg() { + GameInstance.GetActivityLogSystem(this.GetGameInstance()).AddLog("[ERM] Received " + delta + " extra eddies."); + } - protected func GetDebugMsgDuration() -> Float { - return 12.0; - } + this.lastRequestHandled = true; - private func ShouldDeltaEddies(multiplier: Float) -> Bool { - if multiplier == 1.0 || multiplier < 0.0 { - return false; + // this.Log("Request handled. " + request.diffAmount + " * " + multiplier + " = " + (delta + request.diffAmount)); + } + else { + this.lastRequestHandled = false; + + // this.Log("request not handled."); + } + } + + private func Log(msg: String) -> Void { + LogChannel(n"ERMSystem", msg); + } +} + +public class ERMCallback extends InventoryScriptCallback { + public let ermSys: ref; + + public func OnItemQuantityChanged(item: ItemID, diff: Int32, total: Uint32, flaggedAsSilent: Bool) -> Void { + let request: ref; + + if Equals(MarketSystem.Money(), item) { + if IsDefined(this.ermSys) { + request = new ERMHandleEddiesChangedRequest(); + request.diffAmount = diff; + + this.ermSys.QueueRequest(request); + } + } } +} - return !this.flag && this.GetIsEnabled(); - } +public class ERMHandleEddiesChangedRequest extends ScriptableSystemRequest { + public let diffAmount: Int32; +} - protected func ShowMessage(message : String) -> Void { - let warningMsg: SimpleScreenMessage; - warningMsg.isShown = true; - warningMsg.duration = this.GetDebugMsgDuration(); - warningMsg.message = message; - this.blackboard.SetVariant(GetAllBlackboardDefs().UI_Notifications.WarningMessage, ToVariant(warningMsg), true); - } +@if(!ModuleExists("ModSettingsModule")) +public func GetSettings() -> ref { + return new ERMSettings(); } + +@if(ModuleExists("ModSettingsModule")) +public func GetSettings() -> ref { + return new Menu(); +} \ No newline at end of file diff --git a/src/r6/scripts/EddiesReceivedMult/erm_menu.reds b/src/r6/scripts/EddiesReceivedMult/erm_menu.reds new file mode 100644 index 0000000..e8efba1 --- /dev/null +++ b/src/r6/scripts/EddiesReceivedMult/erm_menu.reds @@ -0,0 +1,50 @@ +module ERM.Settings + +public class Menu extends ERMSettings { + @runtimeProperty("ModSettings.mod", "Eddies Received Mult") + @runtimeProperty("ModSettings.category", "Main") + @runtimeProperty("ModSettings.displayName", "Enabled") + @runtimeProperty("ModSettings.description", "Enable/Disable mod.") + public let IsEnabled: Bool = true; + + @runtimeProperty("ModSettings.mod", "Eddies Received Mult") + @runtimeProperty("ModSettings.category", "Main") + @runtimeProperty("ModSettings.displayName", "Multiplier") + @runtimeProperty("ModSettings.description", "Eddies received will be multiplied by this value.") + @runtimeProperty("ModSettings.step", "0.1") + @runtimeProperty("ModSettings.min", "0.1") + @runtimeProperty("ModSettings.max", "5.0") + public let EddiesMultiplier: Float = 1.0; + + @runtimeProperty("ModSettings.mod", "Eddies Received Mult") + @runtimeProperty("ModSettings.category", "Extra") + @runtimeProperty("ModSettings.displayName", "Show Extra Eddies Msg") + @runtimeProperty("ModSettings.description", "Enable/Disable the showing of an extra eddies received activity log notification.") + public let ShowExtraEddiesMsg: Bool = false; + + public func Setup() -> Void { + RegisterMenu(this); + + LogChannel(n"ERMSystem", "ModSettingsModule found. Using menu."); + } + + public func GetIsEnabled() -> Bool { + return this.IsEnabled; + } + + public func GetMultiplier() -> Float { + return this.EddiesMultiplier; + } + + public func GetShowExtraEddiesMsg() -> Bool { + return this.ShowExtraEddiesMsg; + } +} + +@if(!ModuleExists("ModSettingsModule")) +public func RegisterMenu(listener: ref) {} + +@if(ModuleExists("ModSettingsModule")) +public func RegisterMenu(listener: ref) { + ModSettings.RegisterListenerToClass(listener); +} \ No newline at end of file diff --git a/src/r6/scripts/EddiesReceivedMult/erm_overrides.reds b/src/r6/scripts/EddiesReceivedMult/erm_overrides.reds deleted file mode 100644 index 1c60dda..0000000 --- a/src/r6/scripts/EddiesReceivedMult/erm_overrides.reds +++ /dev/null @@ -1,36 +0,0 @@ -// Eddies Received Multiplier by pMarK -// v1.1 - -module EddiesReceivedMult.Overrides -import EddiesReceivedMult.Base.EddiesReceivedMult - -@if(ModuleExists("EddiesReceivedMult.Menu")) -import EddiesReceivedMult.Menu.EddiesReceivedMultWithMenu - -@addField(PlayerPuppet) -private let eddiesReceivedMultiplierMod: ref; - -@wrapMethod(PlayerPuppet) -protected cb func OnItemAddedToInventory(evt: ref) -> Bool { - wrappedMethod(evt); - - if Equals(evt.itemID, MarketSystem.Money()) { - if !IsDefined(this.eddiesReceivedMultiplierMod) { - this.InitializeEddiesReceivedMult(); - this.eddiesReceivedMultiplierMod.Setup(this); - } - - this.eddiesReceivedMultiplierMod.DeltaEddies(evt.itemData.GetQuantity(), evt.currentQuantity); - } -} - -@if(ModuleExists("EddiesReceivedMult.Menu")) -@addMethod(PlayerPuppet) -private func InitializeEddiesReceivedMult() -> Void { - this.eddiesReceivedMultiplierMod = new EddiesReceivedMultWithMenu(); -} -@if(!ModuleExists("EddiesReceivedMult.Menu")) -@addMethod(PlayerPuppet) -private func InitializeEddiesReceivedMult() -> Void { - this.eddiesReceivedMultiplierMod = new EddiesReceivedMult(); -} diff --git a/src/r6/scripts/EddiesReceivedMult/erm_settings.reds b/src/r6/scripts/EddiesReceivedMult/erm_settings.reds new file mode 100644 index 0000000..eeb75a1 --- /dev/null +++ b/src/r6/scripts/EddiesReceivedMult/erm_settings.reds @@ -0,0 +1,30 @@ +module ERM.Settings + +public class ERMSettings { + private let multiplier: Float; + private let showExtraEddiesMsg: Bool; + + public func Setup() -> Void { + // ------ Settings Start ------ + + // Eddies received will be multiplied by this value. Default = 1.0 + this.multiplier = 1.0; + + // Show an extra eddies received activity log notification. Default = false + this.showExtraEddiesMsg = false; + + // ------ Settings End ------ + } + + public func GetMultiplier() -> Float { + return this.multiplier; + } + + public func GetIsEnabled() -> Bool { + return true; + } + + public func GetShowExtraEddiesMsg() -> Bool { + return this.showExtraEddiesMsg; + } +} \ No newline at end of file