Ejemplo n.º 1
0
    public void Add(ItemBase toAdd, int amount)
    {
        DataLogger.LogMessage("Item added: " + toAdd.name);
        InventoryItem myInvItem;

        if (toAdd is Equipment)
        {
            InventoryEquipment myEq = myEquipments.Find(x => x.item.name == toAdd.name);
            myInvItem = new InventoryEquipment((Equipment)toAdd, amount);
            if (myEq != null)
            {
                myEq.chargesLeft += amount;
            }
            else
            {
                myEquipments.Add((InventoryEquipment)myInvItem);
            }

            if (activeEquipment == null)
            {
                EquipItem((InventoryEquipment)myInvItem);
            }
        }
        else if (toAdd is Ingredient)
        {
            InventoryIngredient myIng = myIngredients.Find(x => x.item.name == toAdd.name);
            myInvItem = new InventoryIngredient((Ingredient)toAdd, amount);
            if (myIng != null)
            {
                myIng.chargesLeft += amount;
            }
            else
            {
                myIngredients.Add((InventoryIngredient)myInvItem);
            }
        }
        else
        {
            InventoryPotion myPot = myPotions.Find(x => x.item.name == toAdd.name);
            myInvItem = new InventoryPotion((Potion)toAdd, amount);
            if (myPot != null)
            {
                myPot.chargesLeft += amount;
            }
            else
            {
                myPotions.Add((InventoryPotion)myInvItem);
            }
        }

        if (ItemGainedScreen.s != null)
        {
            ItemGainedScreen.s.ShowGainedItem(myInvItem);
        }

        SaveMaster.s.Save();
    }
Ejemplo n.º 2
0
    public void Remove(ItemBase toRemove, int amount)
    {
        //InventoryItem myInvItem;
        if (toRemove is Equipment)
        {
            InventoryEquipment myEq = myEquipments.Find(x => x.item.name == toRemove.name);
            //myInvItem = new InventoryEquipment ((Equipment)toRemove, toRemove.durability);

            bool didRemove = false;
            if (myEq != null)
            {
                myEq.chargesLeft -= amount;
                if (myEq.chargesLeft <= 0)
                {
                    myEquipments.Remove(myEq);
                    didRemove = true;
                }
            }
            else
            {
                DataLogger.LogError("Cant remove item! " + toRemove.name + " - " + amount.ToString());
            }

            if (didRemove)
            {
                if (toRemove.name == activeEquipment.item.name)
                {
                    activeEquipment = null;
                }
            }
        }
        else if (toRemove is Ingredient)
        {
            InventoryIngredient myIng = myIngredients.Find(x => x.item.name == toRemove.name);
            //myInvItem = new InventoryIngredient ((Ingredient)toRemove, toRemove.durability);
            if (myIng != null)
            {
                myIng.chargesLeft -= amount;
                if (myIng.chargesLeft <= 0)
                {
                    myIngredients.Remove(myIng);
                }
            }
            else
            {
                DataLogger.LogError("Cant remove item! " + toRemove.name + " - " + amount.ToString());
            }
        }
        else
        {
            InventoryPotion myPot = myPotions.Find(x => x.item.name == toRemove.name);
            //myInvItem = new InventoryPotion ((Potion)toRemove, toRemove.durability);
            if (myPot != null)
            {
                myPot.chargesLeft -= amount;
                if (myPot.chargesLeft <= 0)
                {
                    myPotions.Remove(myPot);
                }
            }
            else
            {
                DataLogger.LogError("Cant remove item! " + toRemove.name + " - " + amount.ToString());
            }
        }
    }