Exemplo n.º 1
0
    public void MaybePopulate()
    {
        if (!_populated && Random.value < .01f)
        {
            var gridPosition = _block.GetGridPosition();
            var treesNearby  = _worldPlane.GetNearbyBlocksWithinRange(gridPosition, 10f)
                               .Count(block =>
            {
                if (!block.OccupiedByGreens())
                {
                    return(false);
                }

                var predatorSpawn = block.GetOccupantGreens().GetComponent <PredatorSpawn>();
                if (!predatorSpawn)
                {
                    return(false);
                }

                return(!predatorSpawn.IsPopulated());
            });

            if (treesNearby > 30)
            {
                Populate();
                _populated = true;
            }
        }
    }
Exemplo n.º 2
0
    private void Woodcut()
    {
        var nearbyTreeOrNull = _worldPlane.GetNearbyBlocksWithinRange(_block.GetGridPosition(), 2f)
                               .Where(block => block.OccupiedByGreens())
                               .OrderBy(_ => Random.value)
                               .FirstOrDefault();

        if (nearbyTreeOrNull != null)
        {
            PlayWoodcutterSound();
            StartCoroutine(DoSoon());
            _cityWoodcutters.RequestStorageSpace();

            IEnumerator DoSoon()
            {
                yield return(new WaitForSeconds(1.5f));

                if (nearbyTreeOrNull != null)
                {
                    nearbyTreeOrNull.GetOccupantGreens().Cut();

                    _cityWoodcutters.StoreWood();
                }
            }
        }
    }
Exemplo n.º 3
0
    public void ResurrectNearbyBlocks(Vector3 gridPosition)
    {
        var nearbyWaterBlocks = _worldPlane.GetNearbyBlocksWithinRange(gridPosition, 4f)
                                .Where(block => block.IsOutsideWater() || block.IsWater());

        foreach (var waterBlock in nearbyWaterBlocks)
        {
            waterBlock.GetComponent <FloodingWater>().Resurrect();
        }
    }
    private void TrySpawnShrineAtRandomGrassBlock()
    {
        _spawnShrine = false;

        _blocksWithGreens = _worldPlane
                            .GetBlocksWithGreens()
                            .ToList();

        var count = _blocksWithGreens.Count;

        if (count > 0)
        {
            var block = _blocksWithGreens[Random.Range(0, count)];

            var greensNearby = _worldPlane
                               .GetNearbyBlocksWithinRange(block.GetGridPosition(), 5)
                               .Count(otherBlock => otherBlock.OccupiedByGrownGreens());

            if (greensNearby > 60)
            {
                SpawnShrine(block);
            }
        }
    }
Exemplo n.º 5
0
    void Update()
    {
        if (!_started)
        {
            return;
        }

        if (_huntStarted)
        {
            if (_huntStep == 0)
            {
                var progress = Mathf.Clamp((Time.fixedTime - _huntStartedAt) / HuntLength, 0, 1.5f);
                transform.position = Vector3.Lerp(_startingPosition, _target.transform.position, progress);

                if (progress > 1f)
                {
                    _huntStep = 1;
                }
            }
            else if (_huntStep == 1)
            {
                _target.Kill();
                PlayEatingSoundSoon();

                _huntStep = 2;
            }
            else if (_huntStep == 2)
            {
                _cooldownStart = Time.fixedTime;
                _huntStep      = 3;
            }
            else if (_huntStep == 3)
            {
                if ((Time.fixedTime - _cooldownStart) > 5)
                {
                    _huntStarted = false;
                }
            }
        }
        else
        {
            _theta += .006f;

            var center = _homeTransform.transform.position;
            var x      = Mathf.Cos(_theta) * Radius + center.x;
            var z      = Mathf.Sin(_theta) * Radius + center.z;

            var yPosition = 1.2f - transform.localScale.y * .5f - .005f;
            var y         = yPosition;

            transform.position = new Vector3(x, y, z);

            if (Random.value < .01f)
            {
                var nearbyPersonTargets = _worldPlane
                                          .GetNearbyBlocksWithinRange(_block.GetGridPosition(), 5f)
                                          .Where(block =>
                {
                    if (!block.OccupiedByHouse())
                    {
                        return(false);
                    }

                    var house       = block.GetOccupantHouse();
                    var personSpawn = house.GetComponent <PersonSpawn>();
                    if (!personSpawn)
                    {
                        return(false);
                    }
                    if (personSpawn.GetPerson() == null)
                    {
                        return(false);
                    }

                    return(!personSpawn.GetPerson().Targeted());
                })
                                          .Select(block => block.GetOccupantHouse().GetComponent <PersonSpawn>().GetPerson())
                                          .ToList();

                if (nearbyPersonTargets.Any())
                {
                    var nearbyPerson = nearbyPersonTargets.First();
                    nearbyPerson.SetAsTargeted();
                    _target           = nearbyPerson;
                    _huntStartedAt    = Time.fixedTime;
                    _startingPosition = transform.position;
                    _huntStep         = 0;
                    _huntStarted      = true;
                }
            }
        }
    }