Beispiel #1
0
    public Item AddItem(Weapon weapon)
    {
        Item item;

        item                = Instantiate(_template, transform);
        item.Weapon         = weapon;
        item.OnButtonClick += (X) => OnWeaponBuy?.Invoke(X);
        item.name           = _template.name + (transform.childCount + 1);
        return(item);
    }
Beispiel #2
0
        public bool BuyWeapon(WeaponIndex type)
        {
            IWeaponItem item = inventory.Weapons.Get(type);

            if (item.IsAmmo)
            {
                bool boughtAsAmmo = BuyAmmo(item.AmmoType, false);

                if (boughtAsAmmo)
                {
                    item.IsBought = true;
                }

                return(boughtAsAmmo);
            }

            if (!CanBeBought(type))
            {
                Debug.Log("ShopSystem: weapon must be buyable: " + type);
                return(false);
            }

            if (!EnoughMoneyToBuy(item))
            {
                return(false);
            }

            int price = GetWeaponPrice(item);

            inventory.Money -= price;

            item.IsBought = true;
            item.Health   = item.Durability;

            // weapon is bought, most likely that player
            // wants to add it to selected
            inventory.Weapons.Select(item.Index);

            OnWeaponBuy?.Invoke(item.Index, price);

            return(true);
        }