using SepCore.Definition; using SepCore.Entity; using SepCore.Event; using UnityEngine; using UnityGameFramework.Runtime; namespace SepCore.Battle { public readonly struct HarvestSettlementResult { public static readonly HarvestSettlementResult Empty = new(0, 0, 0); public int Income { get; } public int Growth { get; } public int NewHarvest { get; } public HarvestSettlementResult(int income, int growth, int newHarvest) { Income = income; Growth = growth; NewHarvest = newHarvest; } } public static class HarvestSettlementUtility { public const float HarvestCompoundRate = 0.05f; public const string HarvestModifierSource = "HarvestInterest"; public static HarvestSettlementResult Settle(Player player) { if (player == null || !player.Available) { return HarvestSettlementResult.Empty; } int currentHarvest = Mathf.FloorToInt(player.StatComponent.GetStatValue(StatType.Harvesting)); if (currentHarvest <= 0) { return HarvestSettlementResult.Empty; } // 1. 发放等额金币/材料 player.Coin += currentHarvest; // 2. 复合增长(利息):永久提升 5%(向上取整) int growth = Mathf.CeilToInt(currentHarvest * HarvestCompoundRate); if (growth > 0) { player.StatComponent.AddModifier( StatType.Harvesting, new StatModifier(growth, ModifierType.Flat, HarvestModifierSource)); } int newHarvest = Mathf.FloorToInt(player.StatComponent.GetStatValue(StatType.Harvesting)); // 3. 广播收获结算事件 GameEntry.Event.Fire(player, WaveHarvestSettlementEventArgs.Create(currentHarvest, growth, newHarvest)); return new HarvestSettlementResult(currentHarvest, growth, newHarvest); } } }