//Imports inventories from file given filename
        public static void ImportInventories(string filename)
        {
            #region Setup
            string    storageFile = Directory.GetCurrentDirectory() + "\\" + filename;
            string[]  lines       = File.ReadAllLines(storageFile);
            Inventory inv         = null;
            #endregion

            foreach (string data in lines)                                                              //For each line
            {
                switch (data)
                {
                case var someVal when(new Regex("^[\\w\\s]+$").IsMatch(someVal)):                       //If it has no attributes, but isn't empty
                    inv = new Inventory(data, new List <Item>());                                       //It's the name of a new inventory, so prep one.

                    break;

                case var someVal when(new Regex(AttFinder).Matches(someVal).Count != 0):                //There are attributes
                    Item item = ItemCreate(new ItemData(data));                                         //Create an item from the data on this line

                    inv.inventData.Add(item);                                                           //Add it to the current inventory.
                    break;

                default:                                                                                //It is empty, this is the end of an inventory
                    Inventories.Add(inv);                                                               //So add it to the list of inventories
                    break;
                }
            }
        }
示例#2
0
        //Generate a random inventory!
        public static Inventory GenerateInv()
        {
            var r     = new Random();
            int i     = 0;
            int level = 0;

            do
            {
                level++;                                                //Keep incrementing the level until you roll a 1
                i = r.Next(5);
            }while (i != 1);
            level = Math.Min(level, ItemTable.Length);                  //limit the level by the ItemTable list length

            string inventName;

            do
            {
                InventoryNum++;
                inventName = "Inventory" + InventoryNum.ToString();     //Generate a unique inventory name by Inventory+the counter
            }while (Inventories.Exists(x => x.name == inventName));

            var newInv = new Inventory(inventName, new List <Item>());   //Create the new inventory

            int num = r.Next(level);

            for (int j = 0; j < num; j++)                               //Add a random number of items between 1 and level
            {
                newInv.inventData.Add(ItemTable[r.Next(level)]);        //Of a random index between 1 and level
            }
            Inventories.Add(newInv);                                    //Add the inventory
            return(newInv);                                             //Return the inventory
        }
示例#3
0
 public void AddInventory(IInventory inv)
 {
     if (GetInventoryByUUID(inv.InventoryUUID) == null)
     {
         //Debug.Log("Adding inventory [" + inv.InventoryUUID + "] to the inventory manager");
         Inventories.Add(inv);
     }
 }
示例#4
0
        public InventoryModel CreateNewPlayerHand()
        {
            var inventory = new InventoryModel();

            inventory.PaperCount    = 3;
            inventory.ScissorsCount = 3;
            inventory.RockCount     = 3;
            Inventories.Add(inventory);
            return(inventory);
        }
示例#5
0
        /// <summary>
        /// 添加一个库存
        /// </summary>
        /// <param name="key"></param>
        /// <param name="inventory"></param>
        private void Add(string key, IMyInventory inventory)
        {
            if (!Inventories.ContainsKey(key))
            {
                Inventories.Add(key, new List <IMyInventory>());
            }
            Inventories[key].Add(inventory);
            var inventoryItems = new List <MyInventoryItem>();

            inventory.GetItems(inventoryItems);
            foreach (MyInventoryItem inventoryItem in inventoryItems)
            {
                AddItem(inventoryItem);
            }
        }
示例#6
0
        public void AddInventoryTest()
        {
            Inventories target = DatabaseObject.Inventories;

            Inventory inventory = new Inventory();

            inventory.Stock = new Stock {
                Code = "TAN", Name1 = "Tan Brown"
            };
            inventory.Warehouse = new Warehouse {
                Name1 = "Bukit Pinang"
            };
            inventory.Width  = 72;
            inventory.Height = 24;

            target.Add(50, inventory);
            //target.SaveToFile();
        }
示例#7
0
 //Shorthand constructor for use by the wall class
 public Entity(string name, Coordinate position, char icon, Inventory inventory, int[] stats, string description)
 {
     Name           = name;
     this.position  = position;
     this.Inventory = inventory;
     DrawPriority   = 1;
     this.Icon      = icon;
     Stats          = stats;
     Description    = description;
     Passive        = true;
     Passable       = true;
     if (inventory != null)
     {
         if (!Inventories.Contains(inventory))
         {
             Inventories.Add(inventory);
         }
     }
     EquipUpdate();
 }
示例#8
0
        public TerminalBlock(IMyTerminalBlock block, bool light = true)
        {
            Name = block.CustomName;
            var def = block.BlockDefinition;

            Type = $"{def.TypeId}/{def.SubtypeId}";
            Id   = block.EntityId;

            if (light)
            {
                return;
            }

            if (block.HasInventory)
            {
                var count = block.InventoryCount;
                for (var i = 0; i < count; i++)
                {
                    Inventories.Add(new Inventory(block.GetInventory(i)));
                }
            }

            block.GetProperties(new List <ITerminalProperty>(), p =>
            {
                var prop = new BlockProperty(p, block);
                if (prop.IsValid)
                {
                    Properties.Add(prop);
                }
                return(false);
            });

            foreach (var action in MyTerminalControlFactory.GetActions(block.GetType()))
            {
                Actions.Add(action.Id);
            }
        }
 internal void FatBlockAdded(MyCubeBlock myCubeBlock)
 {
     try
     {
         var battery = myCubeBlock as MyBatteryBlock;
         if (battery != null)
         {
             if (Batteries.Add(battery))
             {
                 SourceCount++;
             }
             UpdatePowerSources = true;
         }
         else if (myCubeBlock is IMyCargoContainer || myCubeBlock is IMyAssembler || myCubeBlock is IMyShipConnector || myCubeBlock is MyCockpit)
         {
             MyInventory inventory;
             if (myCubeBlock.TryGetInventory(out inventory) && Inventories.Add(inventory))
             {
                 inventory.InventoryContentChanged += CheckAmmoInventory;
                 foreach (var item in inventory.GetItems())
                 {
                     var ammoMag = item.Content as MyObjectBuilder_AmmoMagazine;
                     if (ammoMag != null && AmmoInventories.ContainsKey(ammoMag.GetObjectId()))
                     {
                         CheckAmmoInventory(inventory, item, item.Amount);
                     }
                 }
             }
         }
         else if (myCubeBlock is IMyUserControllableGun || myCubeBlock is MyConveyorSorter)
         {
             ScanBlockGroups = true;
         }
     }
     catch (Exception ex) { Log.Line($"Exception in Controller FatBlockAdded: {ex}"); }
 }
示例#10
0
 public void AddInventory(Inventory inventory)
 {
     Inventories.Add(inventory);
 }
示例#11
0
        private void AddItemsToInventoryTracker(GameLocation loc)
        {
            var locObjs = loc.Objects;

            foreach (var key in locObjs.Keys)
            {
                if (locObjs[key] != null)
                {
                    if (locObjs[key].Name == "Chest" && locObjs[key].As <ChestAccessor, Chest>().Items.Count > 0)
                    {
                        var chest = new InventoryTracker();
                        chest.Id = ChestCount + 1;
                        ChestCount++;
                        chest.Position = new Vector2 {
                            X = locObjs[key].As <ChestAccessor, Chest>().BoundingBox.X, Y = locObjs[key].As <ChestAccessor, Chest>().BoundingBox.Y
                        };
                        chest.Location = loc.Name;

                        for (int i = 0; i < locObjs[key].As <ChestAccessor, Chest>().Items.Count; i++)
                        {
                            var item = locObjs[key].As <ChestAccessor, Chest>().Items[i];

                            if (item != null && item.Underlying.GetType().ToString() == "StardewValley.Object")
                            {
                                chest.Items.Add(item.As <ObjectAccessor, ObjectItem>());
                            }
                        }

                        if (!Inventories.Contains(chest))
                        {
                            Inventories.Add(chest);
                        }
                        else
                        {
                            Inventories.Remove(chest);
                            Inventories.Add(chest);
                        }
                    }
                }
            }

            //Add character inventory too.
            var playerInv = new InventoryTracker {
                Location = "Character"
            };

            //First, check if it exists and remove it if it does.
            if (Inventories.Exists(c => c.Location == "Character"))
            {
                int index = Inventories.FindIndex(c => c.Location == "Character");
                Inventories.RemoveAt(index);
            }

            // Get all items in players inventory and add them to the List<ObjectItem>
            for (int i = 0; i < Root.Player.Items.Count; i++)
            {
                if (Root.Player.Items[i] != null && Root.Player.Items[i].Underlying.GetType().ToString() == "StardewValley.Object")
                {
                    playerInv.Items.Add(Root.Player.Items[i].As <ObjectAccessor, ObjectItem>());
                }
            }

            Inventories.Add(playerInv);
        }