Ejemplo n.º 1
0
    public void applyScriptToPlayer()
    {
        foreach (GameObject go in playerGO)
        {
            ActionManipulator.resetScript(go.GetComponent <Script>());
            go.GetComponent <Script>().actions = ActionManipulator.ScriptContainerToActionList(scriptComposer);
            gameData.nbStep = ActionManipulator.getNbStep(go.GetComponent <Script>());
        }

        //Check if If actions are valid
        int nbStepToAdd = 0;

        foreach (GameObject scripted in controllableGO)
        {
            int nbStepPlayer = 0;
            ActionManipulator.invalidAllIf(scripted.GetComponent <Script>());
            Action nextIf = ActionManipulator.getCurrentIf(scripted);

            while (nextIf != null && !ActionManipulator.endOfScript(scripted))
            {
                //Check if ok
                bool    ifok = nextIf.ifNot;
                Vector2 vec  = new Vector2();
                switch (ActionManipulator.getDirection(scripted.GetComponent <Direction>().direction, nextIf.ifDirection))
                {
                case Direction.Dir.North:
                    vec = new Vector2(0, 1);
                    break;

                case Direction.Dir.South:
                    vec = new Vector2(0, -1);
                    break;

                case Direction.Dir.East:
                    vec = new Vector2(1, 0);
                    break;

                case Direction.Dir.West:
                    vec = new Vector2(-1, 0);
                    break;
                }

                switch (nextIf.ifEntityType)
                {
                case 0:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in wallGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i)
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;

                case 1:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in controllableGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i &&
                                go.tag == "Ennemy")
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;

                case 2:
                    for (int i = 1; i <= nextIf.range; i++)
                    {
                        foreach (GameObject go in controllableGO)
                        {
                            if (go.GetComponent <Position>().x == scripted.GetComponent <Position>().x + vec.x * i && go.GetComponent <Position>().z == scripted.GetComponent <Position>().z + vec.y * i &&
                                go.tag == "Player")
                            {
                                ifok = !nextIf.ifNot;
                            }
                        }
                    }
                    break;
                }

                if (ifok)
                {
                    nextIf.ifValid = true;
                    if (scripted.tag == "Player")
                    {
                        nbStepPlayer += ActionManipulator.getNbStep(nextIf, true);
                    }
                }
                else
                {
                    nextIf.currentAction = nextIf.actions.Count - 1;
                    ActionManipulator.incrementActionScript(scripted.GetComponent <Script>());
                }
                nextIf = ActionManipulator.getCurrentIf(scripted);
            }

            if (nbStepPlayer > nbStepToAdd)
            {
                nbStepToAdd = nbStepPlayer;
            }
        }
        gameData.nbStep += nbStepToAdd;

        if (gameData.nbStep > 0)
        {
            gameData.totalExecute++;
        }
    }