Added in spouse specific gifts, spouse birthday messages, and translated birthday messages.

This commit is contained in:
Joshua Navarro 2018-12-06 16:13:41 -08:00
parent b69882cf20
commit 0b914e17b5
4 changed files with 112 additions and 49 deletions

View File

@ -93,7 +93,7 @@ namespace Omegasis.HappyBirthday
string path = Path.Combine( "Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, birthdayFileDict);
//Handle normal birthday wishes.
if (!File.Exists(path))
if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath,path)))
{
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(path, defaultBirthdayWishes);
@ -107,9 +107,9 @@ namespace Omegasis.HappyBirthday
//handle spouse birthday wishes.
string spouseBirthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation);
string spousePath = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, spouseBirthdayFileDict);
if (!File.Exists(spousePath))
if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath,spousePath)))
{
HappyBirthday.ModMonitor.Log("Creating Spouse Messages", StardewModdingAPI.LogLevel.Alert);
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(spousePath, defaultSpouseBirthdayWishes);
this.spouseBirthdayWishes = defaultSpouseBirthdayWishes;
}
@ -122,32 +122,49 @@ namespace Omegasis.HappyBirthday
foreach(var translation in HappyBirthday.Config.translationInfo.translationCodes)
{
if (translation.Key == "English") continue;
string basePath = Path.Combine("Content", "Dialogue", translation.Key);
string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath,"Content", "Dialogue", translation.Key);
if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath);
string tempBirthdayFile =Path.Combine(basePath,HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key));
string tempSpouseBirthdayFile =Path.Combine(basePath,HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key));
string tempBirthdayFile =Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key));
string tempSpouseBirthdayFile =Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key));
Dictionary<string, string> tempBirthdayDict = new Dictionary<string, string>();
foreach(var pair in defaultBirthdayWishes)
if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, tempBirthdayFile)))
{
tempBirthdayDict.Add(pair.Key, "");
foreach (var pair in defaultBirthdayWishes)
{
tempBirthdayDict.Add(pair.Key, "");
}
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(tempBirthdayFile, tempBirthdayDict);
}
if(!File.Exists(tempBirthdayFile)) HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(tempBirthdayFile, tempBirthdayDict);
else
{
tempBirthdayDict = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(tempBirthdayFile);
}
Dictionary<string, string> tempSpouseBirthdayDict = new Dictionary<string, string>();
foreach (var pair in defaultSpouseBirthdayWishes)
if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, tempSpouseBirthdayFile)))
{
tempSpouseBirthdayDict.Add(pair.Key, "");
foreach (var pair in defaultSpouseBirthdayWishes)
{
tempSpouseBirthdayDict.Add(pair.Key, "");
}
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(tempSpouseBirthdayFile, tempSpouseBirthdayDict);
}
else
{
tempBirthdayDict = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(tempSpouseBirthdayFile);
}
if (!File.Exists(tempSpouseBirthdayFile)) HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(tempSpouseBirthdayFile, tempSpouseBirthdayDict);
//Set translated birthday info.
if (HappyBirthday.Config.translationInfo.currentTranslation == translation.Key)
{
this.birthdayWishes = tempBirthdayDict;
this.spouseBirthdayWishes = tempSpouseBirthdayDict;
HappyBirthday.ModMonitor.Log("Language set to: " + translation);
}
}

View File

@ -107,7 +107,7 @@ namespace Omegasis.HappyBirthday.Framework
}
catch (Exception err)
{
HappyBirthday.ModMonitor.Log("WTF SOMETHING IS WRONG!", StardewModdingAPI.LogLevel.Warn);
//Vocalization.ModMonitor.Log(err.ToString());
//Vocalization.ModMonitor.Log("Attempted to get translation: " + translation);
return ".json";

View File

@ -61,9 +61,7 @@ namespace Omegasis.HappyBirthday
public Dictionary<string, string> defaultSpouseBirthdayGifts = new Dictionary<string, string>() {
["Universal_Love_Gift"] = "74 1 446 1 204 1 446 5 773 1",
["Universal_Like_Gift"] = "-2 3 -7 1 -26 2 -75 5 -80 3 72 1 220 1 221 1 395 1 613 1 634 1 635 1 636 1 637 1 638 1 724 1 233 1 223 1 465 20 -79 5",
["Universal_Neutral_Gift"] = "194 1 262 5 -74 5 -75 3 334 5 335 1 390 20 388 20 -81 5 -79 3",
["Universal_Gifts"] = "74 1 446 1 204 1 446 5 773 1",
["Alex"] = "",
["Elliott"] = "",
["Harvey"] = "",
@ -90,28 +88,28 @@ namespace Omegasis.HappyBirthday
{
this.BirthdayGifts = new List<Item>();
this.loadVillagerBirthdayGifts();
this.loadSpouseBirthdayGifts();
}
/// <summary>
/// Load birthday gift information from disk. Preferably from BirthdayGift.json in the mod's directory.
/// </summary>
/// <returns></returns>
public Dictionary<string,string> loadVillagerBirthdayGifts()
public void loadVillagerBirthdayGifts()
{
if (HappyBirthday.Config.useLegacyBirthdayFiles == false)
{
if (File.Exists("BirthdayGifts.json"))
string villagerGifts = Path.Combine("Content", "Gifts", "BirthdayGifts.json");
if (File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, villagerGifts)))
{
HappyBirthday.ModMonitor.Log("Load from BirthdayGifts.json");
this.defaultBirthdayGifts = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "BirthdayGifts.json"));
return this.defaultBirthdayGifts;
this.defaultBirthdayGifts = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(villagerGifts);
}
else
{
HappyBirthday.ModMonitor.Log("BirthdayGifts.json created from default birthday gift information and can be overridden.");
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "BirthdayGifts.json"), this.defaultBirthdayGifts);
return defaultBirthdayGifts;
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(villagerGifts, this.defaultBirthdayGifts);
}
}
else
{
@ -119,12 +117,10 @@ namespace Omegasis.HappyBirthday
if (File.Exists(Path.Combine(Game1.content.RootDirectory, "Data", "PossibleBirthdayGifts.xnb"))){
HappyBirthday.ModMonitor.Log("Legacy loading detected. Attempting to load from StardewValley/Content/Data/PossibleBirthdayGifts.xnb");
this.defaultBirthdayGifts = Game1.content.Load<Dictionary<string, string>>(Path.Combine("Data", "PossibleBirthdayGifts"));
return this.defaultBirthdayGifts;
}
else
{
HappyBirthday.ModMonitor.Log("No birthday gift information found. Loading from internal birthday list");
return this.defaultBirthdayGifts;
}
}
}
@ -133,9 +129,19 @@ namespace Omegasis.HappyBirthday
/// Used to load spouse birthday gifts from disk.
/// </summary>
/// <returns></returns>
public Dictionary<string, string> loadSpouseBirthdayGifts()
public void loadSpouseBirthdayGifts()
{
throw new NotImplementedException();
string spouseGifts = Path.Combine("Content", "Gifts", "SpouseBirthdayGifts.json");
if (File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, spouseGifts)))
{
HappyBirthday.ModMonitor.Log("Load from SpouseBirthdayGifts.json");
this.defaultSpouseBirthdayGifts = HappyBirthday.ModHelper.Data.ReadJsonFile<Dictionary<string, string>>(spouseGifts);
}
else
{
HappyBirthday.ModMonitor.Log("SpouseBirthdayGifts.json created from default spouse birthday gift information and can be overridden.");
HappyBirthday.ModHelper.Data.WriteJsonFile<Dictionary<string, string>>(spouseGifts, this.defaultSpouseBirthdayGifts);
}
}
@ -147,7 +153,7 @@ namespace Omegasis.HappyBirthday
try
{
// read from birthday gifts file
IDictionary<string, string> data = loadVillagerBirthdayGifts();
IDictionary<string, string> data = defaultBirthdayGifts;
data.TryGetValue(name, out string text);
if (text != null)
{
@ -221,31 +227,43 @@ namespace Omegasis.HappyBirthday
if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel)
this.BirthdayGifts.AddRange(this.GetUniversalItems("Neutral", false));
}
//Add in spouse specific birthday gifts.
if (Game1.player.isMarried())
{
if (name == Game1.player.spouse)
{
this.BirthdayGifts.Add((Item)new StardewValley.Object(204, 1));
this.BirthdayGifts.Add((Item)new StardewValley.Object(220, 1));
this.BirthdayGifts.Add((Item)new StardewValley.Object(221, 1));
this.BirthdayGifts.Add((Item)new StardewValley.Object(223, 3));
this.BirthdayGifts.Add((Item)new StardewValley.Object(233, 3));
this.BirthdayGifts.Add((Item)new StardewValley.Object(234, 1));
this.BirthdayGifts.Add((Item)new StardewValley.Object(608, 1)); //pumpkin pie
this.BirthdayGifts.Add((Item)new StardewValley.Object(612, 5));
this.BirthdayGifts.Add((Item)new StardewValley.Object(773, 1)); //life elixer
this.BirthdayGifts.AddRange(getSpouseBirthdayGifts(name));
this.BirthdayGifts.AddRange(getSpouseBirthdayGifts("Universal_Gifts"));
}
}
//TODO: Make different tiers of gifts depending on the friendship, and if it is the spouse.
/*
*/
return gifts;
}
/// <summary>
/// Get
/// </summary>
/// <param name="group"></param>
/// <param name=""></param>
/// <returns></returns>
private IEnumerable<Item> getSpouseBirthdayGifts(string npcName)
{
Dictionary<string, string> data = this.defaultSpouseBirthdayGifts;
data.TryGetValue(npcName, out string text);
if (String.IsNullOrEmpty(text))
yield break;
// parse
string[] array = text.Split(' ');
for (int i = 0; i < array.Length; i += 2)
{
foreach (SObject obj in this.GetItems(Convert.ToInt32(array[i]), Convert.ToInt32(array[i + 1])))
yield return obj;
}
}
/// <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\BirthdayGifts.xnb</c> instead of the game data.</param>

View File

@ -111,6 +111,11 @@ namespace Omegasis.HappyBirthday
}
/// <summary>
/// Used to check when a menu is closed.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e)
{
this.isDailyQuestBoard = false;
@ -318,13 +323,36 @@ namespace Omegasis.HappyBirthday
if (npc is Child || npc is Horse || npc is Junimo || npc is Monster || npc is Pet)
continue;
//Add in birthday dialogues for npc.
try
{
if (Game1.player.getFriendshipHeartLevelForNPC(npc.Name) >= Config.minimumFriendshipLevelForBirthdayWish)
{
Dialogue d = new Dialogue(messages.birthdayWishes[npc.Name], npc);
npc.CurrentDialogue.Push(d);
if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(messages.birthdayWishes[npc.Name]);
bool spouseMessage = false; //Used to determine if there is a valid spouse message for the player. If false load in the generic birthday wish.
//Check if npc name is spouse's name. If no spouse then add in generic dialogue.
if (messages.spouseBirthdayWishes.ContainsKey(npc.Name) && Game1.player.isMarried())
{
Monitor.Log("Spouse Checks out");
//Check to see if spouse message exists.
if (!String.IsNullOrEmpty(messages.spouseBirthdayWishes[npc.Name]))
{
spouseMessage = true;
Dialogue d = new Dialogue(messages.spouseBirthdayWishes[npc.Name], npc);
npc.CurrentDialogue.Push(d);
if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(messages.spouseBirthdayWishes[npc.Name]);
}
else
{
Monitor.Log("No spouse message???", LogLevel.Warn);
}
}
if (spouseMessage == false)
{
//Load in
Dialogue d = new Dialogue(messages.birthdayWishes[npc.Name], npc);
npc.CurrentDialogue.Push(d);
if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(messages.birthdayWishes[npc.Name]);
}
}
}
catch