Beispiel #1
0
    void SpawnDefenseDome()
    {
        PlayRandomEventSound();

        //Unique
        int             indexTile  = -1;
        List <HexIndex> randomList = TerrainGenerator.instance.grid.GetRandom();
        GameObject      tile;

        do
        {
            indexTile++;
        } while (HexIndex.Distance(HexIndex.origin, randomList[indexTile]) > 15); //TerrainGenerator.instance.currentRadius

        TerrainGenerator.instance.GetGameObject(randomList[indexTile], out tile);
        if (DataManager.instance.isMulti)
        {
            RpcSpawnDefenseDome(tile.transform.position);
        }
        else
        {
            GameObject dome;
            dome = Instantiate(defenseDome, tile.transform.position, Quaternion.identity);
            dome.transform.parent = transform;
        }

        //int nbrDome = Random.Range(0, 7);

        //int indexTile = -1;
        //List<HexIndex> randomList = TerrainGenerator.instance.grid.GetRandom();

        //for (int i = 0; i <= nbrDome; i++)
        //{
        //    GameObject tile;

        //    do
        //    {
        //        indexTile++;

        //    } while (HexIndex.Distance(HexIndex.origin, randomList[indexTile]) > 15); //TerrainGenerator.instance.currentRadius

        //    TerrainGenerator.instance.GetGameObject(randomList[indexTile], out tile);

        //    GameObject dome = Instantiate(giftDome, tile.transform.position, Quaternion.identity);
        //}
    }
Beispiel #2
0
    // Coroutine Trapped_Arrow (Spell2)
    IEnumerator CoroutineTA()
    {
        tile = null;

        Tile            playerTile;
        List <HexIndex> hexIndex = new List <HexIndex>();

        RaycastHit playerCurrentTile;
        RaycastHit hit;
        Ray        rayCurrentTile;
        Ray        ray;

        HexIndex origin     = HexIndex.origin;
        HexIndex currentPos = HexIndex.origin;

        TerrainGenerator terrain = TerrainGenerator.instance;

        GameObject go = Instantiate(trap);

        go.GetComponent <Trap>().archer = this;
        bool isValid = false;

        yield return(new WaitUntil(() =>
        {
            if (playWithGamepad)
            {
                rayCurrentTile = new Ray(transform.position + Vector3.up, Vector3.down);
                ray = new Ray(transform.position + Vector3.up + new Vector3(pc.direction.x, pc.direction.y, pc.direction.z) * rangeTrap, Vector3.down);
            }
            else
            {
                rayCurrentTile = new Ray(transform.position + Vector3.up, Vector3.down);
                ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }

            if (Physics.Raycast(rayCurrentTile, out playerCurrentTile, 10000, LayerMask.GetMask("Hexagon")))
            {
                playerTile = playerCurrentTile.collider.transform.parent.gameObject.GetComponent <Tile>();

                if (playerTile != null)
                {
                    terrain.GetHexIndex(playerTile.gameObject, out origin);
                }
            }

            if (Physics.Raycast(ray, out hit, 10000, LayerMask.GetMask("Hexagon")))
            {
                tile = hit.collider.transform.parent.gameObject.GetComponent <Tile>();

                if (tile != null)
                {
                    terrain.GetHexIndex(tile.gameObject, out currentPos);

                    isValid = false;

                    if (DataManager.instance.isMulti)
                    {
                        if (Vector3.Distance(Vector3.zero, go.transform.position) > 2.6f && Vector3.Distance(transform.position, go.transform.position) <= rangeTrap * 1.5f && (tile.Type == Tile.TileType.Empty || tile.Type == Tile.TileType.Liquid || tile.Type == Tile.TileType.SafeZone))
                        {
                            isValid = true;
                            go.SetActive(true);
                        }
                        else
                        {
                            go.SetActive(false);
                        }
                    }
                    else
                    {
                        if (HexIndex.Distance(HexIndex.origin, currentPos) > 1 && HexIndex.Distance(origin, currentPos) <= rangeTrap && (tile.Type == Tile.TileType.Empty || tile.Type == Tile.TileType.Liquid || tile.Type == Tile.TileType.SafeZone))
                        {
                            isValid = true;
                            go.SetActive(true);
                        }
                        else
                        {
                            go.SetActive(false);
                        }
                    }
                    Quaternion q = Quaternion.Euler(0.0f, 0.0f, 0.0f);
                    go.transform.position = hit.collider.transform.position;
                }
            }
            return TrapLaunched;
        }));

        if (isValid)
        {
            go.GetComponent <Trap>().tile               = tile;
            go.GetComponent <Trap>().placed             = true;
            go.GetComponent <CapsuleCollider>().enabled = true;

            if (DataManager.instance.isMulti)
            {
                CmdTrap(go, go.transform.position, go.transform.rotation);
                Destroy(go);
            }
            else
            {
                LocalTrap(go, go.transform.position, go.transform.rotation);
            }

            counterTrap--;
            nbTrapPlaced++;

            if (DataManager.instance.isMulti)
            {
                CmdPlaySound(1, 69, 1.0f, 0, 0, 0.0f, 0, false, AudioType.SFX);
            }
            else
            {
                SoundCharacter(1, 69, 1.0f, AudioType.SFX);
            }
        }
        else
        {
            Destroy(go);
        }
    }