Beispiel #1
0
/// <summary>
/// called when the player dies at x,y. writes values to the ini
/// </summary>
        public int PlayerDeathINI(float x, float y)
        {
            EmptyInventory(true); //empty the inventory and destroy the player's weapon
            //FillInventoryFromINI();

            ini.Open(DetermineINIPath());

            //jump to the current death section
            int DeathSectionNumber = 0;

            while (ini.IsSectionExists("Death" + ((DeathSectionNumber).ToString())))
            {
                DeathSectionNumber++;
            }

            //variables to be used later
            string DeathSection        = "Death" + ((DeathSectionNumber).ToString());
            bool   InventoryItemsExist = false;

            for (int i = 0; i < InventoryItems.Length; i++)
            {
                if (ini.ReadValue("Inventory", InventoryItems[i].ItemID, 0) >= 1)
                {
                    //if the ini read value of the InventoryItems iterated item is >=1
                    //then we want to write that value to [Death] in the ini file
                    //finally, delete the found key in "Inventory" section so the player doesnt have the items until he collects them again
                    if (!isPurchasable(InventoryItems[i].ItemID)) //only write in non purchasable items
                    {
                        if (!InventoryItemsExist)                 //only write the level and x,y once so that it does not write repeatedly if no items are passed
                        {
                            InventoryItemsExist = true;
                            //write level of death
                            ini.WriteValue(DeathSection, "Level", SceneManager.GetActiveScene().name);
                            //write X and Y Values
                            ini.WriteValue(DeathSection, "x", x);
                            ini.WriteValue(DeathSection, "y", y);
                        }

                        ini.WriteValue(DeathSection, InventoryItems[i].ItemID, ini.ReadValue("Inventory", InventoryItems[i].ItemID, 0)); //write the a death key for each inventory item found
                        ini.KeyDelete("Inventory", InventoryItems[i].ItemID);                                                            // delete the found key so it doesnt spawn with the player again
                    }
                }
            }
            ini.Close();
            //ini.RemoveBlankLines(DetermineINIPath());
            return(DeathSectionNumber);
        }