public bool VerifyRestriction(GameElementData restriction)
        {
            if (restriction.type != GameElementType.State)
            {
                return(false);
            }

            if (restriction.key == ProgressType.maxLevel.ToString())
            {
                return(_data.maxLevel >= restriction.value);
            }
            else if (restriction.key == ProgressType.rank.ToString())
            {
                return(_data.rankIndex >= restriction.value);
            }
            else if (restriction.key == ProgressType.xp.ToString())
            {
                return(_data.xp >= restriction.value);
            }
            else if (restriction.key == ProgressType.topScore.ToString())
            {
                return(_data.maxLevel >= restriction.value);
            }

            int index = _data.progress.GetIndex(restriction);

            if (index == -1)
            {
                return(false);
            }
            return(_data.progress[index].value >= restriction.value);
        }
Пример #2
0
 public bool IncreaseCurrency(GameElementData amount)
 {
     currencyIncreasingSignal.Dispatch(amount);
     _data.currencies.Increase(amount);
     updateCurrencySignal.Dispatch(_data);
     return(Save());
 }
Пример #3
0
        private BuyItemResult BuyItemByCostArray(string itemId, IEnumerable <GameElementData> costs)
        {
            if (!restrictionVerifier.VerifyRestrictions(itemConfigModel.GetRestrictions(itemId)))
            {
                Debug.Log("StoreManager.BuyItemByCostArray - Restrictions not met for item - " + itemId);
                return(new BuyItemResult(BuyItemResultCode.RestrictionsNotMet));
            }
            else if (!currencyStateModel.SufficientCurrency(costs))
            {
                Debug.Log("StoreManager.BuyItemByCostArray - Insufficient currency for item - " + itemId);
                return(new BuyItemResult(BuyItemResultCode.InsufficientCurrency));
            }

            currencyStateModel.DecreaseCurrency(costs);

            ItemConfigData itemData = itemConfigModel.GetItem(itemId);

            GameElementData ge    = itemConfigModel.ToGameElement(itemData);
            var             items = new List <GameElementData> {
                ge
            };

            collectGameElementsSignal.Dispatch(items);

            if (itemData.itemType == ItemType.Reward)
            {
                rewardItemBoughtSignal.Dispatch(itemData);
            }

            return(new BuyItemResult(BuyItemResultCode.Success));
        }
        public void OnClick()
        {
            soundManager.PlaySound(SoundMapping.Map.GeneralButtonClick, SoundLayer.Main);

            GameElementData gameElementData = new GameElementData(rewardType, key, amount);

            requestRewardedAdsSignal.Dispatch(gameElementData);
        }
        private void CollectPurchasedItem()
        {
            GameElementData ge = itemConfigModel.ToGameElement(_purchasedItem);

            collectGameElementsSignal.Dispatch(new List <GameElementData> {
                ge
            });
        }
Пример #6
0
        public bool IncreaseCurrencyEarned(System.Enum key, int value)
        {
            GameElementData currencyEarned = GameElementData.CreateCurrency(key, value);

            currencyStateModel.IncreaseCurrency(currencyEarned);
            Player.currenciesEarned.Increase(currencyEarned);

            return(true);
        }
Пример #7
0
        public GameElementData GetProgress(System.Enum key)
        {
            int index = Player.progress.FirstIndex(p => p.key == key.ToString());

            if (index == -1)
            {
                return(GameElementData.CreateState(key.ToString(), 0));
            }
            return(Player.progress[index].Clone() as GameElementData);
        }
Пример #8
0
        private void BuyItemPack(ItemGroupConfigData itemGroupData, Promise <BuyItemResult> promise)
        {
            if (itemGroupData.items.Count == 0)
            {
                logger.LogError(Tag, "BuyItemPack - Group contains no items");
                promise.Resolve(new BuyItemResult(BuyItemResultCode.Error));
                return;
            }

            string itemIdToBuy = itemGroupData.items[0];

            // For item groups with more than
            if (itemGroupData.items.Count > 1)
            {
                ItemConfigData packCost = itemGroupConfigModel.GetPackCost(itemGroupData.id);
                if (packCost == null)
                {
                    logger.LogError(Tag, "Cannot find Pack cost - item groups with more than one item require a pack cost item");
                    promise.Resolve(new BuyItemResult(BuyItemResultCode.Error));
                    return;
                }

                itemIdToBuy = packCost.id;
            }

            // Pay the costs, then give the player the rest of the items in the group
            BuyItem(itemIdToBuy).Done(buyItemResult => {
                if (buyItemResult.resultCode.Equals(BuyItemResultCode.Success))
                {
                    foreach (string itemId in itemGroupConfigModel.GetItemIds(itemGroupData.id))
                    {
                        ItemConfigData item = itemConfigModel.GetItem(itemId);

                        if (item.itemType == ItemType.PackCost)
                        {
                            continue;
                        }

                        GameElementData ge = itemConfigModel.ToGameElement(item);
                        var items          = new List <GameElementData> {
                            ge
                        };

                        collectGameElementsSignal.Dispatch(items);
                    }
                }
                else
                {
                    logger.Log(Tag, "BuyItemPack - Will not collect game elements since buy attempt failed. Result code: " + buyItemResult.resultCode);
                }

                promise.Resolve(buyItemResult);
            });
        }
Пример #9
0
 public bool DecreaseCurrency(GameElementData amount)
 {
     if (SufficientCurrency(amount))
     {
         int index = GetIndex(amount);
         currencyDecreasingSignal.Dispatch(amount);
         _data.currencies[index] -= amount;
         updateCurrencySignal.Dispatch(_data);
     }
     return(Save());
 }
Пример #10
0
        public static void Set(this List <GameElementData> _this, GameElementData amount)
        {
            int gameElementIndex = _this.FirstIndex(element => element.key == amount.key && element.type == amount.type);

            if (gameElementIndex == -1)
            {
                _this.Add(amount);
            }
            else
            {
                _this[gameElementIndex].value = amount.value;
            }
        }
        public bool ResetProgress(string key, int value = 0)
        {
            int index = _data.progress.GetIndex(key);

            if (index == -1)
            {
                return(false);
            }

            _data.progress[index] = GameElementData.CreateState(key, value);

            return(Save());
        }
Пример #12
0
        public bool SufficientCurrency(GameElementData amount)
        {
            int index = GetIndex(amount);

            if (index == -1)
            {
                insufficientCurrencySignal.Dispatch(_data);
                return(false);
            }
            else
            {
                return(_data.currencies[index].value >= amount.value);
            }
        }
Пример #13
0
        public static void Increase(this List <GameElementData> _this, GameElementData amount)
        {
            int gameElementIndex = _this.FirstIndex(element => element.key == amount.key && element.type == amount.type);

            if (gameElementIndex == -1)
            {
                _this.Add(amount);
                Debug.Log("<color=yellow>GameElementListExtensions - first</color> " + amount.value.ToString());
            }
            else
            {
                _this[gameElementIndex].value += amount.value;
                Debug.Log("<color=yellow>GameElementListExtensions</color> " + amount.value.ToString());
            }
        }
Пример #14
0
        public GameElementData GetLevelProgress(string levelConfigId, System.Enum key)
        {
            LevelStateData data = _sharedStateItems.FirstOrDefault(l => l.id == levelConfigId);

            if (data != null)
            {
                int index = data.progress.FirstIndex(p => p.key == key.ToString());
                if (index != -1)
                {
                    return(data.progress[index].Clone() as GameElementData);
                }
            }

            return(GameElementData.CreateState(key.ToString(), 0));
        }
        public void SetProgress(GameElementData data)
        {
            int index = _data.progress.GetIndex(data.key);

            if (index == -1)
            {
                _data.progress.Add(data);
                Save();
            }
            else
            {
                _data.progress[index].type  = data.type;
                _data.progress[index].value = data.value;
                Save();
            }
        }
        public void SetProgress(string key, int value = 0, GameElementType type = default(GameElementType))
        {
            GameElementData newData = null;

            int index = _data.progress.GetIndex(key);

            if (index == -1)
            {
                newData = new GameElementData(type, key, value);
                _data.progress.Add(newData);
                Save();
            }
            else
            {
                newData       = _data.progress[index];
                newData.value = value;
                Save();
            }
        }
Пример #17
0
        /// <summary>
        /// Sets the progress.
        /// </summary>
        /// <param name="setOnlyIfHigher">If set to <c>true</c> will assign only if the value is higher.</param>
        public bool SetProgress(System.Enum key, int value, bool setOnlyIfHigher = false)
        {
            int index = Player.progress.FirstIndex(p => p.key == key.ToString());

            if (index == -1)
            {
                Player.progress.Add(GameElementData.CreateState(key.ToString(), value));
                return(true);
            }
            else
            {
                if (value >= Player.progress[index].value || !setOnlyIfHigher)
                {
                    Player.progress[index] = GameElementData.CreateState(key.ToString(), value);
                    return(true);
                }
            }
            return(false);
        }
Пример #18
0
        public GameElementData ToGameElement(ItemConfigData item)
        {
            GameElementType eType = GameElementType.Item;
            string          key   = item.id;

            switch (item.itemType)
            {
            case ItemType.Currency:
                eType = GameElementType.Currency;
                key   = item.itemTypeKey;
                break;

            // A Pack cost does not give any game elements, it only significes costs - so we'll give 0 soft currencies
            case ItemType.PackCost:
                return(new GameElementData(GameElementType.Currency, CurrenciesType.soft.ToString(), 0));
            }

            GameElementData ge = new GameElementData(eType, key, item.quantity);

            return(ge);
        }
Пример #19
0
        public bool IncreaseProgress(System.Enum key, int value = 1)
        {
            GameElementData progress = GetProgress(key);

            return(SetProgress(key, progress.value + value));
        }
        public int GetProgressValue(string key)
        {
            GameElementData data = GetProgress(key);

            return((null != data) ? data.value : 0);
        }
 public bool IncreaseProgress(GameElementData progress)
 {
     _data.progress.Increase(progress);
     return(Save());
 }
 public bool IncreaseProgress(string key, int value)
 {
     return(IncreaseProgress(GameElementData.CreateState(key, value)));
 }
Пример #23
0
        public object Clone()
        {
            GameElementData c = new GameElementData(type, key, value);

            return(c);
        }
Пример #24
0
 public bool IncreaseCurrency(System.Enum key, int value)
 {
     return(IncreaseCurrency(GameElementData.CreateCurrency(key, value)));
 }
Пример #25
0
 private int GetIndex(GameElementData currency)
 {
     return(_data.currencies.FirstIndex(data => data.key == currency.key));
 }
Пример #26
0
 public bool VerifyRestriction(GameElementData restriction)
 {
     return(GetCurrencyAmount(restriction.key) >= restriction.value);
 }
 public bool VerifyRestriction(GameElementData restriction)
 {
     return(restriction.type == GameElementType.Item && GetQuantity(restriction.key) >= restriction.value);
 }
Пример #28
0
 public static int GetIndex(this List <GameElementData> _this, GameElementData gameElementData)
 {
     return(_this.FirstIndex(element => element.key == gameElementData.key));
 }
Пример #29
0
 public bool SufficientCurrency(System.Enum key, int value)
 {
     return(SufficientCurrency(GameElementData.CreateCurrency(key, value)));
 }
 public bool IncreaseQuantity(GameElementData gameElement)
 {
     return(IncreaseQuantity(gameElement.key, gameElement.value));
 }