Пример #1
0
        public int GetPurchableskinnerBoxCount(PurchableSkinnerBoxInfo boxInfo)
        {
            SkinnerBoxSavedData skinnerBoxSavedData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <SkinnerBoxSavedData>() ??
                new SkinnerBoxSavedData();

            if (!skinnerBoxSavedData.ItemCount.ContainsKey(boxInfo.Id))
            {
                return(0);
            }
            return(skinnerBoxSavedData.ItemCount[boxInfo.Id]);
        }
Пример #2
0
        public bool IsFreeSkinnerBoxAvailable(FreeSkinnerBoxInfo boxInfo)
        {
            SkinnerBoxSavedData skinnerBoxSavedData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <SkinnerBoxSavedData>() ??
                new SkinnerBoxSavedData();

            if (!skinnerBoxSavedData.FreeItemUseTime.ContainsKey(boxInfo.Id))
            {
                return(true);
            }
            if (skinnerBoxSavedData.FreeItemUseTime[boxInfo.Id] < DateTime.Now)
            {
                return(true);
            }
            return(false);
        }
Пример #3
0
        public TimeSpan GetFreeSkinnerBoxAvailabiltyDuration(FreeSkinnerBoxInfo boxInfo)
        {
            SkinnerBoxSavedData skinnerBoxSavedData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <SkinnerBoxSavedData>() ??
                new SkinnerBoxSavedData();

            if (!skinnerBoxSavedData.FreeItemUseTime.ContainsKey(boxInfo.Id))
            {
                return(TimeSpan.Zero);
            }
            if (skinnerBoxSavedData.FreeItemUseTime[boxInfo.Id] <= DateTime.Now)
            {
                return(TimeSpan.Zero);
            }
            return(skinnerBoxSavedData.FreeItemUseTime[boxInfo.Id] - DateTime.Now);
        }
Пример #4
0
        public SkinnerBoxItemInfo OpenBox(SkinnerBoxInfo boxInfo)
        {
            SkinnerBoxSavedData skinnerBoxSavedData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <SkinnerBoxSavedData>() ??
                new SkinnerBoxSavedData();
            FreeSkinnerBoxInfo freeSkinnerBoxInfo = boxInfo as FreeSkinnerBoxInfo;

            if (freeSkinnerBoxInfo != null)
            {
                if (!IsFreeSkinnerBoxAvailable(freeSkinnerBoxInfo))
                {
                    throw new Exception("no free skinner box avialable.");
                }
                SkinnerBoxItemInfo skinnerBoxItemInfo = PickItem(freeSkinnerBoxInfo.Items);
                skinnerBoxSavedData.FreeItemUseTime[boxInfo.Id] = DateTime.Now +
                                                                  TimeSpan.FromSeconds(freeSkinnerBoxInfo.UseDelay);
                ServiceLocator.Resolve <IStorageService>().UpdateData(skinnerBoxSavedData);
                ApplySkinnerBoxItemInfo(skinnerBoxItemInfo);
                return(skinnerBoxItemInfo);
            }
            PurchableSkinnerBoxInfo purchableSkinnerBoxInfo = boxInfo as PurchableSkinnerBoxInfo;

            if (purchableSkinnerBoxInfo != null)
            {
                if (GetPurchableskinnerBoxCount(purchableSkinnerBoxInfo) <= 0)
                {
                    throw new Exception("no purchasable skinner box avialable.");
                }
                SkinnerBoxItemInfo skinnerBoxItemInfo = PickItem(purchableSkinnerBoxInfo.Items);
                skinnerBoxSavedData.ItemCount[purchableSkinnerBoxInfo.Id]--;
                ServiceLocator.Resolve <IStorageService>().UpdateData(skinnerBoxSavedData);
                ApplySkinnerBoxItemInfo(skinnerBoxItemInfo);
                return(skinnerBoxItemInfo);
            }
            return(null);
        }