Files
zfxaction26_1/godot/scripts/hero/rules/HeroRunState.cs
2026-04-21 22:54:14 +02:00

79 lines
2.2 KiB
C#

#nullable enable
using System.Collections.Generic;
using System.Linq;
namespace SideScrollerGame.Hero.Rules;
public sealed class HeroRunState
{
public HeroRunState(string activeDifficultyId, int shieldCharges, int retryCount, HeroRuleConfig config)
{
ActiveDifficultyId = activeDifficultyId;
ShieldCharges = shieldCharges;
RetryCount = retryCount;
m_PrimaryWeaponSlots = Enumerable.Repeat<string?>(null, config.PrimaryWeaponSlotCount).ToList();
ResetInventory(config);
LastStateChange = "Hero ready";
}
public int FindEmptyPrimarySlot()
{
return m_PrimaryWeaponSlots.FindIndex(string.IsNullOrWhiteSpace);
}
public void ReplacePrimaryWeaponSlot(int index, string? weaponId)
{
m_PrimaryWeaponSlots[index] = weaponId;
}
public void ResetInventory(HeroRuleConfig config)
{
for (int i = 0; i < m_PrimaryWeaponSlots.Count; i++)
{
m_PrimaryWeaponSlots[i] = null;
}
if (m_PrimaryWeaponSlots.Count > 0)
{
m_PrimaryWeaponSlots[0] = config.BasePrimaryWeaponId;
}
SelectedPrimaryWeaponSlotIndex = 0;
CurrentSecondaryWeaponId = config.BaseSecondaryWeaponId;
CurrentSpecialWeaponId = config.DefaultSpecialWeaponId;
SpecialAmmo = config.DefaultSpecialAmmo;
SquadronMateTypeId = string.Empty;
SquadronMateCount = 0;
}
public string ActiveDifficultyId { get; set; }
public HeroLifeState LifeState { get; set; } = HeroLifeState.Alive;
public int Level { get; set; } = 1;
public int Points { get; set; }
public int ShieldCharges { get; set; }
public int RetryCount { get; set; }
public IReadOnlyList<string?> PrimaryWeaponSlots => m_PrimaryWeaponSlots;
public int SelectedPrimaryWeaponSlotIndex { get; set; }
public string CurrentSecondaryWeaponId { get; set; } = string.Empty;
public string CurrentSpecialWeaponId { get; set; } = string.Empty;
public int SpecialAmmo { get; set; }
public string SquadronMateTypeId { get; set; } = string.Empty;
public int SquadronMateCount { get; set; }
public string LastStateChange { get; set; } = string.Empty;
private readonly List<string?> m_PrimaryWeaponSlots;
}