Skip to content

Commit

Permalink
refactor for reduced footprint
Browse files Browse the repository at this point in the history
add media
  • Loading branch information
p-marques committed Dec 1, 2022
1 parent 96fb21f commit 31a70a4
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 125 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.png filter=lfs diff=lfs merge=lfs -text
*.jpg filter=lfs diff=lfs merge=lfs -text
3 changes: 3 additions & 0 deletions media/eddiesReceivedMultiplier_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions media/erm_menu_showcase.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
203 changes: 114 additions & 89 deletions src/r6/scripts/EddiesReceivedMult/erm_base.reds
Original file line number Diff line number Diff line change
@@ -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<PlayerPuppet>;
private let transactionSystem: ref<TransactionSystem>;
private let blackboard: ref<IBlackboard>;
private let flag: Bool;
private let debugMode: Bool;
public func Setup(player: wref<PlayerPuppet>) -> 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<Int32>(Cast<Float>(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<Int32>(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<PlayerPuppet>;
private let transactionSystem: ref<TransactionSystem>;
private let ermCallback: ref<ERMCallback>;
private let inventoryListener: ref<InventoryScriptListener>;
private let lastRequestHandled: Bool;
private let settings: ref<ERMSettings>;
private func OnPlayerAttach(request: ref<PlayerAttachRequest>) -> 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<PlayerDetachRequest>) -> 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<ERMHandleEddiesChangedRequest>) -> 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<Int32>(Cast<Float>(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<ERMSystem>;
public func OnItemQuantityChanged(item: ItemID, diff: Int32, total: Uint32, flaggedAsSilent: Bool) -> Void {
let request: ref<ERMHandleEddiesChangedRequest>;
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<ERMSettings> {
return new ERMSettings();
}

@if(ModuleExists("ModSettingsModule"))
public func GetSettings() -> ref<ERMSettings> {
return new Menu();
}
50 changes: 50 additions & 0 deletions src/r6/scripts/EddiesReceivedMult/erm_menu.reds
Original file line number Diff line number Diff line change
@@ -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<IScriptable>) {}

@if(ModuleExists("ModSettingsModule"))
public func RegisterMenu(listener: ref<IScriptable>) {
ModSettings.RegisterListenerToClass(listener);
}
36 changes: 0 additions & 36 deletions src/r6/scripts/EddiesReceivedMult/erm_overrides.reds

This file was deleted.

30 changes: 30 additions & 0 deletions src/r6/scripts/EddiesReceivedMult/erm_settings.reds
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 31a70a4

Please sign in to comment.