Refactor game state management to use a unified Stat system and update UI labels for production and corruption

This commit is contained in:
2025-08-23 02:44:54 +02:00
parent 2998e4c02a
commit 18312671d7
23 changed files with 298 additions and 109 deletions

View File

@@ -6,24 +6,16 @@ namespace ParasiticGod.Scripts.Core.Effects;
[GlobalClass]
public partial class AddResourceEffect : Effect
{
[Export] public ResourceType TargetResource { get; set; }
[Export] public Stat TargetResource { get; set; }
[Export] public double Value { get; set; }
public override void Execute(GameState state)
{
switch (TargetResource)
{
case ResourceType.Faith:
state.Faith += Value;
break;
case ResourceType.Followers:
state.Followers += (long)Value;
break;
case ResourceType.Corruption:
state.Corruption += Value;
break;
default:
throw new ArgumentOutOfRangeException();
}
state.Modify(TargetResource, Value);
}
public override string ToString()
{
return $"Add {Value} to {TargetResource}";
}
}

View File

@@ -5,9 +5,7 @@ namespace ParasiticGod.Scripts.Core.Effects;
[GlobalClass]
public partial class ApplyBuffEffect : Effect
{
public enum BuffTarget { FaithGeneration }
[Export] public BuffTarget TargetStat { get; set; }
[Export] public Stat TargetStat { get; set; }
[Export] public float Multiplier { get; set; } = 2.0f;
[Export] public double Duration { get; set; } = 30.0;
@@ -21,4 +19,9 @@ public partial class ApplyBuffEffect : Effect
gameState.ActiveBuffs.Add(newBuff);
}
public override string ToString()
{
return $"Apply Buff: x{Multiplier} to {TargetStat} for {Duration} seconds";
}
}

View File

@@ -5,32 +5,21 @@ namespace ParasiticGod.Scripts.Core.Effects;
[GlobalClass]
public partial class ConvertResourceEffect : Effect
{
[Export] public ResourceType FromResource { get; set; }
[Export] public Stat FromResource { get; set; }
[Export] public double FromAmount { get; set; }
[Export] public ResourceType ToResource { get; set; }
[Export] public Stat ToResource { get; set; }
[Export] public double ToAmount { get; set; }
public override void Execute(GameState gameState)
{
double GetValue(ResourceType type) => type switch {
ResourceType.Faith => gameState.Faith,
ResourceType.Followers => gameState.Followers,
ResourceType.Corruption => gameState.Corruption,
_ => 0
};
if (!(gameState.Get(FromResource) >= FromAmount)) return;
void SetValue(ResourceType type, double value) {
switch(type) {
case ResourceType.Faith: gameState.Faith = value; break;
case ResourceType.Followers: gameState.Followers = (long)value; break;
case ResourceType.Corruption: gameState.Corruption = value; break;
}
}
if (GetValue(FromResource) >= FromAmount)
{
SetValue(FromResource, GetValue(FromResource) - FromAmount);
SetValue(ToResource, GetValue(ToResource) + ToAmount);
}
gameState.Set(FromResource, gameState.Get(FromResource) - FromAmount);
gameState.Set(ToResource, gameState.Get(ToResource) + ToAmount);
}
public override string ToString()
{
return $"Convert {FromAmount} {FromResource} to {ToAmount} {ToResource}";
}
}

View File

@@ -8,4 +8,9 @@ public partial class DestroySelfEffect : Effect
public override void Execute(GameState gameState)
{
}
public override string ToString()
{
return "";
}
}

View File

@@ -5,4 +5,9 @@ namespace ParasiticGod.Scripts.Core.Effects;
public abstract partial class Effect : Resource
{
public abstract void Execute(GameState gameState);
public override string ToString()
{
return GetType().Name.Replace("Effect", "");
}
}

View File

@@ -5,7 +5,6 @@ namespace ParasiticGod.Scripts.Core.Effects;
[GlobalClass]
public partial class ModifyStatEffect : Effect
{
public enum Stat { FaithPerFollower }
public enum Operation { Add, Multiply }
[Export] public Stat TargetStat { get; set; }
@@ -14,17 +13,26 @@ public partial class ModifyStatEffect : Effect
public override void Execute(GameState gameState)
{
if (TargetStat == Stat.FaithPerFollower)
switch (Op)
{
switch (Op)
{
case Operation.Add:
gameState.FaithPerFollower += Value;
break;
case Operation.Multiply:
gameState.FaithPerFollower *= Value;
break;
}
case Operation.Add:
var currentValue = gameState.Get(TargetStat);
gameState.Set(TargetStat, currentValue + Value);
break;
case Operation.Multiply:
var currentValueMul = gameState.Get(TargetStat);
gameState.Set(TargetStat, currentValueMul * Value);
break;
}
}
public override string ToString()
{
return Op switch
{
Operation.Add => $"Add {Value} to {TargetStat}",
Operation.Multiply => $"Multiply {TargetStat} by {Value}",
_ => "Unknown Operation"
};
}
}

View File

@@ -1,3 +0,0 @@
namespace ParasiticGod.Scripts.Core.Effects;
public enum ResourceType { Faith, Followers, Corruption }

View File

@@ -1 +0,0 @@
uid://do6aurfs8oif0

View File

@@ -13,4 +13,9 @@ public partial class UnlockMiracleEffect : Effect
{
}
public override string ToString()
{
return $"Unlock miracles: {string.Join(", ", MiraclesToUnlock)}";
}
}