From 0c6a21ba6a70482433220c7fd92473eac11878dd Mon Sep 17 00:00:00 2001 From: Adam Salah Date: Sun, 27 Jul 2025 16:46:54 -0400 Subject: [PATCH] fixed mill production boost with farms --- Assets/Scripts/Ally/Mill.cs | 2 +- Assets/Scripts/Ally/ProductionBuilding.cs | 47 +++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Assets/Scripts/Ally/Mill.cs b/Assets/Scripts/Ally/Mill.cs index 2eab4e0..16c70a6 100644 --- a/Assets/Scripts/Ally/Mill.cs +++ b/Assets/Scripts/Ally/Mill.cs @@ -2,5 +2,5 @@ public class Mill : ProductionBuilding { - protected override Enum.ResourceNodeType RessourceNodeType { get { return Enum.ResourceNodeType.BerryBush; } } + protected override Enum.ResourceNodeType RessourceNodeType { get { return Enum.ResourceNodeType.Farm; } } } \ No newline at end of file diff --git a/Assets/Scripts/Ally/ProductionBuilding.cs b/Assets/Scripts/Ally/ProductionBuilding.cs index d1dd136..fedee6f 100644 --- a/Assets/Scripts/Ally/ProductionBuilding.cs +++ b/Assets/Scripts/Ally/ProductionBuilding.cs @@ -1,4 +1,6 @@ -using UnityEngine; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; public abstract class ProductionBuilding : House { @@ -7,31 +9,24 @@ public abstract class ProductionBuilding : House [SerializeField] private float _multiplier; + private const float _pollNearbyTilesInterval = 1.0f; + public override float PopulationGiven => GlobalConfig.Instance.Current.populationGivenPerHouseUpgrade; protected abstract Enum.ResourceNodeType RessourceNodeType { get; } private Vector3 _position; + private List _tilesInRange = new List(); public override void Start() { base.Start(); _position = Position; - ApplyMultiplier(_multiplier); + + StartCoroutine(PollNearbyTiles()); } - public override void LevelStart() - { - base.LevelStart(); - } - - public override void LevelDestroy() + IEnumerator PollNearbyTiles() { ApplyMultiplier(1 / _multiplier); - base.LevelDestroy(); - } - - private void ApplyMultiplier(float multiplier) - { - int x = 0; for (int i = -_range; i <= _range; i++) { for (int j = -_range; j <= _range; j++) @@ -43,10 +38,28 @@ public abstract class ProductionBuilding : House var checkResourceType = tile.ResourceNodeType; if (checkResourceType != RessourceNodeType) continue; - tile.YieldSpeedMultiplier *= multiplier; - x++; + if (!_tilesInRange.Contains(tile)) + { + _tilesInRange.Add(tile); + } } } - Debug.Log(x); + ApplyMultiplier(_multiplier); + yield return new WaitForSeconds(_pollNearbyTilesInterval); + StartCoroutine(PollNearbyTiles()); + } + + public override void LevelDestroy() + { + ApplyMultiplier(1 / _multiplier); + base.LevelDestroy(); + } + + private void ApplyMultiplier(float multiplier) + { + foreach (var tile in _tilesInRange) + { + tile.YieldSpeedMultiplier *= multiplier; + } } } \ No newline at end of file