Пример #1
0
    // Update is called once per frame
    void Update()
    {
        bool firstRun = true;
        if (firstRun)
        {
            map = _TGMap.getMapData();
            firstRun = false;
        }

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hitInfo;

        if (_TGMap.GetComponent<Collider>().Raycast(ray, out hitInfo, Mathf.Infinity))
        {
            int x = Mathf.FloorToInt(hitInfo.point.x / _TGMap.tileSize);
            int z = Mathf.FloorToInt(hitInfo.point.z / _TGMap.tileSize);

            currentTileCoord.x = x;
            currentTileCoord.z = z;
            selectionCube.transform.position = currentTileCoord * _TGMap.tileSize;
        }
        else
        {

        }

        if (Input.GetMouseButtonDown(0))
        {
            occupy = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z);
            if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 1)
            {
                playerSelected = true;
                Debug.Log("Player Selected" + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z));
                playerSelectedCoord = new Vector3(currentTileCoord.x, 0, currentTileCoord.z);

            }
            else if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 0 && playerSelected == true)
            {
                playerSelected = false;
                Debug.Log("Player Moved New coord: " + map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z));
                Debug.Log("Player Moved Old coord: " + map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z));
                path = checkPath(map, map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z), 7);

                if (path != null)
                {
                    Debug.Log(path);
                    Debug.Log(path.path[0]);
                    moving = path.path.Count - 1;
                }

            }

        }
        if(Input.GetMouseButtonDown(1))
        {
            if (map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z).getOccupied() == 2)
            {
                opponent = map.getTile((int)currentTileCoord.x, (int)currentTileCoord.z);
                attacker = map.getTile((int)playerSelectedCoord.x, (int)playerSelectedCoord.z);
                float hitRoll = Random.Range(0, 10);
                float cover = 0;
                //cover calculations
                Debug.Log(opponent.x + "And" + attacker.x + "ys = " + opponent.y + "And " + attacker.y);
                Debug.Log("Neighbors: " + map.getTile(opponent.findNeighbors()[0]).getType() + ", " + map.getTile(opponent.findNeighbors()[1]).getType() + ", " + map.getTile(opponent.findNeighbors()[2]).getType() + ", " + map.getTile(opponent.findNeighbors()[3]).getType());
                //Left cover
                if ((opponent.x > attacker.x && map.getTile(opponent.findNeighbors()[1]).getType() == 3)&& !((Mathf.Abs(opponent.x-attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3))
                {
                    Debug.Log("Covered! Left");
                    cover = 2;
                }
                //Right Cover
                else if (opponent.x < attacker.x && map.getTile(opponent.findNeighbors()[2]).getType() == 3 && !((Mathf.Abs(opponent.x - attacker.x) == 1 && (map.getTile(attacker.findNeighbors()[0]).getType() == 3)) || map.getTile(attacker.findNeighbors()[3]).getType() == 3))
                {
                    Debug.Log("Covered! Right");
                    cover = 2;
                }
                //Down Cover
                else if (opponent.y > attacker.y && map.getTile(opponent.findNeighbors()[0]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3))
                {
                    Debug.Log("Covered! Down");
                    cover = 2;
                }
                //Up Cover
                else if (opponent.y < attacker.y && map.getTile(opponent.findNeighbors()[3]).getType() == 3 && !((Mathf.Abs(opponent.y - attacker.y) == 1 && (map.getTile(attacker.findNeighbors()[1]).getType() == 3)) || map.getTile(attacker.findNeighbors()[2]).getType() == 3))
                {
                    Debug.Log("Covered! Up");
                    cover = 2;
                }
                Debug.Log("Cover Bonus! " + cover);
                //hit
                Debug.Log("HitRoll = " + hitRoll);
                if((hitRoll - (cover * 3)) > 1) //90% base, -30 for half, -60 for fullcover
                {
                    opponent.getEnemy().setHealth(opponent.getEnemy().getHealth() - 3);
                    Debug.Log("Hit! Health: " + opponent.getEnemy().getHealth());
                }
                else
                {

                }
                if(opponent.getEnemy().getHealth() <= 0)
                {
                    opponent.setOccupied(0);
                }
                _TGMap.UpdateGraphics();

            }
        }
        if (moving >= 0)
        {
            TDTile next = (TDTile)path.getPath()[moving];
            Debug.Log(moving);
            occupy.removePlayer();
            map.setTile(next.position, 1, 1);
            map.setTile(occupy.position, 1, 0);
            occupy.switchPlayers(next);
            occupy = next;
            _TGMap.UpdateGraphics();
            moving -= 1;
        }
    }