Esempio n. 1
0
    public override bool Attack(int dx, int dy)
    {
        // Check you have the ammo required to the the attack.
        if (specialInventorySlots[0] != null && specialInventorySlots [0].ammo != "" && GetAmountOf(ItemType.GetItemTypeWithName(specialInventorySlots [0].ammo)) <= 0)
        {
            return(false);
        }

        // Do attack as normal and store if successful.
        bool success = base.Attack(dx, dy);

        // If successful, there is a random chance the weapon used will break.
        if (success == true && specialInventorySlots[0] != null)
        {
            ItemType itemType = specialInventorySlots [0];

            // See if it breaks based on its break chance.
            float r = Random.Range(0f, 1f);
            if (r < itemType.breakChance)
            {
                // The item breaks!

                // Remove it from the special slot if there are none left in your inventory (otherwise remove one of the ones already in the inventory
                //   so that it automatically equips that one.
                if (GetAmountOf(itemType) == 0)
                {
                    RemoveFromSpecial(0);
                }

                // Now remove one of those items from the inventory.
                RemoveFromInventory(itemType);
            }

            // Use up ammo (if it takes ammo).
            if (itemType.ammo != "")
            {
                RemoveFromInventory(ItemType.GetItemTypeWithName(itemType.ammo));
            }
        }

        return(success);
    }
Esempio n. 2
0
 public ItemStack(string itemName, int n)
 {
     Setup(ItemType.GetItemTypeWithName(itemName), n);
 }