Пример #1
0
        public static float ComputeItemChances(ItemBoxSettings settings)
        {
            float total = 0;

            foreach (var item in settings.ItemsChances)
            {
                total += item.Chances;
            }

            return(total);
        }
Пример #2
0
        private void UpgradeSelf(ItemBoxSettings settings)
        {
            var sphereMain = _sphere.main;

            sphereMain.startColor = settings.SphereColor;
            var sphereSurroundingsMain = _sphereSurroundings.main;

            sphereSurroundingsMain.startColor = settings.SphereSurroundingParticlesColor;
            var sphereCenterMain = _sphereCenter.main;

            sphereCenterMain.startColor = settings.SphereCenterColor;
            _centerLight.color          = settings.CenterLightColor;

            CurrentSettings = settings;
        }
Пример #3
0
        public static Item GetRandomItem(ItemBoxSettings settings)
        {
            var chancesCount = 0f;
            var randomChance = Random.Range(0, ComputeItemChances(settings));

            foreach (var item in settings.ItemsChances)
            {
                chancesCount += item.Chances;
                if (chancesCount > randomChance)
                {
                    return(item.Item);
                }
            }

            return(null);
        }
Пример #4
0
        // PRIVATE

        private IEnumerator GetLotteryItem(ItemBoxSettings settings)
        {
            if (LotteryStarted || !_inventory.IsEmpty())
            {
                yield break;
            }
            LotteryStarted = true;
            OnLotteryStart.Invoke();

            while (_lotteryTimer < ItemsLottery.LotteryDuration && _shortenLottery == false)
            {
                yield return(new WaitForSeconds(0.1f));

                _lotteryTimer += 0.1f;
                OnLotteryUpdate.Invoke(_lotteryTimer / ItemsLottery.LotteryDuration);
            }

            var Item = ItemsLottery.GetRandomItem(settings);

            _inventory.SetItem(Item, Item.Count);

            OnLotteryStop.Invoke();
            ResetLottery();
        }