Refactor game state management to use a unified Stat system and update UI labels for production and corruption
This commit is contained in:
@@ -6,7 +6,16 @@ public class GameLogic
|
||||
{
|
||||
public void UpdateGameState(GameState state, double delta)
|
||||
{
|
||||
state.Faith += state.FaithPerSecond * delta;
|
||||
var totalMultiplier = 1.0;
|
||||
foreach (var buff in state.ActiveBuffs)
|
||||
{
|
||||
totalMultiplier *= buff.Multiplier;
|
||||
}
|
||||
var faithPerSecond = state.Get(Stat.Followers) * state.Get(Stat.FaithPerFollower) * totalMultiplier;
|
||||
|
||||
state.Modify(Stat.Faith, faithPerSecond * delta);
|
||||
state.Modify(Stat.Production, state.Get(Stat.ProductionPerSecond) * delta);
|
||||
state.Modify(Stat.Corruption, state.Get(Stat.CorruptionPerSecond) * delta);
|
||||
|
||||
for (var i = state.ActiveBuffs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@@ -21,13 +30,13 @@ public class GameLogic
|
||||
|
||||
public bool TryToPerformMiracle(GameState state, MiracleDefinition miracle)
|
||||
{
|
||||
if (state.Faith < miracle.FaithCost || state.Followers < miracle.FollowersRequired)
|
||||
if (state.Get(Stat.Faith) < miracle.FaithCost || state.Get(Stat.Followers) < miracle.FollowersRequired)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
state.Faith -= miracle.FaithCost;
|
||||
|
||||
state.Modify(Stat.Faith, -miracle.FaithCost);
|
||||
|
||||
if (miracle.Effects != null)
|
||||
{
|
||||
foreach (var effect in miracle.Effects)
|
||||
@@ -35,9 +44,8 @@ public class GameLogic
|
||||
effect.Execute(state);
|
||||
}
|
||||
}
|
||||
|
||||
state.Corruption = Math.Clamp(state.Corruption, 0, 100);
|
||||
|
||||
|
||||
state.Set(Stat.Corruption, Math.Clamp(state.Get(Stat.Corruption), 0, 100));
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user