コード例 #1
0
        private void HarvestCoops(AnimalTasks stats)
        {
            Farm    farm   = Game1.getFarm();
            SFarmer farmer = Game1.player;

            foreach (Building building in farm.buildings)
            {
                if (building is Coop)
                {
                    List <Vector2> itemsToRemove = new List <Vector2>();

                    foreach (KeyValuePair <Vector2, Object> keyvalue in building.indoors.Value.Objects.Pairs)
                    {
                        Object obj = keyvalue.Value;

                        this.Monitor.Log($"Found coop object: {obj.Name} / {obj.Category}/{obj.isAnimalProduct()}", LogLevel.Trace);

                        if (obj.isAnimalProduct() || obj.ParentSheetIndex == 107)
                        {
                            if (this.AddItemToInventory(obj, farmer))
                            {
                                itemsToRemove.Add(keyvalue.Key);
                                stats.ProductsHarvested++;
                                farmer.gainExperience(0, 5);
                            }
                            else
                            {
                                this.Monitor.Log("Inventory full, could not add animal product.", LogLevel.Trace);
                            }
                        }
                    }

                    // Remove the object that were picked up.
                    foreach (Vector2 itemLocation in itemsToRemove)
                    {
                        building.indoors.Value.removeObject(itemLocation, false);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gathers the Animal Products
        /// </summary>
        private void GatherProducts()
        {
            Farm           farm       = Game1.getFarm();
            SFarmer        who        = Game1.player;
            List <Vector2> produceLoc = new List <Vector2>();

            //Scan Coops
            foreach (Building building in farm.buildings)
            {
                if (building is Coop)
                {
                    foreach (var produce in building.indoors.Value.objects.Pairs)
                    {
                        SObject obj = produce.Value;

                        if (obj.isAnimalProduct() || obj.ParentSheetIndex == 107)
                        {
                            if (GiveItemToPlayer(obj, who))
                            {
                                produceLoc.Add(produce.Key);
                                who.gainExperience(0, 5);
                            }
                            else
                            {
                                Monitor.Log("Couldnt add the item to the players inventory, and couldnt find a chest.", LogLevel.Trace);
                            }
                        }
                    }
                    //Now we remove the produce from the coops
                    foreach (var pro in produceLoc)
                    {
                        building.indoors.Value.removeObject(pro, false);
                    }
                }
            }

            produceLoc.Clear();

            //Now we scan for Truffles
            foreach (var obj in farm.Objects.Pairs)
            {
                if (obj.Value.Name.Contains("Truffle"))
                {
                    bool doubleChance = Game1.random.NextDouble() < 0.2;


                    obj.Value.Quality = who.professions.Contains(16) ? 4 : obj.Value.Quality;

                    if (Game1.player.professions.Contains(13) && doubleChance)
                    {
                        obj.Value.Stack = 2;
                    }

                    //Try to add to inventory or chest
                    if (GiveItemToPlayer(obj.Value, who))
                    {
                        produceLoc.Add(obj.Key);
                        int amt = obj.Value.Stack > 1 ? 14 : 7;

                        who.gainExperience(2, amt);
                    }
                    else
                    {
                        Monitor.Log($"Inventory was full, couldnt add {obj.Value.Name}.");
                    }
                }
            }

            foreach (var p in produceLoc)
            {
                farm.removeObject(p, false);
            }
        }