Пример #1
0
    public void RemoveEntity(int p_x, int p_z)
    {
        foreach (Script_IEntity entity in _entityList.ToList())
        {
            if (entity is Script_TradingPost)
            {
                int x = entity.GetGridPosition().x;
                int z = entity.GetGridPosition().z;

                if (x == p_x && z == p_z)
                {
                    _tradingPost = null;
                    _entityList.Remove(entity);
                    entity.Destruction();
                }
            }

            if (entity is Script_StarChaser)
            {
                int x = entity.GetGridPosition().x;
                int z = entity.GetGridPosition().z;

                if (x == p_x && z == p_z)
                {
                    _chaser = null;
                    _entityList.Remove(entity);
                    entity.Destruction();
                }
            }


            if (entity is Script_SpaceShip)
            {
                int x = entity.GetGridPosition().x;
                int z = entity.GetGridPosition().z;

                if (x == p_x && z == p_z)
                {
                    _spaceShip = null;
                    _entityList.Remove(entity);
                    entity.Destruction();
                }
            }


            if (entity is Script_FallenStar)
            {
                int x = entity.GetGridPosition().x;
                int z = entity.GetGridPosition().z;

                if (x == p_x && z == p_z)
                {
                    _fallenStar = null;
                    _entityList.Remove(entity);
                    entity.Destruction();
                }
            }
        }
    }
Пример #2
0
    void InstantiateEntityAtRandomLocation <T> () where T : Script_IEntity
    {
        //While this does not have a 100% chance of success, seeing as there is a very small chance of not having any walkable tiles,
        //and we could also be randoming at positions that aren't walkable until we've tried 64 times, i deem it enough.
        //if this fails, we will have to place them on our own.
        int randomWalkablePositionX = Random.Range(0, width);
        int randomWalkablePositionZ = Random.Range(0, height);
        int attemptsToSpawn         = 64;
        int currentAttempts         = 0;

        while (_grid.AccessGridTile(randomWalkablePositionX, randomWalkablePositionZ).GetWalkable() == false || currentAttempts < attemptsToSpawn)
        {
            randomWalkablePositionX = Random.Range(0, width);
            randomWalkablePositionZ = Random.Range(0, height);
            currentAttempts++;
        }

        if (_grid.AccessGridTile(randomWalkablePositionX, randomWalkablePositionZ).GetWalkable() == true)
        {
            Vector3Int spawnLocation = new Vector3Int(randomWalkablePositionX, 0, randomWalkablePositionZ);

            if (typeof(T) == typeof(Script_StarChaser))
            {
                _chaser = new Script_StarChaser(this, _grid, spawnLocation);
                _entityList.Add(_chaser as Script_IEntity);
            }
            if (typeof(T) == typeof(Script_TradingPost))
            {
                _tradingPost = new Script_TradingPost(this, _grid, spawnLocation);
                _entityList.Add(_tradingPost as Script_IEntity);
            }
            if (typeof(T) == typeof(Script_FallenStar))
            {
                _fallenStar = new Script_FallenStar(this, _grid, spawnLocation);
                _entityList.Add(_fallenStar as Script_IEntity);
            }
            if (typeof(T) == typeof(Script_SpaceShip))
            {
                _spaceShip = new Script_SpaceShip(this, _grid, spawnLocation);
                _entityList.Add(_spaceShip as Script_IEntity);
            }
        }
    }
Пример #3
0
    public void PlaceEntity <T> (int p_x, int p_z) where T : Script_IEntity
    {
        if (typeof(T) == typeof(Script_TradingPost))
        {
            bool alreadyExists = false;
            foreach (Script_IEntity entity in _entityList.ToList())
            {
                if (entity is Script_TradingPost)
                {
                    entity.Destruction();
                    _entityList.Remove(entity);
                    Vector3Int position = new Vector3Int(p_x, 0, p_z);
                    _tradingPost = new Script_TradingPost(this, _grid, position);
                    _entityList.Add(_tradingPost);
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists)
            {
                Vector3Int position = new Vector3Int(p_x, 0, p_z);
                _tradingPost = new Script_TradingPost(this, _grid, position);
                _entityList.Add(_tradingPost);
            }
        }

        if (typeof(T) == typeof(Script_StarChaser))
        {
            bool alreadyExists = false;
            foreach (Script_IEntity entity in _entityList.ToList())
            {
                if (entity is Script_StarChaser)
                {
                    entity.Destruction();
                    _entityList.Remove(entity);
                    Vector3Int position = new Vector3Int(p_x, 0, p_z);
                    _chaser = new Script_StarChaser(this, _grid, position);
                    _entityList.Add(_chaser);
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists)
            {
                Vector3Int position = new Vector3Int(p_x, 0, p_z);
                _chaser = new Script_StarChaser(this, _grid, position);
                _entityList.Add(_chaser);
            }
        }

        if (typeof(T) == typeof(Script_FallenStar))
        {
            bool alreadyExists = false;
            foreach (Script_IEntity entity in _entityList.ToList())
            {
                if (entity is Script_FallenStar)
                {
                    entity.Destruction();
                    _entityList.Remove(entity);
                    Vector3Int position = new Vector3Int(p_x, 0, p_z);
                    _fallenStar = new Script_FallenStar(this, _grid, position);
                    _entityList.Add(_fallenStar);
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists)
            {
                Vector3Int position = new Vector3Int(p_x, 0, p_z);
                _fallenStar = new Script_FallenStar(this, _grid, position);
                _entityList.Add(_fallenStar);
            }
        }

        if (typeof(T) == typeof(Script_SpaceShip))
        {
            bool alreadyExists = false;
            foreach (Script_IEntity entity in _entityList.ToList())
            {
                if (entity is Script_SpaceShip)
                {
                    entity.Destruction();
                    _entityList.Remove(entity);
                    Vector3Int position = new Vector3Int(p_x, 0, p_z);
                    _spaceShip = new Script_SpaceShip(this, _grid, position);
                    _entityList.Add(_spaceShip);
                    alreadyExists = true;
                    break;
                }
            }
            if (!alreadyExists)
            {
                Vector3Int position = new Vector3Int(p_x, 0, p_z);
                _spaceShip = new Script_SpaceShip(this, _grid, position);
                _entityList.Add(_spaceShip);
            }
        }
    }