protected virtual void DestroyWall(BaseWall baseWall)
 {
     if (baseWall != null)
     {
         baseWall.Destroy();
     }
 }
        protected virtual void AddWall(BaseWall baseWall)
        {
            BaseCurrentMap.Board[baseWall.CellPositionX, baseWall.CellPositionY]          = baseWall;
            BaseCurrentMap.CollisionLayer[baseWall.CellPositionX, baseWall.CellPositionY] = true;

            _baseWallList.Add(baseWall);
        }
Example #3
0
    private void Awake()
    {
        for (int i = 0; i < _DEFAULT_POOL_SIZE; i++)
        {
            Generate();
        }

        _rectTransform = this.transform.GetComponent <RectTransform>();

        this.UpdateAsObservable()
        .Subscribe(_ =>
        {
            _elapsedTime += Time.deltaTime;
            if (_elapsedTime >= _GENERATE_INTERVAL)
            {
                _elapsedTime = 0;
                BaseWall obj = Search();
                if (obj == null)
                {
                    obj = Generate();
                }
                obj.gameObject.SetActive(true);
                obj.transform.localPosition = new Vector3(this.transform.localPosition.x, this.transform.localPosition.y - _rectTransform.sizeDelta.y / 2, this.transform.localPosition.z);
            }
        });
    }
        protected virtual void RemoveWall(BaseWall wall)
        {
            if (BaseCurrentMap.Board[wall.CellPosition.X, wall.CellPosition.Y] is BaseWall)
            {
                BaseCurrentMap.Board[wall.CellPosition.X, wall.CellPosition.Y] = null;
            }

            BaseCurrentMap.CollisionLayer[wall.CellPosition.X, wall.CellPosition.Y] = false;

            _baseWallList.Remove(wall);
        }
Example #5
0
    /// <summary>
    /// Checks line of sight to a target object or the "Player" based on a raycast to the target object. This raycast will not hit trigger colliders;
    /// </summary>
    /// <param name="actor"></param>
    /// <returns></returns>
    private void LookForActor(GameObject actor)
    {
        //TODO set up field of view
        RaycastHit hit;
        Vector3    direction = actor.transform.position - this.transform.position;
        Ray        sightLine = new Ray(this.transform.position, direction);

        //make sure if the player isn't seen, the flag is not true
        targetInSight = false;

        if (Physics.Raycast(sightLine, out hit))
        {
            //Raycasts to the player to check line of sight
            if (hit.collider.gameObject.transform.tag == "Player")
            {
                targetInSight = true;
                lastPlayerPos = actor.transform;
                enemyTarget   = EnemyTarget.Player;
            }

            //Raycasts to the player to check line of sight
            if (hit.collider.gameObject.transform.tag == "Survivor")
            {
                targetInSight = true;
                lastPlayerPos = actor.transform;
                enemyTarget   = EnemyTarget.Survivor;
            }
        }

        if (Physics.Raycast(sightLine, out hit, maxSightDistance, buildLayer, QueryTriggerInteraction.Collide))
        {
            //If the player can not be seen and a wall is in the way, target that wall

            enemyTarget       = EnemyTarget.Structure;
            targetInSight     = true;
            targetwall        = hit.collider.gameObject.GetComponent <BaseWall>();
            hasAttackPosition = true;
        }

        if (!targetInSight)
        {
            enemyTarget = EnemyTarget.None;
        }
    }
        // If we were building the foundation then change it to flooring - walls
        private static void FoundationCreate(Vector2 actualPosition, Vector2 actualSize)
        {
            List <BaseWall> newWalls = new List <BaseWall>();

            // Build the Top / Bottom wall
            for (int x = 0; x < actualSize.X; x++)
            {
                // Top Wall
                Tile topTile = WorldController.GetTileAt((int)actualPosition.X + x, (int)actualPosition.Y);
                if (topTile != null)
                {
                    if (topTile.GetInfrastructureItem() == null)
                    {
                        BaseWall wall = new BaseWall(topTile.position);
                        newWalls.Add(wall);
                        topTile.SetInfrastructureItem(wall);
                    }
                }

                // Bottom Wall
                Tile bottomTile = WorldController.GetTileAt((int)actualPosition.X + x, (int)actualPosition.Y + (int)actualSize.Y - 1);
                if (bottomTile != null)
                {
                    if (bottomTile.GetInfrastructureItem() == null)
                    {
                        BaseWall wall = new BaseWall(bottomTile.position);
                        newWalls.Add(wall);
                        bottomTile.SetInfrastructureItem(wall);
                    }
                }
            }

            // Build the Left / Right Wall
            for (int y = 0; y < actualSize.Y; y++)
            {
                // Left Wall
                Tile leftTile = WorldController.GetTileAt((int)actualPosition.X, (int)actualPosition.Y + y);
                if (leftTile != null)
                {
                    if (leftTile.GetInfrastructureItem() == null)
                    {
                        BaseWall wall = new BaseWall(leftTile.position);
                        newWalls.Add(wall);
                        leftTile.SetInfrastructureItem(wall);
                    }
                }

                // Right Wall
                Tile rightTile = WorldController.GetTileAt((int)actualPosition.X + (int)actualSize.X - 1, (int)actualPosition.Y + y);
                if (rightTile != null)
                {
                    if (rightTile.GetInfrastructureItem() == null)
                    {
                        BaseWall wall = new BaseWall(rightTile.position);
                        newWalls.Add(wall);
                        rightTile.SetInfrastructureItem(wall);
                    }
                }
            }

            // Build the floor
            for (int x = 1; x < actualSize.X - 1; x++)
            {
                for (int y = 1; y < actualSize.Y - 1; y++)
                {
                    Tile tile = WorldController.GetTileAt((int)actualPosition.X + x, (int)actualPosition.Y + y);
                    if (tile != null)
                    {
                        if (tile.GetGameplayItem() == null)
                        {
                            FlooringCheapConcrete flooring = new FlooringCheapConcrete(tile.position);
                        }
                    }
                }
            }

            // Set up the wall sprites
            foreach (Building wall in newWalls)
            {
                wall.SetSpritesCorrectly();
            }
        }