Implement even more inventory/UI stuff
This commit is contained in:
@@ -73,12 +73,10 @@ namespace GameJamDungeon
|
||||
|
||||
[Node] public Label VTNumber { get; set; } = default!;
|
||||
|
||||
[Node] public Label LevelNumber { get; set; } = default!;
|
||||
|
||||
[Node] public IArea3D CollisionDetector { get; set; } = default!;
|
||||
|
||||
private AutoProp<double> _currentHP { get; set; } = default!;
|
||||
|
||||
private AutoProp<int> _currentVT { get; set; } = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||
@@ -100,11 +98,6 @@ namespace GameJamDungeon
|
||||
|
||||
GameRepo.SetPlayerStatInfo(PlayerStatInfo);
|
||||
|
||||
_currentHP = new AutoProp<double>(PlayerStatInfo.MaximumHP);
|
||||
_currentVT = new AutoProp<int>(PlayerStatInfo.MaximumVT);
|
||||
_currentHP.Sync += OnHPChanged;
|
||||
_currentVT.Sync += OnVTChanged;
|
||||
|
||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||
CollisionDetector.AreaEntered += OnEnemyHitBoxEntered;
|
||||
}
|
||||
@@ -125,8 +118,6 @@ namespace GameJamDungeon
|
||||
var attackSpeed = (float)weaponInfo.AttackSpeed;
|
||||
AnimationPlayer.SetSpeedScale(attackSpeed);
|
||||
AnimationPlayer.Play("attack");
|
||||
if (weaponInfo.WeaponTags.Contains(WeaponTag.SelfDamage))
|
||||
_currentHP.OnNext(_currentHP.Value - 5);
|
||||
})
|
||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||
{
|
||||
@@ -153,7 +144,7 @@ namespace GameJamDungeon
|
||||
{
|
||||
if (area is IHitbox hitBox)
|
||||
{
|
||||
if (_currentHP.Value > 0)
|
||||
if (GameRepo.PlayerStatInfo.Value.CurrentHP > 0)
|
||||
{
|
||||
var enemy = hitBox.GetParent<IEnemy>();
|
||||
var isCriticalHit = false;
|
||||
@@ -162,8 +153,8 @@ namespace GameJamDungeon
|
||||
var roll = rng.Randf();
|
||||
if (roll <= enemy.EnemyStatInfo.Luck)
|
||||
isCriticalHit = true;
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(hitBox.Damage, PlayerStatInfo, enemy.EnemyStatInfo, GameRepo.EquippedArmor.Value.ArmorInfo, isCriticalHit);
|
||||
_currentHP.OnNext(_currentHP.Value - damage);
|
||||
var damage = DamageCalculator.CalculateEnemyDamage(PlayerStatInfo, enemy.EnemyStatInfo, GameRepo.EquippedArmor.Value.ArmorInfo, isCriticalHit);
|
||||
GameRepo.PlayerStatInfo.Value.CurrentHP = GameRepo.PlayerStatInfo.Value.CurrentHP - damage;
|
||||
GD.Print($"Player hit for {damage} damage.");
|
||||
}
|
||||
}
|
||||
@@ -178,6 +169,13 @@ namespace GameJamDungeon
|
||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition));
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
OnHPChanged(GameRepo.PlayerStatInfo.Value.CurrentHP);
|
||||
OnVTChanged(GameRepo.PlayerStatInfo.Value.CurrentVT);
|
||||
OnLevelChanged(GameRepo.PlayerStatInfo.Value.CurrentLevel);
|
||||
}
|
||||
|
||||
public Vector3 GetGlobalInputVector()
|
||||
{
|
||||
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
||||
@@ -224,8 +222,6 @@ namespace GameJamDungeon
|
||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||
}
|
||||
|
||||
private void OnEquippedWeaponChanged(Weapon info) => Hitbox.Damage = info.WeaponInfo.Damage;
|
||||
|
||||
private void OnHPChanged(double newHP)
|
||||
{
|
||||
HPNumber.Text = $"{Mathf.RoundToInt(newHP)}/{PlayerStatInfo.MaximumHP}";
|
||||
@@ -242,14 +238,19 @@ namespace GameJamDungeon
|
||||
VTNumber.Text = $"{newVT}/{PlayerStatInfo.MaximumVT}";
|
||||
}
|
||||
|
||||
private void OnLevelChanged(int newLevel)
|
||||
{
|
||||
LevelNumber.Text = $"{newLevel}";
|
||||
}
|
||||
|
||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||
|
||||
private void OnHealthTimerTimeout()
|
||||
{
|
||||
if (_currentVT.Value > 0)
|
||||
_currentVT.OnNext(_currentVT.Value - 1);
|
||||
if (GameRepo.PlayerStatInfo.Value.CurrentVT > 0)
|
||||
GameRepo.PlayerStatInfo.Value.CurrentVT = GameRepo.PlayerStatInfo.Value.CurrentVT - 1;
|
||||
else
|
||||
_currentHP.OnNext(_currentHP.Value - 1);
|
||||
GameRepo.PlayerStatInfo.Value.CurrentHP = GameRepo.PlayerStatInfo.Value.CurrentHP - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ CurrentDefense = 8
|
||||
MaxDefense = 8
|
||||
BonusAttack = 0
|
||||
BonusDefense = 0
|
||||
Luck = 0.0
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_wedu3"]
|
||||
|
||||
@@ -215,7 +216,8 @@ texture = ExtResource("10_rsd7v")
|
||||
expand_mode = 1
|
||||
stretch_mode = 4
|
||||
|
||||
[node name="Level" type="Label" parent="PlayerInfoUI/HBoxContainer/CenterContainer"]
|
||||
[node name="LevelNumber" type="Label" parent="PlayerInfoUI/HBoxContainer/CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(80, 80)
|
||||
layout_mode = 2
|
||||
text = "99"
|
||||
|
||||
@@ -45,6 +45,9 @@ namespace GameJamDungeon
|
||||
[Export]
|
||||
public int BonusDefense { get => _bonusDefense.Value; set => _bonusDefense.OnNext(value); }
|
||||
|
||||
[Export]
|
||||
public double Luck { get => _luck.Value; set => _luck.OnNext(value); }
|
||||
|
||||
// AutoProp backing data
|
||||
private readonly AutoProp<double> _currentHP = new AutoProp<double>(0);
|
||||
private readonly AutoProp<double> _maximumHP = new AutoProp<double>(0);
|
||||
@@ -64,5 +67,7 @@ namespace GameJamDungeon
|
||||
|
||||
private readonly AutoProp<int> _bonusAttack = new AutoProp<int>(0);
|
||||
private readonly AutoProp<int> _bonusDefense = new AutoProp<int>(0);
|
||||
|
||||
private readonly AutoProp<double> _luck = new AutoProp<double>(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user