Finish refactoring other than making sure bonuses appear on player stat side
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Chickensoft.Collections;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.LogicBlocks;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
|
||||
@@ -70,22 +71,21 @@ namespace GameJamDungeon
|
||||
StateMachine = PlayerLogic,
|
||||
Velocity = Velocity,
|
||||
Inventory = new Inventory(),
|
||||
CurrentHP = new AutoProp<int>(PlayerStatResource.CurrentHP),
|
||||
MaximumHP = new AutoProp<int>(PlayerStatResource.MaximumHP),
|
||||
CurrentVT = new AutoProp<int>(PlayerStatResource.CurrentVT),
|
||||
MaximumVT = new AutoProp<int>(PlayerStatResource.MaximumVT),
|
||||
CurrentAttack = new AutoProp<int>(PlayerStatResource.CurrentAttack),
|
||||
MaxAttack = new AutoProp<int>(PlayerStatResource.MaxAttack),
|
||||
CurrentDefense = new AutoProp<int>(PlayerStatResource.CurrentDefense),
|
||||
MaxDefense = new AutoProp<int>(PlayerStatResource.MaxDefense),
|
||||
CurrentExp = new AutoProp<int>(PlayerStatResource.CurrentExp),
|
||||
ExpToNextLevel = new AutoProp<int>(PlayerStatResource.ExpToNextLevel),
|
||||
CurrentLevel = new AutoProp<int>(PlayerStatResource.CurrentLevel),
|
||||
BonusAttack = new AutoProp<int>(PlayerStatResource.BonusAttack),
|
||||
BonusDefense = new AutoProp<int>(PlayerStatResource.BonusDefense),
|
||||
Luck = new AutoProp<double>(PlayerStatResource.Luck)
|
||||
};
|
||||
|
||||
PlayerData.SetCurrentHP(PlayerStatResource.CurrentHP);
|
||||
PlayerData.SetMaximumHP(PlayerStatResource.MaximumHP);
|
||||
PlayerData.SetCurrentVT(PlayerStatResource.CurrentVT);
|
||||
PlayerData.SetMaximumVT(PlayerStatResource.MaximumVT);
|
||||
PlayerData.SetCurrentAttack(PlayerStatResource.CurrentAttack);
|
||||
PlayerData.SetMaxAttack(PlayerStatResource.MaxAttack);
|
||||
PlayerData.SetCurrentDefense(PlayerStatResource.CurrentDefense);
|
||||
PlayerData.SetMaxDefense(PlayerStatResource.MaxDefense);
|
||||
PlayerData.SetCurrentExp(PlayerStatResource.CurrentExp);
|
||||
PlayerData.SetCurrentLevel(PlayerStatResource.CurrentLevel);
|
||||
PlayerData.SetExpToNextLevel(PlayerStatResource.ExpToNextLevel);
|
||||
PlayerData.SetLuck(PlayerStatResource.Luck);
|
||||
|
||||
PlayerLogic = new PlayerLogic();
|
||||
PlayerLogic.Set(this as IPlayer);
|
||||
PlayerLogic.Set(Settings);
|
||||
@@ -93,10 +93,7 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Set(GameRepo);
|
||||
PlayerLogic.Set(PlayerData);
|
||||
|
||||
PlayerData.Inventory.EquippedWeapon.Sync += EquippedWeapon_Sync;
|
||||
PlayerData.Inventory.EquippedArmor.Sync += EquippedArmor_Sync;
|
||||
PlayerData.Inventory.EquippedAccessory.Sync += EquippedAccessory_Sync;
|
||||
|
||||
PlayerData.CurrentHP.Sync += CurrentHP_Sync;
|
||||
}
|
||||
|
||||
@@ -130,6 +127,13 @@ namespace GameJamDungeon
|
||||
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
|
||||
}
|
||||
|
||||
private void Inventory_AccessoryUnequipped(Accessory unequippedAccessory)
|
||||
{
|
||||
PlayerData.SetMaximumHP(PlayerData.MaximumHP.Value - unequippedAccessory.AccessoryInfo.MaxHPUp);
|
||||
PlayerData.SetMaximumVT(PlayerData.MaximumVT.Value - unequippedAccessory.AccessoryInfo.MaxVTUp);
|
||||
PlayerData.SetLuck(PlayerData.Luck.Value - unequippedAccessory.AccessoryInfo.LUCKUp);
|
||||
}
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
SetPhysicsProcess(true);
|
||||
@@ -213,39 +217,16 @@ namespace GameJamDungeon
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (PlayerData.CurrentVT.Value > 0)
|
||||
PlayerData.CurrentVT.OnNext(PlayerData.CurrentVT.Value - 1);
|
||||
PlayerData.SetCurrentVT(PlayerData.CurrentVT.Value - 1);
|
||||
else
|
||||
PlayerData.CurrentHP.OnNext(PlayerData.CurrentHP.Value - 1);
|
||||
PlayerData.SetCurrentHP(PlayerData.CurrentHP.Value - 1);
|
||||
}
|
||||
|
||||
private void EquippedAccessory_Sync(Accessory equippedItem)
|
||||
{
|
||||
PlayerData.BonusAttack.OnNext(PlayerData.BonusAttack.Value - PlayerData.Inventory.EquippedAccessory.Value.AccessoryInfo.ATKUp);
|
||||
PlayerData.BonusDefense.OnNext(PlayerData.BonusDefense.Value - PlayerData.Inventory.EquippedAccessory.Value.AccessoryInfo.DEFUp);
|
||||
PlayerData.MaximumHP.OnNext(PlayerData.MaximumHP.Value - PlayerData.Inventory.EquippedAccessory.Value.AccessoryInfo.MaxHPUp);
|
||||
PlayerData.MaximumVT.OnNext(PlayerData.MaximumVT.Value - PlayerData.Inventory.EquippedAccessory.Value.AccessoryInfo.MaxVTUp);
|
||||
PlayerData.Luck.OnNext(PlayerData.Luck.Value - PlayerData.Inventory.EquippedAccessory.Value.AccessoryInfo.LUCKUp);
|
||||
|
||||
PlayerData.BonusAttack.OnNext(PlayerData.BonusAttack.Value + equippedItem.AccessoryInfo.ATKUp);
|
||||
PlayerData.BonusDefense.OnNext(PlayerData.BonusDefense.Value + equippedItem.AccessoryInfo.DEFUp);
|
||||
PlayerData.MaximumHP.OnNext(PlayerData.MaximumHP.Value + equippedItem.AccessoryInfo.MaxHPUp);
|
||||
PlayerData.MaximumVT.OnNext(PlayerData.MaximumVT.Value + equippedItem.AccessoryInfo.MaxVTUp);
|
||||
PlayerData.Luck.OnNext(PlayerData.Luck.Value + equippedItem.AccessoryInfo.LUCKUp);
|
||||
PlayerData.Inventory.Equip(equippedItem);
|
||||
}
|
||||
|
||||
private void EquippedArmor_Sync(Armor equippedItem)
|
||||
{
|
||||
PlayerData.BonusDefense.OnNext(PlayerData.BonusDefense.Value - PlayerData.Inventory.EquippedArmor.Value.ArmorStats.Defense);
|
||||
PlayerData.BonusDefense.OnNext(PlayerData.BonusDefense.Value + equippedItem.ArmorStats.Defense);
|
||||
PlayerData.Inventory.Equip(equippedItem);
|
||||
}
|
||||
|
||||
private void EquippedWeapon_Sync(Weapon equippedItem)
|
||||
{
|
||||
PlayerData.BonusAttack.OnNext(PlayerData.BonusAttack.Value - PlayerData.Inventory.EquippedWeapon.Value.WeaponStats.Damage);
|
||||
PlayerData.BonusAttack.OnNext(PlayerData.BonusAttack.Value + equippedItem.WeaponStats.Damage);
|
||||
PlayerData.Inventory.Equip(equippedItem);
|
||||
PlayerData.SetMaximumHP(PlayerData.MaximumHP.Value + equippedItem.AccessoryInfo.MaxHPUp);
|
||||
PlayerData.SetMaximumVT(PlayerData.MaximumVT.Value + equippedItem.AccessoryInfo.MaxVTUp);
|
||||
PlayerData.SetLuck(PlayerData.Luck.Value + equippedItem.AccessoryInfo.LUCKUp);
|
||||
}
|
||||
|
||||
private void OnEnemyHitBoxEntered(Area3D area)
|
||||
@@ -259,8 +240,8 @@ namespace GameJamDungeon
|
||||
var roll = rng.Randf();
|
||||
if (roll <= enemy.EnemyStatResource.Luck)
|
||||
isCriticalHit = true;
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(PlayerData.CurrentDefense.Value + PlayerData.BonusDefense.Value, enemy.EnemyStatResource, GameRepo.PlayerData.Inventory.EquippedArmor.Value.ArmorStats, isCriticalHit);
|
||||
PlayerData.CurrentHP.OnNext(PlayerData.CurrentHP.Value - Mathf.RoundToInt(damage));
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(PlayerData.CurrentDefense.Value + PlayerData.BonusDefense, enemy.EnemyStatResource, GameRepo.PlayerData.Inventory.EquippedArmor.Value.ArmorStats, isCriticalHit);
|
||||
PlayerData.SetCurrentHP(PlayerData.CurrentHP.Value - Mathf.RoundToInt(damage));
|
||||
GD.Print($"Player hit for {damage} damage.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,32 +17,100 @@ namespace GameJamDungeon
|
||||
[Save("inventory")]
|
||||
public required Inventory Inventory { get; init; }
|
||||
[Save("currentHP")]
|
||||
public required AutoProp<int> CurrentHP { get; init; }
|
||||
public IAutoProp<int> CurrentHP => _currentHP;
|
||||
[Save("maximumHP")]
|
||||
public required AutoProp<int> MaximumHP { get; init; }
|
||||
public IAutoProp<int> MaximumHP => _maximumHP;
|
||||
[Save("currentVT")]
|
||||
public required AutoProp<int> CurrentVT { get; init; }
|
||||
public IAutoProp<int> CurrentVT => _currentVT;
|
||||
[Save("maximumVT")]
|
||||
public required AutoProp<int> MaximumVT { get; init; }
|
||||
public IAutoProp<int> MaximumVT => _maximumVT;
|
||||
[Save("currentExp")]
|
||||
public required AutoProp<int> CurrentExp { get; init; }
|
||||
[Save("expToNextLevel")]
|
||||
public required AutoProp<int> ExpToNextLevel { get; init; }
|
||||
public IAutoProp<int> CurrentExp => _currentExp;
|
||||
[Save("currentLevel")]
|
||||
public required AutoProp<int> CurrentLevel { get; init; }
|
||||
public IAutoProp<int> CurrentLevel => _currentLevel;
|
||||
[Save("currentAttack")]
|
||||
public required AutoProp<int> CurrentAttack { get; init; }
|
||||
public IAutoProp<int> CurrentAttack => _currentAttack;
|
||||
[Save("currentDefense")]
|
||||
public required AutoProp<int> CurrentDefense { get; init; }
|
||||
public IAutoProp<int> CurrentDefense => _currentDefense;
|
||||
[Save("maxAttack")]
|
||||
public required AutoProp<int> MaxAttack { get; init; }
|
||||
public IAutoProp<int> MaxAttack => _maxAttack;
|
||||
[Save("maxDefense")]
|
||||
public required AutoProp<int> MaxDefense { get; init; }
|
||||
[Save("bonusAttack")]
|
||||
public required AutoProp<int> BonusAttack { get; init; }
|
||||
[Save("bonusDefense")]
|
||||
public required AutoProp<int> BonusDefense { get; init; }
|
||||
public IAutoProp<int> MaxDefense => _maxDefense;
|
||||
public int BonusAttack => Inventory.EquippedWeapon.Value.WeaponStats.Damage + Inventory.EquippedAccessory.Value.AccessoryInfo.ATKUp;
|
||||
public int BonusDefense => Inventory.EquippedArmor.Value.ArmorStats.Defense + Inventory.EquippedAccessory.Value.AccessoryInfo.DEFUp;
|
||||
[Save("expToNextLevel")]
|
||||
public IAutoProp<int> ExpToNextLevel => _expToNextLevel;
|
||||
[Save("luck")]
|
||||
public required AutoProp<double> Luck { get; init; }
|
||||
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(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, ExpToNextLevel.Value);
|
||||
_currentExp.OnNext(clampedValue);
|
||||
}
|
||||
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 SetCurrentDefense(int newValue)
|
||||
{
|
||||
var clampedValue = Mathf.Clamp(newValue, 0, MaxDefense.Value);
|
||||
_currentDefense.OnNext(clampedValue);
|
||||
}
|
||||
public void SetMaxAttack(int newValue)
|
||||
{
|
||||
_maxAttack.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(int.MaxValue);
|
||||
private readonly AutoProp<int> _maximumHP = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _currentVT = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _maximumVT = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _currentExp = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _currentLevel = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _currentAttack = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _currentDefense = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _maxAttack = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _maxDefense = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _bonusAttack = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _bonusDefense = new(int.MaxValue);
|
||||
private readonly AutoProp<int> _expToNextLevel = new(int.MaxValue);
|
||||
private readonly AutoProp<double> _luck = new(double.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user