// Method that is used to prefix private static void Farmer_doDivorce_Prefix(Farmer __instance, out DivorceState __state) { // Create a state variable to check the state in the prefix, used for logic in the postfix __state = DivorceState.UnAssigned; try { // Use the same logic as doDivorce() to decide which kind of divorce is happening and log for use in postfix if (!__instance.isMarried()) { __state = DivorceState.UnMarriedNoDivorce; } else if (__instance.spouse != null) { __state = DivorceState.NPCDivorce; } else if (__instance.team.GetSpouse(__instance.UniqueMultiplayerID).HasValue) { __state = DivorceState.MultiplayerDivorce; } } catch (Exception ex) { Monitor.Log($"Failed to log divorce state in prefix with exception: {ex}", LogLevel.Error); } }
// Method that is used to postfix private static void Farmer_doDivorce_Postfix(Farmer __instance, DivorceState __state) { switch (__state) { // If the prefix failed, don't do the postfix case DivorceState.UnAssigned: Monitor.Log($"Failed to log divorce state in prefix, skipping divorce conversation topic postfix", LogLevel.Error); break; // If the prefix logged that the player is not married, obviously they can't get divorced case DivorceState.UnMarriedNoDivorce: Monitor.Log($"Player tried to get divorced when they were not married", LogLevel.Warn); break; // If the prefix logged that the player is married to another player, add divorce conversation topics to both players case DivorceState.MultiplayerDivorce: // Add divorce conversation topic to current player's player spouse try { // Get spouse long? spouseID = __instance.team.GetSpouse(__instance.UniqueMultiplayerID); Farmer spouse = Game1.getFarmerMaybeOffline(spouseID.Value); // Check if spouse is offline or nonexistent, otherwise add divorce conversation topic to spouse if (spouse is null) { Monitor.Log($"Player was married to multiplayer spouse in prefix but multiplayer spouse not found in postfix", LogLevel.Error); } else { MCTHelperFunctions.AddOrExtendCT(spouse, "divorce", Config.DivorceDuration); if (!Game1.getOnlineFarmers().Contains(spouse)) { Monitor.Log($"Added divorce conversation topic to offline multiplayer spouse, unknown behavior may result", LogLevel.Warn); } } } catch (Exception ex) { Monitor.Log($"Failed to add player's spouse divorce conversation topic with exception: {ex}", LogLevel.Error); } // Add divorce conversation topic to current player goto case DivorceState.NPCDivorce; // If the prefix logged that the player is married to an NPC, only add divorce conversation topic to player case DivorceState.NPCDivorce: try { MCTHelperFunctions.AddOrExtendCT(__instance, "divorce", Config.DivorceDuration); } catch (Exception ex) { Monitor.Log($"Failed to add player's divorce conversation topic with exception: {ex}", LogLevel.Error); } break; } }