Ejemplo n.º 1
0
    public void ItemTapped()
    {
        if (current >= allowTapThreshold)
        {
//			Debug.Log("spewing " + (int)current + " coins");

            if (clickAnimation != null)
            {
                clickAnimation.Play();
            }

            // Spew out the reward here
            StatsManager.Instance.ChangeStats(coinsDelta: (int)current, coinsPos: transform.position, is3DObject: true);

            // Update mutable datas
            ItemManager.Instance.UpdateFarmLastRedeemTime(itemId, LgDateTime.GetTimeNow());

            // Reset the generator
            CancelInvoke("RepeatFarm");                 // Clear previous invoke before starting new one
            InvokeRepeating("RepeatFarm", 1f, 1f);
            isFull  = false;
            current = 0;
            CheckShowButton();
        }
    }
Ejemplo n.º 2
0
 public void Init()
 {
     IsFirstTimeRescue   = true;
     LastPlayPeriodUsed  = DateTime.MinValue;
     LastInhalerPlayTime = LgDateTime.GetTimeNow();
     timesUsedInARow     = 0;
 }
Ejemplo n.º 3
0
    // Put anything in here that should happen as a result of the pet using the daily inhaler.
    private void GameDone()
    {
        InhalerGameUIManager.Instance.StopShowHintTimer();
        StatsManager.Instance.ChangeStats(healthDelta: 20, hungerDelta: 80, isInternal: true);
        DateTime now  = LgDateTime.GetTimeNow();
        DateTime then = DataManager.Instance.GameData.Inhaler.LastPlayPeriodUsed;
        TimeSpan lastTimeSinceInhaler = now - then;

        if (lastTimeSinceInhaler.TotalHours > 24)
        {
            DataManager.Instance.GameData.Inhaler.timesUsedInARow = 0;
        }
        DataManager.Instance.GameData.Inhaler.timesUsedInARow++;

        // Save settings into DataManager
        IsFirstTimeRescue = false;
        DataManager.Instance.GameData.Inhaler.LastPlayPeriodUsed  = PlayPeriodLogic.GetCurrentPlayPeriod();
        DataManager.Instance.GameData.Inhaler.LastInhalerPlayTime = LgDateTime.GetTimeNow();

        // Finish inhaler tutorial
        if (!IsTutorialCompleted)
        {
            DataManager.Instance.GameData.Tutorial.ListPlayed.Add(TutorialManagerBedroom.TUT_INHALER);
        }

        // Send out a task completion event for the wellapad
        WellapadMissionController.Instance.TaskCompleted("DailyInhaler");

        // Calculate the next play period for the inhaler
        PlayPeriodLogic.Instance.InhalerGameDonePostLogic();

        // Show ending UI
        InhalerGameUIManager.Instance.GameEndUI();
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Checks if inhaler can be used at the current time.
    /// Open if yes or show notification.
    /// </summary>
    private void CheckToOpenInhaler()
    {
        if (PlayPeriodLogic.Instance.CanUseEverydayInhaler())
        {
            OpenRealInhaler();
        }
        else
        {
            TimeFrames currentTimeFrame = PlayPeriodLogic.GetTimeFrame(LgDateTime.GetTimeNow());
            string     popupMessage;

            if (currentTimeFrame == TimeFrames.Morning)
            {
                popupMessage = "POPUP_INHALER_TONIGHT";
                AudioManager.Instance.PlayClip("superWellaInhalerTonight");
            }
            else
            {
                popupMessage = "POPUP_INHALER_MORNING";
                AudioManager.Instance.PlayClip("superWellaInhalerMorning");
            }

            // Display tutorial notification
            Hashtable notificationEntry = new Hashtable();
            notificationEntry.Add(NotificationPopupData.PrefabName, "PopupInhalerRecharging");
            notificationEntry.Add(NotificationPopupData.Title, null);
            notificationEntry.Add(NotificationPopupData.Message, Localization.Localize(popupMessage));
            notificationEntry.Add(NotificationPopupData.SpecialButtonCallback, null);
            NotificationUIManager.Instance.AddToQueue(notificationEntry);
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Refreshs check.
    /// Function that checks to see if the wellapad missions
    /// list should be refreshed.  If it should, it will
    /// delete the current save data.
    /// </summary>
    public void RefreshCheck()
    {
        //do not refresh wellapad task for lite version
        // if(VersionManager.IsLite()) return;

        DateTime now          = LgDateTime.GetTimeNow();
        TimeSpan sinceCreated = now - DataManager.Instance.GameData.Wellapad.DateMissionsCreated;

        // the list needs to be refreshed if it has been more than 12 hours from creation OR the creation time frame (morning/evening)
        // is different than the current time frame (morning/evening)
        DateTime dateMissionsCreated = DataManager.Instance.GameData.Wellapad.DateMissionsCreated;
        bool     IsRefresh           = sinceCreated.TotalHours >= 12 ||
                                       PlayPeriodLogic.GetTimeFrame(now) != PlayPeriodLogic.GetTimeFrame(dateMissionsCreated);

        //bool IsRefresh = needMission;
        // alert...if the user has not finished the last tutorial, no matter what, don't refresh

        /*if(!DataManager.Instance.GameData.Tutorial.AreTutorialsFinished())
         *      IsRefresh = false;*/

        // if we have to refresh, just delete our data...the missions list will take it from there
        if (IsRefresh)
        {
            //Before reseting mission. Go through current mission and send failed tasks to analytics server
            foreach (KeyValuePair <string, MutableDataWellapadTask> taskList in DataManager.Instance.GameData.Wellapad.CurrentTasks)
            {
                MutableDataWellapadTask _task = taskList.Value;

                //task is incomplete
                if (_task.Completed == WellapadTaskCompletionStates.Uncompleted)
                {
                    Analytics.Instance.WellapadTaskEvent(Analytics.TASK_STATUS_FAIL,
                                                         _task.TaskID, _task.TaskID);
                    if (_task.TaskID == "DailyInhaler")
                    {
                        Analytics.Instance.DidUseInhaler(false);
                    }
                }
            }

            DataManager.Instance.GameData.Wellapad.ResetMissions();

            //AddDefaultMissions();

            // have the screens of the wellapad refresh before we send out the event below, because we want to make sure the
            // missions screen is active
            //WellapadUIManager.Instance.RefreshScreen();

            // send event
            if (OnMissionsRefreshed != null)
            {
                OnMissionsRefreshed(this, EventArgs.Empty);
            }
            IsRefresh = false;
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Calculates the time left till next play period.
    /// </summary>
    public TimeSpan CalculateTimeLeftTillNextPlayPeriod()
    {
        TimeSpan timeTillNextPlayPeriod = NextPlayPeriod - LgDateTime.GetTimeNow();

        if (timeTillNextPlayPeriod < TimeSpan.Zero)
        {
            Debug.LogError("Negative timespan detected");
        }
        return(timeTillNextPlayPeriod);
    }
Ejemplo n.º 7
0
 void NextPlayPeriodPolling()
 {
     // If the time now crosses over the play play period
     if (nextPlayPeriodAux < LgDateTime.GetTimeNow())
     {
         nextPlayPeriodAux = NextPlayPeriod;                 // Update the aux to the next play period
         // Fire event
         if (OnNextPlayPeriod != null)
         {
             OnNextPlayPeriod(this, EventArgs.Empty);
         }
     }
 }
Ejemplo n.º 8
0
    private void CheckTime()
    {
        DateTime now = LgDateTime.GetTimeNow();

        if (now.Hour >= 6 && now.Hour < 18)
        {
            SetImageByTime(true);
        }
        else
        {
            SetImageByTime(false);
        }
    }
Ejemplo n.º 9
0
    private void CheckTime()
    {
        DateTime now = LgDateTime.GetTimeNow();

        if (now.Hour >= 6 && now.Hour < 18)
        {
            ActivateDay();
        }
        else
        {
            ActivateNight();
        }
    }
Ejemplo n.º 10
0
    void OnApplicationPause(bool isPaused)
    {
        if (!isPaused)
        {
            // Save current information
            SetLastPlayPeriod();

            //calculate time diff since last play session ended and submit to game analytics
            TimeSpan timeSinceLastSession = LgDateTime.GetTimeSpanSinceLastPlayed();
            int      timeDifference       = (int)timeSinceLastSession.TotalHours;

            Analytics.Instance.TimeBetweenPlaySession(timeDifference);
        }
    }
Ejemplo n.º 11
0
    public void AddTask(string taskID)
    {
        ImmutableDataWellapadTask task = DataLoaderWellapadTasks.GetTask(taskID);

        DataManager.Instance.GameData.Wellapad.CurrentTasks[taskID] = new MutableDataWellapadTask(task);

        // reset the time -- I probably want to change this to a per mission basis at some point if we expand the system?
        DataManager.Instance.GameData.Wellapad.DateMissionsCreated = LgDateTime.GetTimeNow();
        // send event
        if (OnMissionsRefreshed != null)
        {
            OnMissionsRefreshed(this, EventArgs.Empty);
        }
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Depending on how long the player has been away and what time of day it is, return the number of
    /// new triggers that should spawn.
    /// <summary>
    private int GetNewTriggerCount()
    {
        int newTriggers = 0;
        MutableDataDegradation degradationData = DataManager.Instance.GameData.Degradation;
        int playPeriodsOffset = GetNumPlayPeriodsOffset();

        //There are missed play periods
        if (playPeriodsOffset > 1)
        {
            //max of 2 missed play period will be accounted
            if (playPeriodsOffset > 2)
            {
                playPeriodsOffset = 2;
            }

            //calculate num of new triggers
            newTriggers = playPeriodsOffset * 3;

            //update lastTriggerSpawnedPlayPeriod. Important that we update it here
            //otherwise more triggers will be spawned if user return from pause
            degradationData.LastPlayPeriodTriggerSpawned = PlayPeriodLogic.GetCurrentPlayPeriod();
            Debug.Log("Missed play periods spawning " + newTriggers + "triggers");
        }
        //No missed play periods. spawn triggers for Next Play Period
        else
        {
            DateTime now = LgDateTime.GetTimeNow();
            DateTime lastTriggerSpawnedPlayPeriod = degradationData.LastPlayPeriodTriggerSpawned;
            TimeSpan timeSinceLastTriggerSpawned  = now - lastTriggerSpawnedPlayPeriod;

            //only spawn new trigger if time hasn't been rewind somehow
            if (lastTriggerSpawnedPlayPeriod <= now)
            {
                //new play period need to refresh variable
                if (timeSinceLastTriggerSpawned.TotalHours >= 12)
                {
                    degradationData.IsTriggerSpawned = false;
                }

                if (!degradationData.IsTriggerSpawned)
                {
                    newTriggers = 3;
                    degradationData.IsTriggerSpawned             = true;
                    degradationData.LastPlayPeriodTriggerSpawned = PlayPeriodLogic.GetCurrentPlayPeriod();
                }
            }
        }
        return(newTriggers);
    }
Ejemplo n.º 13
0
    //--------------------------------------------------------------------------
    // UpdateNextPlayPeriodTime()
    // Health Degradation and Trigger Degradation both depends on NextPlayPeriod
    // for timing logic, so if we ever need to update NextPlayPeriod it needs to be
    // done only after both functions run their logic with the same NextPlayPeriod value
    //--------------------------------------------------------------------------
    //	private void UpdateNextPlayPeriodTime(){
    //		int numOfMissedPlayPeriod = GetNumOfMissedPlayPeriod();	//TODO tie this to inhaler
    //
    //		if(numOfMissedPlayPeriod > 0){
    //			Debug.LogWarning("DANGING LOGIC FIX");
    ////			PlayPeriodLogic.Instance.CalculateCurrentPlayPeriod();
    //			// Debug.Log("current play period: " + PlayPeriodLogic.Instance.NextPlayPeriod);
    //		}
    //	}

    /// <summary>
    /// Gets the number play periods offset
    /// If number is 1, that means you did not miss any play periods
    /// </summary>
    /// <returns>The number play periods offset.</returns>
    private int GetNumPlayPeriodsOffset()
    {
        int      playPeriodsOffset = 0;
        DateTime lastPlayPeriod    = PlayPeriodLogic.Instance.GetLastPlayPeriod();

        // Difference in hours between now and next play period
        TimeSpan timeSinceStartOfPlayPeriod = LgDateTime.GetTimeNow() - lastPlayPeriod;

        //if within 12 hours no punishment
        //if > 12 hrs punishment for every 12 hrs miss
        playPeriodsOffset = (int)timeSinceStartOfPlayPeriod.TotalHours / 12;

        //Debug.Log("last play period " + lastPlayPeriod + " || time since start of play period " + timeSinceStartOfPlayPeriod + " || missed play period " + (playPeriodsOffset-1));
        return(playPeriodsOffset);
    }
Ejemplo n.º 14
0
    //Serialize the data whenever the game is paused
    void OnApplicationPause(bool paused)
    {
        if (paused)
        {
//			#if DEVELOPMENT_BUILD
//				return;
//			#endif
            Debug.Log("APPLICATION PAUSE CALLED");

            // check immediately if a tutorial is playing...if one is, we don't want to save the game on pause
            if (TutorialManager.Instance && TutorialManager.Instance.IsTutorialActive())
            {
                Debug.Log("Auto save canceled because we are in a tutorial");
                return;
            }

            // also early out if we happen to be in the inhaler game.  Ultimately we may want to create a more elaborate hash/list
            // of scenes it is okay to save in, if we ever create more scenes that shouldn't serialize data
            if (SceneUtils.CurrentScene == SceneUtils.INHALERGAME)
            {
                Debug.Log("Not saving the game because its inhaler scene");
                return;
            }

            //game can be paused at anytime and sometimes MenuScene doesn't have
            //any thing that needs saving, so check before saving
            if (gameData != null)
            {
                // special case: when we are about to serialize the game, we have to cache the moment it happens so we know when the user stopped
                DataManager.Instance.GameData.PlayPeriod.LastTimeUserPlayedGame = LgDateTime.GetTimeNow();

                // Save last play period here again..
                if (PlayPeriodLogic.Instance != null)
                {
                    PlayPeriodLogic.Instance.SetLastPlayPeriod();
                }

                Analytics.Instance.QuitGame(SceneUtils.CurrentScene);
                SaveGameData();

                //No longer first time
                PlayerPrefs.SetInt("IsFirstTime", 0);
            }
        }
    }
Ejemplo n.º 15
0
 // Check and calculate how much time until last redeem and populate current
 private void RefreshLastTimeSinceLastPlayed(DateTime lastRedeemTime)
 {
     lastTimeDurationAux = LgDateTime.GetTimeNow() - lastRedeemTime;
     // Initialize current
     current = ratePerHour / 3600f * (float)lastTimeDurationAux.TotalSeconds;
     if (current >= capacity)
     {
         current = capacity;
         isFull  = true;
         CancelInvoke("RepeatFarm");
     }
     else
     {
         CancelInvoke("RepeatFarm");                 // Clear previous invoke before starting new one
         InvokeRepeating("RepeatFarm", 1f, 1f);
     }
     CheckShowButton();
 }
Ejemplo n.º 16
0
    void Update()
    {
        if (isCoolDownMode)
        {
            // Update the cool down timer
            TimeSpan timeLeft = PlayPeriodLogic.Instance.CalculateTimeLeftTillNextPlayPeriod();
            coolDownLabel.text = StringUtils.FormatTimeLeft(timeLeft);

            DateTime initialSavedTime = PlayPeriodLogic.Instance.GetLastInhalerTime();
            TimeSpan timeOffset       = LgDateTime.GetTimeNow() - initialSavedTime;

            // Calculate the denomicator once and cache it
            if (!isInitialCalculatedOffsetCached)
            {
                initialCalculatedOffset         = PlayPeriodLogic.Instance.NextPlayPeriod - initialSavedTime;
                isInitialCalculatedOffsetCached = true;
            }

            float completePercentage = (float)timeOffset.TotalMinutes / (float)initialCalculatedOffset.TotalMinutes;
            coolDownSprite.fillAmount = completePercentage;
        }
    }
Ejemplo n.º 17
0
    void Start()
    {
        if (allowTapThreshold > showButtonThreshold)
        {
            Debug.LogWarning(gameObject.name + " - Farm button shown before it is allowed to tap!");
        }

        DateTime lastRedeemTime;

        if (isFlagResetWhenStart)               // Start from zero
        {
            ItemManager.Instance.UpdateFarmLastRedeemTime(itemId, LgDateTime.GetTimeNow());
            lastRedeemTime = LgDateTime.GetTimeNow();
        }
        else                                                    // Get last redeemed time and calculate
        {
            lastRedeemTime = ItemManager.Instance.GetFarmLastRedeemTime(itemId);
        }

        RefreshLastTimeSinceLastPlayed(lastRedeemTime);
        CheckShowButton();              // Hide this by default, enabled later on
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Local recurring notification. Recurring weekly once you havent touched the app in more than 7 days
    /// Also populates rate app notification
    /// </summary>
    public void ScheduleLocalNotification()
    {
                #if UNITY_IOS
        // Reset the badge icon
        UnityEngine.iOS.LocalNotification resetNotif = new UnityEngine.iOS.LocalNotification();
        resetNotif.applicationIconBadgeNumber = -1;
        resetNotif.hasAction = false;
        NotificationServices.PresentLocalNotificationNow(resetNotif);

        // Clear and cancel
        NotificationServices.ClearLocalNotifications();                                                            // Clear all received notifications
        foreach (UnityEngine.iOS.LocalNotification localNotif in NotificationServices.scheduledLocalNotifications) // Remove reminder notifications
        {
            if (localNotif.repeatInterval == UnityEngine.iOS.CalendarUnit.Week)
            {
                NotificationServices.CancelLocalNotification(localNotif);
                Debug.Log("CANCELLING RECURRING NOTIFICATIONS");
            }
        }

        // Prepare to fire new notification
        string iOSAction = "visit " + DataManager.Instance.GameData.PetInfo.PetName;            // Action (ie. slide to _)
        string iOSBody   = DataManager.Instance.GameData.PetInfo.PetName + " misses you!";

        DateTime fireDate = LgDateTime.GetTimeNow().AddDays(7);                 // Schedule for 7 days from now

        UnityEngine.iOS.LocalNotification notif = new UnityEngine.iOS.LocalNotification();
        notif.fireDate                   = fireDate;
        notif.alertAction                = iOSAction;
        notif.alertBody                  = iOSBody;
        notif.soundName                  = UnityEngine.iOS.LocalNotification.defaultSoundName;
        notif.repeatInterval             = UnityEngine.iOS.CalendarUnit.Week;
        notif.applicationIconBadgeNumber = -1;
        NotificationServices.ScheduleLocalNotification(notif);


        // Also check if we need to push the rate app notification
        // Conditions - passed day 7 retention, only seen once
        TimeSpan difference = LgDateTime.GetTimeNow().Subtract(DataManager.Instance.GameData.PlayPeriod.FirstPlayPeriod);
        if (!DataManager.Instance.GameData.PlayPeriod.IsDisplayedAppNotification &&                     // Displayed for first time
            DataManager.Instance.GameData.PlayPeriod.IsFirstPlayPeriodAux &&                            // Started first play session in
            difference > new TimeSpan(7, 0, 0, 0))                                                      // Past 7 days

        {
            UnityEngine.iOS.LocalNotification rateNotif = new UnityEngine.iOS.LocalNotification();

            // Shoot for next 8:47am
            DateTime now        = LgDateTime.GetTimeNow();
            DateTime today847am = now.Date.AddHours(8).AddMinutes(47);
            DateTime next847am  = now <= today847am ? today847am : today847am.AddDays(1);

            rateNotif.fireDate    = next847am;
            rateNotif.alertAction = "open game";
            rateNotif.alertBody   = "Is 'Wizdy Pets' helping your kids with asthma? Leave us a review in the AppStore!";
            rateNotif.soundName   = UnityEngine.iOS.LocalNotification.defaultSoundName;
            rateNotif.applicationIconBadgeNumber = -1;

            NotificationServices.ScheduleLocalNotification(rateNotif);
            DataManager.Instance.GameData.PlayPeriod.IsDisplayedAppNotification = true;
        }
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
        string title = DataManager.Instance.GameData.PetInfo.PetName + " misses you!";
        string body  = "Why not stop by and visit?";

        AndroidNotifications.cancelNotification(1);
        int id = 1;
        NotificationBuilder build    = new NotificationBuilder(id, title, body);
        TimeSpan            interval = new TimeSpan(168, 0, 0);
        build.setInterval(interval);
        build.setAutoCancel(false);
        build.setDelay(interval);
        AndroidNotifications.scheduleNotification(build.build());
#endif
    }
Ejemplo n.º 19
0
 /// <summary>
 /// Gets the current play period.
 /// </summary>
 public static DateTime GetCurrentPlayPeriod()
 {
     //if the time now is morning, current play period = 12am
     //if afternoon, current play period = 12pm
     return((LgDateTime.GetTimeNow().Hour < 12) ? LgDateTime.Today : LgDateTime.Today.AddHours(12));
 }