Overhaul game state logic to support gameplay loop
This commit is contained in:
@@ -8,9 +8,9 @@ public interface IPlayer : IKillable
|
||||
{
|
||||
public void InitializePlayerState();
|
||||
|
||||
public void Attack();
|
||||
public void Activate();
|
||||
|
||||
public void PlayerPause();
|
||||
public void Attack();
|
||||
|
||||
public void TakeDamage(double damage, ElementType elementType = ElementType.None, bool isCriticalHit = false);
|
||||
|
||||
@@ -44,7 +44,7 @@ public interface IPlayer : IKillable
|
||||
|
||||
public IInventory Inventory { get; }
|
||||
|
||||
public PlayerStatController Stats { get; }
|
||||
public PlayerStats Stats { get; }
|
||||
|
||||
public Vector3 CurrentPosition { get; }
|
||||
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
using Zennysoft.Game.Ma;
|
||||
|
||||
public class PlayerStatController
|
||||
{
|
||||
public void Init(PlayerStats playerStats)
|
||||
{
|
||||
_currentHP.OnNext(playerStats.CurrentHP);
|
||||
_maximumHP.OnNext(playerStats.MaximumHP);
|
||||
_currentVT.OnNext(playerStats.CurrentVT);
|
||||
_maximumVT.OnNext(playerStats.MaximumVT);
|
||||
_currentExp.OnNext(playerStats.CurrentExp);
|
||||
_expToNextLevel.OnNext(playerStats.ExpToNextLevel);
|
||||
_currentLevel.OnNext(playerStats.CurrentLevel);
|
||||
_currentAttack.OnNext(playerStats.CurrentAttack);
|
||||
_bonusAttack.OnNext(playerStats.BonusAttack);
|
||||
_maxAttack.OnNext(playerStats.MaxAttack);
|
||||
_currentDefense.OnNext(playerStats.CurrentDefense);
|
||||
_bonusDefense.OnNext(playerStats.BonusDefense);
|
||||
_maxDefense.OnNext(playerStats.MaxDefense);
|
||||
_luck.OnNext(playerStats.Luck);
|
||||
}
|
||||
|
||||
public IAutoProp<int> CurrentHP => _currentHP;
|
||||
public IAutoProp<int> MaximumHP => _maximumHP;
|
||||
public IAutoProp<int> CurrentVT => _currentVT;
|
||||
public IAutoProp<int> MaximumVT => _maximumVT;
|
||||
public IAutoProp<int> CurrentAttack => _currentAttack;
|
||||
public IAutoProp<int> MaxAttack => _maxAttack;
|
||||
public IAutoProp<int> BonusAttack => _bonusAttack;
|
||||
public IAutoProp<int> CurrentDefense => _currentDefense;
|
||||
public IAutoProp<int> MaxDefense => _maxDefense;
|
||||
public IAutoProp<int> BonusDefense => _bonusDefense;
|
||||
public IAutoProp<double> CurrentExp => _currentExp;
|
||||
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
|
||||
public IAutoProp<int> CurrentLevel => _currentLevel;
|
||||
public IAutoProp<double> Luck => _luck;
|
||||
|
||||
public void SetCurrentHP(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
|
||||
_currentHP.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumHP(int newValue)
|
||||
{
|
||||
_maximumHP.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentVT(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
|
||||
_currentVT.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumVT(int newValue)
|
||||
{
|
||||
_maximumVT.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentExp(double newValue)
|
||||
{
|
||||
_currentExp.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentLevel(int newValue)
|
||||
{
|
||||
_currentLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentAttack(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
|
||||
_currentAttack.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusAttack(int newValue)
|
||||
{
|
||||
_bonusAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxAttack(int newValue)
|
||||
{
|
||||
_maxAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentDefense(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
|
||||
_currentDefense.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusDefense(int newValue)
|
||||
{
|
||||
_bonusDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxDefense(int newValue)
|
||||
{
|
||||
_maxDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetExpToNextLevel(int newValue)
|
||||
{
|
||||
_expToNextLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetLuck(double newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
|
||||
_luck.OnNext(clampedValue);
|
||||
}
|
||||
|
||||
private readonly AutoProp<int> _currentHP = new(-1);
|
||||
private readonly AutoProp<int> _maximumHP = new(-1);
|
||||
private readonly AutoProp<int> _currentVT = new(-1);
|
||||
private readonly AutoProp<int> _maximumVT = new(-1);
|
||||
private readonly AutoProp<double> _currentExp = new(-1);
|
||||
private readonly AutoProp<int> _currentLevel = new(-1);
|
||||
private readonly AutoProp<int> _currentAttack = new(-1);
|
||||
private readonly AutoProp<int> _bonusAttack = new(-1);
|
||||
private readonly AutoProp<int> _maxAttack = new(-1);
|
||||
private readonly AutoProp<int> _currentDefense = new(-1);
|
||||
private readonly AutoProp<int> _bonusDefense = new(-1);
|
||||
private readonly AutoProp<int> _maxDefense = new(-1);
|
||||
private readonly AutoProp<int> _expToNextLevel = new(-1);
|
||||
private readonly AutoProp<double> _luck = new(-1);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Chickensoft.Serialization;
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
[Meta, Id("player_stats")]
|
||||
public partial record PlayerStats
|
||||
public partial record PlayerInitialState
|
||||
{
|
||||
[Save("currentHP")]
|
||||
public int CurrentHP { get; init; }
|
||||
|
||||
115
Zennysoft.Game.Ma.Implementation/Player/PlayerStats_1.cs
Normal file
115
Zennysoft.Game.Ma.Implementation/Player/PlayerStats_1.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
namespace Zennysoft.Ma.Adapter;
|
||||
|
||||
using Chickensoft.Collections;
|
||||
using Godot;
|
||||
|
||||
public class PlayerStats
|
||||
{
|
||||
public PlayerStats(AutoProp<int> currentHP,
|
||||
AutoProp<int> maximumHP,
|
||||
AutoProp<int> currentVT,
|
||||
AutoProp<int> maximumVT,
|
||||
AutoProp<int> currentAttack,
|
||||
AutoProp<int> maxAttack,
|
||||
AutoProp<int> bonusAttack,
|
||||
AutoProp<int> currentDefense,
|
||||
AutoProp<int> maxDefense,
|
||||
AutoProp<int> bonusDefense,
|
||||
AutoProp<double> currentExp,
|
||||
AutoProp<int> expToNextLevel,
|
||||
AutoProp<int> currentLevel,
|
||||
AutoProp<double> luck)
|
||||
{
|
||||
CurrentHP = currentHP;
|
||||
MaximumHP = maximumHP;
|
||||
CurrentVT = currentVT;
|
||||
MaximumVT = maximumVT;
|
||||
CurrentAttack = currentAttack;
|
||||
MaxAttack = maxAttack;
|
||||
BonusAttack = bonusAttack;
|
||||
CurrentDefense = currentDefense;
|
||||
MaxDefense = maxDefense;
|
||||
BonusDefense = bonusDefense;
|
||||
CurrentExp = currentExp;
|
||||
ExpToNextLevel = expToNextLevel;
|
||||
CurrentLevel = currentLevel;
|
||||
Luck = luck;
|
||||
}
|
||||
|
||||
public AutoProp<int> CurrentHP { get; init; }
|
||||
public AutoProp<int> MaximumHP { get; init; }
|
||||
public AutoProp<int> CurrentVT { get; init; }
|
||||
public AutoProp<int> MaximumVT { get; init; }
|
||||
public AutoProp<int> CurrentAttack { get; init; }
|
||||
public AutoProp<int> MaxAttack { get; init; }
|
||||
public AutoProp<int> BonusAttack { get; init; }
|
||||
public AutoProp<int> CurrentDefense { get; init; }
|
||||
public AutoProp<int> MaxDefense { get; init; }
|
||||
public AutoProp<int> BonusDefense { get; init; }
|
||||
public AutoProp<double> CurrentExp { get; init; }
|
||||
public AutoProp<int> ExpToNextLevel { get; init; }
|
||||
public AutoProp<int> CurrentLevel { get; init; }
|
||||
public AutoProp<double> Luck { get; init; }
|
||||
|
||||
public void SetCurrentHP(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumHP.Value);
|
||||
CurrentHP.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumHP(int newValue)
|
||||
{
|
||||
MaximumHP.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentVT(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaximumVT.Value);
|
||||
CurrentVT.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaximumVT(int newValue)
|
||||
{
|
||||
MaximumVT.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentExp(double newValue)
|
||||
{
|
||||
CurrentExp.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentLevel(int newValue)
|
||||
{
|
||||
CurrentLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentAttack(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxAttack.Value);
|
||||
CurrentAttack.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusAttack(int newValue)
|
||||
{
|
||||
BonusAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxAttack(int newValue)
|
||||
{
|
||||
MaxAttack.OnNext(newValue);
|
||||
}
|
||||
public void SetCurrentDefense(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
|
||||
CurrentDefense.OnNext(clampedValue);
|
||||
}
|
||||
public void SetBonusDefense(int newValue)
|
||||
{
|
||||
BonusDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetMaxDefense(int newValue)
|
||||
{
|
||||
MaxDefense.OnNext(newValue);
|
||||
}
|
||||
public void SetExpToNextLevel(int newValue)
|
||||
{
|
||||
ExpToNextLevel.OnNext(newValue);
|
||||
}
|
||||
public void SetLuck(double newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, 1.0);
|
||||
Luck.OnNext(clampedValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user