Exemplo n.º 1
0
        /// <summary>
        /// Stops running a script, optionally resetting its state.
        /// </summary>
        /// <param name="runner"></param>
        /// <param name="onComplete"></param>
        /// <param name="reset">True if the quest's state should be reset</param>
        public void Stop(ScriptDirectoryItem runner, Action onComplete = null, bool reset = false)
        {
            m_runningItems.Remove(runner);

            if (runner.ScriptReference != null)
            {
                ScriptManager.Instance.StopRunningScript(runner.ScriptReference.ObjectId, runner.Id, reset, onComplete);
            }
            else
            {
                if (onComplete != null)
                {
                    onComplete();
                }
            }

            SaveState();

            lock (m_runningItems)
            {
                if (m_runningItems.Count == 0)
                {
                    Platform.Instance.StopLiveSession(this);
                }
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
        internal bool HasState(ScriptDirectoryItem dirItem)
        {
            if (dirItem == null || dirItem.ScriptReference == null)
            {
                return(false);
            }

            return(ScriptManager.Instance.HasState(dirItem.ScriptReference.ObjectId, dirItem.Id));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Launches a new script directory item. If "OneAtATime" is set, this will cancel any
        /// running quests.
        /// </summary>
        /// <param name="episode"></param>
        public virtual void Launch(ScriptDirectoryItem episode)
        {
#if MOTIVE_IAP
            var purchaseState = EpisodePurchaseManager.Instance.GetEpisodeState(episode);

            if (purchaseState != EpisodeSelectState.AvailableToLaunch &&
                purchaseState != EpisodeSelectState.Running)
            {
                return;
            }
#endif

            // when an episode is launched, stop all other episodes
            if (!AllowMultiple)
            {
                foreach (var dItem in m_runningItems.ToList())
                {
                    if (dItem.ScriptReference.ObjectId != episode.ScriptReference.ObjectId)
                    {
                        Stop(dItem);
                    }
                }
            }

            if (episode.ScriptReference != null)
            {
                ScriptManager.Instance.LaunchScript(episode.ScriptReference.ObjectId, episode.Id, (success) =>
                {
                    Stop(episode);
                });
            }

            m_runningItems.Add(episode);

            SaveState();

            lock (m_runningItems)
            {
                if (m_runningItems.Count == 1)
                {
                    Platform.Instance.StartLiveSession(this);
                }
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
        private void StartSessionAndLaunchScript(ScriptDirectoryItem dirItem, bool reset)
        {
            if (reset)
            {
                ScriptRunnerManager.Instance.Stop(dirItem, () =>
                {
                    ScriptRunnerManager.Instance.Launch(dirItem);
                }, true);
            }
            else
            {
                ScriptRunnerManager.Instance.Launch(dirItem);
            }

            Back();
        }
Exemplo n.º 5
0
        public void Populate(ScriptDirectoryItem directoryItem)
        {
            m_scriptDirectoryItem = directoryItem;

            Text.text        = directoryItem.Title;
            Description.text = directoryItem.Description;

            if (directoryItem.PublishingStatus == PublishingStatus.Draft)
            {
                Text.text += " (draft)";
            }
            else if (directoryItem.PublishingStatus == PublishingStatus.Development)
            {
                Text.text += " (in development)";
            }

            UpdateState();
        }
        public EpisodeSelectState GetEpisodeState(ScriptDirectoryItem episode)
        {
            // default, unless conditions determine otherwise
            var state = EpisodeSelectState.AvailableToLaunch;

            // not available if is item that user has not purchased
            if (!string.IsNullOrEmpty(episode.ProductIdentifier) && EpisodePurchaseManager.Instance.IsInitialized)
            {
                var wasPurchased = false;
                EpisodePurchaseManager.Instance.CheckProductReceipt(episode.ProductIdentifier, () =>
                {
                    // if was purchased
                    state        = EpisodeSelectState.AvailableToLaunch;
                    wasPurchased = true;
                });

                if (!wasPurchased)
                {
                    state = EpisodeSelectState.Disabled;
                }

                // don't return, state must change if currently running
            }

            // todo what are the conditions for which an episode is DISABLED:
            if (IsDisabled(episode))
            {
                state = EpisodeSelectState.Disabled;
            }

            var isRunning = ScriptRunnerManager.Instance.IsRunning(episode);

            if (isRunning)
            {
                state = EpisodeSelectState.Running;
            }

            return(state);
        }
Exemplo n.º 7
0
        public void UpdateCurrentTour()
        {
            // should only be one
            var runningEpisodes = ScriptRunnerManager.Instance.GetRunningItems();

            RunningQuest = runningEpisodes != null?runningEpisodes.FirstOrDefault() : null;

            bool running = (RunningQuest != null);

            if (TourNameText)
            {
                if (running)
                {
                    TourNameText.text = RunningQuest.Title.ToUpper();
                }
                else
                {
                    TourNameText.text = null;
                }
            }

            if (ActivateWhenRunning != null)
            {
                foreach (var obj in ActivateWhenRunning)
                {
                    if (obj)
                    {
                        obj.SetActive(running);
                    }
                }
            }

            if (QuestUpdated != null)
            {
                QuestUpdated.Invoke();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Resets a quest and all associated data. Does not reset any global data for this quest
        /// (inventory, wallet, etc.)
        /// </summary>
        /// <param name="runner"></param>
        public void Reset(ScriptDirectoryItem runner)
        {
            m_runningItems.Remove(runner);

            if (runner.ScriptReference != null)
            {
                ScriptManager.Instance.StopRunningScript(runner.ScriptReference.ObjectId, runner.Id, true, null);
            }

            lock (m_runningItems)
            {
                if (m_runningItems.Count == 0)
                {
                    Platform.Instance.StopLiveSession(this);
                }
            }

            SaveState();

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
        void LaunchScript(ScriptDirectoryItem dirItem)
        {
            Action launch = () =>
            {
                if (StartOrResetDialog)
                {
                    if (ScriptRunnerManager.Instance.HasState(dirItem))
                    {
                        StartOrResetDialog.Show(new string[] { "startOver", "resume" }, (opt) =>
                        {
                            switch (opt)
                            {
                            case "startOver":
                                StartSessionAndLaunchScript(dirItem, true);
                                break;

                            case "resume":
                                if (!ScriptRunnerManager.Instance.IsRunning(dirItem))
                                {
                                    StartSessionAndLaunchScript(dirItem, false);
                                }
                                else
                                {
                                    Back();
                                }
                                // Script is already running, so don't do anything
                                break;
                            }
                        });
                    }
                    else
                    {
                        StartSessionAndLaunchScript(dirItem, true);
                    }
                }
                else
                {
                    StartSessionAndLaunchScript(dirItem, true);
                }
            };

            if (!ScriptRunnerManager.Instance.AllowMultiple && StopCurrentDigalog)
            {
                var currTour = GetCurrentRunner();

                if (currTour != null && currTour != dirItem)
                {
                    StopCurrentDigalog.Show(new string[] { "stop", "cancel" }, (opt) =>
                    {
                        if (opt == "stop")
                        {
                            ScriptRunnerManager.Instance.Stop(currTour, launch);
                        }
                    });

                    return;
                }
            }

            launch();
        }
Exemplo n.º 10
0
 public bool IsDisabled(ScriptDirectoryItem episode)
 {
     // todo
     return(false);
 }
Exemplo n.º 11
0
 public ScriptRunnerSelectItemEventArgs(ScriptDirectoryItem _script)
 {
     ScriptDirectoryItem = _script;
 }
Exemplo n.º 12
0
 public bool IsRunning(ScriptDirectoryItem directoryItem)
 {
     return((m_runningItems) != null && m_runningItems.Exists(i => i.Id == directoryItem.Id));
 }