void Update() { if (!FeatureToggles.Get().woodcutters) { return; } if (Random.value < .01f) { var houseCount = _worldPlane.GetBlocksWithHouses().Count; if (houseCount < 3) { return; } var woodcutters = _worldPlane.GetBlocksWithWoodcutters().Count(); var woodcutterToHouseRatio = (float)Mathf.Max(woodcutters, 1) / (float)houseCount; if (woodcutterToHouseRatio > .1f) { return; } var greensAndVacantLot = _worldPlane .GetBlocksWithGreens() .SelectMany(block => { return(_worldPlane .GetNearbyVacantLots(block.GetGridPosition()) .Select(vacantLot => new Tuple <Block, Block>(block, vacantLot))); }) .OrderBy(_ => Random.value) .FirstOrDefault(); if (greensAndVacantLot != null) { SpawnWoodcutter(greensAndVacantLot); } } if (_hasUnfulfilledRequestToStoreWood) { _hasUnfulfilledRequestToStoreWood = false; SpawnStockpile(); } }
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); } } }