Additional refactoring and fixing of equipment data
Add attack data to enemy attacks (might need to rework a little bit for primary/secondary attacks)
This commit is contained in:
@@ -4,7 +4,6 @@ using Chickensoft.Introspection;
|
||||
using Chickensoft.SaveFileBuilder;
|
||||
using Godot;
|
||||
using SimpleInjector;
|
||||
using System;
|
||||
using Zennysoft.Ma.Adapter;
|
||||
using Zennysoft.Ma.Adapter.Entity;
|
||||
|
||||
@@ -207,7 +206,7 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
|
||||
Transform = newTransform;
|
||||
}
|
||||
|
||||
public void TakeDamage(Damage damage)
|
||||
public void TakeDamage(AttackData damage)
|
||||
{
|
||||
var damageReceived = DamageCalculator.CalculateDamage(damage, DefenseComponent.TotalDefense, ((Armor)EquipmentComponent.EquippedArmor.Value).Stats.ElementalResistanceSet);
|
||||
HealthComponent.Damage(damageReceived);
|
||||
@@ -263,47 +262,12 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
|
||||
return;
|
||||
}
|
||||
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
Unequip(EquipmentComponent.EquippedWeapon.Value);
|
||||
weapon.IsEquipped = true;
|
||||
EquipmentComponent.Equip(weapon);
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
Unequip(EquipmentComponent.EquippedArmor.Value);
|
||||
armor.IsEquipped = true;
|
||||
EquipmentComponent.Equip(armor);
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
Unequip(EquipmentComponent.EquippedAccessory.Value);
|
||||
accessory.IsEquipped = true;
|
||||
EquipmentComponent.Equip(accessory);
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
EquipmentComponent.Equip(equipable);
|
||||
}
|
||||
|
||||
public void Unequip(EquipableItem equipable)
|
||||
{
|
||||
if (equipable is Weapon weapon)
|
||||
{
|
||||
weapon.IsEquipped = false;
|
||||
EquipmentComponent.Unequip(weapon);
|
||||
}
|
||||
else if (equipable is Armor armor)
|
||||
{
|
||||
armor.IsEquipped = false;
|
||||
EquipmentComponent.Unequip(armor);
|
||||
}
|
||||
else if (equipable is Accessory accessory)
|
||||
{
|
||||
accessory.IsEquipped = false;
|
||||
EquipmentComponent.Unequip(accessory);
|
||||
}
|
||||
else
|
||||
throw new NotImplementedException("Item type is not supported.");
|
||||
EquipmentComponent.Unequip(equipable);
|
||||
}
|
||||
|
||||
private static Vector3 GlobalInputVector
|
||||
@@ -403,24 +367,23 @@ public partial class Player : CharacterBody3D, IPlayer, IProvide<ISaveChunk<Play
|
||||
|
||||
private void HitEnemy(IEnemy enemy)
|
||||
{
|
||||
var ignoreElementalResistance = ((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.IgnoreAffinity;
|
||||
var isCriticalHit = BattleExtensions.IsCriticalHit(LuckComponent.Luck.Value);
|
||||
var element = ((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponElement;
|
||||
var baseAttack = new Damage(
|
||||
(int)(AttackComponent.TotalAttack * ((Weapon)EquipmentComponent.EquippedWeapon.Value).ElementalDamageBonus),
|
||||
element,
|
||||
false,
|
||||
false,
|
||||
ignoreElementalResistance);
|
||||
var damageDealt = DamageCalculator.CalculateDamage(baseAttack, enemy.DefenseComponent.TotalDefense, new ElementalResistanceSet(0, 0, 0, 0, 0));
|
||||
var ignoreElementalResistance = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreAffinity;
|
||||
var ignoreDefense = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponTag == WeaponTag.IgnoreDefense;
|
||||
var isCriticalHit = BattleExtensions.IsCriticalHit(LuckComponent.Luck.Value + EquipmentComponent.BonusLuck);
|
||||
var totalDamage = AttackComponent.TotalAttack + EquipmentComponent.BonusAttack;
|
||||
var element = (EquipmentComponent.EquippedWeapon.Value as Weapon).WeaponElement;
|
||||
|
||||
if (isCriticalHit)
|
||||
totalDamage += (int)(totalDamage * 0.5f);
|
||||
|
||||
var baseAttack = new AttackData(totalDamage, element, ignoreDefense, ignoreElementalResistance);
|
||||
var damageDealt = DamageCalculator.CalculateDamage(baseAttack, enemy.DefenseComponent.TotalDefense, ElementalResistanceSet.None);
|
||||
enemy.HealthComponent.Damage(damageDealt);
|
||||
|
||||
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.Knockback && enemy is IKnockbackable knockbackable)
|
||||
knockbackable.Knockback(0.3f, -CurrentBasis.Z.Normalized());
|
||||
if (((Weapon)EquipmentComponent.EquippedWeapon.Value).WeaponTag == WeaponTag.SelfDamage)
|
||||
TakeDamage(new Damage(5, ElementType.None, false, true, true));
|
||||
|
||||
_gameRepo.OnPlayerAttackedEnemy();
|
||||
HealthComponent.Damage(5);
|
||||
}
|
||||
|
||||
private void CollisionDetector_AreaEntered(Area3D area)
|
||||
|
||||
Reference in New Issue
Block a user