Esempio n. 1
0
        static private void LoadInv(StreamReader sr)
        {
            int         id      = int.Parse(sr.ReadLine());
            int         counter = int.Parse(sr.ReadLine());
            List <bool> amountNegativeOrPositive = new List <bool>();
            List <Item> items = new List <Item>();

            for (int i = 0; i < counter; i++)
            {
                string   protoData = sr.ReadLine();
                string[] data      = protoData.Split(';');
                int      itemID    = int.Parse(data[0]);
                int      amount    = int.Parse(data[1]);
                items.Add(ItemCreator.CreateItem(itemID, amount));
                if (data[2] == "-")
                {
                    amountNegativeOrPositive.Add(false);
                }
                else
                {
                    amountNegativeOrPositive.Add(true);
                }
            }
            inventoryList.Add(new InventoryTemplate(id, amountNegativeOrPositive, items));
        }
        static private Inventory LoadCityMerchant(string name)
        {
            string       path    = Path.Combine("./Data/City_Data/", name + ".txt");
            StreamReader sr      = new StreamReader(path);
            Inventory    temp    = new Inventory(int.Parse(sr.ReadLine()));
            int          counter = int.Parse(sr.ReadLine());

            for (int i = 0; i < counter; i++)
            {
                string   data  = sr.ReadLine();
                string[] data2 = data.Split(';');

                int placeCounter = 0;
                int tempNr       = 0;
                foreach (string item in itemList)
                {
                    if (item == data2[0])
                    {
                        tempNr = placeCounter;
                    }
                    placeCounter++;
                }

                Item newItem = ItemCreator.CreateItem(tempNr, int.Parse(data2[1]));
                temp.AddItem(newItem);
            }

            return(temp);
        }
        void AddStacks(int itemID, int amount)
        {
            if (amount > 0) // Egentligen onödig men ökar maintainability
            {
                int amountOfStacks = HowManyStacks(amount);
                while (amountOfStacks > 0)
                {
                    int tmp = StackLimit - amount;
                    if (tmp > 0)
                    {
                        itemList.Add(ItemCreator.CreateItem(itemID, amount));

                        --amountOfStacks;
                    }
                    else if (tmp == 0)
                    {
                        itemList.Add(ItemCreator.CreateItem(itemID, StackLimit));
                        --amountOfStacks;
                    }
                    else
                    {
                        itemList.Add(ItemCreator.CreateItem(itemID, StackLimit));
                        amount -= 50;
                        --amountOfStacks;
                    }
                }
            }
        }
        //skum jag vet men fixade problem med referenser som pekar på samma objekt i minnet
        public Inventory(Inventory inv)
        {
            money    = inv.Money;
            itemList = new List <Item>();
            foreach (Item item in inv.ItemList)
            {
                itemList.Add(ItemCreator.CreateItem(item.ID, item.Amount));
            }

            Initialize();
        }
Esempio n. 5
0
 static private void DebugFunctions()
 {
     if (test)
     {
         if (KMReader.prevKeyState.IsKeyUp(Keys.A) && KMReader.keyState.IsKeyDown(Keys.A))
         {
             inventory.AddItem(ItemCreator.CreateItem(0, 20));
         }
         if (KMReader.prevKeyState.IsKeyUp(Keys.B) && KMReader.keyState.IsKeyDown(Keys.B))
         {
             inventory.AddItem(ItemCreator.CreateItem(1, 30));
         }
         if (KMReader.prevKeyState.IsKeyUp(Keys.C) && KMReader.keyState.IsKeyDown(Keys.C))
         {
             inventory.AddItem(ItemCreator.CreateItem(2, 10));
         }
     }
 }
        static private void ReadPlayerData(StreamReader streamReader, Inventory tempInv)
        {
            Player.Location = streamReader.ReadLine();


            for (int i = 0; i < WorldMapMenu.nrCities; i++)
            {
                string temp = streamReader.ReadLine();
                if (temp == "true")
                {
                    Player.VisitedCities[i] = true;
                }
                else if (temp == "false")
                {
                    Player.VisitedCities[i] = false;
                }
            }

            int[] tempLevels = new int[3];
            for (int i = 0; i < 3; i++)
            {
                tempLevels[i] = int.Parse(streamReader.ReadLine());
            }
            Player.SkillLevels = tempLevels;

            CharCreationMenu.ConfirmedAvatar = int.Parse(streamReader.ReadLine());
            tempInv.Money = int.Parse(streamReader.ReadLine());
            int counter = int.Parse(streamReader.ReadLine());

            for (int i = 0; i < counter; i++)
            {
                string   tempData = streamReader.ReadLine();
                string[] data2    = tempData.Split(';');
                Item     newItem  = ItemCreator.CreateItem(int.Parse(data2[0]), int.Parse(data2[1]));
                tempInv.AddItem(newItem);
            }
            Player.Inventory = tempInv;
        }