private static void Event_OnNewDay(object sender, EventArgsNewDay e) { // This calculation needs to be triggered at the end of the day / before saving // So only perform action if e.IsNewDay = true as per SMAPI doc if (ModConfig.enabled && e.IsNewDay == true) { Log.SyncColour($"{Environment.NewLine}Friendship increaser enabled. Starting friendship calculation.{Environment.NewLine}", ConsoleColor.Green); List <IndividualNpcConfig> individualNpcConfigs = ModConfig.individualConfigs; SortedDictionary <string, IndividualNpcConfig> npcConfigsMap = new SortedDictionary <string, IndividualNpcConfig>(); foreach (IndividualNpcConfig individualNpcConfig in individualNpcConfigs) { npcConfigsMap.Add(individualNpcConfig.name, individualNpcConfig); } // Add default configuration if it's not found in the configuration file if (!npcConfigsMap.ContainsKey("Default")) { npcConfigsMap.Add("Default", new IndividualNpcConfig("Default", 2, 0, 2500)); } string[] npcNames = Player.friendships.Keys.ToArray <string>(); foreach (string npcName in npcNames) { IndividualNpcConfig config = npcConfigsMap.ContainsKey(npcName) ? npcConfigsMap[npcName] : npcConfigsMap["Default"]; int[] friendshipParams = Player.friendships[npcName]; int friendshipValue = friendshipParams[0]; Log.SyncColour($"{npcName}'s starting friendship value is {Player.getFriendshipLevelForNPC(npcName)}.", ConsoleColor.Green); Log.SyncColour($"{npcName}'s current heart level is {Player.getFriendshipHeartLevelForNPC(npcName)}.", ConsoleColor.Green); // Not sure why there's a special condition added for spouse. Disabling. //if ((Player.spouse != null) && npcName.Equals(Player.spouse)) //{ // friendshipValue += config.baseIncrease + 20; //} if (Player.hasPlayerTalkedToNPC(npcName)) { friendshipValue += config.talkIncrease; Log.SyncColour($"Talked to {npcName} today. Increasing friendship value by {config.talkIncrease}.", ConsoleColor.Green); } else { friendshipValue += config.baseIncrease; Log.SyncColour($"Didn't talk to {npcName} today. Increasing friendship value by {config.baseIncrease}.", ConsoleColor.Red); } if (friendshipValue > config.max) { friendshipValue = config.max; } Log.SyncColour($"{npcName}'s new friendship value is {friendshipValue}. Maximum permitted value is {config.max}.", ConsoleColor.Green); Player.friendships[npcName][0] = friendshipValue; } Log.SyncColour($"{Environment.NewLine}Finished friendship calculation.{Environment.NewLine}", ConsoleColor.Green); } }
private void on_new_day(object sender, EventArgsNewDay e) { if (!Game1.hasLoadedGame) { return; } add_friendship(sender, e); }
private void TimeEvents_OnNewDay(object sender, EventArgsNewDay e) { //Log.Info("Day of Month Changed"); new_day = true; string name = Game1.player.name; Save_Anywhere_V2.Mod_Core.player_path = Path.Combine(Save_Anywhere_V2.Mod_Core.mod_path, "Save_Data", name); if (Directory.Exists(player_path)) { Directory.Delete(player_path, true); } }
private static void add_friendship(object sender, EventArgsNewDay e) { if (!ModConfig.enabled || !e.IsNewDay) { return; } List <SpecificConfig> SpecificConfigs = ModConfig.individualConfigs; SortedDictionary <string, SpecificConfig> npcConfigsMap = new SortedDictionary <string, SpecificConfig>(); /*Log.Debug("Loading configurations..."); * foreach (SpecificConfig SpecificConfig in SpecificConfigs) * { * npcConfigsMap.Add(SpecificConfig.name, SpecificConfig); * }*/ if (!npcConfigsMap.ContainsKey("Default")) { npcConfigsMap.Add("Default", new SpecificConfig("Default", 5, 8, 2500)); } string[] npcNames = Player.friendships.Keys.ToArray(); if (!ModConfig.noPassiveIncrease) { Log.Info($"=== Adding Friendship ==="); foreach (string npcName in npcNames) { SpecificConfig config = npcConfigsMap.ContainsKey(npcName) ? npcConfigsMap[npcName] : npcConfigsMap["Default"]; int[] friendshipParams = Player.friendships[npcName]; int friendshipValue = friendshipParams[0]; int friendship_increase = friendshipValue > config.max ? 0 : ModConfig.randomizeIncrease ? Player.hasPlayerTalkedToNPC(npcName) ? (rnd.Next(1, config.baseIncrease * 2) * Player.LuckLevel) + rnd.Next(1, config.talkIncrease * 2) : (rnd.Next(1, config.baseIncrease) * Player.LuckLevel) + rnd.Next(1, config.talkIncrease) : Player.hasPlayerTalkedToNPC(npcName) ? config.talkIncrease * 2 : config.baseIncrease * 2; friendshipValue += friendship_increase; Log.Info($"{npcName} friendship level has increased by {friendship_increase} points. (Current = {friendshipValue}.)"); Player.friendships[npcName][0] = friendshipValue; } Log.Info($"=== Finished Adding Friendship ==="); } }
private void TimeEvents_OnNewDay(object sender, EventArgsNewDay e) { try { //Log.Info("Day of Month Changed"); new_day = true; string name = Game1.player.name; Save_Anywhere_V2.Mod_Core.player_path = Path.Combine(Save_Anywhere_V2.Mod_Core.mod_path, "Save_Data", name); if (Directory.Exists(player_path)) { Directory.Delete(player_path, true); } } catch (Exception ex) { try { Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer(); serializer.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; serializer.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All; serializer.Formatting = Newtonsoft.Json.Formatting.Indented; serializer.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; using (StreamWriter sw = new StreamWriter(Path.Combine(Error_Path, "Mod_State.json"))) { using (Newtonsoft.Json.JsonWriter writer2 = new Newtonsoft.Json.JsonTextWriter(sw)) { serializer.Serialize(writer2, this, typeof(Save_Anywhere_V2.Mod_Core)); } } } catch (Exception exc) { Log.Info(exc); } Stardew_Omegasis_Utilities.Mod.Error_Handling.Log_Error(new List <string>(), ex); } }
// sender - event sender // e - Event data private void onNewDay(object sender, EventArgsNewDay e) { if (!e.IsNewDay) { return; } Random r = new Random(); int count = 0; foreach (GameLocation location in Game1.locations) { foreach (KeyValuePair <Vector2, StardewValley.TerrainFeatures.TerrainFeature> pair in location.terrainFeatures) { if (pair.Value is Tree) { Tree tree = (Tree)pair.Value; if (tree.growthStage < 5 && tree.treeType != 6 && r.Next(1, 100) <= chance) { count++; tree.growthStage++; } } else if (pair.Value is FruitTree) { FruitTree tree = (FruitTree)pair.Value; if (tree.growthStage < 5 && r.Next(1, 100) <= chance) { count++; tree.growthStage++; } } } } Log.Info($"{count} trees have grown in the night..."); }
private void OnNewDay(object sender, EventArgsNewDay e) { saveManager.ClearSave(); }