diff --git a/Assets/Scripts/Logic/Data/GameOverview.cs b/Assets/Scripts/Logic/Data/GameOverview.cs index 85aa3eb5268be0549c1d220ccf11062fc9b1fb9c..4935513ebfdba2ae4a924550176629b32ad38ea8 100644 --- a/Assets/Scripts/Logic/Data/GameOverview.cs +++ b/Assets/Scripts/Logic/Data/GameOverview.cs @@ -4,7 +4,6 @@ using System.Linq; using Logic.Command; using Logic.Data.World; using Logic.Event; -using Logic.Event.Team; using Logic.Handler; using Logic.System; @@ -103,12 +102,6 @@ public class GameOverview : IGameOverview { } else { CurrentPhase = GamePhase.Prepare; TimeLeftFromPhase = float.PositiveInfinity; - foreach (GameTeam team in Teams) { - int oldMoney = team.Money; - team.GiveMoney(EconomyConfig.RoundBasePay - + team.PurchasedUnitCount * EconomyConfig.TotalUnitsPurchasedPay); - Events.Raise(new TeamMoneyUpdatedEvent(team, oldMoney)); - } } } else { throw new Exception($"Unexpected phase: {CurrentPhase}"); @@ -126,10 +119,11 @@ public class GameOverview : IGameOverview { private void RegisterSystems() { _systems.Add(new DestroyUnitSystem()); - _systems.Add(new TowerDamagesUnitSystem()); - _systems.Add(new UnitDamagesCastleSystem()); _systems.Add(new InvalidateCachesSystem()); + _systems.Add(new StartNextRoundSystem()); _systems.Add(new TeamStatisticsSystem()); + _systems.Add(new TowerDamagesUnitSystem()); + _systems.Add(new UnitDamagesCastleSystem()); foreach (BaseSystem system in _systems) system.RegisterListeners(Events); } diff --git a/Assets/Scripts/Logic/System/StartNextRoundSystem.cs b/Assets/Scripts/Logic/System/StartNextRoundSystem.cs new file mode 100644 index 0000000000000000000000000000000000000000..73f0f68b6df9966d8af348cf1ec59cb823cfb90f --- /dev/null +++ b/Assets/Scripts/Logic/System/StartNextRoundSystem.cs @@ -0,0 +1,26 @@ +ďťżusing Logic.Data; +using Logic.Event; + +namespace Logic.System { + +/// <summary> +/// System responsible for initializing the next round +/// (e.g. giving money to teams) when it starts. +/// </summary> +internal class StartNextRoundSystem : BaseSystem { + public override void RegisterListeners(EventDispatcher dispatcher) { + dispatcher.AddListener<PhaseAdvancedEvent>(OnNextRound); + } + + private void OnNextRound(PhaseAdvancedEvent e) { + IGameOverview overview = e.Overview; + if (e.OldPhase != GamePhase.Fight || overview.CurrentPhase != GamePhase.Prepare) return; + + foreach (GameTeam team in overview.Teams) { + team.GiveMoney(overview.EconomyConfig.RoundBasePay + + team.PurchasedUnitCount * overview.EconomyConfig.TotalUnitsPurchasedPay); + } + } +} + +} diff --git a/Assets/Scripts/Logic/System/StartNextRoundSystem.cs.meta b/Assets/Scripts/Logic/System/StartNextRoundSystem.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..5e061ca157bc8dee698a00633126863e41fa6e16 --- /dev/null +++ b/Assets/Scripts/Logic/System/StartNextRoundSystem.cs.meta @@ -0,0 +1,3 @@ +ďťżfileFormatVersion: 2 +guid: 7631717c1aec4f0f97ac2871aa320a4b +timeCreated: 1651487626 \ No newline at end of file