Esempio n. 1
0
        /// <summary>
        /// Add an object to a netList of items.
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="I"></param>
        /// <returns></returns>
        public static bool addItemToOtherInventory(NetObjectList <Item> inventory, Item I)
        {
            if (I == null)
            {
                return(false);
            }
            if (isInventoryFull(inventory) == false)
            {
                if (inventory == null)
                {
                    return(false);
                }
                if (inventory.Count == 0)
                {
                    inventory.Add(I);
                    return(true);
                }
                for (int i = 0; i < inventory.Capacity; i++)
                {
                    //   Log.AsyncC("OK????");

                    foreach (var v in inventory)
                    {
                        if (inventory.Count == 0)
                        {
                            addItemToOtherInventory(inventory, I);
                            return(true);
                        }
                        if (v == null)
                        {
                            continue;
                        }
                        if (v.canStackWith(I))
                        {
                            v.addToStack(I.getStack());
                            return(true);
                        }
                    }
                }

                inventory.Add(I);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
 public override void DayUpdate(int dayOfMonth)
 {
     for (int i = itemsToStartSellingTomorrow.Count - 1; i >= 0; i--)
     {
         Item tomorrowItem = itemsToStartSellingTomorrow[i];
         if (itemsFromPlayerToSell.Count < 11)
         {
             bool stacked = false;
             foreach (Item item in itemsFromPlayerToSell)
             {
                 if (item.Name.Equals(tomorrowItem.Name) && (item as Object).quality == (tomorrowItem as Object).quality)
                 {
                     item.Stack += tomorrowItem.Stack;
                     stacked     = true;
                     break;
                 }
             }
             itemsToStartSellingTomorrow.RemoveAt(i);
             if (!stacked)
             {
                 itemsFromPlayerToSell.Add(tomorrowItem);
             }
         }
     }
     base.DayUpdate(dayOfMonth);
 }
Esempio n. 3
0
        private static bool Chest_addItem_Prefix(Chest __instance, Item item, ref Item __result)
        {
            DataAccess  DataAccess = DataAccess.GetDataAccess();
            List <Node> nodes      = DataAccess.LocationNodes[Game1.currentLocation];
            Node        node       = nodes.Find(n => n.Position.Equals(__instance.tileLocation));

            if (node is FilterPipeNode)
            {
                item.resetState();
                __instance.clearNulls();
                NetObjectList <Item> item_list = __instance.items;
                if (__instance.SpecialChestType == Chest.SpecialChestTypes.MiniShippingBin || __instance.SpecialChestType == Chest.SpecialChestTypes.JunimoChest)
                {
                    item_list = __instance.GetItemsForPlayer(Game1.player.UniqueMultiplayerID);
                }
                if (!item_list.Any(x => x.Name.Equals(item.Name)))
                {
                    if (item_list.Count < __instance.GetActualCapacity())
                    {
                        item_list.Add(item.getOne());
                        __result = null;
                    }
                    else
                    {
                        __result = item;
                    }
                }
                return(false);
            }
            return(true);
        }
 public override NetObjectList <Item> UpdateFilter(NetObjectList <Item> filteredItems)
 {
     Filter = new NetObjectList <Item>();
     if (filteredItems == null)
     {
         Filter.Add(Farm.lastItemShipped);
     }
     else
     {
         foreach (Item item in filteredItems.ToList())
         {
             Filter.Add(item);
         }
     }
     return(Filter);
 }
 public bool onDresserItemDeposited(ISalable deposited_salable)
 {
     if (deposited_salable is Item)
     {
         heldItems.Add(deposited_salable as Item);
         if (Game1.activeClickableMenu != null && Game1.activeClickableMenu is ShopMenu)
         {
             Dictionary <ISalable, int[]> contents = new Dictionary <ISalable, int[]>();
             List <Item> list = heldItems.ToList();
             list.Sort(SortItems);
             foreach (Item item in list)
             {
                 contents[item] = new int[2]
                 {
                     0,
                     1
                 };
             }
             (Game1.activeClickableMenu as ShopMenu).setItemPriceAndStock(contents);
             Game1.playSound("dwop");
             return(true);
         }
     }
     return(false);
 }
        private void Harvest(GameLocation greenhouse)
        {
            IsHarvesting         = true;
            currentHarvestingMap = greenhouse;

            try
            {
                var chests = GetChests(greenhouse).ToArray();
                if (!chests.Any())
                {
                    Monitor.Log($"To enable auto harvesting in {greenhouse.Name}, place a chest on the map",
                                LogLevel.Info);
                    return;
                }

                var items    = Game1.player.items;
                int maxItems = Game1.player.MaxItems;
                Game1.player.MaxItems = chests.Length * Chest.capacity;
                var objects = new NetObjectList <Item>();

                for (int i = 0; i < Game1.player.MaxItems * 10; i++)
                {
                    objects.Add(null);
                }

                Helper.Reflection.GetField <NetObjectList <Item> >(Game1.player, "items").SetValue(objects);

                foreach (var terrains in greenhouse.terrainFeatures)
                {
                    foreach (var terrain in terrains)
                    {
                        if (terrain.Value is HoeDirt dirt)
                        {
                            AttemptHarvest(greenhouse, dirt, terrain);
                        }
                    }
                }

                foreach (var item in objects)
                {
                    AttemptToAddToChest(chests, item, greenhouse);
                }

                CollectDebris(chests, greenhouse);

                Game1.player.MaxItems = maxItems;
                Helper.Reflection.GetField <NetObjectList <Item> >(Game1.player, "items").SetValue(items);
                CollectDebris(chests, greenhouse);
            }
            catch (Exception e)
            {
                Monitor.Log(e.ToString(), LogLevel.Error);
            }

            IsHarvesting         = false;
            currentHarvestingMap = null;
        }
Esempio n. 7
0
        public Chest(string type, Vector2 location, MineShaft mine)
        {
            tileLocation.Value = location;
            switch (type)
            {
            case "OreChest":
            {
                for (int i = 0; i < 8; i++)
                {
                    items.Add(new Object(tileLocation, (Game1.random.NextDouble() < 0.5) ? 384 : 382, 1));
                }
                break;
            }

            case "dungeon":
                switch ((int)location.X % 5)
                {
                case 1:
                    coins.Value = (int)location.Y % 3 + 2;
                    break;

                case 2:
                    items.Add(new Object(tileLocation, 382, (int)location.Y % 3 + 1));
                    break;

                case 3:
                    items.Add(new Object(tileLocation, (mine.getMineArea() == 0) ? 378 : ((mine.getMineArea() == 40) ? 380 : 384), (int)location.Y % 3 + 1));
                    break;

                case 4:
                    chestType.Value = "Monster";
                    break;
                }
                break;

            case "Grand":
                tint.Value  = new Color(150, 150, 255);
                coins.Value = (int)location.Y % 8 + 6;
                break;
            }
            base.name         = "Chest";
            base.type.Value   = "interactive";
            boundingBox.Value = new Rectangle((int)tileLocation.X * 64, (int)tileLocation.Y * 64, 64, 64);
        }
Esempio n. 8
0
 public override NetObjectList <Item> UpdateFilter(NetObjectList <Item> filteredItems)
 {
     Filter = new NetObjectList <Item>();
     if (filteredItems == null)
     {
         NetObjectList <Item> itemList = GetItemList();
         foreach (Item item in itemList.ToList())
         {
             Filter.Add(item);
         }
     }
     else
     {
         foreach (Item item in filteredItems.ToList())
         {
             Filter.Add(item);
         }
     }
     return(Filter);
 }
Esempio n. 9
0
 public HikawaShrine(string map, string name)
     : base(map, name)
 {
     for (var i = 0; i < 2; ++i)
     {
         _shrineAnimals.Add(new FarmAnimal("White Chicken", ModEntry.Multiplayer.getNewID(), -1));
         _shrineAnimals[i].Position  = new Vector2(49 + 2 * i, 22 + i) * 64f;
         _shrineAnimals[i].age.Value = _shrineAnimals[i].ageWhenMature.Value;
         _shrineAnimals[i].reloadData();
     }
 }
Esempio n. 10
0
 public virtual Item AddItem(Item item)
 {
     item.resetState();
     ClearNulls();
     for (int i = 0; i < heldItems.Count; i++)
     {
         if (heldItems[i] != null && heldItems[i].canStackWith(item))
         {
             item.Stack = heldItems[i].addToStack(item);
             if (item.Stack <= 0)
             {
                 return(null);
             }
         }
     }
     if (heldItems.Count < 36)
     {
         heldItems.Add(item);
         return(null);
     }
     return(item);
 }
Esempio n. 11
0
 public override void DayUpdate(int dayOfMonth)
 {
     base.DayUpdate(dayOfMonth);
     for (int j = 0; j < characters.Count; j++)
     {
         if (characters[j] != null && characters[j] is Monster)
         {
             characters.RemoveAt(j);
             j--;
         }
     }
     addedSlimesToday.Value = false;
     map.Properties.TryGetValue("Stumps", out PropertyValue rawStumpData);
     if (rawStumpData == null)
     {
         return;
     }
     string[] stumpData = rawStumpData.ToString().Split(' ');
     for (int i = 0; i < stumpData.Length; i += 3)
     {
         int     x          = Convert.ToInt32(stumpData[i]);
         int     y          = Convert.ToInt32(stumpData[i + 1]);
         Vector2 tile       = new Vector2(x, y);
         bool    foundStump = false;
         foreach (ResourceClump stump in stumps)
         {
             if (stump.tile.Equals(tile))
             {
                 foundStump = true;
                 break;
             }
         }
         if (!foundStump)
         {
             stumps.Add(new ResourceClump(600, 2, 2, tile));
             removeObject(tile, showDestroyedObject: false);
             removeObject(tile + new Vector2(1f, 0f), showDestroyedObject: false);
             removeObject(tile + new Vector2(1f, 1f), showDestroyedObject: false);
             removeObject(tile + new Vector2(0f, 1f), showDestroyedObject: false);
         }
     }
 }
Esempio n. 12
0
 public virtual Item AddItem(Item item)
 {
     for (int index = 0; index < Items.Count; ++index)
     {
         if (Items[index] != null && Items[index].canStackWith(item))
         {
             item.Stack = Items[index].addToStack(item.Stack);
             if (item.Stack <= 0)
             {
                 return(null);
             }
         }
     }
     if (Items.Count >= 36)
     {
         return(item);
     }
     Items.Add(item);
     return(null);
 }
Esempio n. 13
0
        public Train()
        {
            initNetFields();
            Random r = new Random();

            if (r.NextDouble() < 0.1)
            {
                type.Value = 3;
            }
            else if (r.NextDouble() < 0.1)
            {
                type.Value = 1;
            }
            else if (r.NextDouble() < 0.1)
            {
                type.Value = 2;
            }
            else if (r.NextDouble() < 0.05)
            {
                type.Value = 5;
            }
            else if (Game1.currentSeason.ToLower().Equals("winter") && r.NextDouble() < 0.2)
            {
                type.Value = 6;
            }
            else
            {
                type.Value = 0;
            }
            int numCars = r.Next(8, 25);

            if (r.NextDouble() < 0.1)
            {
                numCars *= 2;
            }
            speed      = 0.2f;
            smokeTimer = speed * 2000f;
            Color  color = Color.White;
            double chanceForPassengerCar = 1.0;
            double chanceForCoalCar      = 1.0;

            switch ((int)type)
            {
            case 0:
                chanceForPassengerCar = 0.2;
                chanceForCoalCar      = 0.2;
                break;

            case 1:
                chanceForPassengerCar = 0.0;
                chanceForCoalCar      = 0.0;
                color = Color.DimGray;
                break;

            case 3:
                chanceForPassengerCar = 1.0;
                chanceForCoalCar      = 0.0;
                speed = 0.4f;
                break;

            case 2:
                chanceForPassengerCar = 0.0;
                chanceForCoalCar      = 0.7;
                break;

            case 5:
                chanceForCoalCar      = 0.0;
                chanceForPassengerCar = 0.0;
                color = Color.MediumBlue;
                speed = 0.4f;
                break;

            case 6:
                chanceForPassengerCar = 0.0;
                chanceForCoalCar      = 1.0;
                color = Color.Red;
                break;
            }
            cars.Add(new TrainCar(r, 3, -1, Color.White));
            for (int i = 1; i < numCars; i++)
            {
                int whichCar = 0;
                if (r.NextDouble() < chanceForPassengerCar)
                {
                    whichCar = 2;
                }
                else if (r.NextDouble() < chanceForCoalCar)
                {
                    whichCar = 1;
                }
                Color carColor = color;
                if (color.Equals(Color.White))
                {
                    bool redTint   = false;
                    bool greenTint = false;
                    bool blueTint  = false;
                    switch (r.Next(3))
                    {
                    case 0:
                        redTint = true;
                        break;

                    case 1:
                        greenTint = true;
                        break;

                    case 2:
                        blueTint = true;
                        break;
                    }
                    carColor = new Color(r.Next((!redTint) ? 100 : 0, 250), r.Next((!greenTint) ? 100 : 0, 250), r.Next((!blueTint) ? 100 : 0, 250));
                }
                int frontDecal = -1;
                if ((int)type == 1)
                {
                    frontDecal = 2;
                }
                else if ((int)type == 5)
                {
                    frontDecal = 1;
                }
                else if ((int)type == 6)
                {
                    frontDecal = -1;
                }
                else if (r.NextDouble() < 0.3)
                {
                    frontDecal = r.Next(35);
                }
                int resourceType = 0;
                if (whichCar == 1)
                {
                    resourceType = r.Next(9);
                    if ((int)type == 6)
                    {
                        resourceType = 9;
                    }
                }
                cars.Add(new TrainCar(r, whichCar, frontDecal, carColor, resourceType, r.Next(4, 10)));
            }
        }