Esempio n. 1
0
 private void Start()
 {
     agent         = GetComponent <NavTileAgent>();
     currentHealth = maxHealth;
     if (agent.isLocalAgent)
     {
         GameController.Instance.AddControlableAgent(agent);
     }
 }
Esempio n. 2
0
    /// <summary>
    /// Moves the piece on the local.
    /// </summary>
    /// <returns><c>true</c>, if the piece was moved, <c>false</c> otherwise.</returns>
    /// <param name="fromXIndex">From X index.</param>
    /// <param name="fromZIndex">From Z index.</param>
    /// <param name="toXIndex">To X index.</param>
    /// <param name="toZIndex">To Z index.</param>
    public bool MovePieceLocal(int fromXIndex, int fromZIndex, int toXIndex, int toZIndex, bool pFromLocal)
    {
        NavTileAgent selectedAgent = LevelArray.currentLevelArray.GetAgentInCell(fromXIndex, fromZIndex);
        NavTileAgent agent         = LevelArray.currentLevelArray.GetAgentInCell(toXIndex, toZIndex);

        if (agent == null)
        {
            selectedAgent.MoveAgentToPos(toXIndex, toZIndex);
            if (pFromLocal)
            {
                if (selectedAgent.GetComponent <Tower>())
                {
                    TowerMoves.Instance.OneTowerMoved();
                }
                GameController.Instance.OnMoveableObjectMoved();
            }
            return(true);
        }
        else
        {
            if (agent.isLocalAgent == pFromLocal)
            {
                if (selectedAgent == agent)
                {
                    if (pFromLocal)
                    {
                        GameController.Instance.OnMoveableObjectMoved();
                    }
                }
                else
                {
                    Notification.Instance.ShowNotification("Prohibited move");
                }
                return(false);
            }
            else
            {
                selectedAgent.GetComponent <GridObjectBase>().AttackTarget(agent.GetComponent <GridObjectBase>());
                if (pFromLocal)
                {
                    if (selectedAgent.GetComponent <Tower>())
                    {
                        TowerMoves.Instance.OneTowerMoved();
                    }
                    GameController.Instance.OnMoveableObjectMoved();
                }
                return(true);
            }
        }
        return(false);
    }
Esempio n. 3
0
    public void setAsOccupied(float xPos, float zPos, NavTileAgent pAgent)
    {
        if (!isInPosRange(xPos, zPos))
        {
            Debug.LogError("Index not in range");
            return;
        }

        Debug.Log("Cell ID is " + GetXIndex(xPos) + "," + GetZIndex(zPos));

        if (levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent == null)
        {
            levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent = pAgent;
        }
    }
Esempio n. 4
0
    public void releaseAsOccupied(float xPos, float zPos, NavTileAgent pAgent)
    {
        if (!isInPosRange(xPos, zPos))
        {
            Debug.LogError("Index not in range");
            return;
        }

        if (levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent == pAgent)
        {
            levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent = null;
            return;
        }
        else
        {
            Debug.LogError("Object occupied by wrong agent, agent = " + levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent, levelMapArray[GetXIndex(xPos), GetZIndex(zPos)].occupiedAgent.gameObject);
        }
    }
    /// <summary>
    /// Shows the cubes for an agent movement.
    /// </summary>
    /// <param name="agent">Agent.</param>
    public void ShowCubesForAgentMovement(NavTileAgent agent)
    {
        enabled = true;
        //activate the deafult post for an agent, this will allow the user to cancel his movement
        int cellXIndex = LevelArray.currentLevelArray.GetXIndex(agent.transform.position.x);
        int cellZIndex = LevelArray.currentLevelArray.GetZIndex(agent.transform.position.z);

        LevelArray.currentLevelArray.setLightCubeForCell(cellXIndex, cellZIndex, moveLightParent.GetChild(currentMoveIndex).gameObject);
        currentMoveIndex++;

        if (agent.movementType == MovementType.PlusShaped || agent.movementType == MovementType.PlusAndXShaped)
        {
            ShowPlusCubesForAgent(agent);
        }

        if (agent.movementType == MovementType.XShaped || agent.movementType == MovementType.PlusAndXShaped)
        {
            ShowXCubesForAgent(agent);
        }
    }
Esempio n. 6
0
 public void OnMoveableObjectSelect(NavTileAgent agent)
 {
     selectedAgent = agent;
     GameController.Instance.ChangeGameState(this);
 }
Esempio n. 7
0
 public void RemoveControlableAgent(NavTileAgent agent)
 {
     controlableAgents.Remove(agent);
     CheckForLoss();
 }
Esempio n. 8
0
 public void AddControlableAgent(NavTileAgent agent)
 {
     controlableAgents.Add(agent);
 }
Esempio n. 9
0
 public void OnMoveableObjectSelect(NavTileAgent agent)
 {
     GetComponent <StatePlayerMoveObject>().OnMoveableObjectSelect(agent);
 }
Esempio n. 10
0
    private void ShowPlusCubesForObject(GridObjectBase gridObject)
    {
        int cellXIndex = LevelArray.currentLevelArray.GetXIndex(gridObject.transform.position.x);
        int cellZIndex = LevelArray.currentLevelArray.GetZIndex(gridObject.transform.position.z);

        int newCellXIndex;
        int newCellZIndex;

        int steps = gridObject.attackSteps;

        while (steps > 0)
        {
            newCellXIndex = cellXIndex + steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex - steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex + steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex - steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex);
                if (agent != null)
                {
                    if (agent.isLocalAgent == false)
                    {
                        LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject);
                        currentAttackIndex++;
                    }
                }
            }

            steps--;
        }
    }
Esempio n. 11
0
    private void ShowPlusCubesForAgent(NavTileAgent agent)
    {
        int cellXIndex = LevelArray.currentLevelArray.GetXIndex(agent.transform.position.x);
        int cellZIndex = LevelArray.currentLevelArray.GetZIndex(agent.transform.position.z);

        int newCellXIndex;
        int newCellZIndex;

        int steps = agent.AllowedSteps;

        while (steps > 0)
        {
            newCellXIndex = cellXIndex + steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                if (!LevelArray.currentLevelArray.IsCubeCellLighted(newCellXIndex, newCellZIndex))
                {
                    LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, moveLightParent.GetChild(currentMoveIndex).gameObject);
                    currentMoveIndex++;
                }
            }

            newCellXIndex = cellXIndex - steps;
            newCellZIndex = cellZIndex;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                if (!LevelArray.currentLevelArray.IsCubeCellLighted(newCellXIndex, newCellZIndex))
                {
                    LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, moveLightParent.GetChild(currentMoveIndex).gameObject);
                    currentMoveIndex++;
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex + steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                if (!LevelArray.currentLevelArray.IsCubeCellLighted(newCellXIndex, newCellZIndex))
                {
                    LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, moveLightParent.GetChild(currentMoveIndex).gameObject);
                    currentMoveIndex++;
                }
            }

            newCellXIndex = cellXIndex;
            newCellZIndex = cellZIndex - steps;

            if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex))
            {
                if (!LevelArray.currentLevelArray.IsCubeCellLighted(newCellXIndex, newCellZIndex))
                {
                    LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, moveLightParent.GetChild(currentMoveIndex).gameObject);
                    currentMoveIndex++;
                }
            }

            steps--;
        }
    }
Esempio n. 12
0
    public override void excuteState()
    {
        if (Input.GetMouseButtonDown(0))
        {
            touchStartPos  = Input.mousePosition;
            touchStartTime = Time.timeSinceLevelLoad;
        }
        if (Input.GetMouseButtonUp(0))
        {
            float timeDiffrence = Time.timeSinceLevelLoad - touchStartTime;
            //the time diffrence when we consider this a tap or swipe, otherwise do nothing
            const float TAP_SWIPE_MAX_TIME = 0.5f;
            //the max distance to consider this a tap
            const float MAX_TAP_DISTANCE = 3f;
            if (timeDiffrence <= TAP_SWIPE_MAX_TIME)
            {
                //if true, it's a tap
                if (Vector2.Distance(touchStartPos, Input.mousePosition) <= MAX_TAP_DISTANCE)
                {
                    LayerMask  gridsLayer = 1 << LayerMask.NameToLayer("BlueLightCube");
                    RaycastHit vHit       = new RaycastHit();
                    Ray        vRay       = gameCamera.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(vRay, out vHit, 1000, gridsLayer))
                    {
                        Debug.Log("OK " + vHit.collider.gameObject.name);
                        NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInPos(vHit.collider.transform.position.x, vHit.collider.transform.position.z);
                        if (agent == null)
                        {
                            Notification.Instance.ShowNotification("Selected cell is empty");
                            return;
                        }

                        if (!agent.isLocalAgent)
                        {
                            Notification.Instance.ShowNotification("You may only select objects deployed by you!");
                            return;
                        }

                        if (agent.GetComponent <GridObjectBase>().IsFrozen)
                        {
                            Notification.Instance.ShowNotification("Selection is frozen!");
                            return;
                        }


                        if (agent.GetComponent <Tower>())
                        {
                            if (!TowerMoves.Instance.IsTowerMoveAllowed)
                            {
                                Notification.Instance.ShowNotification("Not enough moves!");
                                return;
                            }
                        }

                        //raise the event that a moveable object have been selected
                        GameController.Instance.OnMoveableObjectSelect(agent);
                    }
                }
            }
        }
    }