/// <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); }
/// <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); }