From 62a9f99b81d79e41c0e02bcda4d093fbf03b94ae Mon Sep 17 00:00:00 2001 From: Zenny Date: Tue, 10 Sep 2024 01:22:34 -0700 Subject: [PATCH] Implement even more inventory/UI stuff --- src/enemy/Enemy.cs | 5 ++-- src/enemy/EnemyStatInfo.cs | 2 +- src/game/Game.cs | 8 ++---- src/game/IGameRepo.cs | 15 ++++++++++ src/hitbox/Hitbox.cs | 2 -- src/inventory_menu/InventoryMenu.cs | 13 +++++++-- src/inventory_menu/InventoryMenu.tscn | 8 ++---- src/items/accessory/Accessory.cs | 2 +- src/items/accessory/AccessoryInfo.cs | 10 +++---- src/items/throwable/ThrowableItem.cs | 1 - src/items/weapons/Weapon.cs | 2 +- src/items/weapons/WeaponInfo.cs | 2 +- src/items/weapons/resources/Kubel.tres | 2 +- src/player/Player.cs | 39 +++++++++++++------------- src/player/Player.tscn | 4 ++- src/player/PlayerStatInfo.cs | 5 ++++ src/system/stats/DamageCalculator.cs | 8 +++--- src/system/stats/ICharacterStats.cs | 2 ++ 18 files changed, 79 insertions(+), 51 deletions(-) diff --git a/src/enemy/Enemy.cs b/src/enemy/Enemy.cs index 826ee185..57e1e1bd 100644 --- a/src/enemy/Enemy.cs +++ b/src/enemy/Enemy.cs @@ -113,7 +113,6 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide { Raycast.DebugShapeCustomColor = Color.FromString("Purple", Colors.Purple); EnemyLogic.Input(new EnemyLogic.Input.Alerted()); - } } } @@ -139,6 +138,8 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide }) .Handle((in EnemyLogic.Output.HitByPlayer output) => { + if (GameRepo.EquippedWeapon.Value.WeaponInfo.WeaponTags.Contains(WeaponTag.SelfDamage)) + GameRepo.PlayerStatInfo.Value.CurrentHP -= 5; }); this.Provide(); @@ -183,7 +184,7 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide var roll = rng.Randf(); if (roll <= GameRepo.EquippedWeapon.Value.WeaponInfo.Luck) isCriticalHit = true; - var damage = DamageCalculator.CalculatePlayerDamage(hitBox.Damage, hitBox.GetParent().PlayerStatInfo, EnemyStatInfo, GameRepo.EquippedWeapon.Value.WeaponInfo, isCriticalHit); + var damage = DamageCalculator.CalculatePlayerDamage(hitBox.GetParent().PlayerStatInfo, EnemyStatInfo, GameRepo.EquippedWeapon.Value.WeaponInfo, isCriticalHit); GD.Print($"Enemy Hit for {damage} damage."); EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(damage)); } diff --git a/src/enemy/EnemyStatInfo.cs b/src/enemy/EnemyStatInfo.cs index 53f76f75..236e4524 100644 --- a/src/enemy/EnemyStatInfo.cs +++ b/src/enemy/EnemyStatInfo.cs @@ -24,7 +24,7 @@ namespace GameJamDungeon public int MaxDefense { get; set; } [Export] - public float Luck { get; set; } = 0.05f; + public double Luck { get; set; } = 0.05f; [Export] public double TelluricResistance { get; set; } diff --git a/src/game/Game.cs b/src/game/Game.cs index 0494d918..e038ed1f 100644 --- a/src/game/Game.cs +++ b/src/game/Game.cs @@ -50,8 +50,6 @@ public partial class Game : Node3D, IGame private List Floors; - private int _currentFloor = -1; - public void Setup() { GameRepo = new GameRepo(); @@ -88,7 +86,7 @@ public partial class Game : Node3D, IGame .Handle((in GameLogic.Output.LoadNextFloor _) => { AnimationPlayer.Play("wait_and_load"); - var currentFloor = Floors.ElementAt(_currentFloor); + var currentFloor = Floors.ElementAt(GameRepo.CurrentFloor); currentFloor.CallDeferred(MethodName.QueueFree, []); if (GameRepo.EquippedWeapon.Value.WeaponInfo != null && GameRepo.EquippedWeapon.Value.WeaponInfo.WeaponTags.Contains(WeaponTag.BreaksOnChange)) @@ -120,7 +118,7 @@ public partial class Game : Node3D, IGame private void AnimationPlayer_AnimationStarted(StringName animName) { - var newFloor = Floors.ElementAt(_currentFloor + 1); + var newFloor = Floors.ElementAt(GameRepo.CurrentFloor + 1); newFloor.CallDeferred(nameof(newFloor.InitializeDungeon), []); newFloor.Show(); } @@ -129,7 +127,7 @@ public partial class Game : Node3D, IGame { var spawnPoints = GetTree().GetNodesInGroup("Exit").OfType(); Teleport.GlobalPosition = spawnPoints.Last().GlobalPosition; - _currentFloor++; + GameRepo.CurrentFloor++; } public override void _Process(double delta) diff --git a/src/game/IGameRepo.cs b/src/game/IGameRepo.cs index 4a839710..ab930672 100644 --- a/src/game/IGameRepo.cs +++ b/src/game/IGameRepo.cs @@ -46,6 +46,8 @@ public interface IGameRepo : IDisposable public void EquipItem(IEquipable item); public void UnequipItem(IEquipable item); + + public int CurrentFloor { get; set; } } public class GameRepo : IGameRepo @@ -86,6 +88,8 @@ public class GameRepo : IGameRepo public AutoProp PlayerStatInfo => _playerStatInfo; + public int CurrentFloor { get; set; } = -1; + public GameRepo() { _inventoryItems = new AutoProp>([]); @@ -130,6 +134,17 @@ public class GameRepo : IGameRepo public void OnAccessoryEquipped(Accessory equippedItem) { + PlayerStatInfo.Value.BonusAttack -= _equippedAccessory.Value.AccessoryInfo.ATKUp; + PlayerStatInfo.Value.BonusDefense -= _equippedAccessory.Value.AccessoryInfo.DEFUp; + PlayerStatInfo.Value.MaximumHP -= _equippedAccessory.Value.AccessoryInfo.MaxHPUp; + PlayerStatInfo.Value.MaximumVT -= _equippedAccessory.Value.AccessoryInfo.MaxVTUp; + PlayerStatInfo.Value.Luck -= _equippedAccessory.Value.AccessoryInfo.LUCKUp; + + PlayerStatInfo.Value.BonusAttack += equippedItem.AccessoryInfo.ATKUp; + PlayerStatInfo.Value.BonusDefense += equippedItem.AccessoryInfo.DEFUp; + PlayerStatInfo.Value.MaximumHP += equippedItem.AccessoryInfo.MaxHPUp; + PlayerStatInfo.Value.MaximumVT += equippedItem.AccessoryInfo.MaxVTUp; + PlayerStatInfo.Value.Luck += equippedItem.AccessoryInfo.LUCKUp; _equippedAccessory.OnNext(equippedItem); } diff --git a/src/hitbox/Hitbox.cs b/src/hitbox/Hitbox.cs index b7990cc3..2335b124 100644 --- a/src/hitbox/Hitbox.cs +++ b/src/hitbox/Hitbox.cs @@ -3,10 +3,8 @@ using Godot; public interface IHitbox : IArea3D { - public int Damage { get; set; } } public partial class Hitbox : Area3D, IHitbox { - public int Damage { get; set; } } diff --git a/src/inventory_menu/InventoryMenu.cs b/src/inventory_menu/InventoryMenu.cs index 003b35fb..6fa4684b 100644 --- a/src/inventory_menu/InventoryMenu.cs +++ b/src/inventory_menu/InventoryMenu.cs @@ -64,8 +64,7 @@ public partial class InventoryMenu : Control, IInventoryMenu public void PopulatePlayerInfo() { - - FloorLabel.Text = $"Floor 0"; + FloorLabel.Text = $"Level {GameRepo.CurrentFloor:D2}"; var currentLevel = GameRepo.PlayerStatInfo.Value.CurrentLevel; CurrentLevelLabel.Text = $"Level {currentLevel:D2}"; @@ -227,6 +226,16 @@ public partial class InventoryMenu : Control, IInventoryMenu ATKBonusLabel.Text = atkBonus != 0 ? $"{atkBonus:+0;-#}" : "..."; var defBonus = GameRepo.PlayerStatInfo.Value.BonusDefense; DEFBonusLabel.Text = defBonus != 0 ? $"{defBonus:+0;-#}" : "..."; + + var currentHP = GameRepo.PlayerStatInfo.Value.CurrentHP; + var maxHP = GameRepo.PlayerStatInfo.Value.MaximumHP; + + HPValue.Text = $"{currentHP}/{maxHP}"; + + var currentVT = GameRepo.PlayerStatInfo.Value.CurrentVT; + var maxVT = GameRepo.PlayerStatInfo.Value.MaximumVT; + + VTValue.Text = $"{currentVT}/{maxVT}"; } } } diff --git a/src/inventory_menu/InventoryMenu.tscn b/src/inventory_menu/InventoryMenu.tscn index adabde20..ee971e65 100644 --- a/src/inventory_menu/InventoryMenu.tscn +++ b/src/inventory_menu/InventoryMenu.tscn @@ -130,7 +130,7 @@ layout_mode = 2 [node name="FloorLabel" type="Label" parent="InventoryInfo/HBoxContainer/PlayerInfo/FloorBox"] unique_name_in_owner = true layout_mode = 2 -text = "FLOOR 02" +text = "FLOOR 00" label_settings = SubResource("LabelSettings_q0afw") [node name="LevelBox" type="HBoxContainer" parent="InventoryInfo/HBoxContainer/PlayerInfo"] @@ -143,7 +143,7 @@ layout_mode = 2 [node name="CurrentLevelLabel" type="Label" parent="InventoryInfo/HBoxContainer/PlayerInfo/LevelBox"] unique_name_in_owner = true layout_mode = 2 -text = "LEVEL 4" +text = "LEVEL 0" label_settings = SubResource("LabelSettings_yw3yo") [node name="ReferenceRect2" type="ReferenceRect" parent="InventoryInfo/HBoxContainer/PlayerInfo"] @@ -272,7 +272,7 @@ layout_mode = 2 [node name="ATKBonusLabel" type="Label" parent="InventoryInfo/HBoxContainer/PlayerInfo/ATKBox"] unique_name_in_owner = true layout_mode = 2 -text = "+50" +text = "..." label_settings = ExtResource("6_tmdno") [node name="DEFBox" type="HBoxContainer" parent="InventoryInfo/HBoxContainer/PlayerInfo"] @@ -329,7 +329,6 @@ unique_name_in_owner = true custom_minimum_size = Vector2(800, 100) layout_mode = 2 size_flags_horizontal = 0 -text = "Mask of the Goddess of Destruction" label_settings = ExtResource("6_q3oua") autowrap_mode = 2 @@ -338,7 +337,6 @@ unique_name_in_owner = true custom_minimum_size = Vector2(800, 200) layout_mode = 2 size_flags_horizontal = 0 -text = "Raises ATK" label_settings = SubResource("LabelSettings_mundu") autowrap_mode = 2 diff --git a/src/items/accessory/Accessory.cs b/src/items/accessory/Accessory.cs index 8b2d6362..b07fa172 100644 --- a/src/items/accessory/Accessory.cs +++ b/src/items/accessory/Accessory.cs @@ -18,7 +18,7 @@ public partial class Accessory : Node3D, IInventoryItem, IEquipable public InventoryItemInfo Info => AccessoryInfo; [Export] - public AccessoryInfo AccessoryInfo { get; set; } + public AccessoryInfo AccessoryInfo { get; set; } = new AccessoryInfo(); [Node] public Sprite3D Sprite { get; set; } = default!; diff --git a/src/items/accessory/AccessoryInfo.cs b/src/items/accessory/AccessoryInfo.cs index 2f2f51ff..ce7bdafd 100644 --- a/src/items/accessory/AccessoryInfo.cs +++ b/src/items/accessory/AccessoryInfo.cs @@ -7,19 +7,19 @@ namespace GameJamDungeon; public partial class AccessoryInfo : InventoryItemInfo { [Export] - public int ATKUp { get; set; } + public int ATKUp { get; set; } = 0; [Export] - public int DEFUp { get; set; } + public int DEFUp { get; set; } = 0; [Export] - public double LUCKUp { get; set; } + public double LUCKUp { get; set; } = 0; [Export] - public int MaxHPUp { get; set; } + public int MaxHPUp { get; set; } = 0; [Export] - public int MaxVTUp { get; set; } + public int MaxVTUp { get; set; } = 0; [Export] public Godot.Collections.Array AccessoryTags { get; set; } = new Godot.Collections.Array(); diff --git a/src/items/throwable/ThrowableItem.cs b/src/items/throwable/ThrowableItem.cs index e8d751e7..d2fdacef 100644 --- a/src/items/throwable/ThrowableItem.cs +++ b/src/items/throwable/ThrowableItem.cs @@ -31,7 +31,6 @@ public partial class ThrowableItem : Node3D, IInventoryItem public void OnReady() { AnimationPlayer.AnimationFinished += OnAnimationFinished; - Hitbox.Damage = 5; Sprite.Texture = ThrowableItemInfo.Texture; Pickup.BodyEntered += OnEntered; } diff --git a/src/items/weapons/Weapon.cs b/src/items/weapons/Weapon.cs index fbc779d4..4fb5671c 100644 --- a/src/items/weapons/Weapon.cs +++ b/src/items/weapons/Weapon.cs @@ -17,7 +17,7 @@ public partial class Weapon : Node3D, IInventoryItem, IEquipable public InventoryItemInfo Info => WeaponInfo; [Export] - public WeaponInfo WeaponInfo { get; set; } = new WeaponInfo() { Damage = 1 }; + public WeaponInfo WeaponInfo { get; set; } = new WeaponInfo(); [Node] public Sprite3D Sprite { get; set; } = default!; diff --git a/src/items/weapons/WeaponInfo.cs b/src/items/weapons/WeaponInfo.cs index 5dff22ef..5176779e 100644 --- a/src/items/weapons/WeaponInfo.cs +++ b/src/items/weapons/WeaponInfo.cs @@ -5,7 +5,7 @@ using Godot; public partial class WeaponInfo : InventoryItemInfo { [Export] - public int Damage { get; set; } = 1; + public int Damage { get; set; } = 0; [Export] public double Luck { get; set; } = 0.05; diff --git a/src/items/weapons/resources/Kubel.tres b/src/items/weapons/resources/Kubel.tres index 13c6af65..aea80075 100644 --- a/src/items/weapons/resources/Kubel.tres +++ b/src/items/weapons/resources/Kubel.tres @@ -13,7 +13,7 @@ AeolicDamageBonus = 0.0 BaseHydricDamageBonus = 0.0 IgneousDamageBonus = 0.0 FerrumDamageBonus = 0.0 -WeaponTags = [] +WeaponTags = [0] Name = "Kubel" Description = "+9 ATK A very powerful spear. diff --git a/src/player/Player.cs b/src/player/Player.cs index 4f711c00..74d5241d 100644 --- a/src/player/Player.cs +++ b/src/player/Player.cs @@ -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 _currentHP { get; set; } = default!; - - private AutoProp _currentVT { get; set; } = default!; - public void Initialize() { AnimationPlayer.AnimationFinished += OnAnimationFinished; @@ -100,11 +98,6 @@ namespace GameJamDungeon GameRepo.SetPlayerStatInfo(PlayerStatInfo); - _currentHP = new AutoProp(PlayerStatInfo.MaximumHP); - _currentVT = new AutoProp(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(); 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; } } } diff --git a/src/player/Player.tscn b/src/player/Player.tscn index ee1724b1..c0640cd7 100644 --- a/src/player/Player.tscn +++ b/src/player/Player.tscn @@ -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" diff --git a/src/player/PlayerStatInfo.cs b/src/player/PlayerStatInfo.cs index 3305bbf3..341959b5 100644 --- a/src/player/PlayerStatInfo.cs +++ b/src/player/PlayerStatInfo.cs @@ -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 _currentHP = new AutoProp(0); private readonly AutoProp _maximumHP = new AutoProp(0); @@ -64,5 +67,7 @@ namespace GameJamDungeon private readonly AutoProp _bonusAttack = new AutoProp(0); private readonly AutoProp _bonusDefense = new AutoProp(0); + + private readonly AutoProp _luck = new AutoProp(0.0); } } diff --git a/src/system/stats/DamageCalculator.cs b/src/system/stats/DamageCalculator.cs index c0e06325..aa01ad71 100644 --- a/src/system/stats/DamageCalculator.cs +++ b/src/system/stats/DamageCalculator.cs @@ -4,9 +4,9 @@ namespace GameJamDungeon { public static class DamageCalculator { - public static double CalculatePlayerDamage(int attackDamage, PlayerStatInfo playerStatInfo, EnemyStatInfo enemyStatInfo, WeaponInfo weapon, bool isCriticalHit) + public static double CalculatePlayerDamage(PlayerStatInfo playerStatInfo, EnemyStatInfo enemyStatInfo, WeaponInfo weapon, bool isCriticalHit) { - var baseDamage = attackDamage + playerStatInfo.CurrentAttack; + var baseDamage = playerStatInfo.CurrentAttack + playerStatInfo.BonusAttack; var hydricResistance = enemyStatInfo.HydricResistance; var igneousResistance = enemyStatInfo.IgneousResistance; var telluricResistance = enemyStatInfo.TelluricResistance; @@ -36,9 +36,9 @@ namespace GameJamDungeon return calculatedDamage; } - public static double CalculateEnemyDamage(int attackDamage, PlayerStatInfo playerStatInfo, EnemyStatInfo enemyStatInfo, ArmorInfo armor, bool isCriticalHit) + public static double CalculateEnemyDamage(PlayerStatInfo playerStatInfo, EnemyStatInfo enemyStatInfo, ArmorInfo armor, bool isCriticalHit) { - var baseDamage = attackDamage + enemyStatInfo.CurrentAttack; + var baseDamage = enemyStatInfo.CurrentAttack; var elementADamage = (enemyStatInfo.BaseHydricDamageBonus > 0 ? enemyStatInfo.BaseHydricDamageBonus - armor.HydricResistance : 0) / 100; var elementBDamage = (enemyStatInfo.IgneousDamageBonus > 0 ? enemyStatInfo.IgneousDamageBonus - armor.IgneousResistance : 0) / 100; var elementCDamage = (enemyStatInfo.TelluricDamageBonus > 0 ? enemyStatInfo.TelluricDamageBonus - armor.TelluricResistance : 0) / 100; diff --git a/src/system/stats/ICharacterStats.cs b/src/system/stats/ICharacterStats.cs index 0685555f..312b2931 100644 --- a/src/system/stats/ICharacterStats.cs +++ b/src/system/stats/ICharacterStats.cs @@ -13,5 +13,7 @@ public int MaxAttack { get; } public int MaxDefense { get; } + + public double Luck { get; } } }