Exemplo n.º 1
0
        void SetWeaponItem(WeaponIndex w)
        {
            if (inventory == null || shop == null)
            {
                return;
            }

            // get current
            IWeaponItem weaponItem = inventory.Weapons.Get(w);
            IAmmoItem   ammoItem   = inventory.Ammo.Get(weaponItem.AmmoType);

            //// get image
            //var renderTexture = weaponsWorldUI.GetImage(w);

            //Texture2D texture2D = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);
            //RenderTexture.active = renderTexture;
            //texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
            //texture2D.Apply();
            //byte[] png = texture2D.EncodeToPNG();
            //System.IO.File.WriteAllBytes("D:/UI/UI_Weapon_" + Enum.GetName(typeof(WeaponIndex), w) + ".png", png);
            //RenderTexture.active = null;
            //print("saved");

            //// set info
            //weaponShopItem.SetInfo(shop, weaponItem, ammoItem, renderTexture);
            weaponShopItem.SetInfo(shop, weaponItem, ammoItem, weaponItem.Icon.texture);
        }
Exemplo n.º 2
0
        public int CanBeBought(AmmunitionType type)
        {
            IAmmoItem item = inventory.Ammo.Get(type);

            Debug.Assert(item.MaxAmount >= item.CurrentAmount, "Ammo item must be <= than max amount" + item.This);
            return(item.MaxAmount - item.CurrentAmount);
        }
Exemplo n.º 3
0
        public void SetInfo(IShop shop, IWeaponItem weaponItem, IAmmoItem ammoItem, Texture image)
        {
            this.shop       = shop;
            this.weaponItem = weaponItem;
            this.ammoItem   = ammoItem;

            // firstly, set const info
            nameText.text = GetTranslation(weaponItem.TranslationKey);

            ammoImage.sprite = ammoItem.Icon;

            SetPercentage(damageIndicatorImage, maxIndicatorsWidth,
                          Mathf.Clamp(weaponItem.Damage / IndicatorMaxDamage, 0, 1));

            SetPercentage(durabilityIndicatorImage, maxIndicatorsWidth,
                          Mathf.Clamp(weaponItem.Durability / IndicatorMaxDurability, 0, 1));

            SetPercentage(fireRateIndicatorImage, maxIndicatorsWidth,
                          Mathf.Clamp(weaponItem.RoundsPerMinute / IndicatorMaxFireRate, 0, 1));

            SetPercentage(accuracyIndicatorImage, maxIndicatorsWidth,
                          Mathf.Clamp(weaponItem.Accuracy / IndicatorMaxAccuracy, 0, 1));

            // then updateable info
            UpdateInfo();

            SetImage(image);
        }
Exemplo n.º 4
0
        // Action onAmmoDeselection;

        public void Set(IWeaponItem item, IAmmoItem ammo, Action <WeaponIndex> onWeaponSelection, Action <AmmunitionType> onAmmoSelection) // , Action onAmmoDeselection)
        {
            gameObject.SetActive(true);

            // this.onWeaponSelection = () => onWeaponSelection(item.Index);

            this.onAmmoSelection = () => onAmmoSelection(item.AmmoType);
            // this.onAmmoDeselection = onAmmoDeselection;

            SetName(item);
            SetHealth(item);

            if (button == null)
            {
                button = GetComponentInChildren <Button>();
            }

            // reinit listeners
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => onWeaponSelection(item.Index));

            button.interactable = (item.Health > 0 || item.IsAmmo) && ammo.CurrentAmount > 0;

            // Vector2 size = healthImage.sizeDelta;
            // healthImage.sizeDelta = new Vector2((float)item.Health / item.Durability * healthImageMaxWidth, size.y);
        }
Exemplo n.º 5
0
        public void Set(IWeaponItem item, IAmmoItem ammo,
                        Action <WeaponIndex> select, Action <WeaponIndex, bool> highlight, Action unhighlight)
        {
            Check();

            this.select      = () => select(item.Index);
            this.highlight   = (canBeSelected) => highlight(item.Index, canBeSelected);
            this.unhighlight = unhighlight;

            weaponIcon.rectTransform.eulerAngles = new Vector3(0, 0, 0);
            weaponIcon.sprite = item.Icon;

            imageTransform.gameObject.SetActive(true);

            isInteractable = (item.Health > 0 || item.IsAmmo) && ammo.CurrentAmount > 0;

            if (isInteractable)
            {
                image.color = DefaultImageColor;
                imageTransform.sizeDelta = defaultImageSize;
                sectorImage.color        = defaultColor;
            }
            else
            {
                image.color = DisabledImageColor;
                imageTransform.sizeDelta = smallImageSize;
                sectorImage.color        = disabledColor;
            }

            sectorImage.rectTransform.sizeDelta = defaultSectorImageSize;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Set info about ammo item
        /// </summary>
        public void SetInfo(IShop shop, IAmmoItem item)
        {
            this.shop     = shop;
            this.ammoItem = item;

            nameText.text    = GetTranslation(ammoItem.TranslationKey);
            ammoImage.sprite = ammoItem.Icon;

            UpdateInfo();
        }
Exemplo n.º 7
0
        void Highlight(WeaponIndex w, bool canBeSelected)
        {
            IWeaponItem weaponItem = inventory.Weapons.Get(w);
            IAmmoItem   ammoItem   = inventory.Ammo.Get(weaponItem.AmmoType);

            SetName(weaponItem);
            SetHealth(weaponItem);
            SetAmmo(ammoItem);

            isSelected = canBeSelected;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get price for any amount of ammo
        /// </summary>
        public virtual int GetAmmoPrice(IAmmoItem item, int amount)
        {
            if (amount % item.AmountToBuy == 0)
            {
                return(item.Price * (amount / item.AmountToBuy));
            }

            int priceForOne = (int)((float)item.Price / item.AmountToBuy);

            return(amount * priceForOne);
        }
Exemplo n.º 9
0
 public bool EnoughMoneyToBuy(IWeaponItem item)
 {
     if (!item.IsAmmo)
     {
         return(GetWeaponPrice(item) <= inventory.Money);
     }
     else
     {
         IAmmoItem ammoItem = inventory.Ammo.Get(item.AmmoType);
         return(EnoughMoneyToBuy(ammoItem, ammoItem.AmountToBuy));
     }
 }
Exemplo n.º 10
0
        public bool ReceiveAmmoPickup(AmmunitionType type, int amount)
        {
            IAmmoItem ammo = playerInventory.Ammo.Get(type);

            // if ammo is not max
            if (ammo.CurrentAmount < ammo.MaxAmount)
            {
                // then add
                ammo.CurrentAmount += amount;
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        void SetAmmo(IAmmoItem item)
        {
            ammoTypeImage.enabled = ammoAmountText.enabled = item != null;

            if (item == null)
            {
                return;
            }

            ammoAmountText.text  = item.CurrentAmount.ToString();
            ammoTypeImage.sprite = item.Icon;

            ammoAmountText.color = ammoTypeImage.color =
                item.CurrentAmount != 0 ? ammoColor : ammoEmptyColor;
        }
Exemplo n.º 12
0
        public bool BuyAmmo(AmmunitionType type, bool buyAll)
        {
            IAmmoItem item = inventory.Ammo.Get(type);

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

            int current = item.CurrentAmount;

            int newAmount;

            if (buyAll)
            {
                newAmount = item.MaxAmount;
            }
            else
            {
                newAmount = current + item.AmountToBuy;

                if (newAmount > item.MaxAmount)
                {
                    newAmount = item.MaxAmount;
                }
            }

            // how many ammo to buy
            int diff = newAmount - current;

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

            int price = GetAmmoPrice(item, diff);

            inventory.Money -= price;

            OnAmmoBuy?.Invoke(item.This, price);

            item.CurrentAmount = newAmount;

            return(true);
        }
Exemplo n.º 13
0
        void UpdateList()
        {
            IWeaponsHolder weapons = inventory.Weapons;
            IAmmoHolder    ammo    = inventory.Ammo;

            List <WeaponIndex> available = weapons.GetAvailableWeaponsInGame();
            int availableAmount          = available.Count;

            if (availableAmount == 0)
            {
                weaponSelectionObj.SetActive(false);
                noAvailableWeaponsObj.SetActive(true);
            }
            else
            {
                weaponSelectionObj.SetActive(true);
                noAvailableWeaponsObj.SetActive(false);
            }

            int counter = 0;

            foreach (WeaponButton b in buttons.Values)
            {
                if (counter < availableAmount)
                {
                    IWeaponItem w = weapons.Get(available[counter]);
                    IAmmoItem   a = ammo.Get(w.AmmoType);

                    //if (!w.IsAmmo || (w.IsAmmo && a.CurrentAmount > 0))
                    {
                        b.Set(w, a, SelectWeapon, ammoList.HighlightAmmo);
                    }
                    //else
                    //{
                    //    b.gameObject.SetActive(false);
                    //}
                }
                else
                {
                    // disable other buttons
                    b.gameObject.SetActive(false);
                }

                counter++;
            }
        }
Exemplo n.º 14
0
        void UpdateWheel()
        {
            if (inventory == null)
            {
                inventory = GameController.Instance.Inventory;
            }

            IWeaponsHolder weapons = inventory.Weapons;
            IAmmoHolder    ammo    = inventory.Ammo;

            List <WeaponIndex> available = weapons.GetAvailableWeaponsInGame();
            int availableAmount          = available.Count;

            GameObject wheel = GetWheel(availableAmount);

            if (wheel == null)
            {
                return;
            }

            int counter = 0;

            var bs = wheel.GetComponentsInChildren <WeaponWheelButton>(true);

            foreach (WeaponWheelButton b in bs)
            {
                b.SetColors(defaultColor, highlitedColor, disabledColor);

                if (counter < availableAmount)
                {
                    IWeaponItem w = weapons.Get(available[counter]);
                    IAmmoItem   a = ammo.Get(w.AmmoType);

                    b.Set(w, a, Select, Highlight, Unhighlight);
                }
                else
                {
                    // disable buttons without weapon
                    b.Disable();
                }

                counter++;
            }
        }
Exemplo n.º 15
0
 public bool EnoughMoneyToBuy(IAmmoItem item, int amount)
 {
     return(GetAmmoPrice(item, amount) <= inventory.Money);
 }