Beispiel #1
0
        private static bool TryToEatFood(NPC __instance, PlacedFoodData food)
        {
            if (food != null && Vector2.Distance(food.foodTile, __instance.getTileLocation()) < Config.MaxDistanceToEat)
            {
                SMonitor.Log($"eating {food.foodObject.Name} at {food.foodTile}");
                using (IEnumerator <Furniture> enumerator = __instance.currentLocation.furniture.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        if (enumerator.Current.boundingBox.Value != food.furniture.boundingBox.Value)
                        {
                            continue;
                        }
                        if (food.slot > -1)
                        {
                            enumerator.Current.modData.Remove("aedenthorn.FurnitureDisplayFramework/" + food.slot);
                            SMonitor.Log($"ate food at slot {food.slot} in {enumerator.Current.Name}");
                        }
                        else
                        {
                            enumerator.Current.heldObject.Value = null;
                            SMonitor.Log($"ate held food in {enumerator.Current.Name}");
                        }

                        if (__instance.currentLocation is FarmHouse)
                        {
                            Farmer owner = (__instance.currentLocation as FarmHouse).owner;

                            if (owner.friendshipData.ContainsKey(__instance.Name) && (owner.friendshipData[__instance.Name].IsMarried() || owner.friendshipData[__instance.Name].IsRoommate()))
                            {
                                int points = 80;
                                switch (food.value)
                                {
                                case 1:
                                    points = 45;
                                    break;

                                case 2:
                                    points = 20;
                                    break;

                                default:
                                    __instance.doEmote(20);
                                    break;
                                }
                                owner.friendshipData[__instance.Name].Points += (int)(points * Config.PointsMult);
                                SMonitor.Log($"Friendship with {owner.Name} increased by {(int)(points * Config.PointsMult)} points!");
                            }
                        }
                        __instance.modData["aedenthorn.FoodOnTheTable/LastFood"] = Game1.timeOfDay.ToString();
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
        private static void NPC_performTenMinuteUpdate_Postfix(NPC __instance)
        {
            if (!Config.EnableMod || Game1.eventUp || !WantsToEat(__instance))
            {
                return;
            }
            PlacedFoodData food = GetClosestFood(__instance, __instance.currentLocation);

            TryToEatFood(__instance, food);
        }
Beispiel #3
0
        private static void FarmHouse_updateEvenIfFarmerIsntHere_Postfix(FarmHouse __instance)
        {
            if (!Config.EnableMod || !Game1.IsMasterGame)
            {
                return;
            }
            foreach (NPC npc in __instance.characters)
            {
                if (npc.isVillager())
                {
                    NPC villager = npc;
                    if (villager != null && WantsToEat(villager) && Game1.random.NextDouble() < Config.MoveToFoodChance / 100f && villager.controller == null && villager.Schedule == null && !villager.getTileLocation().Equals(Utility.PointToVector2(__instance.getSpouseBedSpot(villager.Name))) && __instance.furniture.Count > 0)
                    {
                        PlacedFoodData food = GetClosestFood(npc, __instance);
                        if (food == null)
                        {
                            return;
                        }
                        if (TryToEatFood(villager, food))
                        {
                            return;
                        }

                        Vector2 possibleLocation = food.foodTile;
                        int     tries            = 0;
                        int     facingDirection  = -3;
                        while (tries < 3)
                        {
                            int xMove = Game1.random.Next(-1, 2);
                            int yMove = Game1.random.Next(-1, 2);
                            possibleLocation.X += xMove;
                            if (xMove == 0)
                            {
                                possibleLocation.Y += yMove;
                            }
                            if (xMove == -1)
                            {
                                facingDirection = 1;
                            }
                            else if (xMove == 1)
                            {
                                facingDirection = 3;
                            }
                            else if (yMove == -1)
                            {
                                facingDirection = 2;
                            }
                            else if (yMove == 1)
                            {
                                facingDirection = 0;
                            }
                            if (__instance.isTileLocationTotallyClearAndPlaceable(possibleLocation))
                            {
                                break;
                            }
                            tries++;
                        }
                        if (tries < 3)
                        {
                            SMonitor.Log($"Moving to {possibleLocation}");

                            villager.controller = new PathFindController(villager, __instance, new Point((int)possibleLocation.X, (int)possibleLocation.Y), facingDirection, false, false);
                        }
                    }
                }
            }
        }