From d692d5c70503646b59ffa0c1816581a5fba137eb Mon Sep 17 00:00:00 2001 From: Zenny Date: Tue, 7 Oct 2025 01:02:04 -0700 Subject: [PATCH] Disable VT timer by default --- .../Player/IPlayer.cs | 2 + Zennysoft.Game.Ma/src/player/Player.cs | 691 +++++++++--------- Zennysoft.Game.Ma/src/player/Player.tscn | 1 - 3 files changed, 353 insertions(+), 341 deletions(-) diff --git a/Zennysoft.Game.Ma.Implementation/Player/IPlayer.cs b/Zennysoft.Game.Ma.Implementation/Player/IPlayer.cs index 7fee19a1..62b732cb 100644 --- a/Zennysoft.Game.Ma.Implementation/Player/IPlayer.cs +++ b/Zennysoft.Game.Ma.Implementation/Player/IPlayer.cs @@ -44,6 +44,8 @@ public interface IPlayer : IKillable public void ModifyBonusLuck(double amount); + public void SetHealthTimerStatus(bool isActive); + public IInventory Inventory { get; } public PlayerStats Stats { get; } diff --git a/Zennysoft.Game.Ma/src/player/Player.cs b/Zennysoft.Game.Ma/src/player/Player.cs index ad148824..afb9feaf 100644 --- a/Zennysoft.Game.Ma/src/player/Player.cs +++ b/Zennysoft.Game.Ma/src/player/Player.cs @@ -62,6 +62,9 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide(Lifestyle.Singleton); - //container.Verify(); + var container = new SimpleInjector.Container(); + container.Register(Lifestyle.Singleton); + //container.Verify(); - PlayerLogic = container.GetInstance(); - PlayerLogic.Set(this as IPlayer); - PlayerLogic.Set(Settings); - PlayerLogic.Set(Stats); - PlayerLogic.Set(_gameRepo); + PlayerLogic = container.GetInstance(); + PlayerLogic.Set(this as IPlayer); + PlayerLogic.Set(Settings); + PlayerLogic.Set(Stats); + PlayerLogic.Set(_gameRepo); - _damageCalculator = new DamageCalculator(); + _damageCalculator = new DamageCalculator(); - Hitbox.AreaEntered += Hitbox_AreaEntered; - CollisionDetector.AreaEntered += CollisionDetector_AreaEntered; - AnimationPlayer.AnimationFinished += OnAnimationFinished; + Hitbox.AreaEntered += Hitbox_AreaEntered; + CollisionDetector.AreaEntered += CollisionDetector_AreaEntered; + AnimationPlayer.AnimationFinished += OnAnimationFinished; } public void OnResolved() { - Settings = new PlayerLogic.Settings() { RotationSpeed = _playerStatResource.RotationSpeed, MoveSpeed = _playerStatResource.MoveSpeed, Acceleration = _playerStatResource.Acceleration }; + Settings = new PlayerLogic.Settings() { RotationSpeed = _playerStatResource.RotationSpeed, MoveSpeed = _playerStatResource.MoveSpeed, Acceleration = _playerStatResource.Acceleration }; - PlayerChunk = new SaveChunk( - onSave: (chunk) => new PlayerData() - { - PlayerStats = Stats, - Inventory = Inventory - }, - onLoad: (chunk, data) => - { - Stats = new PlayerStats( - data.PlayerStats.CurrentHP, - data.PlayerStats.MaximumHP, - data.PlayerStats.CurrentVT, - data.PlayerStats.MaximumVT, - data.PlayerStats.CurrentAttack, - data.PlayerStats.BonusAttack, - data.PlayerStats.MaxAttack, - data.PlayerStats.CurrentDefense, - data.PlayerStats.BonusDefense, - data.PlayerStats.MaxDefense, - data.PlayerStats.CurrentExp, - data.PlayerStats.CurrentLevel, - data.PlayerStats.ExpToNextLevel, - data.PlayerStats.Luck); - Inventory = data.Inventory; - } - ); + PlayerChunk = new SaveChunk( + onSave: (chunk) => new PlayerData() + { + PlayerStats = Stats, + Inventory = Inventory + }, + onLoad: (chunk, data) => + { + Stats = new PlayerStats( + data.PlayerStats.CurrentHP, + data.PlayerStats.MaximumHP, + data.PlayerStats.CurrentVT, + data.PlayerStats.MaximumVT, + data.PlayerStats.CurrentAttack, + data.PlayerStats.BonusAttack, + data.PlayerStats.MaxAttack, + data.PlayerStats.CurrentDefense, + data.PlayerStats.BonusDefense, + data.PlayerStats.MaxDefense, + data.PlayerStats.CurrentExp, + data.PlayerStats.CurrentLevel, + data.PlayerStats.ExpToNextLevel, + data.PlayerStats.Luck); + Inventory = data.Inventory; + } + ); - PlayerBinding = PlayerLogic.Bind(); + PlayerBinding = PlayerLogic.Bind(); - PlayerBinding - .Handle((in PlayerLogic.Output.Animations.Attack output) => - { - if (PlayerIsHittingGeometry()) - { - AnimationPlayer.Play("hit_wall"); - _gameRepo.OnPlayerAttackedWall(); - } - else - { - PlayAttackAnimation(); - } - }) - .Handle((in PlayerLogic.Output.ThrowItem output) => - { - }) - .Handle((in PlayerLogic.Output.Move output) => - { - Move(output.delta); - }); + PlayerBinding + .Handle((in PlayerLogic.Output.Animations.Attack output) => + { + if (PlayerIsHittingGeometry()) + { + AnimationPlayer.Play("hit_wall"); + _gameRepo.OnPlayerAttackedWall(); + } + else + { + PlayAttackAnimation(); + } + }) + .Handle((in PlayerLogic.Output.ThrowItem output) => + { + }) + .Handle((in PlayerLogic.Output.Move output) => + { + Move(output.delta); + }); - GameChunk.AddChunk(PlayerChunk); + GameChunk.AddChunk(PlayerChunk); - PlayerLogic.Start(); - this.Provide(); + PlayerLogic.Start(); + this.Provide(); - SetProcessInput(false); - SetPhysicsProcess(false); + SetProcessInput(false); + SetPhysicsProcess(false); } public void OnReady() { - SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2; + SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2; } #endregion public void Activate() { - SetProcessInput(true); - SetPhysicsProcess(true); - HealthTimer.Start(); + SetProcessInput(true); + SetPhysicsProcess(true); + SetHealthTimerStatus(HealthTimerIsActive); } public void Deactivate() { - SetProcessInput(false); - SetPhysicsProcess(false); - HealthTimer.Stop(); + SetProcessInput(false); + SetPhysicsProcess(false); + SetHealthTimerStatus(false); } public void Attack() { - PlayerLogic.Input(new PlayerLogic.Input.Attack()); + PlayerLogic.Input(new PlayerLogic.Input.Attack()); } public void RaiseHP(int amountToRaise) { - Stats.SetMaximumHP(Stats.MaximumHP.Value + amountToRaise); - Stats.SetCurrentHP(Stats.MaximumHP.Value); - _gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXHP Up."); + Stats.SetMaximumHP(Stats.MaximumHP.Value + amountToRaise); + Stats.SetCurrentHP(Stats.MaximumHP.Value); + _gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXHP Up."); } public void HealHP(int amountToRestore) { - Stats.SetCurrentHP(Stats.CurrentHP.Value + amountToRestore); - var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}"; - _gameRepo.AnnounceMessageInInventory($"{raiseString}HP Restored."); + Stats.SetCurrentHP(Stats.CurrentHP.Value + amountToRestore); + var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}"; + _gameRepo.AnnounceMessageInInventory($"{raiseString}HP Restored."); } public void RaiseVT(int amountToRaise) { - if (Stats.CurrentVT == Stats.MaximumVT) - { - Stats.SetMaximumVT(Stats.MaximumVT.Value + amountToRaise); - Stats.SetCurrentVT(Stats.MaximumVT.Value); - _gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXVT Up."); - } + if (Stats.CurrentVT == Stats.MaximumVT) + { + Stats.SetMaximumVT(Stats.MaximumVT.Value + amountToRaise); + Stats.SetCurrentVT(Stats.MaximumVT.Value); + _gameRepo.AnnounceMessageInInventory($"{amountToRaise}MAXVT Up."); + } } public void HealVT(int amountToRestore) { - Stats.SetCurrentVT(Stats.CurrentVT.Value + amountToRestore); - var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}"; - _gameRepo.AnnounceMessageInInventory($"{raiseString}VT Restored."); + Stats.SetCurrentVT(Stats.CurrentVT.Value + amountToRestore); + var raiseString = amountToRestore == 1000 ? "MAX" : $"{amountToRestore}"; + _gameRepo.AnnounceMessageInInventory($"{raiseString}VT Restored."); } public void ModifyBonusAttack(int amount) { - Stats.SetBonusAttack(Stats.BonusAttack.Value + amount); + Stats.SetBonusAttack(Stats.BonusAttack.Value + amount); } public void ModifyBonusDefense(int amount) { - Stats.SetBonusDefense(Stats.BonusDefense.Value + amount); + Stats.SetBonusDefense(Stats.BonusDefense.Value + amount); } public void ModifyMaximumHP(int amount) { - Stats.SetMaximumHP(Stats.MaximumHP.Value + amount); + Stats.SetMaximumHP(Stats.MaximumHP.Value + amount); } public void ModifyMaximumVT(int amount) { - Stats.SetMaximumVT(Stats.MaximumVT.Value + amount); + Stats.SetMaximumVT(Stats.MaximumVT.Value + amount); } public void ModifyBonusLuck(double amount) { - Stats.SetLuck(Stats.Luck.Value + amount); + Stats.SetLuck(Stats.Luck.Value + amount); + } + + public void SetHealthTimerStatus(bool isActive) + { + if (isActive) + HealthTimer.Start(); + else + HealthTimer.Stop(); } public void Move(float delta) { - var rawInput = GlobalInputVector; - var strafeLeftInput = LeftStrafeInputVector; - var strafeRightInput = RightStrafeInputVector; + var rawInput = GlobalInputVector; + var strafeLeftInput = LeftStrafeInputVector; + var strafeRightInput = RightStrafeInputVector; - var transform = Transform; - transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis; - var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized(); - var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration; - _knockbackStrength *= 0.9f; - Transform = Transform with { Basis = transform.Basis }; - Velocity = velocity + (_knockbackDirection * _knockbackStrength); - MoveAndSlide(); + var transform = Transform; + transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis; + var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized(); + var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration; + _knockbackStrength *= 0.9f; + Transform = Transform with { Basis = transform.Basis }; + Velocity = velocity + (_knockbackDirection * _knockbackStrength); + MoveAndSlide(); } public void TeleportPlayer(Transform3D newTransform) { - Transform = newTransform; + Transform = newTransform; } public void TakeDamage(double damage, ElementType elementType, bool isCriticalHit = false) { - if (Stats.CurrentHP.Value > 0) - { - _damageCalculator.CalculateDamage(damage, elementType, Stats.CurrentDefense.Value + Stats.BonusDefense.Value, ((Armor)_equippedArmor.Value).Stats.ElementalResistanceSet); - Stats.SetCurrentHP(Stats.CurrentHP.Value - (int)damage); - } + if (Stats.CurrentHP.Value > 0) + { + _damageCalculator.CalculateDamage(damage, elementType, Stats.CurrentDefense.Value + Stats.BonusDefense.Value, ((Armor)_equippedArmor.Value).Stats.ElementalResistanceSet); + Stats.SetCurrentHP(Stats.CurrentHP.Value - (int)damage); + } } public void Knockback(float impulse) { - _knockbackStrength = impulse; - _knockbackDirection = GlobalBasis.Z.Normalized(); + _knockbackStrength = impulse; + _knockbackDirection = GlobalBasis.Z.Normalized(); } public void GainExp(double expGained) { - Stats.SetCurrentExp(Stats.CurrentExp.Value + expGained); + Stats.SetCurrentExp(Stats.CurrentExp.Value + expGained); } public void LevelUp() { - var rng = new RandomNumberGenerator(); - rng.Randomize(); - var hpIncrease = rng.RandiRange(3, 6); - Stats.SetMaximumHP(Stats.MaximumHP.Value + hpIncrease); - var nextLevel = Stats.CurrentLevel.Value + 1; - var expToNextLevel = (int)(6.5 * nextLevel + 4.5 * Mathf.Pow(nextLevel, 2) + Mathf.Pow(nextLevel, 3)); - var newCurrentExp = Mathf.Max(Stats.CurrentExp.Value - Stats.ExpToNextLevel.Value, 0); - Stats.SetCurrentLevel(nextLevel); - Stats.SetExpToNextLevel(expToNextLevel); - Stats.SetCurrentExp(newCurrentExp); + var rng = new RandomNumberGenerator(); + rng.Randomize(); + var hpIncrease = rng.RandiRange(3, 6); + Stats.SetMaximumHP(Stats.MaximumHP.Value + hpIncrease); + var nextLevel = Stats.CurrentLevel.Value + 1; + var expToNextLevel = (int)(6.5 * nextLevel + 4.5 * Mathf.Pow(nextLevel, 2) + Mathf.Pow(nextLevel, 3)); + var newCurrentExp = Mathf.Max(Stats.CurrentExp.Value - Stats.ExpToNextLevel.Value, 0); + Stats.SetCurrentLevel(nextLevel); + Stats.SetExpToNextLevel(expToNextLevel); + Stats.SetCurrentExp(newCurrentExp); } public void Die() { - EquippedWeapon.Sync -= EquippedWeapon_Sync; - EquippedArmor.Sync -= EquippedArmor_Sync; - EquippedAccessory.Sync -= EquippedAccessory_Sync; - Stats.CurrentHP.Sync -= CurrentHP_Sync; - Stats.CurrentExp.Sync -= CurrentEXP_Sync; + EquippedWeapon.Sync -= EquippedWeapon_Sync; + EquippedArmor.Sync -= EquippedArmor_Sync; + EquippedAccessory.Sync -= EquippedAccessory_Sync; + Stats.CurrentHP.Sync -= CurrentHP_Sync; + Stats.CurrentExp.Sync -= CurrentEXP_Sync; - HealthTimer.WaitTime = _healthTimerWaitTime; - HealthTimer.Timeout -= OnHealthTimerTimeout; - SwordSlashAnimation.Stop(); - SetProcessInput(false); - SetPhysicsProcess(false); - //Hitbox.AreaEntered -= Hitbox_AreaEntered; - //CollisionDetector.AreaEntered -= CollisionDetector_AreaEntered; - //AnimationPlayer.AnimationFinished -= OnAnimationFinished; + HealthTimer.WaitTime = _healthTimerWaitTime; + HealthTimer.Timeout -= OnHealthTimerTimeout; + SwordSlashAnimation.Stop(); + SetProcessInput(false); + SetPhysicsProcess(false); + //Hitbox.AreaEntered -= Hitbox_AreaEntered; + //CollisionDetector.AreaEntered -= CollisionDetector_AreaEntered; + //AnimationPlayer.AnimationFinished -= OnAnimationFinished; - Game.GameOver(); + Game.GameOver(); } public override void _Input(InputEvent @event) { - if (@event.IsActionPressed(GameInputs.Attack)) - Attack(); - if (@event.IsActionPressed(GameInputs.Sprint)) - Settings.MoveSpeed *= 2; - if (@event.IsActionReleased(GameInputs.Sprint)) - Settings.MoveSpeed /= 2; + if (@event.IsActionPressed(GameInputs.Attack)) + Attack(); + if (@event.IsActionPressed(GameInputs.Sprint)) + Settings.MoveSpeed *= 2; + if (@event.IsActionReleased(GameInputs.Sprint)) + Settings.MoveSpeed /= 2; } public void OnPhysicsProcess(double delta) { - PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta)); - PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform)); + PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta)); + PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform)); } public void Equip(EquipableItem equipable) { - if (equipable.ItemTag == ItemTag.MysteryItem) - { - var rerolledItem = Game.RerollItem(equipable) as EquipableItem; - Equip(rerolledItem); - return; - } + if (equipable.ItemTag == ItemTag.MysteryItem) + { + var rerolledItem = Game.RerollItem(equipable) as EquipableItem; + Equip(rerolledItem); + return; + } - if (equipable is Weapon weapon) - { - Unequip(_equippedWeapon.Value); - weapon.IsEquipped = true; - _equippedWeapon.OnNext(weapon); - } - else if (equipable is Armor armor) - { - Unequip(_equippedArmor.Value); - armor.IsEquipped = true; - _equippedArmor.OnNext(armor); - } - else if (equipable is Accessory accessory) - { - Unequip(_equippedAccessory.Value); - accessory.IsEquipped = true; - _equippedAccessory.OnNext(accessory); - } - else - throw new NotImplementedException("Item type is not supported."); + if (equipable is Weapon weapon) + { + Unequip(_equippedWeapon.Value); + weapon.IsEquipped = true; + _equippedWeapon.OnNext(weapon); + } + else if (equipable is Armor armor) + { + Unequip(_equippedArmor.Value); + armor.IsEquipped = true; + _equippedArmor.OnNext(armor); + } + else if (equipable is Accessory accessory) + { + Unequip(_equippedAccessory.Value); + accessory.IsEquipped = true; + _equippedAccessory.OnNext(accessory); + } + else + throw new NotImplementedException("Item type is not supported."); } public void Unequip(EquipableItem equipable) { - if (equipable is Weapon weapon) - { - weapon.IsEquipped = false; - ModifyBonusAttack(-weapon.Damage); - _equippedWeapon.OnNext(new Weapon()); - } - else if (equipable is Armor armor) - { - armor.IsEquipped = false; - ModifyBonusDefense(-armor.Defense); - _equippedArmor.OnNext(new Armor()); - } - else if (equipable is Accessory accessory) - { - accessory.IsEquipped = false; - ModifyMaximumHP(-accessory.MaxHPUp); - ModifyMaximumVT(-accessory.MaxVTUp); - ModifyBonusAttack(-accessory.ATKUp); - ModifyBonusDefense(-accessory.DEFUp); - ModifyBonusLuck(-accessory.LuckUp); - _equippedAccessory.OnNext(new Accessory()); - } - else - throw new NotImplementedException("Item type is not supported."); + if (equipable is Weapon weapon) + { + weapon.IsEquipped = false; + ModifyBonusAttack(-weapon.Damage); + _equippedWeapon.OnNext(new Weapon()); + } + else if (equipable is Armor armor) + { + armor.IsEquipped = false; + ModifyBonusDefense(-armor.Defense); + _equippedArmor.OnNext(new Armor()); + } + else if (equipable is Accessory accessory) + { + accessory.IsEquipped = false; + ModifyMaximumHP(-accessory.MaxHPUp); + ModifyMaximumVT(-accessory.MaxVTUp); + ModifyBonusAttack(-accessory.ATKUp); + ModifyBonusDefense(-accessory.DEFUp); + ModifyBonusLuck(-accessory.LuckUp); + _equippedAccessory.OnNext(new Accessory()); + } + else + throw new NotImplementedException("Item type is not supported."); } private static Vector3 GlobalInputVector { - get - { - var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown); - var input = new Vector3 - { - X = rawInput.X, - Z = rawInput.Y - }; - return input with { Y = 0f }; - } + get + { + var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown); + var input = new Vector3 + { + X = rawInput.X, + Z = rawInput.Y + }; + return input with { Y = 0f }; + } } private static float LeftStrafeInputVector { - get - { - return Input.GetActionStrength(GameInputs.StrafeLeft); - } + get + { + return Input.GetActionStrength(GameInputs.StrafeLeft); + } } private static float RightStrafeInputVector { - get - { - return Input.GetActionStrength(GameInputs.StrafeRight); - } + get + { + return Input.GetActionStrength(GameInputs.StrafeRight); + } } private void ThrowItem() { - var itemScene = GD.Load("res://src/items/throwable/ThrowableItem.tscn"); - var throwItem = itemScene.Instantiate(); - GetTree().Root.AddChildEx(throwItem); - throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0); - throwItem.GlobalRotation = GlobalRotation; + var itemScene = GD.Load("res://src/items/throwable/ThrowableItem.tscn"); + var throwItem = itemScene.Instantiate(); + GetTree().Root.AddChildEx(throwItem); + throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0); + throwItem.GlobalRotation = GlobalRotation; } private void PlayAttackAnimation() { - var attackSpeed = ((Weapon)EquippedWeapon.Value).AttackSpeed; - AnimationPlayer.SetSpeedScale((float)attackSpeed); - if (EquippedWeapon.Value.ItemName == "Atonement") - AnimationPlayer.Play("atonement_attack"); - else - AnimationPlayer.Play("attack"); - _gameRepo.OnPlayerAttack(); + var attackSpeed = ((Weapon)EquippedWeapon.Value).AttackSpeed; + AnimationPlayer.SetSpeedScale((float)attackSpeed); + if (EquippedWeapon.Value.ItemName == "Atonement") + AnimationPlayer.Play("atonement_attack"); + else + AnimationPlayer.Play("attack"); + _gameRepo.OnPlayerAttack(); } private void OnAnimationFinished(StringName animation) { - PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished()); + PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished()); } private void OnExitTree() { - PlayerLogic.Stop(); - PlayerBinding.Dispose(); - AnimationPlayer.AnimationFinished -= OnAnimationFinished; + PlayerLogic.Stop(); + PlayerBinding.Dispose(); + AnimationPlayer.AnimationFinished -= OnAnimationFinished; } private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition; private void OnHealthTimerTimeout() { - if (Stats.CurrentHP.Value <= 0) - return; + if (Stats.CurrentHP.Value <= 0) + return; - if (Stats.CurrentVT.Value > 0) - { - if (((Accessory)EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption) - { - reduceOnTick = !reduceOnTick; - } - Stats.SetCurrentHP(Stats.CurrentHP.Value + 1); - if (reduceOnTick) - Stats.SetCurrentVT(Stats.CurrentVT.Value - 1); - } - else - Stats.SetCurrentHP(Stats.CurrentHP.Value - 1); + if (Stats.CurrentVT.Value > 0) + { + if (((Accessory)EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption) + { + reduceOnTick = !reduceOnTick; + } + Stats.SetCurrentHP(Stats.CurrentHP.Value + 1); + if (reduceOnTick) + Stats.SetCurrentVT(Stats.CurrentVT.Value - 1); + } + else + Stats.SetCurrentHP(Stats.CurrentHP.Value - 1); } private void EquippedWeapon_Sync(EquipableItem obj) { - ModifyBonusAttack(((Weapon)obj).Damage); + ModifyBonusAttack(((Weapon)obj).Damage); } private void EquippedArmor_Sync(EquipableItem obj) { - ModifyBonusDefense(((Armor)obj).Defense); + ModifyBonusDefense(((Armor)obj).Defense); } private void EquippedAccessory_Sync(EquipableItem accessory) { - ModifyMaximumHP(((Accessory)accessory).MaxHPUp); - ModifyMaximumVT(((Accessory)accessory).MaxVTUp); - ModifyBonusAttack(((Accessory)accessory).ATKUp); - ModifyBonusDefense(((Accessory)accessory).DEFUp); - ModifyBonusLuck(((Accessory)accessory).LuckUp); + ModifyMaximumHP(((Accessory)accessory).MaxHPUp); + ModifyMaximumVT(((Accessory)accessory).MaxVTUp); + ModifyBonusAttack(((Accessory)accessory).ATKUp); + ModifyBonusDefense(((Accessory)accessory).DEFUp); + ModifyBonusLuck(((Accessory)accessory).LuckUp); } private void CurrentHP_Sync(int newHealth) { - if (newHealth <= 0) - Die(); + if (newHealth <= 0) + Die(); } private void CurrentEXP_Sync(double newExp) { - if (Stats.CurrentExp.Value >= Stats.ExpToNextLevel.Value) - LevelUp(); + if (Stats.CurrentExp.Value >= Stats.ExpToNextLevel.Value) + LevelUp(); } private void Hitbox_AreaEntered(Area3D area) { - var target = area.GetOwner(); - if (target is IEnemy enemy) - HitEnemy(enemy); + var target = area.GetOwner(); + if (target is IEnemy enemy) + HitEnemy(enemy); } private void HitEnemy(IEnemy enemy) { - var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value; - var ignoreElementalResistance = ((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.IgnoreAffinity; - var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value); - var element = ((Weapon)EquippedWeapon.Value).WeaponElement; + var attackValue = Stats.CurrentAttack.Value + Stats.BonusAttack.Value; + var ignoreElementalResistance = ((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.IgnoreAffinity; + var isCriticalHit = BattleExtensions.IsCriticalHit(Stats.Luck.Value); + var element = ((Weapon)EquippedWeapon.Value).WeaponElement; - enemy.TakeDamage( - attackValue * ((Weapon)EquippedWeapon.Value).ElementalDamageBonus, - element, - isCriticalHit, - false, - ignoreElementalResistance); + enemy.TakeDamage( + attackValue * ((Weapon)EquippedWeapon.Value).ElementalDamageBonus, + element, + isCriticalHit, + false, + ignoreElementalResistance); - if (((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback) - enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized()); + if (((Weapon)EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback) + enemy.Knockback(0.3f, -CurrentBasis.Z.Normalized()); - _gameRepo.OnPlayerAttackedEnemy(); + _gameRepo.OnPlayerAttackedEnemy(); } private void CollisionDetector_AreaEntered(Area3D area) { - if (area.GetParent() is InventoryItem inventoryItem) - { - var isAdded = Inventory.TryAdd(inventoryItem); - if (isAdded) - { - _gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up."); - inventoryItem.QueueFree(); - } - else - _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}."); - } - if (area.GetParent() is DroppedItem droppedItem) - { - var isAdded = Inventory.TryAdd(droppedItem.Item); - if (isAdded) - { - _gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up."); - droppedItem.QueueFree(); - } - else - _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}."); - } - if (area.GetParent() is ThrownItem thrownItem) - { - var isAdded = Inventory.TryAdd(thrownItem.ItemThatIsThrown); - if (isAdded) - { - _gameRepo.AnnounceMessageOnMainScreen($"{thrownItem.ItemThatIsThrown.ItemName} picked up."); - thrownItem.QueueFree(); - } - else - _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {thrownItem.ItemThatIsThrown.ItemName}."); - } - if (area.GetParent() is Restorative restorative) - { - _gameRepo.OnRestorativePickedUp(restorative); - restorative.QueueFree(); - } + if (area.GetParent() is InventoryItem inventoryItem) + { + var isAdded = Inventory.TryAdd(inventoryItem); + if (isAdded) + { + _gameRepo.AnnounceMessageOnMainScreen($"{inventoryItem.ItemName} picked up."); + inventoryItem.QueueFree(); + } + else + _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {inventoryItem.ItemName}."); + } + if (area.GetParent() is DroppedItem droppedItem) + { + var isAdded = Inventory.TryAdd(droppedItem.Item); + if (isAdded) + { + _gameRepo.AnnounceMessageOnMainScreen($"{droppedItem.Item.ItemName} picked up."); + droppedItem.QueueFree(); + } + else + _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {droppedItem.Item.ItemName}."); + } + if (area.GetParent() is ThrownItem thrownItem) + { + var isAdded = Inventory.TryAdd(thrownItem.ItemThatIsThrown); + if (isAdded) + { + _gameRepo.AnnounceMessageOnMainScreen($"{thrownItem.ItemThatIsThrown.ItemName} picked up."); + thrownItem.QueueFree(); + } + else + _gameRepo.AnnounceMessageOnMainScreen($"Could not pick up {thrownItem.ItemThatIsThrown.ItemName}."); + } + if (area.GetParent() is Restorative restorative) + { + _gameRepo.OnRestorativePickedUp(restorative); + restorative.QueueFree(); + } } private PlayerStats InitializePlayerStats() { - var playerStats = new PlayerStats( - currentHP: new AutoProp(_playerStatResource.CurrentHP), - maximumHP: new AutoProp(_playerStatResource.MaximumHP), - currentVT: new AutoProp(_playerStatResource.CurrentVT), - maximumVT: new AutoProp(_playerStatResource.MaximumVT), - currentAttack: new AutoProp(_playerStatResource.CurrentAttack), - currentDefense: new AutoProp(_playerStatResource.CurrentDefense), - maxAttack: new AutoProp(_playerStatResource.MaxAttack), - maxDefense: new AutoProp(_playerStatResource.MaxDefense), - bonusAttack: new AutoProp(_playerStatResource.BonusAttack), - bonusDefense: new AutoProp(_playerStatResource.BonusDefense), - currentExp: new AutoProp(_playerStatResource.CurrentExp), - expToNextLevel: new AutoProp(_playerStatResource.ExpToNextLevel), - currentLevel: new AutoProp(_playerStatResource.CurrentLevel), - luck: new AutoProp(_playerStatResource.Luck)); + var playerStats = new PlayerStats( + currentHP: new AutoProp(_playerStatResource.CurrentHP), + maximumHP: new AutoProp(_playerStatResource.MaximumHP), + currentVT: new AutoProp(_playerStatResource.CurrentVT), + maximumVT: new AutoProp(_playerStatResource.MaximumVT), + currentAttack: new AutoProp(_playerStatResource.CurrentAttack), + currentDefense: new AutoProp(_playerStatResource.CurrentDefense), + maxAttack: new AutoProp(_playerStatResource.MaxAttack), + maxDefense: new AutoProp(_playerStatResource.MaxDefense), + bonusAttack: new AutoProp(_playerStatResource.BonusAttack), + bonusDefense: new AutoProp(_playerStatResource.BonusDefense), + currentExp: new AutoProp(_playerStatResource.CurrentExp), + expToNextLevel: new AutoProp(_playerStatResource.ExpToNextLevel), + currentLevel: new AutoProp(_playerStatResource.CurrentLevel), + luck: new AutoProp(_playerStatResource.Luck)); - return playerStats; + return playerStats; } private bool PlayerIsHittingGeometry() { - var collisions = WallCheck.GetCollidingBodies(); - return collisions.Count > 0; + var collisions = WallCheck.GetCollidingBodies(); + return collisions.Count > 0; } private void WallCheck_BodyEntered(Node body) { - PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished()); - GD.Print("Hit wall"); - AnimationPlayer.Stop(); + PlayerLogic.Input(new PlayerLogic.Input.AttackAnimationFinished()); + GD.Print("Hit wall"); + AnimationPlayer.Stop(); } } diff --git a/Zennysoft.Game.Ma/src/player/Player.tscn b/Zennysoft.Game.Ma/src/player/Player.tscn index 784b1f22..01c1f9f6 100644 --- a/Zennysoft.Game.Ma/src/player/Player.tscn +++ b/Zennysoft.Game.Ma/src/player/Player.tscn @@ -376,7 +376,6 @@ shape = SubResource("CapsuleShape3D_dw45s") unique_name_in_owner = true process_mode = 1 wait_time = 3.0 -autostart = true [node name="Animation" type="Node3D" parent="."]