refactor: enhance GameStateStore integration and improve skill management
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
using Godot;
|
||||
using Mr.BrickAdventures;
|
||||
using Mr.BrickAdventures.scripts.components;
|
||||
|
||||
namespace Mr.BrickAdventures.Autoloads;
|
||||
|
||||
public partial class ConsoleManager : Node
|
||||
{
|
||||
private GameStateStore Store => GameStateStore.Instance;
|
||||
private GameManager GameManager => GameManager.Instance;
|
||||
private AchievementManager AchievementManager => AchievementManager.Instance;
|
||||
private SkillManager _skillManager;
|
||||
@@ -18,114 +18,103 @@ public partial class ConsoleManager : Node
|
||||
|
||||
private void AddCoinsCommand(int amount)
|
||||
{
|
||||
GameManager.AddCoins(amount);
|
||||
if (Store == null) return;
|
||||
Store.Player.Coins += amount;
|
||||
EventBus.EmitCoinsChanged(Store.GetTotalCoins());
|
||||
}
|
||||
|
||||
private void SetCoinsCommand(int amount)
|
||||
{
|
||||
GameManager.SetCoins(amount);
|
||||
if (Store == null) return;
|
||||
Store.Player.Coins = Mathf.Max(0, amount);
|
||||
EventBus.EmitCoinsChanged(Store.GetTotalCoins());
|
||||
}
|
||||
|
||||
private void SetLivesCommand(int amount)
|
||||
{
|
||||
GameManager.SetLives(amount);
|
||||
if (Store == null) return;
|
||||
Store.Player.Lives = amount;
|
||||
EventBus.EmitLivesChanged(amount);
|
||||
}
|
||||
|
||||
private void AddLivesCommand(int amount)
|
||||
{
|
||||
GameManager.AddLives(amount);
|
||||
Store?.AddLives(amount);
|
||||
}
|
||||
|
||||
private void SetHealthCommand(float amount)
|
||||
{
|
||||
var playerHealthComponent = GameManager.Player.GetNode<HealthComponent>("HealthComponent");
|
||||
var playerHealthComponent = GameManager?.Player?.GetNode<HealthComponent>("HealthComponent");
|
||||
if (playerHealthComponent != null)
|
||||
{
|
||||
playerHealthComponent.Health = amount;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetSessionCommand()
|
||||
{
|
||||
GameManager.ResetCurrentSessionState();
|
||||
Store?.ResetSession();
|
||||
}
|
||||
|
||||
private void UnlockSkillCommand(string skillName)
|
||||
{
|
||||
if (!GetSkillManagement()) return;
|
||||
if (!EnsureSkillManagement()) return;
|
||||
|
||||
var skill = _skillManager.GetSkillByName(skillName);
|
||||
if (skill == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (skill == null) return;
|
||||
|
||||
GameManager.UnlockSkill(skill);
|
||||
Store?.UnlockSkillPermanently(skill);
|
||||
_skillManager.ActivateSkill(skill);
|
||||
_skillUnlockerComponent.EmitSignal(SkillUnlockerComponent.SignalName.SkillUnlocked, skill);
|
||||
}
|
||||
|
||||
private bool GetSkillManagement()
|
||||
{
|
||||
var player = GameManager.Player;
|
||||
if (player == null || !IsInstanceValid(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_skillUnlockerComponent ??= player.GetNode<SkillUnlockerComponent>("SkillUnlockerComponent");
|
||||
|
||||
if (_skillManager != null && _skillUnlockerComponent != null) return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private void UnlockAllSkillsCommand()
|
||||
{
|
||||
if (!GetSkillManagement()) return;
|
||||
|
||||
if (!EnsureSkillManagement()) return;
|
||||
_skillUnlockerComponent.UnlockAllSkills();
|
||||
}
|
||||
|
||||
private void RemoveSkillCommand(string skillName)
|
||||
{
|
||||
if (!GetSkillManagement()) return;
|
||||
if (!EnsureSkillManagement()) return;
|
||||
|
||||
var skill = _skillManager.GetSkillByName(skillName);
|
||||
if (skill == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (skill == null) return;
|
||||
|
||||
GameManager.RemoveSkill(skill.Name);
|
||||
Store?.RemoveUnlockedSkill(skill.Name);
|
||||
_skillManager.DeactivateSkill(skill);
|
||||
}
|
||||
|
||||
private void RemoveAllSkillsCommand()
|
||||
{
|
||||
if (!GetSkillManagement()) return;
|
||||
if (!EnsureSkillManagement()) return;
|
||||
|
||||
foreach (var skill in _skillManager.AvailableSkills)
|
||||
{
|
||||
GameManager.RemoveSkill(skill.Name);
|
||||
Store?.RemoveUnlockedSkill(skill.Name);
|
||||
_skillManager.DeactivateSkill(skill);
|
||||
}
|
||||
}
|
||||
|
||||
private void GoToNextLevelCommand()
|
||||
{
|
||||
GameManager.OnLevelComplete();
|
||||
GameManager?.OnLevelComplete();
|
||||
}
|
||||
|
||||
private void UnlockAchievementCommand(string achievementId)
|
||||
{
|
||||
AchievementManager.UnlockAchievement(achievementId);
|
||||
AchievementManager?.UnlockAchievement(achievementId);
|
||||
}
|
||||
|
||||
private void ResetAchievementCommand(string achievementId)
|
||||
{
|
||||
AchievementManager.LockAchievement(achievementId);
|
||||
AchievementManager?.LockAchievement(achievementId);
|
||||
}
|
||||
|
||||
}
|
||||
private bool EnsureSkillManagement()
|
||||
{
|
||||
var player = GameManager?.Player;
|
||||
if (player == null || !IsInstanceValid(player)) return false;
|
||||
|
||||
_skillUnlockerComponent ??= player.GetNode<SkillUnlockerComponent>("SkillUnlockerComponent");
|
||||
return _skillManager != null && _skillUnlockerComponent != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user