2016-10-20 15:01:51 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using System.IO;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
using System.Linq;
|
2017-07-31 11:07:07 +08:00
|
|
|
|
using Omegasis.HappyBirthday.Framework;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
using StardewValley;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
using StardewValley.Characters;
|
|
|
|
|
using StardewValley.Monsters;
|
|
|
|
|
using SObject = StardewValley.Object;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-28 08:28:39 +08:00
|
|
|
|
namespace Omegasis.HappyBirthday
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
|
|
|
|
public class HappyBirthday : Mod
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/*********
|
|
|
|
|
** Properties
|
|
|
|
|
*********/
|
2017-08-06 03:51:44 +08:00
|
|
|
|
/// <summary>The relative path for the current player's data file.</summary>
|
|
|
|
|
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
|
|
|
|
|
|
|
|
|
|
/// <summary>The absolute path for the current player's legacy data file.</summary>
|
|
|
|
|
private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "Player_Birthdays", $"HappyBirthday_{Game1.player.name}.txt");
|
|
|
|
|
|
|
|
|
|
/// <summary>The mod configuration.</summary>
|
|
|
|
|
private ModConfig Config;
|
|
|
|
|
|
|
|
|
|
/// <summary>The data for the current player.</summary>
|
|
|
|
|
private PlayerData PlayerData;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Whether the player has chosen a birthday.</summary>
|
2017-08-06 03:51:44 +08:00
|
|
|
|
private bool HasChosenBirthday => !string.IsNullOrEmpty(this.PlayerData.BirthdaySeason) && this.PlayerData.BirthdayDay != 0;
|
2016-11-08 17:19:56 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The queue of villagers who haven't given a gift yet.</summary>
|
|
|
|
|
private List<string> VillagerQueue;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The gifts that villagers can give.</summary>
|
|
|
|
|
private List<Item> PossibleBirthdayGifts;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The next birthday gift the player will receive.</summary>
|
|
|
|
|
private Item BirthdayGiftToReceive;
|
|
|
|
|
|
|
|
|
|
/// <summary>Whether we've already checked for and (if applicable) set up the player's birthday today.</summary>
|
|
|
|
|
private bool CheckedForBirthday;
|
|
|
|
|
//private Dictionary<string, Dialogue> Dialogue;
|
|
|
|
|
//private bool SeenEvent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** Public methods
|
|
|
|
|
*********/
|
|
|
|
|
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
|
|
|
|
|
/// <param name="helper">Provides simplified APIs for writing mods.</param>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.Config = helper.ReadConfig<ModConfig>();
|
|
|
|
|
|
2017-08-06 03:20:46 +08:00
|
|
|
|
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
|
|
|
|
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
2017-08-06 03:51:44 +08:00
|
|
|
|
SaveEvents.BeforeSave += this.SaveEvents_BeforeSave;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** Private methods
|
|
|
|
|
*********/
|
2017-08-06 03:20:46 +08:00
|
|
|
|
/// <summary>The method invoked after a new day starts.</summary>
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
2017-08-06 03:20:46 +08:00
|
|
|
|
private void TimeEvents_AfterDayStarted(object sender, EventArgs e)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.CheckedForBirthday = false;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The method invoked when the presses a keyboard button.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// show birthday selection menu
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (Context.IsPlayerFree && !this.HasChosenBirthday && e.KeyPressed.ToString() == this.Config.KeyBinding)
|
|
|
|
|
Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday);
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The method invoked after the player loads a save.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void SaveEvents_AfterLoad(object sender, EventArgs e)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-08-06 11:00:37 +08:00
|
|
|
|
// reset state
|
|
|
|
|
this.VillagerQueue = new List<string>();
|
|
|
|
|
this.PossibleBirthdayGifts = new List<Item>();
|
|
|
|
|
this.BirthdayGiftToReceive = null;
|
|
|
|
|
this.CheckedForBirthday = false;
|
|
|
|
|
|
|
|
|
|
// load settings
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.MigrateLegacyData();
|
|
|
|
|
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
|
2018-01-31 04:46:04 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
//this.SeenEvent = false;
|
|
|
|
|
//this.Dialogue = new Dictionary<string, Dialogue>();
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-06 03:51:44 +08:00
|
|
|
|
/// <summary>The method invoked just before the game updates the saves.</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void SaveEvents_BeforeSave(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.HasChosenBirthday)
|
|
|
|
|
this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary>
|
|
|
|
|
/// <param name="sender">The event sender.</param>
|
|
|
|
|
/// <param name="e">The event data.</param>
|
|
|
|
|
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-08-06 03:23:10 +08:00
|
|
|
|
if (!Context.IsWorldReady || Game1.eventUp || Game1.isFestival())
|
2017-07-30 06:02:49 +08:00
|
|
|
|
return;
|
2017-02-22 15:29:00 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (!this.CheckedForBirthday)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.CheckedForBirthday = true;
|
|
|
|
|
|
|
|
|
|
// set up birthday
|
|
|
|
|
if (this.IsBirthday())
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Messages.ShowStarMessage("It's your birthday today! Happy birthday!");
|
2016-10-20 15:01:51 +08:00
|
|
|
|
Game1.mailbox.Enqueue("birthdayMom");
|
|
|
|
|
Game1.mailbox.Enqueue("birthdayDad");
|
2017-02-22 15:29:00 +08:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.ResetVillagerQueue();
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
catch (Exception ex)
|
2017-02-22 15:29:00 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (GameLocation location in Game1.locations)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (NPC npc in location.characters)
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (npc is Child || npc is Horse || npc is Junimo || npc is Monster || npc is Pet)
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-10-20 15:01:51 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Dialogue d = new Dialogue(Game1.content.Load<Dictionary<string, string>>("Data\\FarmerBirthdayDialogue")[npc.name], npc);
|
2016-11-08 17:19:56 +08:00
|
|
|
|
npc.CurrentDialogue.Push(d);
|
|
|
|
|
if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(Game1.content.Load<Dictionary<string, string>>("Data\\FarmerBirthdayDialogue")[npc.name]);
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2016-11-08 17:19:56 +08:00
|
|
|
|
Dialogue d = new Dialogue("Happy Birthday @!", npc);
|
|
|
|
|
npc.CurrentDialogue.Push(d);
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (npc.CurrentDialogue.ElementAt(0) != d)
|
|
|
|
|
npc.setNewDialogue("Happy Birthday @!");
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-08 17:19:56 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// ask for birthday date
|
2017-08-06 03:51:44 +08:00
|
|
|
|
if (!this.HasChosenBirthday)
|
2016-11-08 17:19:56 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday);
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.CheckedForBirthday = false;
|
2016-11-08 17:19:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// unreachable since we exit early if Game1.eventUp
|
|
|
|
|
//if (Game1.eventUp)
|
|
|
|
|
//{
|
|
|
|
|
// foreach (string npcName in this.VillagerQueue)
|
|
|
|
|
// {
|
|
|
|
|
// NPC npc = Game1.getCharacterFromName(npcName);
|
|
|
|
|
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// this.Dialogue.Add(npcName, npc.CurrentDialogue.Pop());
|
|
|
|
|
// }
|
|
|
|
|
// catch (Exception ex)
|
|
|
|
|
// {
|
|
|
|
|
// this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
|
|
|
|
// this.Dialogue.Add(npcName, npc.CurrentDialogue.ElementAt(0));
|
|
|
|
|
// npc.loadSeasonalDialogue();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// this.SeenEvent = true;
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//if (!Game1.eventUp && this.SeenEvent)
|
|
|
|
|
//{
|
|
|
|
|
// foreach (KeyValuePair<string, Dialogue> v in this.Dialogue)
|
|
|
|
|
// {
|
|
|
|
|
// NPC npc = Game1.getCharacterFromName(v.Key);
|
|
|
|
|
// npc.CurrentDialogue.Push(v.Value);
|
|
|
|
|
// }
|
|
|
|
|
// this.Dialogue.Clear();
|
|
|
|
|
// this.SeenEvent = false;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// set birthday gift
|
2016-10-20 15:01:51 +08:00
|
|
|
|
if (Game1.currentSpeaker != null)
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
string name = Game1.currentSpeaker.name;
|
|
|
|
|
if (this.IsBirthday() && this.VillagerQueue.Contains(name))
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.SetNextBirthdayGift(Game1.currentSpeaker.name);
|
|
|
|
|
this.VillagerQueue.Remove(Game1.currentSpeaker.name);
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
catch (Exception ex)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.Monitor.Log(ex.ToString(), LogLevel.Error);
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (this.BirthdayGiftToReceive != null && Game1.currentSpeaker != null)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
while (this.BirthdayGiftToReceive.Name == "Error Item" || this.BirthdayGiftToReceive.Name == "Rock" || this.BirthdayGiftToReceive.Name == "???")
|
|
|
|
|
this.SetNextBirthdayGift(Game1.currentSpeaker.name);
|
|
|
|
|
Game1.player.addItemByMenuIfNecessaryElseHoldUp(this.BirthdayGiftToReceive);
|
|
|
|
|
this.BirthdayGiftToReceive = null;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Set the player's birtday/</summary>
|
|
|
|
|
/// <param name="season">The birthday season.</param>
|
|
|
|
|
/// <param name="day">The birthday day.</param>
|
|
|
|
|
private void SetBirthday(string season, int day)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.PlayerData.BirthdaySeason = season;
|
|
|
|
|
this.PlayerData.BirthdayDay = day;
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Reset the queue of villager names.</summary>
|
|
|
|
|
private void ResetVillagerQueue()
|
2017-02-22 15:29:00 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.VillagerQueue.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (GameLocation location in Game1.locations)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (NPC npc in location.characters)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (npc is Child || npc is Horse || npc is Junimo || npc is Monster || npc is Pet)
|
2017-02-22 15:29:00 +08:00
|
|
|
|
continue;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (this.VillagerQueue.Contains(npc.name))
|
|
|
|
|
continue;
|
|
|
|
|
this.VillagerQueue.Add(npc.name);
|
2017-02-22 15:29:00 +08:00
|
|
|
|
}
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Set the next birthday gift the player will receive.</summary>
|
|
|
|
|
/// <param name="name">The villager's name who's giving the gift.</param>
|
|
|
|
|
/// <remarks>This returns gifts based on the speaker's heart level towards the player: neutral for 0-3, good for 4-6, and best for 7-10.</remarks>
|
|
|
|
|
private void SetNextBirthdayGift(string name)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Item gift;
|
|
|
|
|
if (this.PossibleBirthdayGifts.Count > 0)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Random random = new Random();
|
|
|
|
|
int index = random.Next(this.PossibleBirthdayGifts.Count);
|
|
|
|
|
gift = this.PossibleBirthdayGifts[index];
|
|
|
|
|
if (Game1.player.isInventoryFull())
|
|
|
|
|
Game1.createItemDebris(gift, Game1.player.getStandingPosition(), Game1.player.getDirection());
|
|
|
|
|
else
|
|
|
|
|
this.BirthdayGiftToReceive = gift;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetDefaultBirthdayGifts(name));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
|
|
|
|
Random rnd2 = new Random();
|
2017-07-30 06:02:49 +08:00
|
|
|
|
int r2 = rnd2.Next(this.PossibleBirthdayGifts.Count);
|
|
|
|
|
gift = this.PossibleBirthdayGifts.ElementAt(r2);
|
|
|
|
|
if (Game1.player.isInventoryFull())
|
|
|
|
|
Game1.createItemDebris(gift, Game1.player.getStandingPosition(), Game1.player.getDirection());
|
|
|
|
|
else
|
|
|
|
|
this.BirthdayGiftToReceive = gift;
|
|
|
|
|
|
|
|
|
|
this.PossibleBirthdayGifts.Clear();
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Get the default gift items.</summary>
|
|
|
|
|
/// <param name="name">The villager's name.</param>
|
|
|
|
|
private IEnumerable<SObject> GetDefaultBirthdayGifts(string name)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
List<SObject> gifts = new List<SObject>();
|
2016-10-20 15:01:51 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// read from birthday gifts file
|
|
|
|
|
IDictionary<string, string> data = Game1.content.Load<Dictionary<string, string>>("Data\\PossibleBirthdayGifts");
|
2016-10-20 15:01:51 +08:00
|
|
|
|
string text;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
data.TryGetValue(name, out text);
|
2016-10-20 15:01:51 +08:00
|
|
|
|
if (text != null)
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
string[] fields = text.Split('/');
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// love
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7)
|
|
|
|
|
{
|
|
|
|
|
string[] loveFields = fields[1].Split(' ');
|
|
|
|
|
for (int i = 0; i < loveFields.Length; i += 2)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
gifts.AddRange(this.GetItems(Convert.ToInt32(loveFields[i]), Convert.ToInt32(loveFields[i + 1])));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
catch { }
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// like
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
string[] likeFields = fields[3].Split(' ');
|
|
|
|
|
for (int i = 0; i < likeFields.Length; i += 2)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
gifts.AddRange(this.GetItems(Convert.ToInt32(likeFields[i]), Convert.ToInt32(likeFields[i + 1])));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
catch { }
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// neutral
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3)
|
|
|
|
|
{
|
|
|
|
|
string[] neutralFields = fields[5].Split(' ');
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
for (int i = 0; i < neutralFields.Length; i += 2)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
gifts.AddRange(this.GetItems(Convert.ToInt32(neutralFields[i]), Convert.ToInt32(neutralFields[i + 1])));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
catch { }
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
}
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get NPC's preferred gifts
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7)
|
|
|
|
|
gifts.AddRange(this.GetUniversalItems("Love", true));
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6)
|
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Like", true));
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3)
|
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Neutral", true));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get NPC's preferred gifts
|
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 7)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Love", false));
|
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetLovedItems(name));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 4 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 6)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetLikedItems(name));
|
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Like", false));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= 0 && Game1.player.getFriendshipHeartLevelForNPC(name) <= 3)
|
|
|
|
|
this.PossibleBirthdayGifts.AddRange(this.GetUniversalItems("Neutral", false));
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
//TODO: Make different tiers of gifts depending on the friendship, and if it is the spouse.
|
|
|
|
|
/*
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(198, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(204, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(220, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(221, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(223, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(233, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(234, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(286, 5));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(368, 5));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(608, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(612, 1));
|
|
|
|
|
this.possible_birthday_gifts.Add((Item)new SytardewValley.Object(773, 1));
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
return gifts;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Get the items loved by all villagers.</summary>
|
|
|
|
|
/// <param name="group">The group to get (one of <c>Like</c>, <c>Love</c>, <c>Neutral</c>).</param>
|
|
|
|
|
/// <param name="isBirthdayGiftList">Whether to get data from <c>Data\PossibleBirthdayGifts.xnb</c> instead of the game data.</param>
|
|
|
|
|
private IEnumerable<SObject> GetUniversalItems(string group, bool isBirthdayGiftList)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
if (!isBirthdayGiftList)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get raw data
|
|
|
|
|
string text;
|
|
|
|
|
Game1.NPCGiftTastes.TryGetValue($"Universal_{group}", out text);
|
|
|
|
|
if (text == null)
|
|
|
|
|
yield break;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// parse
|
|
|
|
|
string[] neutralIDs = text.Split(' ');
|
|
|
|
|
foreach (string neutralID in neutralIDs)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (SObject obj in this.GetItems(Convert.ToInt32(neutralID)))
|
|
|
|
|
yield return obj;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get raw data
|
|
|
|
|
Dictionary<string, string> data = Game1.content.Load<Dictionary<string, string>>("Data\\PossibleBirthdayGifts");
|
|
|
|
|
string text;
|
|
|
|
|
data.TryGetValue($"Universal_{group}_Gift", out text);
|
|
|
|
|
if (text == null)
|
|
|
|
|
yield break;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// parse
|
|
|
|
|
string[] array = text.Split(' ');
|
|
|
|
|
for (int i = 0; i < array.Length; i += 2)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (SObject obj in this.GetItems(Convert.ToInt32(array[i]), Convert.ToInt32(array[i + 1])))
|
|
|
|
|
yield return obj;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Get a villager's loved items.</summary>
|
|
|
|
|
/// <param name="name">The villager's name.</param>
|
|
|
|
|
private IEnumerable<SObject> GetLikedItems(string name)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get raw data
|
2016-10-20 15:01:51 +08:00
|
|
|
|
string text;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Game1.NPCGiftTastes.TryGetValue(name, out text);
|
|
|
|
|
if (text == null)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
// parse
|
|
|
|
|
string[] data = text.Split('/');
|
|
|
|
|
string[] likedIDs = data[3].Split(' ');
|
|
|
|
|
foreach (string likedID in likedIDs)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (SObject obj in this.GetItems(Convert.ToInt32(likedID)))
|
|
|
|
|
yield return obj;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>Get a villager's loved items.</summary>
|
|
|
|
|
/// <param name="name">The villager's name.</param>
|
|
|
|
|
private IEnumerable<SObject> GetLovedItems(string name)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
// get raw data
|
2016-10-20 15:01:51 +08:00
|
|
|
|
string text;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
Game1.NPCGiftTastes.TryGetValue(name, out text);
|
|
|
|
|
if (text == null)
|
|
|
|
|
yield break;
|
|
|
|
|
|
|
|
|
|
// parse
|
|
|
|
|
string[] data = text.Split('/');
|
|
|
|
|
string[] lovedIDs = data[1].Split(' ');
|
|
|
|
|
foreach (string lovedID in lovedIDs)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (SObject obj in this.GetItems(Convert.ToInt32(lovedID)))
|
|
|
|
|
yield return obj;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Get the items matching the given ID.</summary>
|
|
|
|
|
/// <param name="id">The category or item ID.</param>
|
|
|
|
|
private IEnumerable<SObject> GetItems(int id)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
return id < 0
|
|
|
|
|
? ObjectUtility.GetObjectsInCategory(id)
|
|
|
|
|
: new[] { new SObject(id, 1) };
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2017-07-30 06:02:49 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>Get the items matching the given ID.</summary>
|
|
|
|
|
/// <param name="id">The category or item ID.</param>
|
|
|
|
|
/// <param name="stack">The stack size.</param>
|
|
|
|
|
private IEnumerable<SObject> GetItems(int id, int stack)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2017-07-30 06:02:49 +08:00
|
|
|
|
foreach (SObject obj in this.GetItems(id))
|
|
|
|
|
yield return new SObject(obj.parentSheetIndex, stack);
|
|
|
|
|
}
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-07-30 06:02:49 +08:00
|
|
|
|
/// <summary>Get whether today is the player's birthday.</summary>
|
|
|
|
|
private bool IsBirthday()
|
|
|
|
|
{
|
|
|
|
|
return
|
2017-08-06 03:51:44 +08:00
|
|
|
|
this.PlayerData.BirthdayDay == Game1.dayOfMonth
|
|
|
|
|
&& this.PlayerData.BirthdaySeason == Game1.currentSeason;
|
2017-07-30 06:02:49 +08:00
|
|
|
|
}
|
2016-10-20 15:01:51 +08:00
|
|
|
|
|
2017-08-06 03:51:44 +08:00
|
|
|
|
/// <summary>Migrate the legacy settings for the current player.</summary>
|
|
|
|
|
private void MigrateLegacyData()
|
2017-07-30 06:02:49 +08:00
|
|
|
|
{
|
2017-08-06 03:51:44 +08:00
|
|
|
|
// skip if no legacy data or new data already exists
|
|
|
|
|
try
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2018-01-31 04:46:04 +08:00
|
|
|
|
if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath))
|
|
|
|
|
if (this.PlayerData == null) this.PlayerData = new PlayerData();
|
|
|
|
|
return;
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2018-01-31 04:46:04 +08:00
|
|
|
|
catch(Exception err)
|
2016-10-20 15:01:51 +08:00
|
|
|
|
{
|
2018-01-31 04:46:04 +08:00
|
|
|
|
// migrate to new file
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string[] text = File.ReadAllLines(this.LegacyDataFilePath);
|
|
|
|
|
this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData
|
|
|
|
|
{
|
|
|
|
|
BirthdaySeason = text[3],
|
|
|
|
|
BirthdayDay = Convert.ToInt32(text[5])
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
FileInfo file = new FileInfo(this.LegacyDataFilePath);
|
|
|
|
|
file.Delete();
|
|
|
|
|
if (!file.Directory.EnumerateFiles().Any())
|
|
|
|
|
file.Directory.Delete();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
this.Monitor.Log($"Error migrating data from the legacy 'Player_Birthdays' folder for the current player. Technical details:\n {ex}", LogLevel.Error);
|
|
|
|
|
}
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
2018-01-31 04:46:04 +08:00
|
|
|
|
|
2016-10-20 15:01:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|