Ejemplo n.º 1
0
    public void ClearGrid(bool all)
    {
        if (all == true)
        {
            currentLevelObjects.Clear();
            gridObjectLevelIDDictionary.Clear();
            gridObjectLevelPositionDictionary.Clear();
            //gridTrackColorDictionary.Clear();

            if (gridContainer)
            {
                foreach (Transform t in gridContainer)
                {
                    GameObject.Destroy(t.gameObject);
                }
            }
        }
        else
        {
            for (int i = 0; i < currentLevelObjects.Count; i++)
            {
                if (currentLevelObjects[i].component.placedBy == "P")
                {
                    GridObjectBehavior g = currentLevelObjects[i];
                    gridObjectLevelIDDictionary.Remove(g.component.id);
                    gridObjectLevelPositionDictionary.Remove(g.transform.position);
                    currentLevelObjects.Remove(g);
                    Destroy(g.gameObject);
                    i--;
                }
            }
        }
    }
Ejemplo n.º 2
0
 public void LinkTo(GridObjectBehavior g)
 {
     if (component != null && g.component != null)
     {
         component.configuration.link = g.component.id;
     }
 }
Ejemplo n.º 3
0
 public void CreateTutorialPopup(TutorialEvent t, GridObjectBehavior gridObject)
 {
     //two versions, depending on if we want to set the position at the same time as setting the pop up to open
     tutorialManager.tutorialOverlay.SetTooltip(t.popupDescription, gridObject.gameObject, t.nextTutorial);
     tutorialManager.tutorialOverlay.tutorialCloseButton.onClick.AddListener(() => tutorialManager.tutorialOverlay.ClosePanel());
     tutorialManager.tutorialOverlay.OpenPanel();
 }
Ejemplo n.º 4
0
 void ChangePlaybackStep()
 {
     Level lvl = GameManager.Instance.GetDataManager().currentLevelData;
     for (int i = 0; i < lvl.components.Count; i++)
     {
         GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(lvl.components[i].id);
         g.ReturnToStep(timeSteps[currentStep]);
     }
 }
Ejemplo n.º 5
0
 public void UpdateGridObjectPosition(Vector3 oldPosition, Vector3 newPosition)
 {
     Debug.Log("Checking to update object from position " + oldPosition + " to " + newPosition);
     if (gridObjectLevelPositionDictionary.ContainsKey(oldPosition))
     {
         Debug.Log("Updating object from position " + oldPosition + " to " + newPosition);
         GridObjectBehavior g = gridObjectLevelPositionDictionary[oldPosition];
         gridObjectLevelPositionDictionary.Remove(oldPosition);
         gridObjectLevelPositionDictionary.Add(newPosition, g);
     }
 }
 void EndHoverEvent()
 {
     if (connectVisibilityLock || hoverObject == null)
     {
         return;
     }
     stationaryTime = 0f;
     hoverObject.EndHoverBehavior();
     GameManager.Instance.tracker.CreateEventExt("EndHoverBehavior", hoverObject.component.type);
     hoverObject = null;
 }
 public override float DoStep(StepData inputStep, Dictionary <int, List <StepData> > dictionary = null)
 {
     base.DoStep(inputStep);
     if (inputStep.componentStatus.delivered != null)
     {
         //	deliveryPopup.IncrementNumerator( inputStep.componentStatus.delivered );
     }
     if (inputStep.eventType == "F")
     {
         GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentID);
         g.ErrorBehavior(Color.black);
     }
     return(0);
 }
    public override void SetHighlight(bool isEnabled)
    {
        base.SetHighlight(isEnabled);

        if (isEnabled && component.configuration.link != -1)
        {
            GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(component.configuration.link);
            if (g != null)
            {
                g.SetHighlight(isEnabled);
                //IF CONSTANT COLORS FOR COMPONENTS...
                /**/
                if (Constants.ComponentLinkColor.componentLinkColors.ContainsKey(g.component.type))
                {
                    if (lineRenderer)
                    {
                        //int randomLineIndex = Random.Range(0, Constants.ComponentLinkColor.componentLinkColors[g.component.type].Count);
                        int   randomLineIndex = component.id % Constants.ComponentLinkColor.componentLinkColors[g.component.type].Count;
                        Color lineColor       = Constants.ComponentLinkColor.componentLinkColors[g.component.type][randomLineIndex];// * g.lineColorVariant;
                        lineColor.a = 1f;
                        lineRenderer.SetColors(lineColor, lineColor);
                        lineRenderer.sortingOrder = Constants.ComponentSortingOrder.connectionOverlay + 1;
                    }
                }
                else
                {
                    if (lineRenderer)
                    {
                        lineRenderer.SetColors(Constants.ComponentLinkColor.componentLinkColors["default"][0], Constants.ComponentLinkColor.componentLinkColors["default"][0]);
                    }
                }
                /**/

                UpdateBezier(transform.position, g.transform.position);
            }
        }
        else if (!isEnabled)
        {
            if (component.configuration.link != -1)
            {
                GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(component.configuration.link);
                if (g != null)
                {
                    g.SetHighlight(isEnabled);
                }
            }
            UpdateBezier(transform.position, transform.position);
        }
    }
Ejemplo n.º 9
0
 public override float DoStep(StepData inputStep)
 {
     Debug.Log("Delivery Do Step: " + inputStep.eventType);
     base.DoStep(inputStep);
     if (inputStep.componentStatus.delivered != null)
     {
         //	deliveryPopup.IncrementNumerator( inputStep.componentStatus.delivered );
     }
     if (inputStep.eventType == "F")
     {
         GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentID);
         g.ErrorBehavior(Color.black);
     }
     return(0);
 }
Ejemplo n.º 10
0
    public GridObjectBehavior RetrieveGridObjectOfType(Vector3 inputMousePosition, string inputType)
    {
        GridObjectBehavior returnObject = new GridObjectBehavior();

        Vector3 testPosition = worldCamera.ScreenToWorldPoint(inputMousePosition);

        testPosition.z = 0;
        testPosition.x = Mathf.RoundToInt(testPosition.x);
        testPosition.y = Mathf.RoundToInt(testPosition.y);

        if (gridObjectLevelPositionDictionary.ContainsKey(testPosition))
        {
            if (gridObjectLevelPositionDictionary[testPosition].behaviorType == GridObjectBehavior.BehaviorTypes.component && gridObjectLevelPositionDictionary[testPosition].component.type == inputType)
            {
                returnObject = gridObjectLevelPositionDictionary[testPosition];
            }
        }
        return(returnObject);
    }
Ejemplo n.º 11
0
    public void ForgetGridElement(GridObjectBehavior objectToRemove)
    {
        Vector3 testPosition      = new Vector3(objectToRemove.component.posX, objectToRemove.component.posY, 0);
        Vector3 reversedYposition = new Vector3(testPosition.x, GameManager.Instance.GetLevelHeight() - testPosition.y, 0);
        string  s = "At location " + reversedYposition.ToString() + ", Removing object from ";

        if (gridObjectLevelPositionDictionary.ContainsKey(reversedYposition))
        {
            s += "Grid Object Level Position Dictionary, "; gridObjectLevelPositionDictionary.Remove(reversedYposition);
        }
        if (gridObjectLevelIDDictionary.ContainsKey(objectToRemove.component.id))
        {
            s += "Grid Object Level ID Dictionary, "; gridObjectLevelIDDictionary.Remove(objectToRemove.component.id);
        }
        if (currentLevelObjects.Contains(objectToRemove))
        {
            s += "and Current Level Objects"; currentLevelObjects.Remove(objectToRemove);
        }
    }
    public override float DoStep(StepData inputStep, Dictionary <int, List <StepData> > dictionary = null)
    {
        if (behaviorType == BehaviorTypes.component && component != null)
        {
            switch (component.type.ToLower())
            {
            case "signal":
                if (inputStep.eventType == "E")
                {
                    int passed = component.configuration.passed;
                    if (inputStep.componentStatus != null)
                    {
                        if (inputStep.componentStatus.passed != null)
                        {
                            if (inputStep.componentStatus.passed >= 1)
                            {
                                passed = inputStep.componentStatus.passed - component.configuration.passed;
                                component.configuration.passed         = inputStep.componentStatus.passed;
                                GetComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite(component);
                                iTween.ScaleFrom(gameObject, iTween.Hash(
                                                     "scale", Vector3.one * 1.5f,
                                                     "time", 0.5f,
                                                     "oncomplete", "ResetSprite"
                                                     ));
                            }
                        }
                    }

                    GridObjectBehavior linkedObject = GameManager.Instance.GetGridManager().GetGridObjectByID(component.configuration.link);
                    if (linkedObject != null && linkedObject.component != null && linkedObject.component.type == "conditional")
                    {
                        for (int i = 0; i < passed; i++)
                        {
                            linkedObject.BeginInteraction();
                        }
                    }
                }
                break;
            }
        }
        return(0);
    }
Ejemplo n.º 13
0
    public GridObjectBehavior RetrieveEditableGridObject(Vector3 inputMousePosition)
    {
        Vector3 testPosition = worldCamera.ScreenToWorldPoint(inputMousePosition);

        testPosition.z = 0;
        testPosition.x = Mathf.RoundToInt(testPosition.x);
        testPosition.y = Mathf.RoundToInt(testPosition.y);

        GridObjectBehavior returnGridObject = new GridObjectBehavior();

        foreach (GridObjectBehavior g in currentLevelObjects)
        {
            if (g.transform.position == testPosition && g.behaviorType == GridObjectBehavior.BehaviorTypes.component && g.component.editable == "E")
            {
                returnGridObject = g;
            }
        }

        return(returnGridObject);
    }
Ejemplo n.º 14
0
    void UpdateCabooses(IEnumerable <int> payloadIds, bool instant)
    {
        List <int> currentCabooses = new List <int>();

        currentCabooses.AddRange(payloadIds);

        List <int> newCabooses = new List <int>();

        newCabooses.AddRange(payloadIds);

        List <GameObject> popCabooses = new List <GameObject>();

        /* figure out what cabooses to add to current */
        foreach (GameObject g in trailObjectList)
        {
            CabooseObject c         = g.GetComponent <CabooseObject>();
            int           currentId = c.packageOriginID;

            if (newCabooses.Contains(currentId))
            {
                if (c.instant != instant)
                {
                    c.UpdateFollow(instant);
                }
                newCabooses.Remove(currentId);
            }
            if (!currentCabooses.Contains(currentId))
            {
                popCabooses.Add(g);
            }
        }

        /* figure out what cabooses to remove from current */
        for (int p = popCabooses.Count - 1; p >= 0; p--)
        {
            CabooseObject caboose = popCabooses[p].GetComponent <CabooseObject>();
            caboose.Disconnect();
            trailObjectList.Remove(popCabooses[p]);
            Destroy(popCabooses[p]);
        }

        foreach (int payloadId in newCabooses)
        {
            GridObjectBehavior payloadObject = GameManager.Instance.GetGridManager().GetGridObjectByID(payloadId);
            GameObject         g             = new GameObject();
            g.transform.position   = gameObject.transform.position;
            g.transform.localScale = Vector3.zero;

            trailObjectList.Add(g);
            g.name = "payload_" + payloadId;
            g.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_tint_01");//payloadObject.GetComponent<SpriteRenderer>().sprite;
            g.GetComponent <SpriteRenderer>().color  = GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color);

            GameObject gChild = new GameObject();
            switch (payloadObject.component.configuration.type)
            {
            case "Conditional":
            {
                gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_03");
            }
            break;

            case "Unconditional":
            {
                gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_02");
            }
            break;

            case "Limited":
            {
                gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_01");
            }
            break;

            case "Empty":
            {
            }
            break;
            }
            gChild.GetComponent <SpriteRenderer>().sortingOrder = Constants.ComponentSortingOrder.basicComponents + 1;
            gChild.transform.position = g.transform.position;
            gChild.transform.SetParent(g.transform);
            gChild.transform.localScale = Vector3.one;

            if (true /* item is in exchange */)
            {
                /* figure out where the exchange point is, spawn it there */
                g.AddComponent <CabooseObject>().BeginFollow(this, (float)trailObjectList.Count, payloadId, instant);
            }
            else
            {
                g.AddComponent <CabooseObject>().BeginFollow(this, (float)trailObjectList.Count, payloadId, instant);
            }
        }
    }
    IEnumerator SimulationBehavior()
    {
        Level lvl               = GameManager.Instance.GetDataManager().currentLevelData;
        int   currentStep       = 0;
        int   maxStep           = 0;
        int   maxGoalsCompleted = 0;
        Dictionary <int, List <StepData> > stepDictionary           = new Dictionary <int, List <StepData> >();
        Dictionary <int, List <int> >      componentStepsDictionary = new Dictionary <int, List <int> >();

        for (int i = 0; i < lvl.execution.Count; i++)
        {
            StepData step = lvl.execution[i];

            if (step.timeStep > maxStep)
            {
                maxStep = step.timeStep;
            }

            if (step.eventType == "M")
            {
                if (!componentStepsDictionary.ContainsKey(step.componentID))
                {
                    componentStepsDictionary.Add(step.componentID, new List <int>()); componentStepsDictionary[step.componentID].Add(i);
                }
                else
                {
                    componentStepsDictionary[step.componentID].Add(i);
                }
            }

            if (stepDictionary.ContainsKey(step.timeStep))
            {
                if (step.eventType == "D")
                {
                    stepDictionary[step.timeStep].Insert(0, step);
                }
                else
                {
                    stepDictionary[step.timeStep].Add(step);
                }
            }
            else
            {
                stepDictionary[step.timeStep] = new List <StepData>();
                stepDictionary[step.timeStep].Add(step);
            }
        }

        foreach (int componentId in componentStepsDictionary.Keys)
        {
            //componentStepsDictionary[componentId].Sort();
            for (int listIndex = 0; listIndex < componentStepsDictionary[componentId].Count - 1; listIndex++)
            {
                int executionIndex     = componentStepsDictionary[componentId][listIndex];
                int nextExecutionIndex = componentStepsDictionary[componentId][listIndex + 1];
                lvl.execution[executionIndex].SetNextStep(nextExecutionIndex);
            }
        }

        while (interactionPhase == InteractionPhases.simulation && currentStep <= maxStep)
        {
            if (stepDictionary.ContainsKey(currentStep))
            {
                foreach (StepData step in stepDictionary[currentStep])
                {
                    if (step.componentID == 0)
                    {
                        if (step.componentStatus == null)
                        {
                            continue;
                        }
                        if (step.componentStatus.goals_completed != null)
                        {
                            if (maxGoalsCompleted < step.componentStatus.goals_completed)
                            {
                                maxGoalsCompleted = step.componentStatus.goals_completed;
                            }
                        }
                        if (step.componentStatus.final_condition != null && step.componentStatus.final_condition != -1)
                        {
                            string goalString = "";
                            switch (step.componentStatus.final_condition)
                            {
                            case 2:
                            case 8:
                            case 10:
                                goalString = "Successfully completed the level!";
                                break;

                            default:
                                goalString = "";
                                if ((step.componentStatus.final_condition & 1) != 0)
                                {
                                    goalString += "You hit a dead end. ";
                                }
                                if ((step.componentStatus.final_condition & 16) != 0)
                                {
                                    goalString += "You missed some deliveries. ";
                                }
                                if ((step.componentStatus.final_condition & 32) != 0)
                                {
                                    goalString += "You " +
                                                  "have starvation. ";
                                }
                                goalString += "Sorry, try again!";
                                break;
                            }

                            yield return(StartCoroutine(playerInteraction_UI.TriggerGoalPopUp(goalString)));
                        }
                    }
                    else
                    {
                        GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(step.componentID);
                        if (g != null)
                        {
                            g.DoStep(step);
                        }
                        else
                        {
                            Debug.Log("Could not find " + step.componentID);
                        }
                    }
                }
                yield return(new WaitForSeconds(0.5f));
            }
            currentStep++;
            Debug.Log(currentStep);
        }


        //yield return new WaitForSeconds(1f);
        //todo: switch statement of the selected goal option

        ResetStartValues();

        switch (playerInteraction_UI.goalOverlay.userInput)
        {
        case PlayerInteraction_UI.Goal_UIOverlay.UserInputs.exit:
        case PlayerInteraction_UI.Goal_UIOverlay.UserInputs.levels:
            TriggerPlayPhaseEnd();
            EndSimulation();
            break;

        case PlayerInteraction_UI.Goal_UIOverlay.UserInputs.replay:

            interactionPhase = InteractionPhases.ingame_default;
            GameManager.Instance.TriggerLevelSimulation(LinkJava.SimulationFeedback.none);

            break;

        default:
            GameManager.Instance.TriggerLoadLevel();
            EndSimulation();
            break;
        }
    }
    public void PlayerInteractionListener()
    {
        switch (interactionPhase)
        {
        case InteractionPhases.ingame_default:
            if (playerInteraction_UI.IsSubPanelOpen())
            {
                return;
            }

            /*
             * if player LEFT clicks during basic play, they can
             * (1) Click and drag movable elements
             */
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                if (GameManager.Instance.GetGridManager().IsEditableElement(Input.mousePosition))
                {
                    currentGridObject = GameManager.Instance.GetGridManager().RetrieveEditableGridObject(Input.mousePosition);
                    currentGridObject.BeginDrag();
                    interactionPhase = InteractionPhases.ingame_dragging;
                    GameManager.Instance.tracker.CreateEventExt("BeginReposition", currentGridObject.component.type);

                    if (currentGridObject.component.type == "signal" && connectVisibilityLock)
                    {
                        Signal_GridObjectBehavior s = (Signal_GridObjectBehavior)currentGridObject;
                        s.SetHighlight(false);
                    }
                }
                if (hoverObject)
                {
                    if (!connectVisibility)
                    {
                        hoverObject.EndHoverBehavior();
                    }
                    hoverObject = null;
                }
            }

            /*
             * if player RIGHT clicks during basic play, they can:
             * (1) link connectable elements through Signals
             * (2) Open/Close Semaphores
             */
            else if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                if (GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "signal") /*&& GameManager.Instance.GetGridManager().IsEditableElement( Input.mousePosition )*/)
                {
                    currentGridObject = GameManager.Instance.GetGridManager().RetrieveGridObjectOfType(Input.mousePosition, "signal");
                    currentGridObject.EnableGridObjectEventBehaviors(GridObjectBehavior.InteractTypes.rightClick);
                    interactionPhase = InteractionPhases.ingame_connecting;
                    currentGridObject.BeginInteraction();

                    List <GridObjectBehavior> otherSignals = GameManager.Instance.GetGridManager().GetGridComponentsOfType(new List <string>()
                    {
                        "signal"
                    });
                    foreach (GridObjectBehavior otherSignal in otherSignals)
                    {
                        if (currentGridObject != otherSignal)
                        {
                            otherSignal.GetComponent <SpriteRenderer>().sortingOrder = Constants.ComponentSortingOrder.connectionOverlay - 1;
                        }
                    }

                    GameManager.Instance.tracker.CreateEventExt("BeginLink", currentGridObject.component.type);

                    playerInteraction_UI.onHoverLightbox.OpenPanel();
                }
                else if (GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "semaphore") && GameManager.Instance.GetGridManager().IsEditableElement(Input.mousePosition))
                {
                    currentGridObject = GameManager.Instance.GetGridManager().RetrieveGridObjectOfType(Input.mousePosition, "semaphore");
                    currentGridObject.EnableGridObjectEventBehaviors(GridObjectBehavior.InteractTypes.rightClick);
                    currentGridObject.BeginInteraction();
                    GameManager.Instance.tracker.CreateEventExt("BeginLink", currentGridObject.component.type);
                }

                if (hoverObject /*&& !connectVisibilityLock*/)
                {
                    hoverObject.EndHoverBehavior();
                    hoverObject = null;
                }
            }

            /*
             * if a player isn't clicking the mouse, we should check for hover behaviors
             */
            else
            {
                if (Input.mousePosition == stationaryMousePosition)                         //if mouse is stationary
                {
                    if (hoverObject == null)
                    {
                        stationaryTime += Time.deltaTime;
                        if (stationaryTime >= 0.2f)
                        {
                            if (
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "signal") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "diverter") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "exchange") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "delivery") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "pickup") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "conditional") ||
                                GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "semaphore")
                                )
                            {
                                hoverObject = GameManager.Instance.GetGridManager().GetGridObjectByMousePosition(Input.mousePosition);
                                hoverObject.OnHoverBehavior();
                                GameManager.Instance.tracker.CreateEventExt("OnHoverBehavior", hoverObject.component.type);
                            }
                        }
                    }
                }
                else                         //if mouse has moved since last frame
                {
                    stationaryMousePosition = Input.mousePosition;
                    if (hoverObject)
                    {
                        if (GameManager.Instance.GetGridManager().IsOccupied(Input.mousePosition))
                        {
                            if (hoverObject != GameManager.Instance.GetGridManager().GetGridObjectByMousePosition(Input.mousePosition))
                            {
                                EndHoverEvent();
                            }
                        }
                        else
                        {
                            EndHoverEvent();
                        }
                    }
                    else
                    {
                        stationaryTime = 0f;
                    }

                    //pop up tooltip close check
                    if (playerInteraction_UI.tooltipOverlay.tooltipActive && Time.time - playerInteraction_UI.tooltipOverlay.openTime > 0.5f)
                    {
                        playerInteraction_UI.tooltipOverlay.ClosePanel();
                    }
                }
                stationaryMousePosition = Input.mousePosition;
                GridObjectBehavior hoverObject__ = GameManager.Instance.GetGridManager().GetGridObjectByMousePosition(Input.mousePosition);
                if (hoverObject__ != null && hoverObject__ != hoverObject_)
                {
                    hoverObject_ = hoverObject__;
                    if (hoverObject_.component != null)
                    {
                        GameManager.Instance.tracker.CreateEventExt("OnMouseComponent", hoverObject_.component.type.ToString() + "/" + hoverObject_.component.id.ToString());
                    }
                }
                if (hoverObject__ == null && hoverObject_ != null)
                {
                    GameManager.Instance.tracker.CreateEventExt("OutMouseComponent", hoverObject_.component.type.ToString() + "/" + hoverObject_.component.id.ToString());
                    hoverObject_ = null;
                }
            }
            break;

        case InteractionPhases.ingame_dragging:
            if (Input.GetKey(KeyCode.Mouse0))
            {
                if (currentGridObject != null)
                {
                    currentGridObject.ContinueDrag();
                    if (trashHover)
                    {
                    }
                    else
                    {
                    }
                }
                else
                {
                    interactionPhase = InteractionPhases.ingame_default;
                }
            }
            else
            {
                if (trashHover)
                {
                    GameManager.Instance.GetGridManager().ForgetGridElement(currentGridObject);
                    if (currentGridObject.component.configuration.link != null && currentGridObject.component.configuration.link > 0)
                    {
                        //	GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID( currentGridObject.component.configuration.link );
                        //	g.component.configuration.link = 0;
                    }
                    GameManager.Instance.tracker.CreateEventExt("Destroying", currentGridObject.component.type);
                    Destroy(currentGridObject.gameObject);
                    currentGridObject = null;
                    interactionPhase  = InteractionPhases.ingame_default;
                }
                else
                {
                    GameManager.Instance.tracker.CreateEventExt("EndReposition", currentGridObject.component.type);
                    currentGridObject.EndDrag();

                    if (currentGridObject.component.type == "signal" && connectVisibilityLock)
                    {
                        Signal_GridObjectBehavior s = (Signal_GridObjectBehavior)currentGridObject;
                        s.SetHighlight(true);
                    }

                    currentGridObject = null;
                    interactionPhase  = InteractionPhases.ingame_default;
                }
            }
            break;

        case InteractionPhases.ingame_connecting:

            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                currentGridObject.EndInteraction();
                if (GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "semaphore"))
                {
                    GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByMousePosition(Input.mousePosition);
                    currentGridObject.LinkTo(g);
                    GameManager.Instance.tracker.CreateEventExt("LinkTo", currentGridObject.component.type);
                }

                else if (GameManager.Instance.GetGridManager().IsObjectOfType(Input.mousePosition, "conditional"))
                {
                    GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByMousePosition(Input.mousePosition);
                    currentGridObject.LinkTo(g);
                    GameManager.Instance.tracker.CreateEventExt("LinkTo", currentGridObject.component.type);
                }

                playerInteraction_UI.onHoverLightbox.ClosePanel();

                List <GridObjectBehavior> otherSignals = GameManager.Instance.GetGridManager().GetGridComponentsOfType(new List <string>()
                {
                    "signal"
                });
                foreach (GridObjectBehavior otherSignal in otherSignals)
                {
                    if (currentGridObject != otherSignal)
                    {
                        otherSignal.GetComponent <SpriteRenderer>().sortingOrder = Constants.ComponentSortingOrder.connectionComponents;
                    }
                    if (connectVisibilityLock)
                    {
                        otherSignal.SetHighlight(true);
                    }
                }


                interactionPhase = InteractionPhases.ingame_default;
            }
            else
            {
                currentGridObject.ContinueInteraction();
            }
            break;

        case InteractionPhases.simulation:
            simulationTime += Time.deltaTime;
            break;
        }
    }
    public override void DoStep(StepData inputStep)
    {
        if (behaviorType == BehaviorTypes.component && component != null)
        {
            switch (component.type.ToLower())
            {
            case "thread":
                if (inputStep.eventType == "M")
                {
                    Vector2 reverseYposition = new Vector2(inputStep.componentPos.x, GameManager.Instance.GetLevelHeight() - inputStep.componentPos.y);
                    float   travelTime       = 0.5f;

                    if (inputStep.GetNextStep() != -1)
                    {
                        StepData nextStep = GameManager.Instance.GetDataManager().currentLevelData.execution[inputStep.GetNextStep()];
                        reverseYposition = new Vector2(nextStep.componentPos.x, GameManager.Instance.GetLevelHeight() - nextStep.componentPos.y);
                        //travelTime = inputStep.componentStatus.speed;
                    }

                    iTween.MoveTo(gameObject, iTween.Hash("x", reverseYposition.x, "y", reverseYposition.y, "time", .5f, "easetype", iTween.EaseType.linear));

                    Vector2 difference = lastSimulationPosition - reverseYposition;

                    Quaternion targetRotation = new Quaternion();
                    if (difference.x > 0)
                    {
                        targetRotation = Quaternion.Euler(0f, 0f, 180f);
                    }
                    else if (difference.x < 0)
                    {
                        targetRotation = Quaternion.Euler(0f, 0f, 0f);
                    }
                    else if (difference.y > 0)
                    {
                        targetRotation = Quaternion.Euler(0f, 0f, -90f);
                    }
                    else if (difference.y < 0)
                    {
                        targetRotation = Quaternion.Euler(0f, 0f, 90f);
                    }
                    if (difference.x == 0 && difference.y == 0)
                    {
                    }
                    else
                    {
                        iTween.RotateTo(gameObject, targetRotation.eulerAngles, .5f);
                    }
                    lastSimulationPosition = reverseYposition;
                }

                else if (inputStep.eventType == "E")
                {
                    if (inputStep.componentStatus != null)
                    {
                        if (inputStep.componentStatus.passed != 0)
                        {
                            //passed is returned in increments for Thread E steps.  What is this for?
                        }
                        else if (inputStep.componentStatus.payload != null)
                        {
                            if (inputStep.componentStatus.payload.Length == 0)
                            {
                                Debug.Log("I am " + component.id + " and For step: " + inputStep.timeStep + " and for object " + inputStep.componentID + " I shall clear mine cabooses.");
                                Debug.Log(JsonUtility.ToJson(inputStep).ToString());
                                ClearCabooses();
                            }
                            else
                            {
                                List <int> currentCabooses = new List <int>();
                                currentCabooses.AddRange(inputStep.componentStatus.payload);

                                List <int> newCabooses = new List <int>();
                                newCabooses.AddRange(inputStep.componentStatus.payload);

                                List <GameObject> popCabooses = new List <GameObject>();

                                /* figure out what cabooses to add to current */
                                foreach (GameObject g in trailObjectList)
                                {
                                    int currentId = g.GetComponent <CabooseObject>().packageOriginID;

                                    if (newCabooses.Contains(currentId))
                                    {
                                        newCabooses.Remove(currentId);
                                    }
                                    if (!currentCabooses.Contains(currentId))
                                    {
                                        popCabooses.Add(g);
                                    }
                                }

                                /* figure out what cabooses to remove from current */
                                for (int p = popCabooses.Count - 1; p >= 0; p--)
                                {
                                    CabooseObject caboose = popCabooses[p].GetComponent <CabooseObject>();
                                    caboose.Disconnect();
                                    trailObjectList.Remove(popCabooses[p]);
                                    Destroy(popCabooses[p]);
                                }

                                foreach (int payloadId in newCabooses)
                                {
                                    GridObjectBehavior payloadObject = GameManager.Instance.GetGridManager().GetGridObjectByID(payloadId);
                                    GameObject         g             = new GameObject();
                                    g.transform.position   = payloadObject.transform.position;
                                    g.transform.localScale = Vector3.zero;

                                    trailObjectList.Add(g);
                                    g.name = "payload_" + payloadId;
                                    g.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_tint_01");                                   //payloadObject.GetComponent<SpriteRenderer>().sprite;
                                    g.GetComponent <SpriteRenderer>().color  = GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color);

                                    GameObject gChild = new GameObject();
                                    switch (payloadObject.component.configuration.type)
                                    {
                                    case "Conditional":
                                    {
                                        gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_03");
                                    }
                                    break;

                                    case "Unconditional":
                                    {
                                        gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_02");
                                    }
                                    break;

                                    case "Limited":
                                    {
                                        gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_01");
                                    }
                                    break;

                                    case "Empty":
                                    {
                                    }
                                    break;
                                    }
                                    gChild.GetComponent <SpriteRenderer>().sortingOrder = Constants.ComponentSortingOrder.basicComponents + 1;
                                    gChild.transform.position = g.transform.position;
                                    gChild.transform.SetParent(g.transform);
                                    gChild.transform.localScale = Vector3.one;

                                    if (true /* item is in exchange */)
                                    {
                                        /* figure out where the exchange point is, spawn it there */
                                        g.AddComponent <CabooseObject>().BeginFollow(transform, (float)trailObjectList.Count, payloadId);
                                    }
                                    else
                                    {
                                        g.AddComponent <CabooseObject>().BeginFollow(transform, (float)trailObjectList.Count, payloadId);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (inputStep.eventType == "D")
                {
                    if (inputStep.componentStatus.exchange_between_b != 0)
                    {
                        Debug.Log("Moving from " + inputStep.componentStatus.exchange_between_a + " to " + inputStep.componentStatus.exchange_between_b);
                        Thread_GridObjectBehavior otherTrain = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentStatus.exchange_between_b) as Thread_GridObjectBehavior;

                        Vector3 fromPosition = transform.position;
                        Vector3 toPosition   = otherTrain.transform.position;

                        if (teleportTrail)
                        {
                            GameObject teleportInstance = (GameObject)Instantiate(teleportTrail, toPosition, Quaternion.identity);
                            iTween.MoveTo(teleportInstance, fromPosition, 2f);
                            Destroy(teleportInstance, 2.5f);
                        }
                    }

                    if (inputStep.componentStatus.delivered_to != 0)
                    {
                        Debug.Log("Should perform delivery for " + inputStep.componentID);
                        if (inputStep.componentStatus.delivered_items.Length > 0)
                        {
                            GridObjectBehavior deliverToObject = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentStatus.delivered_to);

                            /* Feedback for Cabooses */
                            foreach (int deliveryId in inputStep.componentStatus.delivered_items)
                            {
                                for (int i = trailObjectList.Count - 1; i >= 0; i--)
                                {
                                    CabooseObject caboose = trailObjectList[i].GetComponent <CabooseObject>();
                                    if (caboose.packageOriginID == deliveryId)
                                    {
                                        Debug.Log("Disconnecting caboose " + caboose.packageOriginID);
                                        caboose.Disconnect();
                                        if (inputStep.componentStatus.delivered_to != null && inputStep.componentStatus.delivered_to != 0)
                                        {
                                            iTween.MoveTo(caboose.gameObject, deliverToObject.transform.position, 1.5f);
                                        }
                                        iTween.ScaleTo(caboose.gameObject, Vector3.zero, 1.5f);
                                        Destroy(caboose.gameObject, 2f);
                                        trailObjectList.RemoveAt(i);
                                    }
                                }
                            }

                            /* Feedback for Delivery point */
                            if (
                                (inputStep.componentStatus.missed != null && inputStep.componentStatus.missed != 0) ||
                                (inputStep.componentStatus.missed_items != null && inputStep.componentStatus.missed_items.Length > 0)
                                )
                            {
                                deliverToObject.ErrorBehavior(Color.black);
                            }

                            else
                            {
                                deliverToObject.SuccessBehavior(GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color));
                                Delivery_GridObjectBehavior deliveryCast = deliverToObject as Delivery_GridObjectBehavior;
                                Debug.Log("INCREMENT " + deliverToObject.component.id + " BY " + inputStep.componentStatus.delivered_items.Length);
                                deliveryCast.deliveryPopup.IncrementNumerator(inputStep.componentStatus.delivered_items.Length);
                            }
                        }
                    }
                }
                break;
            }
        }
    }
Ejemplo n.º 18
0
    IEnumerator PlaySimulation(int maxStep)
    {
        int maxGoalsCompleted = 0;
        currentStep = 0;
        paused = false;
        playerInteraction.playerInteraction_UI.playbackSlider.value = 0;
        bool nextLevelButtonVisibility = false;
        while (currentStep <= maxStep)
        {
            if (paused != true)
            {
                if (stepDictionary.ContainsKey(currentStep))
                {
                    float waitTime = 0f;
                    int count = 0;
                    foreach (StepData step in stepDictionary[currentStep])
                    {
                        count++;
                        if (step.componentID == 0)
                        {
                            yield return new WaitForSeconds(0.5f);
                            if (step.componentStatus == null) continue;
                            if (step.componentStatus.goals_completed != null && step.componentStatus.final_condition != -1)
                            {
                                if (maxGoalsCompleted < step.componentStatus.goals_completed) { maxGoalsCompleted = step.componentStatus.goals_completed; }
                            }
                            if (step.componentStatus.final_condition != null && step.componentStatus.final_condition != -1)
                            {
                                playerInteraction.score.stepCount = maxStep;
                                string titleFormatString = "<size=18><b>{0}</b></size>\n";
                                string titleString = "";
                                string goalString = "";
                                string levelFileName = "";
                                if (GameManager.Instance.currentLevelReferenceObject != null) levelFileName = GameManager.Instance.currentLevelReferenceObject.file;

                                switch (step.componentStatus.final_condition)
                                {
                                    case 2:
                                    case 8:
                                    case 10:
                                        success = true;
                                        //if "test" versus "submit" change this text
                                        if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.ME)
                                        {
                                            titleString = "SUCCESSFUL SOLUTION";
                                            goalString += "\n• Congratulations! This solution will always work. Please proceed to the next level.";
                                            playerInteraction.score.completed = true;

                                            //get current score
                                            int currentScore = GameManager.Instance.GetScoreManager().GetCalculatedScore(playerInteraction.score);
                                            //update saved score
                                            GameManager.Instance.GetScoreManager().ScoreLevel(playerInteraction.score);
                                            int lvlScore = GameManager.Instance.GetScoreManager().GetCalculatedScore(playerInteraction.score.index);

                                            GameManager.Instance.currentLevelReferenceObject.completionRank = lvlScore;
                                            GameManager.Instance.GetDataManager().UpdateLevelRank(levelFileName, lvlScore);

                                            //use 'current' not 'best' score for the feedback
                                            playerInteraction.playerInteraction_UI.goalOverlay.SetFeedbackScore(currentScore);

                                            nextLevelButtonVisibility = true;
                                        }
                                        else if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.Play)
                                        {
                                            titleString = "TEST COMPLETE";
                                            goalString += "\n• This solution was successful this time. Submit to check if it's always successful.";
                                            playerInteraction.playerInteraction_UI.goalOverlay.SetFeedbackScore(-1);
                                        }
                                        break;
                                    default:
                                        success = false;
                                        //if "test" versus "submit" change this text
                                        if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.ME)
                                        {
                                            titleString = "UNSUCCESSFUL SOLUTION";
                                        }
                                        else if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.Play)
                                        {
                                            titleString = "TEST COMPLETE";
                                            playerInteraction.playerInteraction_UI.goalOverlay.SetFeedbackScore(-1);
                                        }

                                        goalString = "";
                                        if ((step.componentStatus.final_condition & 1) != 0)
                                        {
                                            goalString += "\n• Make sure arrows aren't blocked.";
                                        }
                                        if ((step.componentStatus.final_condition & 4) != 0)
                                        {
                                            goalString += "\n• This solution was unsuccessful.";
                                        }
                                        if ((step.componentStatus.final_condition & 16) != 0)
                                        {
                                            goalString += "\n• Make sure arrows can't deliver at the same time.";
                                        }
                                        if ((step.componentStatus.final_condition & 32) != 0)
                                        {
                                            goalString += "\n• Make sure all arrows can move.";
                                        }
                                        if ((step.componentStatus.final_condition & 64) != 0)
                                        {
                                            goalString += "\n• Make sure arrows don't get caught in an infinite loop.";
                                        }
                                        if ((step.componentStatus.final_condition & 512) != 0)
                                        {
                                            goalString += "\n• Wrong turn! Check the Flow Arrows on the right of the screen.";
                                        }
                                        List<string> errorFeedback = new List<string>();
                                        foreach (string errorKey in step.componentStatus.goal_descriptions)
                                        {
                                            string key = errorKey.Substring(0, 3);
                                            if (Constants.GoalFeedbackValues.GoalErrorFeedback.ContainsKey(key))
                                            {
                                                if (!errorFeedback.Contains(Constants.GoalFeedbackValues.GoalErrorFeedback[key]))
                                                    errorFeedback.Add(Constants.GoalFeedbackValues.GoalErrorFeedback[key]);
                                            }
                                        }
                                        foreach (string s in errorFeedback) goalString += ("• " + s + "\n");

                                        break;
                                }

                                if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.ME)
                                {
                                    playerInteraction.playerInteraction_UI.goalOverlay.levels.gameObject.SetActive(true);
                                }
                                else if (GameManager.Instance.GetCurrentSimulationType() == LinkJava.SimulationTypes.Play)
                                {
                                    playerInteraction.playerInteraction_UI.goalOverlay.levels.gameObject.SetActive(false);
                                }

                                yield return StartCoroutine(playerInteraction.playerInteraction_UI.TriggerGoalPopUp(titleString, goalString));
                            }
                        }
                        else
                        {
                            GridObjectBehavior g = GameManager.Instance.GetGridManager().GetGridObjectByID(step.componentID);
                            if (g != null)
                            {
                                if (g.timeStep == null)
                                    g.SetTimestep(timeSteps[currentStep]);
                                float time = g.DoStep(step, stepDictionary);
                                if (time > waitTime)
                                    waitTime = time;
                            }
                            else { Debug.Log("Could not find " + step.componentID); }
                        }

                        if (PlayerInteraction_GamePhaseBehavior.onSimulationStep != null)
                        {
                            PlayerInteraction_GamePhaseBehavior.onSimulationStep(step);
                            //PauseSimulation();
                            //UnpauseAfterDelay(5);
                        }
                    }
                    while (paused) yield return new WaitForSeconds(0.1f);
                    yield return new WaitForSeconds(waitTime);
                }
                currentStep++;
                playerInteraction.playerInteraction_UI.playbackSlider.value = currentStep;
                //Debug.Log(currentStep);
            }
            else
            {
                yield return new WaitForEndOfFrame();
            }
        }

        yield return StartCoroutine(FinishSimulation());
    }
Ejemplo n.º 19
0
    public void GenerateGrid(List <GridTrack> gridTracks, List <GridComponent> gridComponents)
    {
        /*
         * currentGridWidth = layoutList[0].Length;
         * currentGridHeight = layoutList.Count;
         */

        Vector3 averagePosition = new Vector3();

        //Debug.Log(gridTracks.Count + ", " + gridComponents.Count);

        foreach (GridTrack track in gridTracks)
        {
            Vector2 reversedYposition = track.position;
            reversedYposition.y = GameManager.Instance.GetLevelHeight() - reversedYposition.y;

            GameObject gridElementInstance = Instantiate(gridElementPrefab, reversedYposition, Quaternion.identity) as GameObject;

            SpriteRenderer     instanceSpriteRenderer = gridElementInstance.GetComponent <SpriteRenderer>();
            GridObjectBehavior behavior = gridElementInstance.GetComponent <GridObjectBehavior>();

            gridElementInstance.transform.SetParent(gridContainer);

            averagePosition += new Vector3(reversedYposition.x, reversedYposition.y, 0);

            gridElementInstance.name = track.type + "_track";

            behavior.behaviorType = GridObjectBehavior.BehaviorTypes.track;
            behavior.track        = track;

            switch (track.type)
            {
            case 'J':
                // Straight_00
                instanceSpriteRenderer.sprite = gridElementDictionary["straight_road"];
                gridElementInstance.transform.Rotate(0, 0, 90);

                break;

            case 'E':
                // Straight_01
                instanceSpriteRenderer.sprite = gridElementDictionary["straight_road"];
                break;

            case 'N':
                // ThreeWay_00
                instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"];
                gridElementInstance.transform.Rotate(0, 0, 90);
                break;

            case 'M':
                // ThreeWay_01
                instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"];
                gridElementInstance.transform.Rotate(0, 0, 180);
                break;

            case 'K':
                // ThreeWay_02
                instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"];
                gridElementInstance.transform.Rotate(0, 0, -90);
                break;

            case 'G':
                // ThreeWay_03
                instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"];
                break;

            case 'F':
                // Turn_00
                instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"];
                gridElementInstance.transform.Rotate(0, 0, 90);
                break;

            case 'C':
                // Turn_01
                instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"];

                break;

            case 'I':
                // Turn_02
                instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"];
                gridElementInstance.transform.Rotate(0, 0, 270);
                break;

            case 'L':
                // Turn_03
                instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"];
                gridElementInstance.transform.Rotate(0, 0, 180);
                break;

            case 'O':
                // FourWay
                instanceSpriteRenderer.sprite = gridElementDictionary["fourway_road"];
                gridElementInstance.transform.Rotate(0, 0, 180);
                break;

            /*A - EAST DEAD
             * B - NORTH DEAD
             * D - WEST DEAD
             * H - SOUTH DEAD*/

            ///* TODO: Enable Dead ends
            case 'A':
                instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"];
                gridElementInstance.transform.Rotate(0, 0, 90);
                break;

            case 'B':
                instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"];
                //gridElementInstance.transform.Rotate(0,0,180);
                break;

            case 'D':
                instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"];
                gridElementInstance.transform.Rotate(0, 0, -90);
                break;

            case 'H':
                instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"];
                gridElementInstance.transform.Rotate(0, 0, 180);
                break;

            //*/
            default:
                instanceSpriteRenderer.sprite = null;
                break;
            }
            instanceSpriteRenderer.color = new Color(0.2f, 0.2f, 0.2f, 1f);
            currentLevelObjects.Add(behavior);
        }

        averagePosition = averagePosition / gridTracks.Count;
        worldCamera.transform.position = new Vector3(averagePosition.x, averagePosition.y, -15);
        float levelheight = GameManager.Instance.GetLevelHeight();
        float levelRatio  = GameManager.Instance.GetLevelWidth() / GameManager.Instance.GetLevelHeight();

        if (levelRatio > 1.78f)           // 16:9
        {
            Debug.Log("WIDER LEVEL " + levelRatio);
            levelheight *= (levelRatio / 1.78f);
            levelheight /= 0.9f;             // To make room for the right banner
        }
        else
        {
            levelheight += 1;
        }
        worldCamera.orthographicSize = (levelheight / 2.0f) / 0.78f;     // To make room for the bottom banner

        foreach (GridComponent gridComponent in gridComponents)
        {
            int    color     = gridComponent.configuration.color;
            int    positionX = gridComponent.posX;
            int    positionY = GameManager.Instance.GetLevelHeight() - gridComponent.posY;
            string type      = gridComponent.type;

            GameObject gridElementInstance = Instantiate(gridElementPrefab, new Vector3(positionX, positionY), Quaternion.identity) as GameObject;

            SpriteRenderer instanceSpriteRenderer = gridElementInstance.GetComponent <SpriteRenderer>();
            instanceSpriteRenderer.sortingOrder = Constants.ComponentSortingOrder.basicComponents;
            //instanceSpriteRenderer.color = colorDictionary[color];

            GridObjectBehavior behavior = gridElementInstance.GetComponent <GridObjectBehavior>();
            if (type == "signal")
            {
                Signal_GridObjectBehavior signal_Behavior = gridElementInstance.AddComponent <Signal_GridObjectBehavior>();
                signal_Behavior.highlightObject = behavior.highlightObject;
                signal_Behavior.lineRenderer    = gridElementInstance.GetComponentInChildren <LineRenderer>();
                signal_Behavior.teleportTrail   = behavior.teleportTrail;
                signal_Behavior.lockObject      = behavior.lockObject;
                Destroy(behavior);
                behavior = signal_Behavior;
            }
            else if (type == "thread")
            {
                Thread_GridObjectBehavior thread_Behavior = gridElementInstance.AddComponent <Thread_GridObjectBehavior>();
                thread_Behavior.highlightObject = behavior.highlightObject;
                thread_Behavior.teleportTrail   = behavior.teleportTrail;
                Destroy(behavior);
                behavior = thread_Behavior;
            }
            else if (type == "diverter")
            {
                Diverter_GridObjectBehavior diverter_Behavior = gridElementInstance.AddComponent <Diverter_GridObjectBehavior>();
                diverter_Behavior.highlightObject = behavior.highlightObject;
                diverter_Behavior.teleportTrail   = behavior.teleportTrail;
                Destroy(behavior);
                behavior = diverter_Behavior;
                gridElementInstance.layer = 8;
            }
            else if (type == "delivery")
            {
                Delivery_GridObjectBehavior delivery_Behavior = gridElementInstance.AddComponent <Delivery_GridObjectBehavior>();
                delivery_Behavior.highlightObject = behavior.highlightObject;
                delivery_Behavior.teleportTrail   = behavior.teleportTrail;
                Destroy(behavior);
                behavior = delivery_Behavior;
            }

            gridElementInstance.transform.SetParent(gridContainer);

            gridElementInstance.name = type;
            behavior.behaviorType    = GridObjectBehavior.BehaviorTypes.component;
            behavior.component       = gridComponent;

            instanceSpriteRenderer.sprite = GetSprite(gridComponent);

            currentLevelObjects.Add(behavior);
            gridObjectLevelIDDictionary.Add(gridComponent.id, behavior);
            gridObjectLevelPositionDictionary.Add(behavior.transform.position, behavior);

            behavior.InitializeGridComponentBehavior();
        }
    }
Ejemplo n.º 20
0
    public override float DoStep(StepData inputStep, Dictionary <int, List <StepData> > dictionary = null)
    {
        foreach (GameObject g in trailObjectList)
        {
            CabooseObject caboose = g.GetComponent <CabooseObject>();
            if (caboose != null)
            {
                caboose.UpdateFollow(false);
            }
        }
        while (timeStep.timeStep != inputStep.timeStep)
        {
            if (timeStep.timeStep > inputStep.timeStep)
            {
                timeStep = timeStep.previousStep;
            }
            else
            {
                timeStep = timeStep.nextStep;
            }
        }
        if (behaviorType == BehaviorTypes.component && component != null)
        {
            if (inputStep.eventType == "M")
            {
                Vector2 reverseYposition = new Vector2(inputStep.componentPos.x, GameManager.Instance.GetLevelHeight() - inputStep.componentPos.y);

                /*if (inputStep.GetNextMove(dictionary) != null)
                 * {
                 *  StepData nextStep = inputStep.GetNextMove(dictionary);
                 *  reverseYposition = new Vector2(nextStep.componentPos.x, GameManager.Instance.GetLevelHeight() - nextStep.componentPos.y);
                 * }*/

                float xDiff      = Mathf.Abs(Vector2.Distance(new Vector2(gameObject.transform.position.x, 0), new Vector2(reverseYposition.x, 0)));
                float yDiff      = Mathf.Abs(Vector2.Distance(new Vector2(0, gameObject.transform.position.y), new Vector2(0, reverseYposition.y)));
                float travelTime = (xDiff + yDiff) * 0.25f;
                iTween.MoveTo(gameObject, iTween.Hash("x", reverseYposition.x, "y", reverseYposition.y, "time", travelTime, "easetype", iTween.EaseType.linear));

                Vector2    difference     = lastSimulationPosition - reverseYposition;
                Quaternion targetRotation = new Quaternion();
                if (difference.x > 0)
                {
                    targetRotation = Quaternion.Euler(0f, 0f, 180f);
                }
                else if (difference.x < 0)
                {
                    targetRotation = Quaternion.Euler(0f, 0f, 0f);
                }
                else if (difference.y > 0)
                {
                    targetRotation = Quaternion.Euler(0f, 0f, -90f);
                }
                else if (difference.y < 0)
                {
                    targetRotation = Quaternion.Euler(0f, 0f, 90f);
                }
                if (difference.x == 0 && difference.y == 0)
                {
                }
                else
                {
                    iTween.RotateTo(gameObject, targetRotation.eulerAngles, .5f);
                }
                lastSimulationPosition = reverseYposition;
                return(travelTime);
            }
            else if (inputStep.eventType == "E")
            {
                if (inputStep.componentStatus != null)
                {
                    if (inputStep.componentStatus.passed != 0)
                    {
                        //passed is returned in increments for Thread E steps.  What is this for?
                    }
                    else if (inputStep.componentStatus.payload != null)
                    {
                        if (inputStep.componentStatus.payload.Length == 0)
                        {
                            // Moved swapping logic
                        }
                        else
                        {
                            UpdateCabooses(inputStep.componentStatus.payload, false);
                        }
                    }
                }
            }
            else if (inputStep.eventType == "D")
            {
                if (inputStep.componentStatus.exchange_between_b != 0)
                {
                    SwapTrails(inputStep.componentStatus.exchange_between_b);
                }

                if (inputStep.componentStatus.delivered_to != 0)
                {
                    //Debug.Log("Delivery Attempt");
                    //Debug.Log("Should perform delivery for " + inputStep.componentID);
                    GridObjectBehavior deliverToObject = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentStatus.delivered_to);

                    if (inputStep.componentStatus.delivered_items.Length > 0)
                    {
                        /* Feedback for Cabooses */
                        foreach (int deliveryId in inputStep.componentStatus.delivered_items)
                        {
                            for (int i = trailObjectList.Count - 1; i >= 0; i--)
                            {
                                CabooseObject caboose = trailObjectList[i].GetComponent <CabooseObject>();
                                if (caboose.packageOriginID == deliveryId)
                                {
                                    //Debug.Log("Disconnecting caboose " + caboose.packageOriginID );
                                    caboose.Disconnect();
                                    if (inputStep.componentStatus.delivered_to != null && inputStep.componentStatus.delivered_to != 0)
                                    {
                                        iTween.MoveTo(caboose.gameObject, deliverToObject.transform.position, 1.5f);
                                    }
                                    iTween.ScaleTo(caboose.gameObject, Vector3.zero, 1.5f);
                                    Destroy(caboose.gameObject, 2f);
                                    trailObjectList.RemoveAt(i);
                                }
                            }
                        }

                        /* Feedback for Delivery point */
                        if (
                            (inputStep.componentStatus.missed != null && inputStep.componentStatus.missed != 0) ||
                            (inputStep.componentStatus.missed_items != null && inputStep.componentStatus.missed_items.Length > 0)
                            )
                        {
                            deliverToObject.ErrorBehavior(Color.black);
                        }

                        else
                        {
                            deliverToObject.SuccessBehavior(GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color));
                            Delivery_GridObjectBehavior deliveryCast = deliverToObject as Delivery_GridObjectBehavior;
                            Debug.Log("INCREMENT " + deliverToObject.component.id + " BY " + inputStep.componentStatus.delivered_items.Length);
                            deliveryCast.deliveryPopup.IncrementNumerator(inputStep.componentStatus.delivered_items.Length);
                        }
                    }
                    else if (inputStep.componentStatus.missed_items.Length > 0)
                    {
                        deliverToObject.ErrorBehavior(Color.black);
                    }
                }
            }
            else if (inputStep.eventType == "F")
            {
                GridObjectBehavior failed = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentID);
                failed.ErrorBehavior(Color.black);
            }
        }
        return(0);
    }
Ejemplo n.º 21
0
    public void PlaceGridElementAtLocation(Vector2 inputPosition, PlayerInteraction_GamePhaseBehavior.MenuOptions inputGridElement)
    {
        Vector3 testPosition = worldCamera.ScreenToWorldPoint(inputPosition);

        testPosition.z = 0;
        testPosition.x = Mathf.RoundToInt(testPosition.x);
        testPosition.y = Mathf.RoundToInt(testPosition.y);


        GridComponent c = new GridComponent();

        c.configuration = new Configuration();

        string type = "package_exchangepoint_00";

        switch (inputGridElement)
        {
        case PlayerInteraction_GamePhaseBehavior.MenuOptions.semaphore:
            type = "semaphore";
            break;

        case PlayerInteraction_GamePhaseBehavior.MenuOptions.button:
            type = "signal";
            break;
        }

        c.editable = "E";
        c.placedBy = "P";

        playerPlacedElementCount++;
        c.id = 9000 + playerPlacedElementCount;

        c.posX = (int)testPosition.x;
        c.posY = (int)testPosition.y;
        c.type = type;        //inputGridElement.ToString();
        c.configuration.link = -1;

        GameObject     gridElementInstance    = Instantiate(gridElementPrefab, testPosition, Quaternion.identity) as GameObject;
        SpriteRenderer instanceSpriteRenderer = gridElementInstance.GetComponent <SpriteRenderer>();

        instanceSpriteRenderer.sortingOrder = Constants.ComponentSortingOrder.basicComponents;

        instanceSpriteRenderer.sprite = GetSprite(c);

        gridElementInstance.transform.SetParent(gridContainer);

        //instanceSpriteRenderer.color = colorDictionary[color];
        GridObjectBehavior behavior = gridElementInstance.GetComponent <GridObjectBehavior>();

        if (type == "signal")
        {
            Signal_GridObjectBehavior signal_Behavior = gridElementInstance.AddComponent <Signal_GridObjectBehavior>();
            signal_Behavior.highlightObject = behavior.highlightObject;
            signal_Behavior.lineRenderer    = gridElementInstance.GetComponentInChildren <LineRenderer>();
            signal_Behavior.teleportTrail   = behavior.teleportTrail;
            Destroy(behavior);
            behavior = signal_Behavior;
        }

        behavior.component    = c;
        behavior.behaviorType = GridObjectBehavior.BehaviorTypes.component;

        Vector2 reverseYposition = new Vector2(c.posX, GameManager.Instance.GetLevelHeight() - c.posY);

        behavior.UpdateGridObjectPosition(reverseYposition);

        currentLevelObjects.Add(behavior);

        gridObjectLevelIDDictionary.Add(behavior.component.id, behavior);
        gridObjectLevelPositionDictionary.Add(behavior.transform.position, behavior);

        behavior.InitializeGridComponentBehavior();
    }