Implement miracle unlock management and update tooltip logic for MiracleButton
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using ParasiticGod.Scripts.Core;
|
||||
using ParasiticGod.Scripts.Core.Effects;
|
||||
using ParasiticGod.Scripts.Singletons;
|
||||
|
||||
namespace ParasiticGod.Scenes.Main;
|
||||
@@ -79,6 +80,11 @@ public partial class MiracleButton : Button
|
||||
{
|
||||
missingRequirements.Add($"Not enough Production ({state.Get(Stat.Production):F0} / {_miracle.ProductionRequired})");
|
||||
}
|
||||
|
||||
if (AreAllUnlocksAlreadyPresent(state))
|
||||
{
|
||||
missingRequirements.Add("Already unlocked subsequent powers.");
|
||||
}
|
||||
|
||||
if (missingRequirements.Any())
|
||||
{
|
||||
@@ -127,4 +133,16 @@ public partial class MiracleButton : Button
|
||||
}
|
||||
return tooltip.TrimEnd();
|
||||
}
|
||||
|
||||
private bool AreAllUnlocksAlreadyPresent(GameState state)
|
||||
{
|
||||
var unlockEffect = _miracle.Effects.OfType<UnlockMiracleEffect>().FirstOrDefault();
|
||||
|
||||
if (unlockEffect == null || unlockEffect.MiraclesToUnlock.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return unlockEffect.MiraclesToUnlock.All(state.IsMiracleUnlocked);
|
||||
}
|
||||
}
|
@@ -27,6 +27,7 @@ public partial class MiraclePanel : GridContainer
|
||||
{
|
||||
if (miracle.UnlockedByDefault)
|
||||
{
|
||||
GameBus.Instance.CurrentState.AddUnlockedMiracle(miracle.Id);
|
||||
AddButtonForMiracle(miracle);
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ namespace ParasiticGod.Scripts.Core;
|
||||
public class GameState
|
||||
{
|
||||
private readonly Dictionary<Stat, StatData> _stats = new();
|
||||
private readonly Dictionary<string, MiracleDefinition> _miraclesInHand = new();
|
||||
private readonly HashSet<string> _unlockedMiracleIds = [];
|
||||
|
||||
public List<Buff> ActiveBuffs { get; } = [];
|
||||
|
||||
@@ -36,5 +36,7 @@ public class GameState
|
||||
|
||||
public void Unsubscribe(Stat stat, Action<double> listener) => _stats[stat].OnChanged -= listener;
|
||||
|
||||
public Dictionary<string, MiracleDefinition> MiraclesInHand() => _miraclesInHand;
|
||||
public bool IsMiracleUnlocked(string miracleId) => _unlockedMiracleIds.Contains(miracleId);
|
||||
public void AddUnlockedMiracle(string miracleId) => _unlockedMiracleIds.Add(miracleId);
|
||||
public void RemoveUnlockedMiracle(string miracleId) => _unlockedMiracleIds.Remove(miracleId);
|
||||
}
|
@@ -63,18 +63,17 @@ public partial class GameBus : Node
|
||||
{
|
||||
foreach (var id in unlockEffect.MiraclesToUnlock)
|
||||
{
|
||||
if (AllMiracles.TryGetValue(id, out var def))
|
||||
if (AllMiracles.TryGetValue(id, out var def) && !_gameState.IsMiracleUnlocked(id))
|
||||
{
|
||||
if (miraclesToUnlock.Contains(def) || _gameState.MiraclesInHand().ContainsKey(id)) continue;
|
||||
miraclesToUnlock.Add(def);
|
||||
_gameState.MiraclesInHand().Add(id, def);
|
||||
_gameState.AddUnlockedMiracle(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (effect is DestroySelfEffect)
|
||||
{
|
||||
MiracleCompleted?.Invoke(miracle);
|
||||
_gameState.MiraclesInHand().Remove(miracle.Id);
|
||||
_gameState.RemoveUnlockedMiracle(miracle.Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user