Exemple #1
0
        private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e)
        {
            if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayMessageToOthers)
            {
                string message = e.ReadAs <string>();
                Game1.hudMessages.Add(new HUDMessage(message, 1));
            }

            if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayInfoToOthers)
            {
                KeyValuePair <long, PlayerData> message = e.ReadAs <KeyValuePair <long, PlayerData> >();
                if (!this.othersBirthdays.ContainsKey(message.Key))
                {
                    this.othersBirthdays.Add(message.Key, message.Value);
                    MultiplayerSupport.SendBirthdayInfoToConnectingPlayer(e.FromPlayerID);
                    Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name);
                }
                else
                {
                    //Brute force update birthday info if it has already been recevived but dont send birthday info again.
                    this.othersBirthdays.Remove(message.Key);
                    this.othersBirthdays.Add(message.Key, message.Value);
                    Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name);
                }
            }
        }
Exemple #2
0
        /// <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)
        {
            this.DataFilePath = Path.Combine("data", Game1.player.Name + "_" + Game1.player.UniqueMultiplayerID + ".json");

            // reset state
            this.VillagerQueue      = new List <string>();
            this.CheckedForBirthday = false;

            // load settings
            this.MigrateLegacyData();
            this.PlayerData = this.Helper.Data.ReadJsonFile <PlayerData>(this.DataFilePath) ?? new PlayerData();

            messages.createBirthdayGreetings();

            if (PlayerBirthdayData != null)
            {
                ModMonitor.Log("Send all birthday information from " + Game1.player.name);
                MultiplayerSupport.SendBirthdayInfoToOtherPlayers();
            }
            //this.SeenEvent = false;
            //this.Dialogue = new Dictionary<string, Dialogue>();
        }
Exemple #3
0
        /// <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)
        {
            if (!Context.IsWorldReady || Game1.eventUp || Game1.isFestival())
            {
                return;
            }
            if (!this.HasChosenBirthday && Game1.activeClickableMenu == null && Game1.player.Name.ToLower() != "unnamed farmhand")
            {
                Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday);
                this.CheckedForBirthday   = false;
            }

            if (!this.CheckedForBirthday && Game1.activeClickableMenu == null)
            {
                this.CheckedForBirthday = true;

                // set up birthday
                if (this.IsBirthday())
                {
                    Messages.ShowStarMessage("It's your birthday today! Happy birthday!");
                    MultiplayerSupport.SendBirthdayMessageToOtherPlayers();



                    Game1.player.mailbox.Add("birthdayMom");
                    Game1.player.mailbox.Add("birthdayDad");

                    try
                    {
                        this.ResetVillagerQueue();
                    }
                    catch (Exception ex)
                    {
                        this.Monitor.Log(ex.ToString(), LogLevel.Error);
                    }
                    foreach (GameLocation location in Game1.locations)
                    {
                        foreach (NPC npc in location.characters)
                        {
                            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)
                                {
                                    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
                            {
                                if (Game1.player.getFriendshipHeartLevelForNPC(npc.Name) >= Config.minimumFriendshipLevelForBirthdayWish)
                                {
                                    Dialogue d = new Dialogue("Happy Birthday @!", npc);
                                    npc.CurrentDialogue.Push(d);
                                    if (npc.CurrentDialogue.ElementAt(0) != d)
                                    {
                                        npc.setNewDialogue("Happy Birthday @!");
                                    }
                                }
                            }
                        }
                    }
                }

                //Don't constantly set the birthday menu.
                if (Game1.activeClickableMenu != null)
                {
                    if (Game1.activeClickableMenu.GetType() == typeof(BirthdayMenu))
                    {
                        return;
                    }
                }
                // ask for birthday date
                if (!this.HasChosenBirthday && Game1.activeClickableMenu == null)
                {
                    Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday);
                    this.CheckedForBirthday   = false;
                }
            }

            // Set birthday gift for the player to recieve from the npc they are currently talking with.
            if (Game1.currentSpeaker != null)
            {
                string name = Game1.currentSpeaker.Name;
                if (this.IsBirthday() && this.VillagerQueue.Contains(name))
                {
                    try
                    {
                        giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
                        this.VillagerQueue.Remove(Game1.currentSpeaker.Name);
                    }
                    catch (Exception ex)
                    {
                        this.Monitor.Log(ex.ToString(), LogLevel.Error);
                    }
                }

                //Validate the gift and give it to the player.
                if (giftManager.BirthdayGiftToReceive != null)
                {
                    while (giftManager.BirthdayGiftToReceive.Name == "Error Item" || giftManager.BirthdayGiftToReceive.Name == "Rock" || giftManager.BirthdayGiftToReceive.Name == "???")
                    {
                        giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name);
                    }
                    Game1.player.addItemByMenuIfNecessaryElseHoldUp(giftManager.BirthdayGiftToReceive);
                    giftManager.BirthdayGiftToReceive = null;
                }
            }
        }