Пример #1
0
        public bool CanComplete(IPlayerTaskDriver driver)
        {
            if (driver != null && !driver.ActivationContext.IsClosed)
            {
                var task = driver.Task;

                if (driver.IsGiveTask)
                {
                    if (task.ActionItems != null)
                    {
                        if (task.ActionItems.CollectibleCounts != null)
                        {
                            bool isMet = true;

                            foreach (var cc in task.ActionItems.CollectibleCounts)
                            {
                                var count = Inventory.Instance.GetCount(cc.CollectibleId);

                                if (count < cc.Count)
                                {
                                    isMet = false;
                                    break;
                                }
                            }

                            if (!isMet)
                            {
                                return(isMet);
                            }
                        }

                        if (task.ActionItems.CurrencyCounts != null)
                        {
                            bool isMet = true;

                            foreach (var cc in task.ActionItems.CurrencyCounts)
                            {
                                var count = Wallet.Instance.GetCount(cc.Currency);

                                if (count < cc.Count)
                                {
                                    isMet = false;
                                    break;
                                }
                            }

                            if (!isMet)
                            {
                                return(isMet);
                            }
                        }
                    }
                }

                // Other actions can be completed?
                return(true);
            }

            return(false);
        }
Пример #2
0
        public virtual void AddNewTask(IPlayerTaskDriver driver)
        {
            if (ShouldShowNotification(driver))
            {
                ThreadHelper.Instance.CallOnMainThread(() =>
                {
                    gameObject.SetActive(true);

                    if (driver is LocationTaskDriver)
                    {
                        LocationTaskAnnotationHandler.Instance.SelectTaskAnnotation(driver as LocationTaskDriver);
                    }

                    TaskDriver = driver;

                    var item = Table.AddItem(NotificationItem);

                    item.Populate(driver);

                    /*
                     *                  var timer =
                     *                          UnityTimer.Call(item.DisplayDuration, () =>
                     *                                  {
                     *                                          Table.RemoveItem(item);
                     *                                  });
                     */

                    item.OnSelected.AddListener(() =>
                    {
                        //timer.Cancel();
                        Select(item);
                    });
                });
            }
        }
Пример #3
0
        // TODO: everything below here is a bit of a grab-bag that needs a refactor.
        // Essentially, task driver delegates should handle the todo list in some way.
        // For now, we know what we want each one to do so we'll do it directly.
        void SetTodoTask(IPlayerTaskDriver driver)
        {
            // Don't preview complete/closed tasks
            if (driver != null && (driver.IsComplete || driver.ActivationContext.IsClosed))
            {
                m_todoIsOverride = false;
                m_currTodoDriver = null;

                driver.SetFocus(false);

                return;
            }

            if (m_currTodoDriver != null && m_currTodoDriver != driver)
            {
                m_currTodoDriver.SetFocus(false);
            }

            m_currTodoDriver = driver;

            if (m_currTodoDriver != null)
            {
                m_currTodoDriver.SetFocus(true);
            }
        }
Пример #4
0
        public void ClosePlayerTask(IPlayerTaskDriver driver)
        {
            if (driver != null)
            {
                driver.ActivationContext.Close();
            }

            StopTask(driver, update: true);
        }
Пример #5
0
        public virtual void Populate(IPlayerTaskDriver driver)
        {
            TaskDriver = driver;

            if (driver != null)
            {
                SetText(driver.Task.Title);
            }
        }
Пример #6
0
        public void ClearOverrideTodoTask(IPlayerTaskDriver driver)
        {
            m_todoIsOverride = false;

            if (driver == m_currTodoDriver)
            {
                SetTodoTask(null);

                ThreadHelper.Instance.CallExclusive(RaiseEvent);
            }
        }
Пример #7
0
        private void AddTask(IPlayerTaskDriver objTask, int idx)
        {
            var asnItem = new TaskAssignmentItem(m_currentDriver, objTask, idx);

            var item = AddSelectableItem(ItemPrefab, (_item) =>
            {
                PopulateComponents(asnItem);
            });

            item.Populate(asnItem);
        }
Пример #8
0
 void UIModeChanged()
 {
     if (ARQuestAppUIManager.Instance.CurrentMode != ARQuestAppUIManager.Mode.AR)
     {
         // Clear complete task
         m_taskCompleteDriver = null;
     }
     else
     {
         SyncPanels();
     }
 }
Пример #9
0
        void StopTask(IPlayerTaskDriver driver, bool update = true)
        {
            driver.Stop();

            if (update)
            {
                if (Updated != null)
                {
                    Updated(this, EventArgs.Empty);
                }
            }
        }
Пример #10
0
        void SyncPanels()
        {
            // 1. Show AssignmentComplete if required.
            // 2. Show guide.
            // 3. Show task complete.
            var assnDriver = TaskManager.Instance.FirstAssignment;

            if (ShowAssignmentComplete &&
                AssignmentCompletePanel &&
                assnDriver != null &&
                assnDriver.IsComplete && !
                assnDriver.ActivationContext.IsClosed)
            {
                PanelManager.Instance.Push(AssignmentCompletePanel, assnDriver, () =>
                {
                    SyncPanels();
                });

                if (TaskCompletePanel)
                {
                    TaskCompletePanel.Back();
                }

                if (GuidePanel)
                {
                    GuidePanel.Back();
                }

                // Either of these options undoes task complete
                m_taskCompleteDriver = null;
            }
            else if (m_guideData != null && GuidePanel)
            {
                PanelManager.Instance.Push(GuidePanel, m_guideData);

                if (TaskCompletePanel)
                {
                    TaskCompletePanel.Back();
                }

                m_taskCompleteDriver = null;
            }
            else if (m_taskCompleteDriver != null && ShowTaskComplete)
            {
                PanelManager.Instance.Push(TaskCompletePanel, m_taskCompleteDriver, () =>
                {
                    m_taskCompleteDriver = null;

                    SyncPanels();
                });
            }
        }
Пример #11
0
        public void OverrideTodoTask(IPlayerTaskDriver driver)
        {
            if (driver != null)
            {
                m_currTodoObjective = null;

                m_todoIsOverride = true;

                SetTodoTask(driver);

                ThreadHelper.Instance.CallExclusive(RaiseEvent);
            }
        }
        public virtual void SelectTaskAnnotation(IPlayerTaskDriver taskDriver)
        {
            var annotations = m_taskAnnotations[taskDriver.ActivationContext.InstanceId];

            if (annotations != null)
            {
                var ann = annotations.FirstOrDefault();

                if (ann != null)
                {
                    MapController.Instance.SelectAnnotation(ann);
                }
            }
        }
Пример #13
0
        public virtual void ActivateLocationTask(ResourceActivationContext context, LocationTask task)
        {
            IPlayerTaskDriver driver = null;

            if (CreateLocationTaskDriver != null)
            {
                driver = CreateLocationTaskDriver(context, task);
            }
            else
            {
                driver = new LocationTaskDriver(context, task);
            }

            ActivatePlayerTaskDriver(context, driver);
        }
Пример #14
0
        public void ActivateVisualMarkerTask(ResourceActivationContext context, VisualMarkerTask task)
        {
            IPlayerTaskDriver driver = null;

            if (CreateVisualMarkerTaskDriver != null)
            {
                driver = CreateVisualMarkerTaskDriver(context, task);
            }
            else
            {
                driver = new VisualMarkerTaskDriver(context, task);
            }

            ActivatePlayerTaskDriver(context, driver);
        }
Пример #15
0
 protected virtual void ConfigureTaskItem(TaskItem item, IPlayerTaskDriver driver)
 {
     if (item.Driver.Task is LocationTask)
     {
         ConfigureLocationTaskItem(item);
     }
     else if (item.Driver.Task is CharacterTask)
     {
         ConfigureCharacterTaskItem(item);
     }
     else
     {
         ConfigureDefaultTaskItem(item);
     }
 }
Пример #16
0
        public void ActivatePlayerTask(ResourceActivationContext context, PlayerTask task)
        {
            IPlayerTaskDriver driver = null;

            if (CreatePlayerTaskDriver != null)
            {
                driver = CreatePlayerTaskDriver(context, task);
            }
            else
            {
                driver = new PlayerTaskDriver <PlayerTask, IMinigameDriver>(context, task);
            }

            ActivatePlayerTaskDriver(context, driver);
        }
Пример #17
0
        public void PushSuccessPanel(IPlayerTaskDriver driver)
        {
            var panel = PanelManager.Instance.GetPanel <QuizSuccessPanel>();

            if (panel == null)
            {
                m_logger.Error(typeof(QuizSuccessPanel).ToString() + " not found.");
                return;
            }

            Action onStackClose = () =>
            {
                TaskManager.Instance.Complete(driver, false);
            };

            PanelManager.Instance.Push(k_quizStack, panel, driver, onStackClose);
        }
Пример #18
0
        public List <Collectible> GetPlayerRewardCollectibles(IPlayerTaskDriver itemDriver)
        {
            var list = new List <Collectible>();


            // TAKE TASK
            if (itemDriver.IsTakeTask &&
                ((itemDriver.Task.ActionItems != null && itemDriver.Task.ActionItems.CollectibleCounts != null) ||
                 (itemDriver.Task.Reward != null && itemDriver.Task.Reward.CollectibleCounts != null)))
            {
                if (itemDriver.Task.ActionItems != null &&
                    itemDriver.Task.ActionItems.CollectibleCounts != null &&
                    itemDriver.Task.ActionItems.CollectibleCounts.Any())
                {
                    list.AddRange(itemDriver.Task.ActionItems.CollectibleCounts.Select(cc => cc.Collectible));
                }
                if (itemDriver.Task.Reward != null &&
                    itemDriver.Task.Reward.CollectibleCounts != null &&
                    itemDriver.Task.Reward.CollectibleCounts.Any())
                {
                    list.AddRange(itemDriver.Task.Reward.CollectibleCounts.Select(cc => cc.Collectible));
                }
            }
            // GIVE TASK or EXCHANGE TASK
            else if ((itemDriver.IsGiveTask) && itemDriver.Task.Reward != null && itemDriver.Task.Reward.CollectibleCounts != null)
            {
                if (itemDriver.Task.Reward.CollectibleCounts != null &&
                    itemDriver.Task.Reward.CollectibleCounts.Any())
                {
                    list.AddRange(itemDriver.Task.Reward.CollectibleCounts.Select(cc => cc.Collectible));
                }
            }
            else
            {
                if (itemDriver.Task.Reward != null && itemDriver.Task.Reward.CollectibleCounts != null &&
                    itemDriver.Task.Reward.CollectibleCounts.Any())
                {
                    list.AddRange(itemDriver.Task.Reward.CollectibleCounts.Select(cc => cc.Collectible));
                }
            }

            return(list);
        }
Пример #19
0
        protected virtual T AddTaskItem <T>(T prefab, IPlayerTaskDriver driver) where T : TaskItem
        {
            var item = Table.AddItem <T>(prefab);

            item.ActionItemPrefab = ActionItemPrefab;
            item.OnSelected.AddListener(() =>
            {
                OnItemSelected(item);
            });

            item.OnAction.AddListener(() =>
            {
                OnItemAction(item);
            });

            item.Populate(driver);
            ConfigureTaskItem(item, driver);

            return(item);
        }
Пример #20
0
        public override void Populate(IPlayerTaskDriver driver)
        {
            var locDriver = driver as LocationTaskDriver;

            if (Subtitle)
            {
                Subtitle.text = "";

                if (locDriver.Task.Locations != null)
                {
                    var loc = locDriver.Task.Locations.FirstOrDefault();

                    if (loc != null && Subtitle)
                    {
                        Subtitle.text = loc.Name;
                    }
                }
            }

            base.Populate(driver);
        }
Пример #21
0
        public void DeactivateTask(IPlayerTaskDriver driver)
        {
            if (m_drivers.ContainsKey(driver.ActivationContext.InstanceId))
            {
                m_drivers.Remove(driver.ActivationContext.InstanceId);

                StopTask(driver, update: false);

                if (driver.Task.Outcomes != null)
                {
                    foreach (var oc in driver.Task.Outcomes)
                    {
                        m_outcomeDrivers.Remove(oc.Id, driver);
                    }
                }
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
Пример #22
0
        // TODO: everything below here is a bit of a grab-bag that needs a refactor.
        // Essentially, task driver delegates should handle the todo list in some way.
        // For now, we know what we want each one to do so we'll do it directly.
        void SetTodoTask(IPlayerTaskDriver driver)
        {
            // Don't preview complete/closed tasks
            if (driver != null && (driver.IsComplete || driver.ActivationContext.IsClosed))
            {
                m_currTodoDriver = null;

                driver.SetFocus(false);

                SetToDoPanel(null);

                return;
            }

            if (m_currTodoDriver != null && m_currTodoDriver != driver)
            {
                m_currTodoDriver.SetFocus(false);
            }

            m_currTodoDriver = driver;

            if (driver != null)
            {
                if (driver is LocationTaskDriver && LocationTaskAnnotationHandler.Instance)
                {
                    var ann = LocationTaskAnnotationHandler.Instance.GetNearestAnnotation((LocationTaskDriver)driver);

                    if (ann != null)
                    {
                        MapController.Instance.FocusAnnotation(ann);
                    }
                    else
                    {
                        SetToDoPanel(LocationTaskAnnotationHandler.Instance.SelectedLocationPanel, driver);
                    }
                }
                else if (driver is ARTaskDriver && ARTaskAnnotationHandler.Instance)
                {
                    var ann = ARTaskAnnotationHandler.Instance.GetNearestAnnotation((ARTaskDriver)driver);

                    if (ann != null)
                    {
                        MapController.Instance.FocusAnnotation(ann);
                    }
                    else
                    {
                        SetToDoPanel(ARTaskAnnotationHandler.Instance.SelectedLocationPanel, driver);
                    }
                }
#if MOTIVE_VUFORIA
                else if (driver is VisualMarkerTaskDriver)
                {
                    SetToDoPanel(VisualMarkerTaskPanel, driver);
                }
#endif
                else if (driver.Task.Type == "motive.gaming.characterTask")
                {
                    SetToDoPanel(CharacterTaskPanel, driver);
                }
                else
                {
                    SetToDoPanel(SimpleTaskPanel, driver);
                }

                driver.SetFocus(true);
            }
            else
            {
                SetToDoPanel(null);
            }
        }
Пример #23
0
        /// <summary>
        /// Sets the task complete panel for the given driver.
        /// </summary>
        /// <param name="taskDriver"></param>
        public void SetTaskComplete(IPlayerTaskDriver taskDriver)
        {
            m_taskCompleteDriver = taskDriver;

            ThreadHelper.Instance.CallExclusive(SyncPanels);
        }
Пример #24
0
 protected QuizMinigameDriverBase(IPlayerTaskDriver taskDriver, T quizMinigame)
 {
     this.TaskDriver = taskDriver;
     this.Quiz       = quizMinigame;
 }
 public FreeResponseMinigameDriver(IPlayerTaskDriver taskDriver, FreeResponseQuiz quiz) : base(taskDriver, quiz)
 {
 }
Пример #26
0
        void Update()
        {
            // Only update the preview panel if:
            // 1. There is no current panel, or
            // 2. The current driver is either inactive, complete, or closed
            // Otherwise we don't change anything because we want this panel to be
            // somewhat sticky.
            if (m_currTodoDriver != null &&
                (!TaskManager.Instance.ActiveTaskDrivers.Contains(m_currTodoDriver) ||
                 m_currTodoDriver.IsComplete ||
                 m_currTodoDriver.ActivationContext.IsClosed))
            {
                ClearTodoTask(m_currTodoDriver);
            }

            IPlayerTaskDriver driver = null;

            // Keep the current todo driver if it's an override and it's active.
            // Otherwise compute the best todo driver to show the user.
            if (m_currTodoDriver != null &&
                m_todoIsOverride &&
                TaskManager.Instance.ActiveTaskDrivers.Contains(m_currTodoDriver))
            {
                driver = m_currTodoDriver;
            }
            else
            {
                m_todoIsOverride = false;

                // Todo: can we centralize the "todo" item into
                // one property?
                m_currTodoObjective = null;

                var adriver = TaskManager.Instance.FirstAssignment;

                if (adriver != null)
                {
                    driver = TaskManager.Instance.GetActiveObjectiveTasks(adriver)
                             .OrderBy(d => d.ActivationContext.ActivationTime)
                             .FirstOrDefault();
                }

                // Prioritize task drivers attached to the assignment,
                // fall back to the rest of the drivers.
                if (driver == null)
                {
                    driver = TaskManager.Instance.ActiveTaskDrivers
                             .OrderBy(d => d.ActivationContext.ActivationTime)
                             .FirstOrDefault();
                }
            }

            if (driver != null)
            {
                SetTodoTask(driver);
            }

            /*
             * Looking forward to attractions
             * else
             * {
             *  var todo = AttractionManager.Instance.GetNextToDo();
             *
             *  if (todo != null)
             *  {
             *      var annotation = AttractionManager.Instance.GetAnnotation(todo.Attraction.Id);
             *
             *      SetToDoPanel(AttractionManager.Instance.SelectedLocationPanel, annotation);
             *  }
             *  else
             *  {
             *      SetToDoPanel(null);
             *  }
             * }*/

            ThreadHelper.Instance.CallExclusive(RaiseEvent);
        }
Пример #27
0
        /// <summary>
        /// Completes the task and optionally shows the reward screen for "take" items.
        /// </summary>
        /// <param name="driver"></param>
        /// <param name="showRewardScreenForTakeItems"></param>
        public virtual void Complete(IPlayerTaskDriver driver, bool showRewardScreenForTakeItems = true)
        {
            if (CanComplete(driver))
            {
                var args = new Dictionary <string, object>()
                {
                    { "Id", driver.Task.Id },
                    { "Title", driver.Task.Title }
                };

                if (driver is LocationTaskDriver)
                {
                    var location = ((LocationTaskDriver)driver).ActionLocation;

                    if (location != null)
                    {
                        args["LocationName"] = location.Name;
                        args["Coordinates"]  = location.Coordinates.ToString();

                        if (location.LocationTypes != null)
                        {
                            args["LocationTypes"] = string.Join(",", location.LocationTypes);
                        }

                        if (location.StoryTags != null)
                        {
                            args["LocationStoryTags"] = string.Join(",", location.StoryTags);
                        }
                    }
                }

                AnalyticsHelper.FireEvent("CompleteTask", args);

                // Unless overridden, performing "action" completes this task
                driver.ActivationContext.FireEvent("complete");

                var task = driver.Task;

                Action doClose = () =>
                {
                    if (task.Outcomes != null)
                    {
                        foreach (var o in task.Outcomes)
                        {
                            CompleteObjective(o, false);
                        }

                        // Update any assignments..
                        Save();

                        UpdateAssignments();

                        if (ObjectivesUpdated != null)
                        {
                            ObjectivesUpdated(this, EventArgs.Empty);
                        }
                    }

                    if (!driver.Task.IsReplayable)
                    {
                        ClosePlayerTask(driver);
                    }

                    driver.DidComplete();

                    if (Updated != null)
                    {
                        Updated(this, EventArgs.Empty);
                    }
                };

                Action doReward = () =>
                {
                    if (task.Reward != null)
                    {
                        RewardManager.Instance.RewardValuables(task.Reward, doClose);
                    }
                    else
                    {
                        doClose();
                    }
                };

                if (driver.IsGiveTask)
                {
                    TransactionManager.Instance.RemoveValuables(task.ActionItems);

                    doReward();
                }
                else if (driver.IsTakeTask)
                {
                    if (task.ActionItems != null)
                    {
                        // By default we show a reward screen any time a user
                        // collects something. Set to false to add items
                        // directly to the inventory.
                        if (showRewardScreenForTakeItems)
                        {
                            RewardManager.Instance.RewardValuables(task.ActionItems, doClose);
                        }
                        else
                        {
                            TransactionManager.Instance.AddValuables(task.ActionItems);
                        }
                    }
                    else
                    {
                        doReward();
                    }
                }
                else
                {
                    doReward();
                }
            }
        }
Пример #28
0
        public virtual void ActivatePlayerTaskDriver(ResourceActivationContext context, IPlayerTaskDriver driver)
        {
            if (!context.IsClosed)
            {
                context.Open();

                if (driver.Task.Outcomes != null)
                {
                    foreach (var oc in driver.Task.Outcomes)
                    {
                        m_outcomeDrivers.Add(oc.Id, driver);
                    }
                }

                m_drivers[context.InstanceId] = driver;

                // todo auto accept every task based on config option
                if (TaskManager.Instance.AutoAcceptTask)
                {
                    driver.Accept(); // calls start
                }

                //else if (driver.IsAccepted)
                //{
                //    driver.Start();
                //}

                if (context.IsFirstActivation)
                {
                    if (TaskNotifier.Instance)
                    {
                        TaskNotifier.Instance.AddNewTask(driver);
                    }
                }
            }
            else
            {
                // Track closed drivers, but don't do anything else with them.
                // This enables task views that store a "completed" task state.
                if (driver.Task.Outcomes != null)
                {
                    foreach (var oc in driver.Task.Outcomes)
                    {
                        m_outcomeDrivers.Add(oc.Id, driver);
                    }
                }

                m_drivers[context.InstanceId] = driver;
            }

            if (Updated != null)
            {
                Updated(this, EventArgs.Empty);
            }
        }
Пример #29
0
 public TaskAssignmentItem(AssignmentDriver asnDriver, IPlayerTaskDriver driver, int idx = 0)
     : base(asnDriver, idx)
 {
     TaskDriver = driver;
 }
Пример #30
0
 internal virtual void StopMinigame(IPlayerTaskDriver playerTaskDriver)
 {
 }