예제 #1
0
        public void checkTimers()
        {
            foreach (Timer t in timers)
            {
                if (ConditionChecker.check(t.getInitCond()))
                {
                    if (!isRunning(t))
                    {
                        TimerState ts = new TimerState();
                        if (t.isCountDown())
                        {
                            ts.type         = TimerType.COUNTDOWN;
                            ts.max_time     = 0;
                            ts.current_time = System.Convert.ToInt64(t.getTime() * 1000) / 1000f;
                        }
                        else
                        {
                            ts.type         = TimerType.NORMAL;
                            ts.max_time     = System.Convert.ToInt64(t.getTime() * 1000) / 1000f;
                            ts.current_time = 0;
                        }
                        ts.timer = t;

                        running_timers.Add(ts);
                    }
                }
                else if (isRunning(t))
                {
                    removeFromRunning(t);
                }
            }
        }
예제 #2
0
        public void showOptions(ConversationNodeHolder options)
        {
            var optionsNode = options.getNode() as OptionConversationNode;

            if (optionsNode != null)
            {
                // Disable the UI interactivity
                uAdventureRaycaster.Instance.enabled = false;
                InventoryManager.Instance.Show       = false;

                // Enable blurred background
                blur = GameObject.Instantiate(Blur_Prefab);
                blur.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, Camera.main.transform.position.z + 1);

                // Order shuffeling when node is configured for random
                this.order = Enumerable.Range(0, optionsNode.getLineCount()).ToList();
                if (optionsNode.isRandom())
                {
                    this.order.Shuffle();
                }
                this.guioptions = options;
                this.guistate   = GUIState.ANSWERS_MENU;

                // Timeout option
                if (optionsNode.Timeout > 0 && ConditionChecker.check(optionsNode.TimeoutConditions))
                {
                    this.doTimeOut   = true;
                    this.elapsedTime = 0;
                }
                else
                {
                    this.doTimeOut = false;
                }
            }
        }
        private void RefreshBackground(Scene scene)
        {
            backgroundTexture = null;
            foreach (ResourcesUni sr in scene.getResources())
            {
                if (ConditionChecker.check(sr.getConditions()))
                {
                    backgroundTexture = Game.Instance.ResourceManager.getImage(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));
                    SetBackground(backgroundTexture);

                    var foregroundPath = sr.getAssetPath(Scene.RESOURCE_TYPE_FOREGROUND);
                    if (!string.IsNullOrEmpty(foregroundPath))
                    {
                        Texture2D foregroundTexture = Game.Instance.ResourceManager.getImage(foregroundPath);

                        foreground.GetComponent <Renderer>().material.SetTexture("_MainTex", backgroundTexture);
                        foreground.GetComponent <Renderer>().material.SetTexture("_AlphaTex", foregroundTexture);

                        foreground.localScale = background.localScale;
                        var foreGroundPos = background.localPosition;
                        foreGroundPos.z          = 1;
                        foreground.localPosition = foreGroundPos;
                    }

                    LoadBackgroundMusic(sr);

                    break;
                }
            }
        }
예제 #4
0
        public bool Update()
        {
            bool hasBeenUpdated = false;

            if (!Reached)
            {
                switch (Milestone.getType())
                {
                case Completable.Milestone.MilestoneType.COMPLETABLE:
                    var targetCompletable = CompletablesController.Instance.GetCompletable(Milestone.getId());
                    Reached = targetCompletable.End.Reached;
                    break;

                case Completable.Milestone.MilestoneType.CONDITION:
                    Reached = ConditionChecker.check(Milestone.getConditions());
                    break;
                }

                if (Reached)
                {
                    hasBeenUpdated = true;
                }
            }

            return(hasBeenUpdated);
        }
예제 #5
0
        public bool execute()
        {
            bool             forcewait = false;
            ConversationLine l;

            if (node != null)
            {
                if (node is DialogueConversationNode)
                {
                    while (current_line < node.getLineCount() && !forcewait)
                    {
                        l = node.getLine(current_line);
                        if (ConditionChecker.check(l.getConditions()))
                        {
                            forcewait = true;
                            Game.Instance.Talk(l, l.getName());
                        }
                        current_line++;
                    }

                    if (!forcewait && additional_effects != null && additional_effects.effects.Count > 0)
                    {
                        forcewait = additional_effects.execute();
                    }
                }
                else if (node is OptionConversationNode)
                {
                    if (this.child == -2)
                    {
                        if (isTracePending)
                        {
                            EndTrace();
                        }

                        Game.Instance.showOptions(this);
                        forcewait = true;
                    }
                    else if (showOption)
                    {
                        l = node.getLine(child);
                        Game.Instance.Talk(l, l.getName());
                        forcewait  = true;
                        showOption = false;
                    }
                    else
                    {
                        if (additional_effects != null)
                        {
                            forcewait = additional_effects.execute();
                        }
                        else
                        {
                            forcewait = false;
                        }
                    }
                }
            }

            return(forcewait);
        }
예제 #6
0
        public void Destroy(float time, System.Action onDestroy)
        {
            var audioSource = GetComponent <AudioSource>();

            lastClip   = null;
            lastSecond = 0;
            if (audioSource && audioSource.clip)
            {
                lastClip   = audioSource.clip;
                lastSecond = audioSource.time;
            }

            var emptytexture = new Texture2D(1, 1);

            foreground.GetComponent <Renderer>().material.SetTexture("_MainTex", emptytexture);
            foreground.GetComponent <Renderer>().material.SetTexture("_AlphaTex", emptytexture);

            Game.Instance.GameState.OnConditionChanged -= OnConditionChanged;
            GameObject.DestroyImmediate(this.gameObject);

            Scene scene = SceneData as Scene;

            if (scene != null)
            {
                foreach (ResourcesUni sr in scene.getResources())
                {
                    if (ConditionChecker.check(sr.getConditions()))
                    {
                        Game.Instance.ResourceManager.ClearImage(sr.getAssetPath(Scene.RESOURCE_TYPE_BACKGROUND));
                    }
                }
            }

            onDestroy();
        }
예제 #7
0
        public static void AddExamineIfNotExists(Element element, List <Action> actions)
        {
            if (!actions.Any(a => a.getType() == Action.EXAMINE))
            {
                var description = element.getDescriptions()
                                  .Find(d => ConditionChecker.check(d.getConditions()));

                if (description != null)
                {
                    var textToShow = description.getDetailedDescription();
                    if (string.IsNullOrEmpty(textToShow))
                    {
                        textToShow = description.getDescription();
                    }
                    if (string.IsNullOrEmpty(textToShow))
                    {
                        textToShow = description.getName();
                    }

                    // Only add the examine if there's text to show
                    if (!string.IsNullOrEmpty(textToShow))
                    {
                        actions.Add(
                            new Action(Action.EXAMINE)
                        {
                            Effects = new Effects
                            {
                                new SpeakPlayerEffect(textToShow)
                            }
                        }
                            );
                    }
                }
            }
        }
예제 #8
0
        public void checkResources()
        {
            if (element == null || element.getResources() == null)
            {
                return;
            }
            var prevResource = this.resource;

            this.resource = element.getResources()
                            .Find(res => ConditionChecker.check(res.getConditions()));

            if (prevResource != resource)
            {
                if (ResourceMode == ResourceType.ANIMATION)
                {
                    var toPlay = animationUri;
                    animationUri = null;
                    this.Play(toPlay);
                }
                else
                {
                    this.Adaptate();
                }
            }
        }
예제 #9
0
 private void OnConditionChanged(string condition, int value)
 {
     checkResources();
     if (this && gameObject)
     {
         gameObject.SetActive(!Context.IsRemoved() && ConditionChecker.check(Context.Conditions));
     }
 }
예제 #10
0
        public void exit()
        {
            //Game.Instance.hideMenu ();
            if (ConditionChecker.check(ed.getConditions()))
            {
                EffectHolder effect = new EffectHolder(ed.getEffects());

                if (Game.Instance.GameState.isCutscene(ed.getNextSceneId()))
                {
                    effect.effects.Add(new EffectHolderNode(new TriggerCutsceneEffect(ed.getNextSceneId())));
                }
                else
                {
                    effect.effects.Add(new EffectHolderNode(new TriggerSceneEffect(ed.getNextSceneId(), 0, 0, ed.getTransitionTime(), ed.getTransitionType())));
                }

                if (ed.getPostEffects() != null)
                {
                    EffectHolder eh = new EffectHolder(ed.getPostEffects());
                    foreach (EffectHolderNode ehn in eh.effects)
                    {
                        effect.effects.Add(ehn);
                    }
                }

                if (Game.Instance.getAlternativeTarget() != null)
                {
                    if (Game.Instance.getAlternativeTarget().getXApiType() == "menu")
                    {
                        Tracker.T.alternative.Selected(Game.Instance.getAlternativeTarget().getId(), ed.getNextSceneId(), AlternativeTracker.Alternative.Menu);
                    }
                    else
                    {
                        Tracker.T.alternative.Selected(Game.Instance.getAlternativeTarget().getId(), ed.getNextSceneId(), true);
                    }
                }

                Game.Instance.Execute(effect);
                GUIManager.Instance.setCursor("default");
            }
            else
            {
                if (Game.Instance.getAlternativeTarget() != null)
                {
                    if (Game.Instance.getAlternativeTarget().getXApiType() != "menu")
                    {
                        Tracker.T.alternative.Selected(Game.Instance.getAlternativeTarget().getId(), "Incorrect", false);
                    }
                }

                if (ed.isHasNotEffects())
                {
                    Game.Instance.Execute(new EffectHolder(ed.getNotEffects()));
                }
            }

            Tracker.T.RequestFlush();
        }
예제 #11
0
        // Use this for initialization
        protected void Start()
        {
            spriteRenderer = GetComponent <SpriteRenderer>();

            if (this.action.getType() == Action.CUSTOM)
            {
                actionName = ((CustomAction)action).getName();

                CustomAction ca = action as CustomAction;
                foreach (ResourcesUni ru in ca.getResources())
                {
                    if (ConditionChecker.check(ru.getConditions()))
                    {
                        this.resource = ru;
                    }
                }
            }
            else
            {
                /*resource = new ResourcesUni ();
                 * CustomButton button = Game.Instance.getButton (ActionNameWrapper.Names [action.getType ()],DescriptorData.NORMAL_BUTTON);
                 * CustomButton highlighted = Game.Instance.getButton (ActionNameWrapper.Names [action.getType ()],DescriptorData.HIGHLIGHTED_BUTTON);
                 *
                 * if (button == null || highlighted == null) {
                 *  button = Game.Instance.getButton (ActionNameWrapper.AuxNames [action.getType ()], DescriptorData.NORMAL_BUTTON);
                 *  highlighted = Game.Instance.getButton (ActionNameWrapper.AuxNames [action.getType ()], DescriptorData.HIGHLIGHTED_BUTTON);
                 * }
                 *
                 * resource.addAsset (DescriptorData.NORMAL_BUTTON, button.getPath());
                 * resource.addAsset (DescriptorData.HIGHLIGHTED_BUTTON, highlighted.getPath());*/

                resource = GUIManager.Instance.Provider.getButton(this.action);

                actionName = ConstantNames.L["ES"].Actions[action.getType()];
            }

            Sprite tmp;

            if (this.action.getType() == Action.CUSTOM)
            {
                tmp = Game.Instance.ResourceManager.getSprite(resource.getAssetPath("buttonNormal"));
            }
            else
            {
                tmp = Game.Instance.ResourceManager.getSprite(resource.getAssetPath(DescriptorData.NORMAL_BUTTON));
            }

            spriteRenderer.sprite = tmp;
            if (InventoryManager.Instance.Opened)
            {
                this.gameObject.AddComponent <BoxCollider2D>();
            }
            else
            {
                this.gameObject.AddComponent <BoxCollider>();
            }
            //this.transform.localScale = new Vector3(tmp.width / 75f, tmp.height / 75f, 1);
        }
예제 #12
0
        protected void CheckResources()
        {
            if (Element == null)
            {
                return;
            }

            resource = Element.getResources().Find(res => ConditionChecker.check(res.getConditions()));
        }
예제 #13
0
        protected void checkResources()
        {
            if (element == null || element.getResources() == null)
            {
                return;
            }

            this.resource = element.getResources()
                            .Find(res => ConditionChecker.check(res.getConditions()));
        }
예제 #14
0
 protected void checkResources()
 {
     foreach (ResourcesUni resource in element.getResources())
     {
         if (ConditionChecker.check(resource.getConditions()))
         {
             this.resource = resource;
             break;
         }
     }
 }
예제 #15
0
        public int CheckGlobalState(string globalState)
        {
            int         ret = GlobalStateCondition.GS_SATISFIED;
            GlobalState gs  = data.getChapters()[currentChapter].getGlobalState(globalState);

            if (gs != null)
            {
                ret = ConditionChecker.check(gs);
            }
            return(ret);
        }
        private void TraceExit(bool exited, IChapterTarget targetOnExit)
        {
            var ed = area.Element as Exit;

            // ALTERNATIVE
            if ("alternative".Equals(targetOnExit.getXApiClass(), IgnoreCase))
            {
                var parsedType = (AlternativeTracker.Alternative)Enum.Parse(typeof(AlternativeTracker.Alternative), targetOnExit.getXApiType(), true);
                if (ConditionChecker.check(ed.getConditions()))
                {
                    if (targetOnExit.getXApiType() == "menu")
                    {
                        TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), ed.getNextSceneId(), parsedType);
                    }
                    else
                    {
                        TrackerAsset.Instance.setSuccess(true);
                        TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), ed.getNextSceneId(), parsedType);
                    }
                }
                else
                {
                    if (targetOnExit.getXApiType() != "menu")
                    {
                        TrackerAsset.Instance.setSuccess(false);
                        TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), "Incorrect", parsedType);
                    }
                }
                TrackerAsset.Instance.Flush();
            }

            // ACCESIBLE

            // If no exited, accesible doesnt matter
            if (!exited)
            {
                return;
            }

            // If no destination accesible doesnt matter
            var destination = Game.Instance.GameState.GetChapterTarget(ed.getNextSceneId());

            if (destination == null)
            {
                return;
            }

            if ("accesible".Equals(destination.getXApiClass(), IgnoreCase))
            {
                var type = ExParsers.ParseDefault(destination.getXApiType(), AccessibleTracker.Accessible.Accessible);
                TrackerAsset.Instance.Accessible.Accessed(destination.getId(), type);
            }
        }
예제 #17
0
        public void OnConfirmWantsDrag(PointerEventData data)
        {
            dragActions = from action in Element.getActions().Valid(AvailableActions)
                          where action.getType() == Action.DRAG_TO && ConditionChecker.check(action.getConditions())
                          group action by action.getTargetId() into sameTargetActions
                          select sameTargetActions.First();

            if (dragActions.Any())
            {
                data.Use();
            }
        }
예제 #18
0
        private void instanceElement <T>(ElementReference context) where T : Element
        {
            if (!ConditionChecker.check(context.getConditions()))
            {
                return;
            }

            if (!contexts.ContainsKey(context))
            {
                ElementReference new_context = new ElementReference(context.getTargetId(), context.getX(), context.getY());
                new_context.setScale(context.getScale());
                contexts.Add(context, new_context);
            }

            context = contexts[context];

            GameObject base_prefab;
            Transform  parent;
            Element    element;

            if (typeof(T) == typeof(Atrezzo))
            {
                base_prefab = Atrezzo_Prefab;
                parent      = Atrezzos;
                element     = Game.Instance.GameState.getAtrezzo(context.getTargetId());
            }
            else if (typeof(T) == typeof(NPC))
            {
                base_prefab = Character_Prefab;
                parent      = Characters;
                element     = Game.Instance.GameState.getCharacter(context.getTargetId());
            }
            else if (typeof(T) == typeof(Item))
            {
                base_prefab = Object_Prefab;
                parent      = Objects;
                element     = Game.Instance.GameState.getObject(context.getTargetId());
            }
            else
            {
                return;
            }

            GameObject ret   = GameObject.Instantiate(base_prefab);
            Transform  trans = ret.GetComponent <Transform>();

            ret.GetComponent <Representable>().Context = context;
            ret.GetComponent <Representable>().Element = element;
            trans.SetParent(parent);
        }
        public bool execute()
        {
            bool             forcewait = false;
            ConversationLine l;

            if (node != null)
            {
                switch (node.getType())
                {
                case ConversationNodeViewEnum.DIALOGUE:
                    while (current_line < node.getLineCount() && !forcewait)
                    {
                        l = node.getLine(current_line);
                        if (ConditionChecker.check(l.getConditions()))
                        {
                            forcewait = true;
                            Game.Instance.talk(l.getText(), l.getName());
                        }
                        current_line++;
                    }
                    if (!forcewait && additional_effects != null && additional_effects.effects.Count > 0)
                    {
                        forcewait = additional_effects.execute();
                    }

                    break;

                case ConversationNodeViewEnum.OPTION:
                    if (this.child == -2)
                    {
                        Game.Instance.showOptions(this);
                        forcewait = true;
                    }
                    else
                    {
                        if (additional_effects != null)
                        {
                            forcewait = additional_effects.execute();
                        }
                        else
                        {
                            forcewait = false;
                        }
                    }
                    break;
                }
            }

            return(forcewait);
        }
예제 #20
0
        public InteractuableResult Interacted(RaycastHit hit = default(RaycastHit))
        {
            InteractuableResult res = InteractuableResult.IGNORES;

            if (interactable)
            {
                List <Action> available = new List <Action>();

                foreach (Action a in base.Element.getActions())
                {
                    if (ConditionChecker.check(a.getConditions()))
                    {
                        bool addaction = true;
                        foreach (Action a2 in available)
                        {
                            if ((a.getType() == Action.CUSTOM || a.getType() == Action.CUSTOM_INTERACT) && (a2.getType() == Action.CUSTOM || a2.getType() == Action.CUSTOM_INTERACT))
                            {
                                if (((CustomAction)a).getName() == ((CustomAction)a2).getName())
                                {
                                    addaction = false;
                                    break;
                                }
                            }
                            else if (a.getType() == a2.getType())
                            {
                                addaction = false;
                                break;
                            }
                        }

                        if (addaction)
                        {
                            available.Add(a);
                        }
                    }
                }

                if (available.Count > 0)
                {
                    Game.Instance.showActions(available, Input.mousePosition);
                    res = InteractuableResult.DOES_SOMETHING;
                }

                Tracker.T.trackedGameObject.Interacted(((NPC)Element).getId(), GameObjectTracker.TrackedGameObject.Npc);
                Tracker.T.RequestFlush();
            }

            return(res);
        }
예제 #21
0
        // Use this for initialization
        void Start()
        {
            if (this.action.getType() == Action.CUSTOM)
            {
                actionName = ((CustomAction)action).getName();

                CustomAction ca = action as CustomAction;
                foreach (ResourcesUni ru in ca.getResources())
                {
                    if (ConditionChecker.check(ru.getConditions()))
                    {
                        this.resource = ru;
                    }
                }
            }
            else
            {
                /*resource = new ResourcesUni ();
                 * CustomButton button = Game.Instance.getButton (ActionNameWrapper.Names [action.getType ()],DescriptorData.NORMAL_BUTTON);
                 * CustomButton highlighted = Game.Instance.getButton (ActionNameWrapper.Names [action.getType ()],DescriptorData.HIGHLIGHTED_BUTTON);
                 *
                 * if (button == null || highlighted == null) {
                 *  button = Game.Instance.getButton (ActionNameWrapper.AuxNames [action.getType ()], DescriptorData.NORMAL_BUTTON);
                 *  highlighted = Game.Instance.getButton (ActionNameWrapper.AuxNames [action.getType ()], DescriptorData.HIGHLIGHTED_BUTTON);
                 * }
                 *
                 * resource.addAsset (DescriptorData.NORMAL_BUTTON, button.getPath());
                 * resource.addAsset (DescriptorData.HIGHLIGHTED_BUTTON, highlighted.getPath());*/

                resource = GUIManager.Instance.Provider.getButton(this.action);

                actionName = ConstantNames.L["ES"].Actions[action.getType()];
            }

            Texture2D tmp;

            if (this.action.getType() == Action.CUSTOM)
            {
                tmp = ResourceManager.Instance.getImage(resource.getAssetPath("buttonNormal"));
            }
            else
            {
                tmp = ResourceManager.Instance.getImage(resource.getAssetPath(DescriptorData.NORMAL_BUTTON));
            }

            this.GetComponent <Renderer>().material.mainTexture = tmp;
            this.transform.localScale = new Vector3(tmp.width / 75f, tmp.height / 75f, 1);
        }
예제 #22
0
        public void CheckTimers()
        {
            foreach (Timer timer in timers)
            {
                // Finished timers dont restart
                if (timerState[timer] == TimerState.Finished)
                {
                    continue;
                }

                if (!IsRunning(timer))
                {
                    if (timer.isShowTime() && timer.isShowWhenStopped())
                    {
                        if (!timerObject.ContainsKey(timer))
                        {
                            timerObject[timer] = Instantiate(timerPrefab, timersContainer.transform);
                        }

                        var uiTimerController = timerObject[timer].GetComponent <UITimerController>();
                        uiTimerController.Timer   = timer;
                        uiTimerController.Running = false;
                        uiTimerController.Reset();
                    }

                    if (ConditionChecker.check(timer.getInitCond()))
                    {
                        TimerVars timerVars = new TimerVars();
                        InitTimer(timer, timerVars);
                        runningTimers[timer] = timerVars;
                    }
                }

                // If the timer has been just started
                if (IsRunning(timer))
                {
                    // Timer can end either by using its end condition or else by not satisfying his init condition
                    if ((timer.isUsesEndCondition() && ConditionChecker.check(timer.getEndCond())) || !ConditionChecker.check(timer.getInitCond()))
                    {
                        StopTimer(timer);
                    }
                }
            }
        }
예제 #23
0
        void OnGUI()
        {
            float guiscale = Screen.width / 800f;

            style.box.fontSize    = Mathf.RoundToInt(guiscale * 20);
            style.button.fontSize = Mathf.RoundToInt(guiscale * 20);
            style.label.fontSize  = Mathf.RoundToInt(guiscale * 20);
            optionlabel.fontSize  = Mathf.RoundToInt(guiscale * 36);
            style.GetStyle("talk_player").fontSize = Mathf.RoundToInt(guiscale * 20);
            //float rectwith = guiscale * 330;

            switch (guistate)
            {
            case guiState.ANSWERS_MENU:
                GUILayout.BeginArea(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f));
                GUILayout.BeginVertical();
                OptionConversationNode options = (OptionConversationNode)guioptions.getNode();

                GUILayout.Label(GUIManager.Instance.Last, optionlabel);
                for (int i = 0; i < options.getLineCount(); i++)
                {
                    ConversationLine ono = options.getLine(i);
                    if (ConditionChecker.check(options.getLineConditions(i)))
                    {
                        if (GUILayout.Button((string)ono.getText(), style.button))
                        {
                            GameObject.Destroy(blur);
                            guioptions.clicked(i);

                            /*Tracker.T ().Choice (GUIManager.Instance.Last, ono.getText ());
                             * Tracker.T ().RequestFlush ();*/
                            Interacted();
                        }
                    }
                    ;
                }
                GUILayout.EndVertical();
                GUILayout.EndArea();
                break;

            default: break;
            }
        }
예제 #24
0
        private EffectHolder GetExitEffects(out bool exited)
        {
            var     ed      = area.Element as Exit;
            Effects effects = new Effects();

            exited = false;
            if (ConditionChecker.check(ed.getConditions()))
            {
                exited = true;
                effects.AddRange(ed.getEffects());

                if (Game.Instance.GameState.IsCutscene(ed.getNextSceneId()))
                {
                    effects.Add(new TriggerCutsceneEffect(ed.getNextSceneId()));
                }
                else
                {
                    effects.Add(new TriggerSceneEffect(ed.getNextSceneId(), ed.getDestinyX(), ed.getDestinyY(), ed.getDestinyScale(), ed.getTransitionTime(), ed.getTransitionType()));
                }

                if (ed.getPostEffects() != null)
                {
                    effects.AddRange(ed.getPostEffects());
                }
            }
            else
            {
                if (ed.isHasNotEffects())
                {
                    effects.AddRange(ed.getNotEffects());
                }
            }

            var effectHolder = new EffectHolder(effects);

            if (exited)
            {
                effectHolder.effects[ed.getEffects().Count].AddAdditionalInfo("not_trace", true);
            }

            return(effectHolder);
        }
예제 #25
0
        private void RefreshPlayerAndTrajectory(Scene scene)
        {
            var playerContext = Game.Instance.GameState.PlayerContext;

            //###################### BARRIERS ######################
            var barriers = scene.getBarriers().FindAll(b => ConditionChecker.check(b.getConditions())).ToArray();

            var trajectory = scene.getTrajectory();

            if (trajectory == null)
            {
                barriers = barriers.ToList().ConvertAll(b =>
                {
                    Barrier r = b.Clone() as Barrier;
                    r.setValues(r.getX(), 0, r.getWidth(), backgroundTexture.height);
                    return(r);
                }).ToArray();

                trajectory = new Trajectory();
                var width = backgroundTexture ? backgroundTexture.width : Screen.width;
                trajectory.addNode("leftSide", 0, playerContext.getY(), playerContext.Scale);
                trajectory.addNode("rightSide", width, playerContext.getY(), playerContext.Scale);
                trajectory.addSide("leftSide", "rightSide", width);
            }

            trajectoryHandler = new TrajectoryHandler(TrajectoryHandler.CreateBlockedTrajectory(trajectory, barriers));

            if (!ready)
            {
                Representable player = GameObject.Instantiate(playerPrefab, referencesHolder).GetComponent <Representable>();
                player.Element = Game.Instance.GameState.Player;
                player.Context = playerContext;

                var scenePositioner = player.gameObject.AddComponent <ScenePositioner>();
                scenePositioner.Scene         = this;
                scenePositioner.Representable = player;
                scenePositioner.Context       = playerContext;
                // Force the start
                player.SendMessage("Start");
            }
        }
예제 #26
0
        private TrackerAsset.TrackerEvent TraceExit(bool exited, IChapterTarget targetOnExit)
        {
            if (!TrackerAsset.Instance.Started)
            {
                return(null);
            }

            var ed = area.Element as Exit;

            // ALTERNATIVE
            if ("alternative".Equals(targetOnExit.getXApiClass(), IgnoreCase))
            {
                var parsedType = (AlternativeTracker.Alternative)Enum.Parse(typeof(AlternativeTracker.Alternative), targetOnExit.getXApiType(), true);
                if (ConditionChecker.check(ed.getConditions()))
                {
                    if (targetOnExit.getXApiType() == "menu")
                    {
                        return(TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), ed.getNextSceneId(), parsedType));
                    }
                    else
                    {
                        TrackerAsset.Instance.setSuccess(true);
                        return(TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), ed.getNextSceneId(), parsedType));
                    }
                }
                else
                {
                    if (targetOnExit.getXApiType() != "menu")
                    {
                        TrackerAsset.Instance.setSuccess(false);
                        return(TrackerAsset.Instance.Alternative.Selected(targetOnExit.getId(), "Incorrect", parsedType));
                    }
                }
            }
            return(null);
        }
예제 #27
0
        protected void OnGUI()
        {
            if (loadingScreen != null)
            {
                loadingScreen.OnGUI();
            }


            switch (guistate)
            {
            case GUIState.BOOK:
                if (ShowingBook)
                {
                    bookDrawer.Draw(new Rect(Vector2.zero, new Vector2(Screen.width, Screen.height)));
                }
                break;

            case GUIState.ANSWERS_MENU:

                using (new GUIUtil.SkinScope(skin))
                {
                    float guiscale         = Screen.width / 800f;
                    var   buttonImageWidth = (200f / 600f) * Screen.height;
                    skin.box.fontSize                          = Mathf.RoundToInt(guiscale * 20);
                    skin.button.fontSize                       = Mathf.RoundToInt(guiscale * 20);
                    skin.button.alignment                      = TextAnchor.MiddleCenter;
                    skin.button.imagePosition                  = ImagePosition.ImageAbove;
                    skin.button.stretchHeight                  = false;
                    skin.button.stretchWidth                   = true;
                    skin.label.fontSize                        = Mathf.RoundToInt(guiscale * 20);
                    skin.GetStyle("optionLabel").fontSize      = Mathf.RoundToInt(guiscale * 36);
                    skin.GetStyle("talk_player").fontSize      = Mathf.RoundToInt(guiscale * 20);
                    skin.GetStyle("emptyProgressBar").fontSize = Mathf.RoundToInt(guiscale * 20);
                    OptionConversationNode options = (OptionConversationNode)guioptions.getNode();
                    var areawidth = Screen.width * 0.8f;
                    using (new GUILayout.AreaScope(new Rect(Screen.width * 0.1f, Screen.height * 0.1f, areawidth, Screen.height * 0.8f)))
                    {
                        using (new GUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                        {
                            var restWidth        = 1f;
                            var initedHorizontal = false;

                            if (options.isKeepShowing() && GUIManager.Instance.Line != null)
                            {
                                var text = GUIManager.Instance.Line.getText();
                                if (text[0] == '#')
                                {
                                    text = text.Remove(0, Mathf.Max(0, text.IndexOf(' ') + 1));
                                }

                                var textContent = new GUIContent(text);
                                var textRect    = GUILayoutUtility.GetRect(textContent, "optionLabel");

                                GUIUtil.DrawTextBorder(textRect, textContent, Color.black, "optionLabel");
                                GUIUtil.DrawText(textRect, textContent, ((GUIStyle)"optionLabel").normal.textColor, "optionLabel");

                                var resources = GUIManager.Instance.Line.getResources().Checked().FirstOrDefault();
                                if (resources != null)
                                {
                                    var image = resources.existAsset("image") ? Game.Instance.ResourceManager.getImage(resources.getAssetPath("image")) : null;
                                    if (image)
                                    {
                                        GUILayout.BeginHorizontal();
                                        initedHorizontal = true;
                                        restWidth        = 0.7f;
                                        var imageRatio  = image.width / (float)image.height;
                                        var imageWidth  = areawidth * 0.28f;
                                        var imageHeight = Mathf.Min(imageWidth / imageRatio, Screen.height * 0.45f);
                                        using (new GUILayout.VerticalScope(GUILayout.Width(areawidth * 0.3f)))
                                        {
                                            GUILayout.FlexibleSpace();
                                            GUILayout.Box(image, GUILayout.Width(imageWidth), GUILayout.Height(imageHeight));
                                            GUILayout.FlexibleSpace();
                                        }
                                    }
                                }
                            }

                            using (new GUILayout.VerticalScope(GUILayout.Width(areawidth * restWidth)))
                            {
                                if (options.Horizontal)
                                {
                                    GUILayout.FlexibleSpace();
                                }
                                var elementsLeft = options.getLineCount();
                                while (elementsLeft > 0)
                                {
                                    if (options.Horizontal)
                                    {
                                        GUILayout.BeginHorizontal();
                                        GUILayout.FlexibleSpace();
                                    }
                                    else
                                    {
                                        GUILayout.BeginVertical();
                                    }
                                    var start     = options.getLineCount() - elementsLeft;
                                    var amount    = options.MaxElemsPerRow > 0 ? options.MaxElemsPerRow : options.getLineCount();
                                    var end       = Mathf.Clamp(start + amount, 0, options.getLineCount());
                                    var eachWidth = (areawidth * restWidth / (end - start)) - 20;
                                    for (int i = start; i < end; i++)
                                    {
                                        ConversationLine ono = options.getLine(order[i]);
                                        var content          = new GUIContent(ono.getText());
                                        var resources        = ono.getResources().Checked().FirstOrDefault();
                                        auxLimitList.Clear();
                                        if (end - start > 1 && options.Horizontal)
                                        {
                                            auxLimitList.Add(GUILayout.Width(eachWidth));
                                        }

                                        if (resources != null && resources.existAsset("image") && !string.IsNullOrEmpty(resources.getAssetPath("image")))
                                        {
                                            var imagePath = resources.getAssetPath("image");
                                            var image     = ResourceManager.getImage(imagePath);
                                            if (image)
                                            {
                                                content.image = image;

                                                /*if (image.height > buttonImageWidth)
                                                 * {*/
                                                auxLimitList.Add(GUILayout.Height(buttonImageWidth - 20));
                                                //}
                                            }
                                        }

                                        if (ConditionChecker.check(options.getLineConditions(order[i])) && GUILayout.Button(content, auxLimitList.ToArray()))
                                        {
                                            OptionSelected(order[i]);
                                        }
                                    }
                                    elementsLeft = options.getLineCount() - end;
                                    if (options.Horizontal)
                                    {
                                        GUILayout.FlexibleSpace();
                                        GUILayout.EndHorizontal();
                                    }
                                    else
                                    {
                                        GUILayout.EndVertical();
                                    }

                                    if (doTimeOut)
                                    {
                                        if (Event.current.type == EventType.Repaint && elapsedTime > options.Timeout)
                                        {
                                            OptionSelected(options.getChildCount() - 1);
                                        }

                                        var timeLeft     = Mathf.Max(0, options.Timeout - elapsedTime);
                                        var timeLeftText = Mathf.Round(timeLeft * 10) / 10 + " s";
                                        GUILayout.FlexibleSpace();
                                        DrawProgressBar(GUILayoutUtility.GetRect(0, 0, "emptyProgressBar", GUILayout.ExpandWidth(true), GUILayout.Height(50)), timeLeftText, 1 - (elapsedTime / options.Timeout));
                                    }
                                }

                                if (initedHorizontal)
                                {
                                    GUILayout.EndHorizontal();
                                }

                                if (options.Horizontal)
                                {
                                    GUILayout.FlexibleSpace();
                                }
                            }
                        }
                    }
                }
                break;

            default: break;
            }
        }
예제 #28
0
        public bool execute()
        {
            var forceWait = false;

            if (effect != null && (!runsOnce || timesRun == 0 || waitForLoadPulse))
            {
                if (!validated)
                {
                    isValid   = conditions == null || ConditionChecker.check(conditions);
                    validated = true;
                }

                if (isValid)
                {
                    switch (effect.getType())
                    {
                    case EffectType.ACTIVATE:
                        Game.Instance.GameState.SetFlag(((ActivateEffect)effect).getTargetId(), FlagCondition.FLAG_ACTIVE);
                        break;

                    case EffectType.DEACTIVATE:
                        Game.Instance.GameState.SetFlag(((DeactivateEffect)effect).getTargetId(), FlagCondition.FLAG_INACTIVE);
                        break;

                    case EffectType.SHOW_TEXT:
                        var showTextEffect = (ShowTextEffect)effect;
                        Game.Instance.Talk(showTextEffect.getText(), showTextEffect.getX(), showTextEffect.getY(),
                                           showTextEffect.getRgbFrontColor(), showTextEffect.getRgbBorderColor());
                        forceWait = true;
                        break;

                    case EffectType.SPEAK_PLAYER:
                        Game.Instance.Talk(((SpeakPlayerEffect)effect).getLine(), Player.IDENTIFIER);
                        forceWait = true;
                        break;

                    case EffectType.SPEAK_CHAR:
                        Game.Instance.Talk(((SpeakCharEffect)effect).getLine(), ((SpeakCharEffect)effect).getTargetId());
                        forceWait = true;
                        break;

                    case EffectType.TRIGGER_SCENE:
                        if (!waitForLoadPulse)
                        {
                            runsOnce = false;
                            TriggerSceneEffect tse = ((TriggerSceneEffect)effect);
                            if (!Game.Instance.GameState.IsFirstPerson)
                            {
                                var playerContext = Game.Instance.GameState.PlayerContext;
                                if (tse.getX() != int.MinValue || tse.getY() != int.MinValue)
                                {
                                    playerContext.setPosition(tse.getX(), tse.getY());
                                    if (tse.DestinyScale > 0)
                                    {
                                        playerContext.Scale = tse.DestinyScale;
                                    }
                                }
                                else
                                {
                                    var targetScene = Game.Instance.GameState.GetChapterTarget(tse.getTargetId()) as Scene;
                                    if (targetScene != null)
                                    {
                                        if (targetScene.getTrajectory() != null)
                                        {
                                            var initial = targetScene.getTrajectory().getInitial();
                                            playerContext.setPosition(initial.getX(), initial.getY());
                                            playerContext.Scale = initial.getScale();
                                        }
                                        else
                                        {
                                            playerContext.setPosition(targetScene.getPositionX(), targetScene.getPositionY());
                                            playerContext.Scale = targetScene.getPlayerScale();
                                        }
                                    }
                                }
                            }

                            var trace = !(additionalInfo.ContainsKey("disable_trace") && (bool)additionalInfo["disable_trace"]);
                            Game.Instance.RunTarget(tse.getTargetId(), tse.getTransitionTime(), tse.getTransitionType(), null, trace);
                            waitForLoadPulse = true;
                            forceWait        = true;
                        }
                        else
                        {
                            waitForLoadPulse = false;
                        }
                        // DODO make something to wait until the target is ready to prevent undesired effect advance
                        break;

                    case EffectType.TRIGGER_CUTSCENE:
                        runsOnce = false;
                        TriggerCutsceneEffect tce = (TriggerCutsceneEffect)effect;
                        if (timesRun > 1)     // The first interaction is the run target callback
                        {
                            if (additionalInfo.ContainsKey("sub_effects_wait"))
                            {
                                forceWait = false;
                            }
                            else
                            {
                                InteractuableResult res = ((Interactuable)additionalInfo["scene"]).Interacted();
                                if (res == InteractuableResult.REQUIRES_MORE_INTERACTION)
                                {
                                    forceWait = true;
                                }
                                else if (res == InteractuableResult.DOES_SOMETHING)
                                {
                                    additionalInfo["sub_effects_wait"] = true;
                                    forceWait = true;
                                }
                            }
                        }
                        else if (timesRun == 1)
                        {
                            forceWait = true;
                        }
                        else if (timesRun == 0)
                        {
                            var trace = !(additionalInfo.ContainsKey("disable_trace") && (bool)additionalInfo["disable_trace"]);

                            additionalInfo.Add("lastscene", Game.Instance.GameState.CurrentTarget);
                            additionalInfo.Add("scene", Game.Instance.RunTarget(tce.getTargetId(), null, trace));
                            forceWait = true;
                        }

                        if (!forceWait && ((Cutscene)((IRunnerChapterTarget)additionalInfo["scene"]).Data).getNext() == Cutscene.GOBACK)
                        {
                            string last = (string)additionalInfo["lastscene"];
                            Game.Instance.RunTarget(last);
                        }

                        break;

                    case EffectType.TRIGGER_LAST_SCENE:
                        runsOnce = false;
                        Game.Instance.SwitchToLastTarget();
                        break;

                    case EffectType.TRIGGER_CONVERSATION:
                        runsOnce = false;
                        runsOnce = false;
                        if (timesRun == 0)
                        {
                            var tcoe = (TriggerConversationEffect)effect;
                            this.additionalInfo.Add("conversation", new GraphConversationHolder(Game.Instance.GameState.GetConversation(tcoe.getTargetId())));
                        }
                        forceWait = ((GraphConversationHolder)this.additionalInfo["conversation"]).execute();
                        break;

                    case EffectType.RANDOM_EFFECT:
                        RandomEffect re = (RandomEffect)effect;

                        if (timesRun == 0)
                        {
                            int pro = re.getProbability(), now = Random.Range(0, 100);

                            if (pro <= now)
                            {
                                if (re.getPositiveEffect() != null)
                                {
                                    additionalInfo.Add("current", new EffectHolderNode(re.getPositiveEffect()));
                                    runsOnce = false;
                                }
                            }
                            else if (re.getNegativeEffect() != null)
                            {
                                additionalInfo.Add("current", new EffectHolderNode(re.getNegativeEffect()));
                                runsOnce = false;
                            }
                        }

                        if (additionalInfo.ContainsKey("current"))
                        {
                            var subEffectHolder = (EffectHolderNode)additionalInfo["current"];
                            forceWait = subEffectHolder.execute();
                            runsOnce  = subEffectHolder.runsOnce;
                        }

                        break;

                    case EffectType.SET_VALUE:
                        SetValueEffect sve = (SetValueEffect)effect;
                        Game.Instance.GameState.SetVariable(sve.getTargetId(), sve.getValue());
                        break;

                    case EffectType.INCREMENT_VAR:
                        IncrementVarEffect ive = (IncrementVarEffect)effect;
                        Game.Instance.GameState.SetVariable(ive.getTargetId(), Game.Instance.GameState.GetVariable(ive.getTargetId()) + ive.getIncrement());
                        break;

                    case EffectType.DECREMENT_VAR:
                        DecrementVarEffect dve = (DecrementVarEffect)effect;
                        Game.Instance.GameState.SetVariable(dve.getTargetId(), Game.Instance.GameState.GetVariable(dve.getTargetId()) - dve.getDecrement());
                        break;

                    case EffectType.MACRO_REF:
                        runsOnce = false;
                        if (timesRun == 0)
                        {
                            MacroReferenceEffect mre = (MacroReferenceEffect)effect;
                            this.additionalInfo.Add("macro", new EffectHolder(Game.Instance.GameState.GetMacro(mre.getTargetId())));
                        }
                        forceWait = ((EffectHolder)this.additionalInfo["macro"]).execute();
                        break;

                    case EffectType.MOVE_OBJECT:
                        MoveObjectEffect moe = (MoveObjectEffect)effect;
                        runsOnce = !moe.isAnimated();

                        if (timesRun == 0)
                        {
                            if (moe.isAnimated())
                            {
                                Game.Instance.GameState.Move(moe.getTargetId(), new Vector2(moe.getX(), moe.getY()), moe.getTranslateSpeed(), this);
                            }
                            else
                            {
                                Game.Instance.GameState.Move(moe.getTargetId(), new Vector2(moe.getX(), moe.getY()));
                            }
                        }
                        if (!runsOnce && !pulsed)
                        {
                            forceWait = true;
                        }
                        break;

                    case EffectType.MOVE_NPC:
                        MoveNPCEffect mne = (MoveNPCEffect)effect;
                        runsOnce = true;

                        if (timesRun == 0)
                        {
                            Game.Instance.GameState.Move(mne.getTargetId(), new Vector2(mne.getX(), mne.getY()), 1, this);
                        }
                        if (!runsOnce && !pulsed)
                        {
                            forceWait = true;
                        }
                        break;

                    case EffectType.GENERATE_OBJECT:
                        GenerateObjectEffect gen = (GenerateObjectEffect)effect;
                        var toAdd = Game.Instance.GameState.FindElement <Item>(gen.getTargetId());
                        InventoryManager.Instance.AddElement(toAdd);
                        break;

                    case EffectType.CONSUME_OBJECT:
                        ConsumeObjectEffect con = (ConsumeObjectEffect)effect;
                        var toRemove            = Game.Instance.GameState.FindElement <Item>(con.getTargetId());
                        InventoryManager.Instance.RemoveElement(toRemove);
                        break;

                    case EffectType.TRIGGER_BOOK:
                        if (timesRun == 0)
                        {
                            if (InventoryManager.Instance.Opened)
                            {
                                InventoryManager.Instance.Close();
                            }
                            TriggerBookEffect triggerBookEffect = (TriggerBookEffect)effect;
                            Game.Instance.ShowBook(triggerBookEffect.getTargetId());
                        }
                        runsOnce  = false;
                        forceWait = Game.Instance.ShowingBook;
                        break;

                    case EffectType.PLAY_SOUND:
                        PlaySoundEffect pse       = (PlaySoundEffect)effect;
                        AudioClip       audioClip = Game.Instance.ResourceManager.getAudio(pse.getPath());
                        PlayMusicOn(audioClip, Game.Instance);
                        break;

                    case EffectType.WAIT_TIME:
                        WaitTimeEffect wte = (WaitTimeEffect)effect;
                        runsOnce = false;
                        if (timesRun == 0)
                        {
                            Game.Instance.PulseOnTime(this, wte.getTime());
                        }
                        if (!pulsed)
                        {
                            forceWait = true;
                        }
                        break;

                    case EffectType.CUSTOM_EFFECT:
                        runsOnce = false;
                        if (timesRun == 0)
                        {
                            this.additionalInfo["custom_effect_runner"] = CustomEffectRunnerFactory.Instance.CreateRunnerFor(effect);
                        }
                        forceWait = ((CustomEffectRunner)this.additionalInfo["custom_effect_runner"]).execute();
                        break;
                    }
                }
            }

            if (!forceWait)
            {
                timesRun = 0;
            }
            else
            {
                timesRun++;
            }

            return(forceWait);
        }
예제 #29
0
 public bool check()
 {
     return(conditions == null || ConditionChecker.check(conditions));
 }
예제 #30
0
 public static IEnumerable <ElementReference> Checked(this IEnumerable <ElementReference> elements)
 {
     return(elements.Where(e => ConditionChecker.check(e.getConditions())));
 }