public virtual void ActivateObjective(TaskObjective objective) { AnalyticsHelper.FireEvent("ActivateObjective", new Dictionary <string, object>() { { "Id", objective.Id }, { "Title", objective.Title } }); lock (m_activatedObjectives) { m_activatedObjectives.Add(objective.Id); } Save(); if (ObjectivesUpdated != null) { ObjectivesUpdated(this, EventArgs.Empty); } if (Updated != null) { Updated(this, EventArgs.Empty); } }
public void LaunchScript(Script script, string runId, IStorageManager callerStorageManager, Action onRunning, Action <bool> onComplete) { AnalyticsHelper.FireEvent("LaunchScript", new Dictionary <string, object> { { "Name", script.Name }, { "Id", script.Id }, { "RunId", runId } }); var key = GetScriptRunId(script.Id, runId); if (m_runningProcessors.ContainsKey(key)) { // Can only run one instance at a time with this implementation. // It is entirely possible to run the same script with multiple // script processors as long as they have different state files. if (onComplete != null) { onComplete(false); } return; } // Store script state in its own directory so we can reset all // scripts easily. var stateMgr = callerStorageManager.GetManager(GetScriptFolderName(script.Id), runId); var proc = new ScriptProcessor(script, stateMgr, runId); m_runningProcessors[key] = proc; proc.Run(onRunning, onComplete); }
public void Reset(Action onComplete) { AnalyticsHelper.FireEvent("Reset"); StopAllProcessors(() => { if (ScriptsReset != null) { ScriptsReset(this, EventArgs.Empty); } try { ScriptEngine.Instance.Reset(); } catch (Exception x) { m_logger.Warning("Unhandled exception {0} resetting script engine. Continuing anyway.", x.ToString()); } StorageManager.DeleteGameFolder(); if (onComplete != null) { onComplete(); } }); }
public Panel PushPanel(Panel toPush) { // Instantiate a copy of the panel. var pref = Instantiate(toPush); pref.SetActive(true); // Set this as the parent. pref.transform.SetParent(transform, false); pref.gameObject.transform.localScale = gameObject.transform.localScale; var p_rt = pref.GetComponent <RectTransform>(); var rt = GetComponent <RectTransform>(); p_rt.anchorMax = rt.anchorMax; p_rt.anchorMin = rt.anchorMin; p_rt.anchoredPosition = rt.anchoredPosition; p_rt.position = rt.position; p_rt.sizeDelta = rt.sizeDelta; AnalyticsHelper.FireEvent("Pushing embedded panel", new Dictionary <string, object> { { "Name", toPush.GetType().ToString() } }); PushSubPanel(ParentPanel, pref, null, () => { Close(pref); }); toPush.SetActive(false); return(pref); }
protected virtual void Complete() { TaskManager.Instance.CompleteAssignment(this); AnalyticsHelper.FireEvent("CompleteAssignment", new Dictionary <string, object>() { { "Id", Assignment.Id }, { "Title", Assignment.Title } }); }
public void Reset(Action onComplete) { AnalyticsHelper.FireEvent("Reset"); StopAllProcessors(() => { if (ScriptsReset != null) { ScriptsReset(this, EventArgs.Empty); } ScriptEngine.Instance.Reset(); StorageManager.DeleteGameFolder(); if (onComplete != null) { onComplete(); } }); }
public virtual void CompleteObjective(TaskObjective objective, bool commit = true) { AnalyticsHelper.FireEvent("CompleteObjective", new Dictionary <string, object>() { { "Id", objective.Id }, { "Title", objective.Title } }); lock (m_completedObjectives) { CompleteObjectiveState os = null; if (!m_completedObjectives.TryGetValue(objective.Id, out os)) { os = new CompleteObjectiveState(); m_completedObjectives[objective.Id] = os; } os.Objective = objective; os.Count++; } if (commit) { Save(); UpdateAssignments(); if (ObjectivesUpdated != null) { ObjectivesUpdated(this, EventArgs.Empty); } if (Updated != null) { Updated(this, EventArgs.Empty); } } }
/// <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(); } } }
void PushPanel(PanelStack stack, Panel p, object data, Action onClose, bool animate = true) { AnalyticsHelper.FireEvent("PushPanel", new Dictionary <string, object> { { "Name", p.GetType().ToString() } }); PanelStack currStack = null; m_pushedPanelStacks.TryGetValue(p, out currStack); if (currStack != null && currStack != stack) { m_logger.Error("Panel {0} already in another stack (curr={1} requested={2}), aborting push", p.GetType().Name, currStack.m_stackName, stack.m_stackName); return; } m_pushedPanelStacks[p] = stack; m_logger.Debug("PushPanel {0} ({1}) stack={1} start", p.name, p.GetType().Name, stack.m_stackName); var curr = stack.CurrentPanel; if (curr == p) { // This panel is already showing, don't go any further. m_logger.Debug("PushPanel {0} stack={1} already on top", p.GetType().Name, stack.m_stackName); p.OnClose = onClose; p.DidPush(data); return; } if (curr) { m_logger.Verbose("PushPanel curr = {0}", curr.GetType().Name); var anim = curr.GetAnimationTarget().GetComponent <Animator>(); if (anim && curr.IsReady) { // Review this: if we remove the animator controller // before it finishes its animation, we can end up // in a situation where the panel is hidden or partially // occluded. // Only set it null if it's marked as "ready". This // indicates that the animation has completed. //anim.runtimeAnimatorController = null; //Destroy(anim); anim.enabled = false; } if (StackBehavior == PanelStackBehavior.Normal) { curr.DidResignTop(); if (!curr.KeepActiveInStack) { SetPanelActive(curr, false); } } else if (StackBehavior == PanelStackBehavior.OneAtATime) { PopPanel(stack, curr); } } p.SetReady(false); // Remove this one from the stack if it's already there stack.m_panels.Remove(p); stack.m_panels.Add(p); p.OnClose = onClose; DoShowPanel(p, animate); p.DidPush(data); m_logger.Verbose("PushPanel {0} end", p.GetType().Name); }
void PopPanel(PanelStack panelStack, Panel p, bool animate = true, RuntimeAnimatorController animController = null) { bool isTop = (p == panelStack.CurrentPanel); // Can only call PopPanel on the top panel /* rc - 11/28/2017: let panels get "popped" from * the middle of a stack. Most of the time the opposite * behaviour is unwanted (a middle panel taking anything that was * pushed after with it) * if (p != panelStack.CurrentPanel) * { * return; * }*/ AnalyticsHelper.FireEvent("PopPanel", new Dictionary <string, object> { { "Name", p.GetType().ToString() } }); m_logger.Debug("PopPanel {0} ({1}) stack={2} start", p.name, p.GetType().Name, panelStack.m_stackName); panelStack.Remove(p); m_pushedPanelStacks.Remove(p); m_showPanels.Remove(p); var curr = panelStack.CurrentPanel; var onClose = p.OnClose; p.OnClose = null; if (onClose != null) { onClose(); } if (!isTop) { // Skip animations, etc. The code // after this conditional is only // applicable when popping the top // panel SetPanelActive(p, false); p.DidPop(); return; } // If the current top panel is the one that we remembered // from before. This handles the case that "onClose" caused // the same panel to be pushed again (e.g. screen message -> // screen message) if (panelStack.CurrentPanel && (panelStack.CurrentPanel == curr)) { m_logger.Verbose("PopPanel from {0} -> {1} is ready={2}", p.GetType().Name, panelStack.CurrentPanel.GetType().Name, panelStack.CurrentPanel.IsReady); SetPanelActive(panelStack.CurrentPanel, true); panelStack.CurrentPanel.DidRegainTop(); } SetPanelOrientation(curr); // Hide this panel last // We might be re-showing the same panel as part of the onClose flow, // if so, don't tell the panel it hid because this will shut the panel down. if (panelStack.CurrentPanel != p) { Action doPop = () => { var animCtl = animController ?? p.PopAnimation; if (animCtl && animate) { p.DoAnimation(animCtl); } else { SetPanelActive(p, false); } p.DidPop(); }; if (panelStack.CurrentPanel && !panelStack.CurrentPanel.IsReady) { m_logger.Verbose("Current panel {0} is not ready!", panelStack.CurrentPanel.name); p.transform.SetAsLastSibling(); StartCoroutine(CallWhenReady(panelStack.CurrentPanel, () => { // Make sure the panel we're disabling didn't become the // current panel if (p != panelStack.CurrentPanel) { doPop(); } })); } else { m_logger.Verbose("Current panel {0} is ready!", panelStack.CurrentPanel ? panelStack.CurrentPanel.name : null); doPop(); } } if (m_showPanels.Count == 0) { ObjectHelper.SetObjectsActive(ShowWhenPanelsShowing, false); ObjectHelper.SetObjectsActive(ShowWhenNoPanelsShowing, true); } m_logger.Verbose("PopPanel {0} end", p.GetType().Name); }