Beispiel #1
0
        public override ISerializable FromObject(object obj)
        {
            this.TargetedOffers = new TargetedOfferSummary();
            Dictionary <string, object> dictionary = obj as Dictionary <string, object>;

            if (dictionary == null)
            {
                return(this);
            }
            if (dictionary.ContainsKey("targetedOffer"))
            {
                this.offerUID = (string)dictionary["targetedOffer"];
            }
            if (dictionary.ContainsKey("targetedOfferResult"))
            {
                this.TargetedOffers.FromObject(dictionary["targetedOfferResult"]);
            }
            if (dictionary.ContainsKey("crateData"))
            {
                this.CrateDataTO = new CrateData();
                this.CrateDataTO.FromObject(dictionary["crateData"]);
            }
            return(this);
        }
        private void UpdateFromTargetedOfferSummary(TargetedOfferSummary offerSummary)
        {
            DateTime         serverDateTime   = Service.Get <ServerAPI>().ServerDateTime;
            IDataController  dataController   = Service.Get <IDataController>();
            bool             flag             = false;
            TargetedBundleVO targetedBundleVO = null;

            if (!string.IsNullOrEmpty(offerSummary.AvailableOffer))
            {
                string availableOffer = offerSummary.AvailableOffer;
                targetedBundleVO = dataController.GetOptional <TargetedBundleVO>(availableOffer);
                if (targetedBundleVO != null)
                {
                    flag = targetedBundleVO.IgnoreCooldown;
                }
            }
            int  secondsFromEpoch        = DateUtils.GetSecondsFromEpoch(serverDateTime);
            uint globalCooldownExpiresAt = offerSummary.GlobalCooldownExpiresAt;

            if (!flag && globalCooldownExpiresAt != 0u && (long)secondsFromEpoch < (long)((ulong)globalCooldownExpiresAt))
            {
                Service.Get <StaRTSLogger>().DebugFormat("Offer global cooldown is in effect until {0}", new object[]
                {
                    LangUtils.FormatTime((long)offerSummary.GlobalCooldownExpiresAt)
                });
                this.GlobalCooldownExpiresAt = offerSummary.GlobalCooldownExpiresAt;
                this.OfferExpiresAt          = 0u;
                this.NextOfferAvailableAt    = 0u;
                this.SetBoundedTimer((long)((ulong)this.GlobalCooldownExpiresAt - (ulong)((long)secondsFromEpoch)), new TimerDelegate(this.CheckForNewOffer), false);
            }
            else if (targetedBundleVO != null)
            {
                Service.Get <StaRTSLogger>().DebugFormat("Available offer: {0}", new object[]
                {
                    offerSummary.AvailableOffer
                });
                if (targetedBundleVO.StartTime <= serverDateTime && serverDateTime < targetedBundleVO.EndTime && AudienceConditionUtils.IsValidForClient(targetedBundleVO.AudienceConditions))
                {
                    this.InitializeTriggerOffer(targetedBundleVO);
                }
                else
                {
                    Service.Get <StaRTSLogger>().WarnFormat("Server provided offer {0} was outside of date range {1} to {2}.", new object[]
                    {
                        offerSummary.AvailableOffer,
                        targetedBundleVO.StartTime,
                        targetedBundleVO.EndTime
                    });
                }
            }
            else if (offerSummary.NextOfferAvailableAt > 0u)
            {
                Service.Get <StaRTSLogger>().DebugFormat("Next offer available at {0}.", new object[]
                {
                    LangUtils.FormatTime((long)offerSummary.NextOfferAvailableAt)
                });
                this.NextOfferAvailableAt    = offerSummary.NextOfferAvailableAt;
                this.GlobalCooldownExpiresAt = 0u;
                this.OfferExpiresAt          = 0u;
                this.SetBoundedTimer((long)((ulong)this.NextOfferAvailableAt - (ulong)((long)DateUtils.GetSecondsFromEpoch(serverDateTime))), new TimerDelegate(this.CheckForNewOffer), false);
            }
            else
            {
                this.GlobalCooldownExpiresAt = 0u;
                this.OfferExpiresAt          = 0u;
                this.NextOfferAvailableAt    = 0u;
            }
            this.lastKnownTargetedOffer = null;
            this.FetchingNewOffer       = false;
            if (this.CurrentTargetedOffer != null)
            {
                Service.Get <EventManager>().SendEvent(EventId.TargetedBundleContentPrepared, null);
            }
        }
Beispiel #3
0
 public override ISerializable FromObject(object obj)
 {
     this.TargetedOffers = new TargetedOfferSummary();
     this.TargetedOffers.FromObject(obj);
     return(this);
 }