Refactor Player class to use components, also use components in Enemy class types and fiddle with boss structure
This commit is contained in:
@@ -5,7 +5,6 @@ using Godot;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
using static Zennysoft.Game.Ma.AudioManager;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -39,16 +38,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private int _currentIndex = 0;
|
||||
|
||||
private IItemSlot[] ItemSlots => ItemsPage.GetChildren().OfType<IItemSlot>().ToArray();
|
||||
private IItemSlot[] ItemSlots => [.. ItemsPage.GetChildren().OfType<IItemSlot>()];
|
||||
|
||||
#region Control Nodes
|
||||
[Node] public Label FloorLabel { get; set; } = default!;
|
||||
[Node] public Label CurrentLevelLabel { get; set; } = default!;
|
||||
[Node] public Label EXPValue { get; set; } = default!;
|
||||
[Node] public Label HPValue { get; set; } = default!;
|
||||
[Node] public Label HPBonusLabel { get; set; } = default!;
|
||||
[Node] public Label VTValue { get; set; } = default!;
|
||||
[Node] public Label VTBonusLabel { get; set; } = default!;
|
||||
[Node] public Label ATKValue { get; set; } = default!;
|
||||
[Node] public Label ATKBonusLabel { get; set; } = default!;
|
||||
[Node] public Label DEFValue { get; set; } = default!;
|
||||
@@ -77,9 +69,25 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
DropButton.Pressed += DropButtonPressed;
|
||||
}
|
||||
|
||||
public void OnExitTree()
|
||||
{
|
||||
Player.AttackComponent.CurrentAttack.Sync -= AttackSync;
|
||||
Player.AttackComponent.MaximumAttack.Sync -= AttackSync;
|
||||
Player.AttackComponent.BonusAttack.Sync -= BonusAttack_Sync;
|
||||
Player.DefenseComponent.CurrentDefense.Sync -= DefenseSync;
|
||||
Player.DefenseComponent.MaximumDefense.Sync -= DefenseSync;
|
||||
Player.DefenseComponent.BonusDefense.Sync -= BonusDefense_Sync;
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
SetProcessInput(false);
|
||||
Player.AttackComponent.CurrentAttack.Sync += AttackSync;
|
||||
Player.AttackComponent.MaximumAttack.Sync += AttackSync;
|
||||
Player.AttackComponent.BonusAttack.Sync += BonusAttack_Sync;
|
||||
Player.DefenseComponent.CurrentDefense.Sync += DefenseSync;
|
||||
Player.DefenseComponent.MaximumDefense.Sync += DefenseSync;
|
||||
Player.DefenseComponent.BonusDefense.Sync += BonusDefense_Sync;
|
||||
}
|
||||
|
||||
public async Task DisplayMessage(string message)
|
||||
@@ -93,56 +101,17 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
SetProcessInput(true);
|
||||
}
|
||||
|
||||
private void BonusAttack_Sync(int bonus)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{Player.Stats.BonusDefense.Value:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
private void AttackSync(int obj) => ATKValue.Text = $"{Player.AttackComponent.CurrentAttack.Value}/{Player.AttackComponent.MaximumAttack.Value}";
|
||||
|
||||
private void BonusDefense_Sync(int bonus)
|
||||
{
|
||||
ATKBonusLabel.Text = $"{Player.Stats.BonusAttack.Value:+0;-#;\\.\\.\\.}";
|
||||
DEFBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
}
|
||||
private void BonusAttack_Sync(int bonus) => ATKBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
|
||||
private void CurrentLevel_Sync(int obj) => CurrentLevelLabel.Text = $"Level {obj:D2}";
|
||||
private void DefenseSync(int obj) => DEFValue.Text = $"{Player.DefenseComponent.CurrentDefense.Value}/{Player.DefenseComponent.MaximumDefense.Value}";
|
||||
|
||||
private void ExpToNextLevel_Sync(int obj) => EXPValue.Text = $"{Player.Stats.CurrentExp.Value}/{obj}";
|
||||
private void BonusDefense_Sync(int bonus) => DEFBonusLabel.Text = $"{bonus:+0;-#;\\.\\.\\.}";
|
||||
|
||||
private void CurrentExp_Sync(double obj) => EXPValue.Text = $"{obj}/{Player.Stats.ExpToNextLevel.Value}";
|
||||
|
||||
private void MaxDefense_Sync(int obj) => DEFValue.Text = $"{Player.Stats.CurrentDefense.Value}/{obj}";
|
||||
|
||||
private void CurrentDefense_Sync(int obj) => DEFValue.Text = $"{obj}/{Player.Stats.MaxDefense.Value}";
|
||||
|
||||
private void MaxAttack_Sync(int obj) => ATKValue.Text = $"{Player.Stats.CurrentAttack.Value}/{obj}";
|
||||
|
||||
private void CurrentAttack_Sync(int obj) => ATKValue.Text = $"{obj}/{Player.Stats.MaxAttack.Value}";
|
||||
|
||||
private void MaximumVT_Sync(int obj) => VTValue.Text = $"{Player.Stats.CurrentVT.Value}/{obj}";
|
||||
|
||||
private void CurrentVT_Sync(int obj) => VTValue.Text = $"{obj}/{Player.Stats.MaximumVT.Value}";
|
||||
|
||||
private void MaximumHP_Sync(int obj) => HPValue.Text = $"{Player.Stats.CurrentHP.Value}/{obj}";
|
||||
|
||||
private void CurrentHP_Sync(int obj) => HPValue.Text = $"{obj}/{Player.Stats.MaximumHP.Value}";
|
||||
|
||||
public async Task RefreshInventoryScreen()
|
||||
{
|
||||
Player.Stats.CurrentHP.Sync += CurrentHP_Sync;
|
||||
Player.Stats.MaximumHP.Sync += MaximumHP_Sync;
|
||||
Player.Stats.CurrentVT.Sync += CurrentVT_Sync;
|
||||
Player.Stats.MaximumVT.Sync += MaximumVT_Sync;
|
||||
Player.Stats.CurrentAttack.Sync += CurrentAttack_Sync;
|
||||
Player.Stats.MaxAttack.Sync += MaxAttack_Sync;
|
||||
Player.Stats.CurrentDefense.Sync += CurrentDefense_Sync;
|
||||
Player.Stats.MaxDefense.Sync += MaxDefense_Sync;
|
||||
Player.Stats.CurrentExp.Sync += CurrentExp_Sync;
|
||||
Player.Stats.ExpToNextLevel.Sync += ExpToNextLevel_Sync;
|
||||
Player.Stats.CurrentLevel.Sync += CurrentLevel_Sync;
|
||||
Player.Stats.BonusAttack.Sync += BonusAttack_Sync;
|
||||
Player.Stats.BonusDefense.Sync += BonusDefense_Sync;
|
||||
|
||||
await ClearItems();
|
||||
PopulateInventory();
|
||||
PopulatePlayerInfo();
|
||||
@@ -165,19 +134,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
}
|
||||
else
|
||||
{
|
||||
Player.Stats.CurrentHP.Sync -= CurrentHP_Sync;
|
||||
Player.Stats.MaximumHP.Sync -= MaximumHP_Sync;
|
||||
Player.Stats.CurrentVT.Sync -= CurrentVT_Sync;
|
||||
Player.Stats.MaximumVT.Sync -= MaximumVT_Sync;
|
||||
Player.Stats.CurrentAttack.Sync -= CurrentAttack_Sync;
|
||||
Player.Stats.MaxAttack.Sync -= MaxAttack_Sync;
|
||||
Player.Stats.CurrentDefense.Sync -= CurrentDefense_Sync;
|
||||
Player.Stats.MaxDefense.Sync -= MaxDefense_Sync;
|
||||
Player.Stats.CurrentExp.Sync -= CurrentExp_Sync;
|
||||
Player.Stats.ExpToNextLevel.Sync -= ExpToNextLevel_Sync;
|
||||
Player.Stats.CurrentLevel.Sync -= CurrentLevel_Sync;
|
||||
Player.Stats.BonusAttack.Sync -= BonusAttack_Sync;
|
||||
Player.Stats.BonusDefense.Sync -= BonusDefense_Sync;
|
||||
Autoload.AudioManager.Play(SoundEffect.Cancel);
|
||||
_gameRepo.CloseInventory();
|
||||
}
|
||||
@@ -261,8 +217,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private void PopulatePlayerInfo()
|
||||
{
|
||||
FloorLabel.Text = $"Floor {_map.CurrentFloorNumber:D2}";
|
||||
|
||||
if (ItemSlots.Length != 0)
|
||||
{
|
||||
var item = ItemSlots.ElementAt(_currentIndex).Item;
|
||||
|
||||
Reference in New Issue
Block a user