Beispiel #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            JToken jToken = JToken.FromObject(value == null ? null : ((PurchaseData[])value).Select(data =>
            {
                string result = null;
                if (data != null)
                {
                    PurchaseNoneLevelBaseData purchaseNoneLevelBaseData = data as PurchaseNoneLevelBaseData;
                    if (purchaseNoneLevelBaseData != null)
                    {
                        if (purchaseNoneLevelBaseData.PurchasableItemInfo != null)
                        {
                            result = purchaseNoneLevelBaseData.PurchasableItemInfo.Id;
                        }
                    }
                    PurchaseLevelBaseData purchaseLevelBaseData = data as PurchaseLevelBaseData;
                    if (purchaseLevelBaseData != null)
                    {
                        if (purchaseLevelBaseData.PurchasableItemInfo != null)
                        {
                            PurchasableLevelInfo[] purchasableLevelInfos = purchaseLevelBaseData.PurchasableItemInfo.GetPurchasableLevelInfos();
                            if (purchaseLevelBaseData.Level < purchasableLevelInfos.Length)
                            {
                                result = purchasableLevelInfos[purchaseLevelBaseData.Level].Id;
                            }
                        }
                    }
                }
                return(result);
            }).ToArray());

            jToken.WriteTo(writer);
        }
Beispiel #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken jToken = JToken.ReadFrom(reader);

            if (jToken.Type == JTokenType.Null || jToken.Type == JTokenType.None)
            {
                return(new PurchaseData[0]);
            }
            return(jToken.ToObject <string[]>().Select(s =>
            {
                PurchaseData result;
                if (!InfoResolver.Resolve <FortInfo>().Purchase.PurchasableTokens.ContainsKey(s))
                {
                    return null;
                }
                PurchasableToken purchasableToken = InfoResolver.Resolve <FortInfo>().Purchase.PurchasableTokens[s];
                if (purchasableToken.NoneLevelBase)
                {
                    result = new PurchaseNoneLevelBaseData
                    {
                        PurchasableItemInfo = (NoneLevelBasePurchasableItemInfo)purchasableToken.PurchasableItemInfo
                    };
                }
                else
                {
                    result = new PurchaseLevelBaseData
                    {
                        PurchasableItemInfo = (LevelBasePurchasableItemInfo)purchasableToken.PurchasableItemInfo,
                        Level = purchasableToken.Index
                    };
                }
                return result;
            }).Where(info => info != null).ToArray());
        }
        private void ApplySkinnerBoxItemInfo(SkinnerBoxItemInfo skinnerBoxItemInfo)
        {
            ValueSkinnerBoxItemInfo valueSkinnerBoxItemInfo = skinnerBoxItemInfo as ValueSkinnerBoxItemInfo;

            if (valueSkinnerBoxItemInfo != null)
            {
                ServiceLocator.Resolve <IUserManagementService>().AddScoreAndBalance(0, valueSkinnerBoxItemInfo.Value);
            }
            PurchasableItemSkinnerBoxItemInfo purchasableItemSkinnerBoxItemInfo = skinnerBoxItemInfo as PurchasableItemSkinnerBoxItemInfo;

            if (purchasableItemSkinnerBoxItemInfo != null)
            {
                RentSkinnerBoxItemInfo rentSkinnerBoxItemInfo = purchasableItemSkinnerBoxItemInfo as RentSkinnerBoxItemInfo;
                if (rentSkinnerBoxItemInfo != null)
                {
                    if (rentSkinnerBoxItemInfo.PurchaseDatas != null)
                    {
                        foreach (PurchaseData purchaseData in rentSkinnerBoxItemInfo.PurchaseDatas.Where(data => data != null))
                        {
                            PurchaseNoneLevelBaseData purchaseNoneLevelBaseData = purchaseData as PurchaseNoneLevelBaseData;
                            if (purchaseNoneLevelBaseData != null && purchaseNoneLevelBaseData.PurchasableItemInfo != null)
                            {
                                ServiceLocator.Resolve <IStoreService>().RentItem(purchaseNoneLevelBaseData.PurchasableItemInfo, 100, TimeSpan.FromSeconds(rentSkinnerBoxItemInfo.RentDuration));
                            }
                            PurchaseLevelBaseData purchaseLevelBaseData = purchaseData as PurchaseLevelBaseData;
                            if (purchaseLevelBaseData != null && purchaseLevelBaseData.PurchasableItemInfo != null)
                            {
                                PurchasableLevelInfo[] purchasableLevelInfos = purchaseLevelBaseData.PurchasableItemInfo.GetPurchasableLevelInfos();
                                if (purchaseLevelBaseData.Level >= 0 && purchaseLevelBaseData.Level < purchasableLevelInfos.Length)
                                {
                                    ((StoreService)ServiceLocator.Resolve <IStoreService>()).RentItem(purchasableLevelInfos[purchaseLevelBaseData.Level], 100, TimeSpan.FromSeconds(rentSkinnerBoxItemInfo.RentDuration));
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (purchasableItemSkinnerBoxItemInfo.PurchaseDatas != null)
                    {
                        foreach (PurchaseData purchaseData in purchasableItemSkinnerBoxItemInfo.PurchaseDatas.Where(data => data != null))
                        {
                            PurchaseNoneLevelBaseData purchaseNoneLevelBaseData = purchaseData as PurchaseNoneLevelBaseData;
                            if (purchaseNoneLevelBaseData != null && purchaseNoneLevelBaseData.PurchasableItemInfo != null)
                            {
                                ServiceLocator.Resolve <IStoreService>().PurchaseItem(purchaseNoneLevelBaseData.PurchasableItemInfo, 100);
                            }
                            PurchaseLevelBaseData purchaseLevelBaseData = purchaseData as PurchaseLevelBaseData;
                            if (purchaseLevelBaseData != null && purchaseLevelBaseData.PurchasableItemInfo != null)
                            {
                                ((StoreService)ServiceLocator.Resolve <IStoreService>()).InternalPurchaseItem(purchaseLevelBaseData.PurchasableItemInfo, 100, purchaseLevelBaseData.Level);
                            }
                        }
                    }
                }
            }
        }