Ejemplo n.º 1
0
        public bool Give()
        {
            if (!CanGive())
            {
                SoomlaUtils.LogDebug(TAG, "(Give) Reward is not approved by Schedule. id: " + _id);
                return(false);
            }

            if (giveInner())
            {
                RewardStorage.SetRewardStatus(this, true);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool Take()
        {
            if (!RewardStorage.IsRewardGiven(this))
            {
                SoomlaUtils.LogDebug(TAG, "Reward not given. id: " + _id);
                return(false);
            }

            if (takeInner())
            {
                RewardStorage.SetRewardStatus(this, false);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="jsonReward">see parent.</param>
        public SequenceReward(JSONObject jsonReward)
            : base(jsonReward)
        {
            List <JSONObject> rewardsObj = jsonReward[JSONConsts.SOOM_REWARDS].list;

            if ((rewardsObj == null || rewardsObj.Count == 0))
            {
                SoomlaUtils.LogWarning(TAG, "Reward has no meaning without children");
                rewardsObj = new List <JSONObject>();
            }

            Rewards = new List <Reward>();
            foreach (JSONObject rewardObj in rewardsObj)
            {
                Rewards.Add(Reward.fromJSONObject(rewardObj));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts the current <c>SoomlaEntity</c> to a JSONObject.
        /// </summary>
        /// <returns>A <c>JSONObject</c> representation of the current <c>SoomlaEntity</c>.</returns>
        public virtual JSONObject toJSONObject()
        {
            if (string.IsNullOrEmpty(this._id))
            {
                SoomlaUtils.LogError(TAG, "This is BAD! We don't have ID in the this SoomlaEntity. Stopping here.");
                return(null);
            }

            JSONObject obj = new JSONObject(JSONObject.Type.OBJECT);

            obj.AddField(JSONConsts.SOOM_ENTITY_NAME, this.Name);
            obj.AddField(JSONConsts.SOOM_ENTITY_DESCRIPTION, this.Description);
            obj.AddField(JSONConsts.SOOM_ENTITY_ID, this._id);
            obj.AddField(JSONConsts.SOOM_CLASSNAME, SoomlaUtils.GetClassName(this));

            return(obj);
        }
Ejemplo n.º 5
0
        public static void Initialize(string recieverName)
        {
            SoomlaUtils.LogDebug(TAG, "Initializing CoreEvents and Soomla Core ...");
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJNI.PushLocalFrame(100);

            using (AndroidJavaClass jniStoreConfigClass = new AndroidJavaClass("com.soomla.SoomlaConfig")) {
                jniStoreConfigClass.SetStatic("logDebug", CoreSettings.DebugMessages);
            }

            // Initializing SoomlaEventHandler
            using (AndroidJavaClass jniEventHandler = new AndroidJavaClass("com.soomla.core.unity.SoomlaEventHandler")) {
                jniEventHandler.CallStatic("initialize");
            }

            // Initializing Soomla Secret
            using (AndroidJavaClass jniSoomlaClass = new AndroidJavaClass("com.soomla.Soomla")) {
                jniSoomlaClass.CallStatic("initialize", CoreSettings.SoomlaSecret);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
            soomlaCore_Init(recieverName, CoreSettings.SoomlaSecret, CoreSettings.DebugMessages);
#endif
        }
Ejemplo n.º 6
0
        public bool Approve(int activationTimes)
        {
            DateTime now = DateTime.Now;

            if (ActivationLimit < 1 && (TimeRanges == null || TimeRanges.Count == 0))
            {
                SoomlaUtils.LogDebug(TAG, "There's no activation limit and no TimeRanges. APPROVED!");
                return(true);
            }

            if (ActivationLimit > 0 && activationTimes >= ActivationLimit)
            {
                SoomlaUtils.LogDebug(TAG, "Activation limit exceeded.");
                return(false);
            }

            if ((TimeRanges == null || TimeRanges.Count == 0))
            {
                SoomlaUtils.LogDebug(TAG, "We have an activation limit that was not reached. Also, we don't have any time ranges. APPROVED!");
                return(true);
            }


            // NOTE: From this point on ... we know that we didn't reach the activation limit AND we have TimeRanges.
            //		 We'll just make sure the time ranges and the Recurrence copmlies.


            foreach (DateTimeRange dtr in TimeRanges)
            {
                if (now >= dtr.Start && now <= dtr.End)
                {
                    SoomlaUtils.LogDebug(TAG, "We are just in one of the time spans, it can't get any better then that. APPROVED!");
                    return(true);
                }
            }

            // we don't need to continue if RequiredRecurrence is NONE
            if (RequiredRecurrence == Recurrence.NONE)
            {
                return(false);
            }

            foreach (DateTimeRange dtr in TimeRanges)
            {
                if (now.Minute >= dtr.Start.Minute && now.Minute <= dtr.End.Minute)
                {
                    SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' minutes span.");

                    if (RequiredRecurrence == Recurrence.EVERY_HOUR)
                    {
                        SoomlaUtils.LogDebug(TAG, "It's a EVERY_HOUR recurrence. APPROVED!");
                        return(true);
                    }

                    if (now.Hour >= dtr.Start.Hour && now.Hour <= dtr.End.Hour)
                    {
                        SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' hours span.");

                        if (RequiredRecurrence == Recurrence.EVERY_DAY)
                        {
                            SoomlaUtils.LogDebug(TAG, "It's a EVERY_DAY recurrence. APPROVED!");
                            return(true);
                        }

                        if (now.DayOfWeek >= dtr.Start.DayOfWeek && now.DayOfWeek <= dtr.End.DayOfWeek)
                        {
                            SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' day-of-week span.");

                            if (RequiredRecurrence == Recurrence.EVERY_WEEK)
                            {
                                SoomlaUtils.LogDebug(TAG, "It's a EVERY_WEEK recurrence. APPROVED!");
                                return(true);
                            }

                            if (now.Day >= dtr.Start.Day && now.Day <= dtr.End.Day)
                            {
                                SoomlaUtils.LogDebug(TAG, "Now is in one of the time ranges' days span.");

                                if (RequiredRecurrence == Recurrence.EVERY_MONTH)
                                {
                                    SoomlaUtils.LogDebug(TAG, "It's a EVERY_MONTH recurrence. APPROVED!");
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }