public void AdjustMoraleNew(OnyxInt value, string reason, bool log) { if (!ConfigHasBeenInit) { InitMods(); } if (!this.HasCrewOnShip()) { return; } if (log) { ShipCrewManager.LogMorale(value); } this.Morale = Mathf.Clamp(this.Morale + (int)value, MinimumMorale, 100); UIShipResourceNotificationManager.PostNotification(new SpriteKey(SingletonBehavior <UIAtlasManager> .Instance.GameSystemIcons, "icon_ship_morale"), GuiStringTable.GetText(3709), value, reason); ShipCrewManager.OnShipMoraleChanged.Trigger(); if (this.GetCurrentMoraleState() == MoraleStateType.Mutinous) { TutorialManager.STriggerTutorialsOfType(TutorialEventType.LowMorale); } }
static bool Prefix(ShipCrewManager __instance, ref OnyxInt value, string reason, bool log) { try { if (!Main.enabled) { return(true); } int currentMorale = __instance.Morale; int change = (int)value; int modified = currentMorale + (int)value; /* * int minimumMorale = Main.settings.MinimumMorale; * int maximumMorale = Main.settings.MaximumMorale; * * OnyxInt minChange = minimumMorale - currentMorale; * OnyxInt maxChange = currentMorale - maximumMorale; * * Main.Log($"Value: {change}"); * Main.Log($"Current: {currentMorale}, Modified: {modified}"); * Main.Log($"Minimum Morale: {minimumMorale}, Maximum Morale: {maximumMorale}"); */ if (log) { MethodInfo methodInfo = __instance.GetType().GetMethod("LogMorale", BindingFlags.NonPublic | BindingFlags.Static); methodInfo.Invoke(__instance, new object[] { value }); } __instance.Morale = Mathf.Clamp(modified, Main.settings.MinimumMorale, Main.settings.MaximumMorale); UIShipResourceNotificationManager.PostNotification(new SpriteKey(SingletonBehavior <UIAtlasManager> .Instance.GameSystemIcons, "icon_ship_morale"), GuiStringTable.GetText(3709), value, reason); ShipCrewManager.OnShipMoraleChanged.Trigger(); if (__instance.GetCurrentMoraleState() == MoraleStateType.Mutinous) { TutorialManager.STriggerTutorialsOfType(TutorialEventType.LowMorale); } /* * if (GetCurrentMoraleState() == MoraleStateType.Mutinous) * * if ( ) * { * value = minChange; * Main.Log($"Min change: {minChange}"); * } * else if (currentMorale > maximumMorale || modified > maximumMorale) * { * value = maxChange; * Main.Log($"Max change: {maxChange}"); * } * else * { * Main.Log("No change"); * } */ return(false); } catch (Exception ex) { Main.LogError(ex); } return(true); }