Play test animation
This commit is contained in:
@@ -40,6 +40,8 @@ public interface IPlayer : IKillable, ICharacterBody3D
|
|||||||
|
|
||||||
public IEquipmentComponent EquipmentComponent { get; }
|
public IEquipmentComponent EquipmentComponent { get; }
|
||||||
|
|
||||||
|
public void PlayTestAnimation();
|
||||||
|
|
||||||
public event Action PlayerDied;
|
public event Action PlayerDied;
|
||||||
public delegate InventoryItem RerollItem(InventoryItem item);
|
public delegate InventoryItem RerollItem(InventoryItem item);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -402,6 +402,7 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
private void EnactEffectItemEffects(EffectItem effectItem)
|
private void EnactEffectItemEffects(EffectItem effectItem)
|
||||||
{
|
{
|
||||||
|
_player.PlayTestAnimation();
|
||||||
switch (effectItem.UsableItemTag)
|
switch (effectItem.UsableItemTag)
|
||||||
{
|
{
|
||||||
case UsableItemTag.TeleportAllEnemiesToRoom:
|
case UsableItemTag.TeleportAllEnemiesToRoom:
|
||||||
@@ -450,6 +451,7 @@ public partial class Game : Node3D, IGame
|
|||||||
|
|
||||||
private void EnactThrowableItemEffects(ThrowableItem throwableItem)
|
private void EnactThrowableItemEffects(ThrowableItem throwableItem)
|
||||||
{
|
{
|
||||||
|
_player.PlayTestAnimation();
|
||||||
switch (throwableItem.ThrowableItemTag)
|
switch (throwableItem.ThrowableItemTag)
|
||||||
{
|
{
|
||||||
case ThrowableItemTag.DoubleExp:
|
case ThrowableItemTag.DoubleExp:
|
||||||
|
|||||||
@@ -107,182 +107,187 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
|
|||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
var container = new SimpleInjector.Container();
|
var container = new SimpleInjector.Container();
|
||||||
container.Register<IPlayerLogic, PlayerLogic>(Lifestyle.Singleton);
|
container.Register<IPlayerLogic, PlayerLogic>(Lifestyle.Singleton);
|
||||||
|
|
||||||
PlayerLogic = container.GetInstance<IPlayerLogic>();
|
PlayerLogic = container.GetInstance<IPlayerLogic>();
|
||||||
PlayerLogic.Set(this as IPlayer);
|
PlayerLogic.Set(this as IPlayer);
|
||||||
PlayerLogic.Set(Settings);
|
PlayerLogic.Set(Settings);
|
||||||
|
|
||||||
Inventory = new Inventory();
|
Inventory = new Inventory();
|
||||||
HealthComponent = new HealthComponent(InitialHP);
|
HealthComponent = new HealthComponent(InitialHP);
|
||||||
VTComponent = new VTComponent(InitialVT);
|
VTComponent = new VTComponent(InitialVT);
|
||||||
AttackComponent = new AttackComponent(InitialAttack);
|
AttackComponent = new AttackComponent(InitialAttack);
|
||||||
DefenseComponent = new DefenseComponent(InitialDefense);
|
DefenseComponent = new DefenseComponent(InitialDefense);
|
||||||
ExperiencePointsComponent = new ExperiencePointsComponent();
|
ExperiencePointsComponent = new ExperiencePointsComponent();
|
||||||
LuckComponent = new LuckComponent(InitialLuck);
|
LuckComponent = new LuckComponent(InitialLuck);
|
||||||
EquipmentComponent = new EquipmentComponent();
|
EquipmentComponent = new EquipmentComponent();
|
||||||
|
|
||||||
_itemReroller = new ItemReroller(ItemDatabase.Instance);
|
_itemReroller = new ItemReroller(ItemDatabase.Instance);
|
||||||
|
|
||||||
Settings = new PlayerLogic.Settings() { RotationSpeed = RotationSpeed, MoveSpeed = MoveSpeed, Acceleration = Acceleration };
|
Settings = new PlayerLogic.Settings() { RotationSpeed = RotationSpeed, MoveSpeed = MoveSpeed, Acceleration = Acceleration };
|
||||||
|
|
||||||
PlayerBinding = PlayerLogic.Bind();
|
PlayerBinding = PlayerLogic.Bind();
|
||||||
|
|
||||||
PlayerBinding
|
PlayerBinding
|
||||||
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
.Handle((in PlayerLogic.Output.ThrowItem output) =>
|
||||||
{
|
{
|
||||||
})
|
})
|
||||||
.Handle((in PlayerLogic.Output.Move output) =>
|
.Handle((in PlayerLogic.Output.Move output) =>
|
||||||
{
|
{
|
||||||
Move(output.delta);
|
Move(output.delta);
|
||||||
});
|
});
|
||||||
|
|
||||||
PlayerLogic.Start();
|
PlayerLogic.Start();
|
||||||
this.Provide();
|
this.Provide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetPlayerData()
|
public void ResetPlayerData()
|
||||||
{
|
{
|
||||||
foreach (var item in Inventory.Items)
|
foreach (var item in Inventory.Items)
|
||||||
Inventory.Remove(item);
|
Inventory.Remove(item);
|
||||||
|
|
||||||
HealthComponent.Reset();
|
HealthComponent.Reset();
|
||||||
VTComponent.Reset();
|
VTComponent.Reset();
|
||||||
AttackComponent.Reset();
|
AttackComponent.Reset();
|
||||||
DefenseComponent.Reset();
|
DefenseComponent.Reset();
|
||||||
ExperiencePointsComponent.Reset();
|
ExperiencePointsComponent.Reset();
|
||||||
LuckComponent.Reset();
|
LuckComponent.Reset();
|
||||||
EquipmentComponent.Reset();
|
EquipmentComponent.Reset();
|
||||||
|
|
||||||
HealthTimer.Timeout += OnHealthTimerTimeout;
|
HealthTimer.Timeout += OnHealthTimerTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Initialization
|
#region Initialization
|
||||||
public void OnReady()
|
public void OnReady()
|
||||||
{
|
{
|
||||||
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
Hitbox.AreaEntered += Hitbox_AreaEntered;
|
||||||
CollisionDetector.AreaEntered += CollisionDetector_AreaEntered;
|
CollisionDetector.AreaEntered += CollisionDetector_AreaEntered;
|
||||||
HealthComponent.HealthReachedZero += Die;
|
HealthComponent.HealthReachedZero += Die;
|
||||||
HealthTimer.WaitTime = _healthTimerWaitTime;
|
HealthTimer.WaitTime = _healthTimerWaitTime;
|
||||||
SetProcessInput(false);
|
SetProcessInput(false);
|
||||||
SetPhysicsProcess(false);
|
SetPhysicsProcess(false);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void Activate()
|
public void Activate()
|
||||||
{
|
{
|
||||||
SetProcessInput(true);
|
SetProcessInput(true);
|
||||||
SetPhysicsProcess(true);
|
SetPhysicsProcess(true);
|
||||||
SetHealthTimerStatus(HealthTimerIsActive);
|
SetHealthTimerStatus(HealthTimerIsActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Deactivate()
|
public void Deactivate()
|
||||||
{
|
{
|
||||||
Velocity = Vector3.Zero;
|
Velocity = Vector3.Zero;
|
||||||
SetProcessInput(false);
|
SetProcessInput(false);
|
||||||
SetPhysicsProcess(false);
|
SetPhysicsProcess(false);
|
||||||
SetHealthTimerStatus(false);
|
SetHealthTimerStatus(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetHealthTimerStatus(bool isActive)
|
private void SetHealthTimerStatus(bool isActive)
|
||||||
{
|
{
|
||||||
if (isActive)
|
if (isActive)
|
||||||
HealthTimer.Start();
|
HealthTimer.Start();
|
||||||
else
|
else
|
||||||
HealthTimer.Stop();
|
HealthTimer.Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TeleportPlayer(Transform3D newTransform)
|
public void TeleportPlayer(Transform3D newTransform)
|
||||||
{
|
{
|
||||||
Transform = newTransform;
|
Transform = newTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TakeDamage(AttackData damage)
|
public void TakeDamage(AttackData damage)
|
||||||
{
|
{
|
||||||
_camera3D.AddShake(1.0f);
|
_camera3D.AddShake(1.0f);
|
||||||
TakeDamageAnimationPlayer.Play("take_damage");
|
TakeDamageAnimationPlayer.Play("take_damage");
|
||||||
var damageReceived = DamageCalculator.CalculateDamage(damage, DefenseComponent.CurrentDefense.Value + EquipmentComponent.BonusDefense, EquipmentComponent.ElementalResistance);
|
var damageReceived = DamageCalculator.CalculateDamage(damage, DefenseComponent.CurrentDefense.Value + EquipmentComponent.BonusDefense, EquipmentComponent.ElementalResistance);
|
||||||
HealthComponent.Damage(damageReceived);
|
HealthComponent.Damage(damageReceived);
|
||||||
SfxDatabase.Instance.Play(SoundEffect.TakeDamage);
|
SfxDatabase.Instance.Play(SoundEffect.TakeDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Knockback(float impulse)
|
public void Knockback(float impulse)
|
||||||
{
|
{
|
||||||
_knockbackStrength = impulse;
|
_knockbackStrength = impulse;
|
||||||
_knockbackDirection = GlobalBasis.Z.Normalized();
|
_knockbackDirection = GlobalBasis.Z.Normalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LevelUp()
|
public void LevelUp()
|
||||||
{
|
{
|
||||||
var rng = new RandomNumberGenerator();
|
var rng = new RandomNumberGenerator();
|
||||||
rng.Randomize();
|
rng.Randomize();
|
||||||
var hpIncrease = rng.RandiRange(3, 6);
|
var hpIncrease = rng.RandiRange(3, 6);
|
||||||
HealthComponent.RaiseMaximumHP(hpIncrease);
|
HealthComponent.RaiseMaximumHP(hpIncrease);
|
||||||
ExperiencePointsComponent.LevelUp();
|
ExperiencePointsComponent.LevelUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Die()
|
public void Die()
|
||||||
{
|
{
|
||||||
PlayerFXAnimations.Play("death");
|
PlayerFXAnimations.Play("death");
|
||||||
HealthTimer.WaitTime = _healthTimerWaitTime;
|
HealthTimer.WaitTime = _healthTimerWaitTime;
|
||||||
HealthTimer.Timeout -= OnHealthTimerTimeout;
|
HealthTimer.Timeout -= OnHealthTimerTimeout;
|
||||||
SetProcessInput(false);
|
SetProcessInput(false);
|
||||||
SetPhysicsProcess(false);
|
SetPhysicsProcess(false);
|
||||||
PlayerDied?.Invoke();
|
PlayerDied?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Input(InputEvent @event)
|
public override void _Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
if (@event.IsActionPressed(GameInputs.Attack))
|
if (@event.IsActionPressed(GameInputs.Attack))
|
||||||
Attack();
|
Attack();
|
||||||
if (@event.IsActionPressed(GameInputs.Sprint))
|
if (@event.IsActionPressed(GameInputs.Sprint))
|
||||||
Settings.MoveSpeed *= 2;
|
Settings.MoveSpeed *= 2;
|
||||||
if (@event.IsActionReleased(GameInputs.Sprint))
|
if (@event.IsActionReleased(GameInputs.Sprint))
|
||||||
Settings.MoveSpeed /= 2;
|
Settings.MoveSpeed /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PlayTestAnimation()
|
||||||
|
{
|
||||||
|
PlayerFXAnimations.Play("test_animation");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPhysicsProcess(double delta)
|
public void OnPhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
PlayerLogic.Input(new PlayerLogic.Input.PhysicsTick(delta));
|
||||||
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform));
|
PlayerLogic.Input(new PlayerLogic.Input.Moved(GlobalPosition, GlobalTransform));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Equip(EquipableItem equipable)
|
public void Equip(EquipableItem equipable)
|
||||||
{
|
{
|
||||||
if (equipable.ItemTag == ItemTag.MysteryItem)
|
if (equipable.ItemTag == ItemTag.MysteryItem)
|
||||||
{
|
{
|
||||||
var rerolledItem = _itemReroller.RerollItem(equipable, Inventory);
|
var rerolledItem = _itemReroller.RerollItem(equipable, Inventory);
|
||||||
Equip(rerolledItem);
|
Equip(rerolledItem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HealthComponent.RaiseMaximumHP(equipable.BonusHP, false);
|
HealthComponent.RaiseMaximumHP(equipable.BonusHP, false);
|
||||||
VTComponent.RaiseMaximumVT(equipable.BonusVT, false);
|
VTComponent.RaiseMaximumVT(equipable.BonusVT, false);
|
||||||
|
|
||||||
EquipmentComponent.Equip(equipable);
|
EquipmentComponent.Equip(equipable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Unequip(EquipableItem equipable)
|
public void Unequip(EquipableItem equipable)
|
||||||
{
|
{
|
||||||
HealthComponent.SetMaximumHealth(HealthComponent.MaximumHP.Value - equipable.BonusHP);
|
HealthComponent.SetMaximumHealth(HealthComponent.MaximumHP.Value - equipable.BonusHP);
|
||||||
VTComponent.SetMaximumVT(VTComponent.MaximumVT.Value - equipable.BonusVT);
|
VTComponent.SetMaximumVT(VTComponent.MaximumVT.Value - equipable.BonusVT);
|
||||||
|
|
||||||
EquipmentComponent.Unequip(equipable);
|
EquipmentComponent.Unequip(equipable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Vector3 GlobalInputVector
|
private static Vector3 GlobalInputVector
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
var rawInput = Input.GetVector(GameInputs.MoveLeft, GameInputs.MoveRight, GameInputs.MoveUp, GameInputs.MoveDown);
|
||||||
var input = new Vector3
|
var input = new Vector3
|
||||||
{
|
{
|
||||||
X = rawInput.X,
|
X = rawInput.X,
|
||||||
Z = rawInput.Y
|
Z = rawInput.Y
|
||||||
};
|
};
|
||||||
return input with { Y = 0f };
|
return input with { Y = 0f };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float LeftStrafeInputVector => Input.GetActionStrength(GameInputs.StrafeLeft);
|
private static float LeftStrafeInputVector => Input.GetActionStrength(GameInputs.StrafeLeft);
|
||||||
@@ -291,143 +296,143 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<IPlayer>
|
|||||||
|
|
||||||
private void Attack()
|
private void Attack()
|
||||||
{
|
{
|
||||||
if (PlayerIsHittingGeometry())
|
if (PlayerIsHittingGeometry())
|
||||||
AnimationPlayer.Play("hit_wall");
|
AnimationPlayer.Play("hit_wall");
|
||||||
else if (!AnimationPlayer.IsPlaying())
|
else if (!AnimationPlayer.IsPlaying())
|
||||||
PlayAttackAnimation();
|
PlayAttackAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ThrowItem()
|
private void ThrowItem()
|
||||||
{
|
{
|
||||||
var itemScene = GD.Load<PackedScene>("res://src/items/throwable/ThrowableItem.tscn");
|
var itemScene = GD.Load<PackedScene>("res://src/items/throwable/ThrowableItem.tscn");
|
||||||
var throwItem = itemScene.Instantiate<ThrowableItem>();
|
var throwItem = itemScene.Instantiate<ThrowableItem>();
|
||||||
GetTree().Root.AddChildEx(throwItem);
|
GetTree().Root.AddChildEx(throwItem);
|
||||||
throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0);
|
throwItem.GlobalPosition = CurrentPosition + new Vector3(0, 3.5f, 0);
|
||||||
throwItem.GlobalRotation = GlobalRotation;
|
throwItem.GlobalRotation = GlobalRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlayAttackAnimation()
|
private void PlayAttackAnimation()
|
||||||
{
|
{
|
||||||
SfxDatabase.Instance.Play(((Weapon)EquipmentComponent.EquippedWeapon.Value).SoundEffect);
|
SfxDatabase.Instance.Play(((Weapon)EquipmentComponent.EquippedWeapon.Value).SoundEffect);
|
||||||
var attackSpeed = ((Weapon)EquipmentComponent.EquippedWeapon.Value).AttackSpeed;
|
var attackSpeed = ((Weapon)EquipmentComponent.EquippedWeapon.Value).AttackSpeed;
|
||||||
AnimationPlayer.SetSpeedScale((float)attackSpeed);
|
AnimationPlayer.SetSpeedScale((float)attackSpeed);
|
||||||
AnimationPlayer.Play("attack");
|
AnimationPlayer.Play("attack");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExitTree()
|
private void OnExitTree()
|
||||||
{
|
{
|
||||||
PlayerLogic.Stop();
|
PlayerLogic.Stop();
|
||||||
PlayerBinding.Dispose();
|
PlayerBinding.Dispose();
|
||||||
Hitbox.AreaEntered -= Hitbox_AreaEntered;
|
Hitbox.AreaEntered -= Hitbox_AreaEntered;
|
||||||
CollisionDetector.AreaEntered -= CollisionDetector_AreaEntered;
|
CollisionDetector.AreaEntered -= CollisionDetector_AreaEntered;
|
||||||
HealthComponent.HealthReachedZero -= Die;
|
HealthComponent.HealthReachedZero -= Die;
|
||||||
HealthTimer.Timeout -= OnHealthTimerTimeout;
|
HealthTimer.Timeout -= OnHealthTimerTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Move(float delta)
|
private void Move(float delta)
|
||||||
{
|
{
|
||||||
var rawInput = GlobalInputVector;
|
var rawInput = GlobalInputVector;
|
||||||
var strafeLeftInput = LeftStrafeInputVector;
|
var strafeLeftInput = LeftStrafeInputVector;
|
||||||
var strafeRightInput = RightStrafeInputVector;
|
var strafeRightInput = RightStrafeInputVector;
|
||||||
|
|
||||||
var transform = Transform;
|
var transform = Transform;
|
||||||
transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis;
|
transform.Basis = new Basis(Vector3.Up, Settings.RotationSpeed * -rawInput.X * delta) * transform.Basis;
|
||||||
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized();
|
var moveDirection = new Vector3(strafeRightInput - strafeLeftInput, 0, rawInput.Z).Normalized();
|
||||||
var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration;
|
var velocity = Basis * moveDirection * Settings.MoveSpeed * Settings.Acceleration;
|
||||||
_knockbackStrength *= 0.9f;
|
_knockbackStrength *= 0.9f;
|
||||||
Transform = Transform with { Basis = transform.Basis };
|
Transform = Transform with { Basis = transform.Basis };
|
||||||
Velocity = velocity + (_knockbackDirection * _knockbackStrength);
|
Velocity = velocity + (_knockbackDirection * _knockbackStrength);
|
||||||
if (!WalkSFX.Playing && !Velocity.IsZeroApprox())
|
if (!WalkSFX.Playing && !Velocity.IsZeroApprox())
|
||||||
WalkSFX.Play();
|
WalkSFX.Play();
|
||||||
else if (Velocity.IsZeroApprox())
|
else if (Velocity.IsZeroApprox())
|
||||||
WalkSFX.Stop();
|
WalkSFX.Stop();
|
||||||
MoveAndSlide();
|
MoveAndSlide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||||
|
|
||||||
private void OnHealthTimerTimeout()
|
private void OnHealthTimerTimeout()
|
||||||
{
|
{
|
||||||
if (VTComponent.CurrentVT.Value > 0)
|
if (VTComponent.CurrentVT.Value > 0)
|
||||||
{
|
{
|
||||||
if (((Accessory)EquipmentComponent.EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption)
|
if (((Accessory)EquipmentComponent.EquippedAccessory.Value).AccessoryTag == AccessoryTag.HalfVTConsumption)
|
||||||
reduceOnTick = !reduceOnTick;
|
reduceOnTick = !reduceOnTick;
|
||||||
|
|
||||||
HealthComponent.Heal(1);
|
HealthComponent.Heal(1);
|
||||||
|
|
||||||
if (reduceOnTick)
|
if (reduceOnTick)
|
||||||
VTComponent.Reduce(1);
|
VTComponent.Reduce(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
HealthComponent.Damage(1);
|
HealthComponent.Damage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hitbox_AreaEntered(Area3D area)
|
private void Hitbox_AreaEntered(Area3D area)
|
||||||
{
|
{
|
||||||
var target = area.GetOwner();
|
var target = area.GetOwner();
|
||||||
if (target is IEnemy enemy)
|
if (target is IEnemy enemy)
|
||||||
HitEnemy(enemy);
|
HitEnemy(enemy);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HitEnemy(IEnemy enemy)
|
private void HitEnemy(IEnemy enemy)
|
||||||
{
|
{
|
||||||
var ignoreElementalResistance = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreAffinity;
|
var ignoreElementalResistance = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreAffinity;
|
||||||
var ignoreDefense = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreDefense;
|
var ignoreDefense = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreDefense;
|
||||||
var isCriticalHit = BattleExtensions.IsCriticalHit(LuckComponent.Luck.Value + EquipmentComponent.BonusLuck);
|
var isCriticalHit = BattleExtensions.IsCriticalHit(LuckComponent.Luck.Value + EquipmentComponent.BonusLuck);
|
||||||
var totalDamage = AttackComponent.CurrentAttack.Value + EquipmentComponent.BonusAttack;
|
var totalDamage = AttackComponent.CurrentAttack.Value + EquipmentComponent.BonusAttack;
|
||||||
var element = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponElement;
|
var element = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponElement;
|
||||||
|
|
||||||
if (isCriticalHit)
|
if (isCriticalHit)
|
||||||
{
|
{
|
||||||
totalDamage += (int)(totalDamage * 0.5f);
|
totalDamage += (int)(totalDamage * 0.5f);
|
||||||
SfxDatabase.Instance.Play(SoundEffect.Crit);
|
SfxDatabase.Instance.Play(SoundEffect.Crit);
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseAttack = new AttackData(totalDamage, element, ignoreDefense, ignoreElementalResistance);
|
var baseAttack = new AttackData(totalDamage, element, ignoreDefense, ignoreElementalResistance);
|
||||||
var damageDealt = DamageCalculator.CalculateDamage(baseAttack, enemy.DefenseComponent.CurrentDefense.Value, ElementalResistanceSet.None);
|
var damageDealt = DamageCalculator.CalculateDamage(baseAttack, enemy.DefenseComponent.CurrentDefense.Value, ElementalResistanceSet.None);
|
||||||
enemy.HealthComponent.Damage(damageDealt);
|
enemy.HealthComponent.Damage(damageDealt);
|
||||||
|
|
||||||
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback && enemy is IKnockbackable knockbackable)
|
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback && enemy is IKnockbackable knockbackable)
|
||||||
knockbackable.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
knockbackable.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
||||||
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.SelfDamage)
|
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.SelfDamage)
|
||||||
HealthComponent.Damage(5);
|
HealthComponent.Damage(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CollisionDetector_AreaEntered(Area3D area)
|
private void CollisionDetector_AreaEntered(Area3D area)
|
||||||
{
|
{
|
||||||
if (area.GetParent() is InventoryItem inventoryItem)
|
if (area.GetParent() is InventoryItem inventoryItem)
|
||||||
{
|
{
|
||||||
var isAdded = Inventory.PickUpItem(inventoryItem);
|
var isAdded = Inventory.PickUpItem(inventoryItem);
|
||||||
if (isAdded)
|
if (isAdded)
|
||||||
inventoryItem.QueueFree();
|
inventoryItem.QueueFree();
|
||||||
}
|
}
|
||||||
if (area.GetParent() is DroppedItem droppedItem)
|
if (area.GetParent() is DroppedItem droppedItem)
|
||||||
{
|
{
|
||||||
var isAdded = Inventory.PickUpItem(droppedItem.Item);
|
var isAdded = Inventory.PickUpItem(droppedItem.Item);
|
||||||
if (isAdded)
|
if (isAdded)
|
||||||
droppedItem.QueueFree();
|
droppedItem.QueueFree();
|
||||||
}
|
}
|
||||||
if (area.GetParent() is ThrownItem thrownItem)
|
if (area.GetParent() is ThrownItem thrownItem)
|
||||||
{
|
{
|
||||||
var isAdded = Inventory.PickUpItem(thrownItem.ItemThatIsThrown);
|
var isAdded = Inventory.PickUpItem(thrownItem.ItemThatIsThrown);
|
||||||
if (isAdded)
|
if (isAdded)
|
||||||
thrownItem.QueueFree();
|
thrownItem.QueueFree();
|
||||||
}
|
}
|
||||||
if (area.GetParent() is Restorative restorative)
|
if (area.GetParent() is Restorative restorative)
|
||||||
{
|
{
|
||||||
restorative.QueueFree();
|
restorative.QueueFree();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool PlayerIsHittingGeometry()
|
private bool PlayerIsHittingGeometry()
|
||||||
{
|
{
|
||||||
var collisions = WallCheck.GetCollidingBodies();
|
var collisions = WallCheck.GetCollidingBodies();
|
||||||
return collisions.Count > 0;
|
return collisions.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WallCheck_BodyEntered(Node body)
|
private void WallCheck_BodyEntered(Node body)
|
||||||
{
|
{
|
||||||
GD.Print("Hit wall");
|
GD.Print("Hit wall");
|
||||||
AnimationPlayer.Stop();
|
AnimationPlayer.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user