Exemple #1
0
 public NetRef <Farmer> getFarmhand()
 {
     if (farmhand.Value == null)
     {
         farmhand.Value = new Farmer(new FarmerSprite(null), new Vector2(0f, 0f), 1, "", Farmer.initialTools(), isMale: true);
         farmhand.Value.UniqueMultiplayerID = Utility.RandomLong(farmhandIDRandom);
         SocializeQuest quest = Quest.getQuestFromId(9) as SocializeQuest;
         farmhand.Value.questLog.Add(quest);
         resetFarmhandState();
     }
     return(farmhand);
 }
        /// <summary>Set the friendship hearts for an NPC.</summary>
        /// <param name="npc">The NPC to change.</param>
        /// <param name="hearts">The friendship hearts to set.</param>
        private void SetFriendshipHearts(NPC npc, int hearts)
        {
            // add friendship if needed
            if (!Game1.player.friendshipData.TryGetValue(npc.Name, out Friendship friendship))
            {
                friendship = new Friendship();
                Game1.player.friendshipData.Add(npc.Name, friendship);
                SocializeQuest socialQuest = Game1.player.questLog.OfType <SocializeQuest>().FirstOrDefault();
                if (socialQuest != null && !socialQuest.completed.Value)
                {
                    socialQuest.checkIfComplete(npc);
                }
            }

            // update friendship points
            friendship.Points = hearts * NPC.friendshipPointsPerHeartLevel;
            this.OnPointsChanged(npc, hearts * NPC.friendshipPointsPerHeartLevel);
        }
Exemple #3
0
        /// <summary>A Harmony postfix patch that excludes a list of NPCs from <see cref="SocializeQuest"/>.</summary>
        /// <param name="__instance">This instance of <see cref="SocializeQuest"/>.</param>
        public static void SocializeQuest_loadQuestInfo(SocializeQuest __instance)
        {
            try
            {
                List <string> excluded = new List <string>();                                    //a record of NPCs excluded during this process

                Dictionary <string, List <string> > exclusions = ModEntry.GetAllNPCExclusions(); //get all exclusion data

                for (int x = __instance.whoToGreet.Count - 1; x >= 0; x--)                       //for each NPC name selected by the original method (looping backward to allow removal)
                {
                    if (exclusions.ContainsKey(__instance.whoToGreet[x]))                        //if this NPC has exclusion data
                    {
                        if (exclusions[__instance.whoToGreet[x]].Exists(entry =>
                                                                        entry.StartsWith("All", StringComparison.OrdinalIgnoreCase) || //if this NPC is excluded from everything
                                                                        entry.StartsWith("TownQuest", StringComparison.OrdinalIgnoreCase) || //OR if this NPC is excluded from town quests
                                                                        entry.StartsWith("Socialize", StringComparison.OrdinalIgnoreCase) //OR if this NPC is excluded from socialize quests
                                                                        ))
                        {
                            excluded.Add(__instance.whoToGreet[x]); //add this NPC to the record
                            __instance.whoToGreet.RemoveAt(x);      //remove this NPC from the greeting list
                        }
                    }
                }

                if (excluded.Count > 0)                                           //if any NPCs were excluded
                {
                    __instance.total.Value -= excluded.Count;                     //subtract the removed NPCs from the quest's total
                    __instance.objective.Value.param[1] = __instance.total.Value; //update the displayed total

                    if (ModEntry.Instance.Monitor.IsVerbose)
                    {
                        ModEntry.Instance.Monitor.Log($"Excluded NPCs from socialize quest: {String.Join(", ", excluded)}", LogLevel.Trace);
                    }
                }
            }
            catch (Exception ex)
            {
                ModEntry.Instance.Monitor.LogOnce($"Harmony patch \"{nameof(SocializeQuest_loadQuestInfo)}\" has encountered an error and may revert to default behavior. Full error message:\n{ex.ToString()}", LogLevel.Error);
            }
        }
Exemple #4
0
        /// <summary>The method invoked each update tick while the player is holding the left mouse button.</summary>
        /// <param name="x">The X-position of the cursor.</param>
        /// <param name="y">The Y-position of the cursor.</param>
        /// <returns>Whether the event has been handled and shouldn't be propagated further.</returns>
        public override void leftClickHeld(int x, int y)
        {
            // calculate new value
            base.leftClickHeld(x, y);
            this.Value = x >= this.bounds.X ? (x <= this.bounds.Right - 10 * Game1.pixelZoom ? (int)((x - this.bounds.X) / (this.bounds.Width - 10d * Game1.pixelZoom) * this.SliderMaxValue) : this.SliderMaxValue) : 0;

            // add friendship if needed
            if (!Game1.player.friendshipData.TryGetValue(this.Npc.Name, out Friendship friendship))
            {
                friendship = new Friendship();
                Game1.player.friendshipData.Add(this.Npc.Name, friendship);
                SocializeQuest socialQuest = Game1.player.questLog.OfType <SocializeQuest>().FirstOrDefault();
                if (socialQuest != null && !socialQuest.completed.Value)
                {
                    socialQuest.checkIfComplete(this.Npc);
                }
                this.greyedOut = false;
            }

            // update friendship points
            friendship.Points = this.Value * NPC.friendshipPointsPerHeartLevel;
            this.OnValueChanged(friendship.Points);
        }