Пример #1
0
    public bool OccupiedNearby(CharacterMove tarMove, GameObject theEnemy, string direction)
    {
        bool canUse = true;
        for (int i = 0; i < gameController.enemiesList.Count; i++)
        {
            EnemyMove enemyMove = GameObject.Find(enemyAI.GetEnemyCurrentlyTakingTurn().name).GetComponent<EnemyMove>();
            if(theEnemy == gameController.enemiesList[i])
            {
                continue;
            }

            if (direction == "up")
            {
                if (tarMove.GetCurRow() - 1 == enemyMove.GetCurRow() && tarMove.GetCurCol() == enemyMove.GetCurCol())
                {
                    canUse = false;
                }
            }
            else if (direction == "down")
            {
                if (tarMove.GetCurRow() + 1 == enemyMove.GetCurRow() && tarMove.GetCurCol() == enemyMove.GetCurCol())
                {
                    canUse = false;
                }
            }
            else if (direction == "left")
            {
                if (tarMove.GetCurRow() == enemyMove.GetCurRow() && tarMove.GetCurCol() - 1 == enemyMove.GetCurCol())
                {
                    canUse = false;
                }
            }
            else if (direction == "right")
            {
                if (tarMove.GetCurRow() == enemyMove.GetCurRow() && tarMove.GetCurCol() + 1 == enemyMove.GetCurCol())
                {
                    canUse = false;
                }
            }
        }
        return canUse;
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        //if(cursorSelection.GetSelectedPlayerCharName() == gameObject.name)
        //{
        //    DebugAttMarPosList();
        //}
        //Debug.Log("calculateAttackRange: " + calculateAttackRange);
        if (gameController.GetDisplayTurnTextState() == false && gameController.GetPlayerTurnState() == true)
        {
            if (cursorSelection.GetSelectedPlayerCharName() == gameObject.name)
            {
                //Debug.Log(attMarkPosList.Count);
                if (calculateAttackRange == true)
                {
                    charStatus = GameObject.Find(cursorSelection.GetSelectedPlayerCharName()).GetComponent<CharacterStatus>();
                    charMove = GameObject.Find(cursorSelection.GetSelectedPlayerCharName()).GetComponent<CharacterMove>();
                    int attackRange = charStatus.GetAttackRange();

                    for (int i = 1; i <= attackRange; i++)
                    {
                        if (charMove.GetCurRow() - i >= 0)
                        {
                            Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() - i].column[charMove.GetCurCol()].transform.position, Quaternion.identity);
                            AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                            attMarPos.row = charMove.GetCurRow() - i;
                            attMarPos.col = charMove.GetCurCol();
                            attMarkPosList.Add(attMarPos);
                        }

                        if (charMove.GetCurRow() + i < grid.row.Length)
                        {
                            Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() + i].column[charMove.GetCurCol()].transform.position, Quaternion.identity);
                            AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                            attMarPos.row = charMove.GetCurRow() + i;
                            attMarPos.col = charMove.GetCurCol();
                            attMarkPosList.Add(attMarPos);
                        }

                        if (charMove.GetCurCol() - i >= 0)
                        {
                            Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow()].column[charMove.GetCurCol() - i].transform.position, Quaternion.identity);
                            AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                            attMarPos.row = charMove.GetCurRow();
                            attMarPos.col = charMove.GetCurCol() - i;
                            attMarkPosList.Add(attMarPos);
                        }

                        if (charMove.GetCurCol() + i < grid.row[charMove.GetCurRow()].column.Length)
                        {
                            Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow()].column[charMove.GetCurCol() + i].transform.position, Quaternion.identity);
                            AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                            attMarPos.row = charMove.GetCurRow();
                            attMarPos.col = charMove.GetCurCol() + i;
                            attMarkPosList.Add(attMarPos);
                        }
                    }

                    int counter = 1;
                    for (int j = 1; j <= attackRange; j++)
                    {
                        while (counter <= attackRange - j)
                        {
                            // Upper left
                            if (charMove.GetCurRow() - counter >= 0 && charMove.GetCurCol() - j > 0)
                            {
                                Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() - counter].column[charMove.GetCurCol() - j].transform.position, Quaternion.identity);
                                AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                                attMarPos.row = charMove.GetCurRow() - counter;
                                attMarPos.col = charMove.GetCurCol() - j;
                                attMarkPosList.Add(attMarPos);
                            }

                            // Lower Left
                            if (charMove.GetCurRow() + counter < grid.row.Length && charMove.GetCurCol() - j > 0)
                            {
                                Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() + counter].column[charMove.GetCurCol() - j].transform.position, Quaternion.identity);
                                AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                                attMarPos.row = charMove.GetCurRow() + counter;
                                attMarPos.col = charMove.GetCurCol() - j;
                                attMarkPosList.Add(attMarPos);
                            }

                            // Upper Right
                            if (charMove.GetCurRow() - counter >= 0 && charMove.GetCurCol() + j < grid.row[charMove.GetCurRow()].column.Length)
                            {
                                Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() - counter].column[charMove.GetCurCol() + j].transform.position, Quaternion.identity);
                                AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                                attMarPos.row = charMove.GetCurRow() - counter;
                                attMarPos.col = charMove.GetCurCol() + j;
                                attMarkPosList.Add(attMarPos);
                            }

                            // Lower Right
                            if (charMove.GetCurRow() + counter < grid.row.Length && charMove.GetCurCol() + j < grid.row[charMove.GetCurRow()].column.Length)
                            {
                                Instantiate(Resources.Load("AttackMarker"), grid.row[charMove.GetCurRow() + counter].column[charMove.GetCurCol() + j].transform.position, Quaternion.identity);
                                AttackMarkerPosition attMarPos = new AttackMarkerPosition();
                                attMarPos.row = charMove.GetCurRow() + counter;
                                attMarPos.col = charMove.GetCurCol() + j;
                                attMarkPosList.Add(attMarPos);
                            }

                            counter++;
                        }
                    }
                    calculateAttackRange = false;
                }
            }
        }
    }