1
This commit is contained in:
@@ -6,18 +6,24 @@ using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Items.Armor;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITFALL.Entities.Armor
|
||||
{
|
||||
[CustomType(typeof(IArmor))]
|
||||
public class EntityArmor : EntityBehavior,IArmor
|
||||
{
|
||||
[SerializeField] private Optional<int> initialArmor;
|
||||
|
||||
[SerializeField,HideInInspector] internal int currentArmor;
|
||||
|
||||
private int _armor;
|
||||
public int Armor
|
||||
{
|
||||
get => _armor;
|
||||
set=>OnArmorChanged?.Invoke(_armor = value);
|
||||
set=>OnArmorChanged?.Invoke(currentArmor = _armor = value);
|
||||
}
|
||||
|
||||
public bool TryGetCurrentArmor(out IBasicItem item)
|
||||
@@ -31,22 +37,38 @@ namespace BITFALL.Entities.Armor
|
||||
public event Action<IBasicItem> OnUnEquipArmor;
|
||||
|
||||
[Inject] private IHealth _health;
|
||||
[Inject] private IPlayerEquipSelector _playerEquipSelector;
|
||||
[Inject] private IEntityInventory _inventory;
|
||||
[Inject] private IEntityEquipmentContainer _equipmentContainer;
|
||||
|
||||
[Inject(true)] private IPlayerEquipSelector _playerEquipSelector;
|
||||
[Inject(true)] private IEntityInventory _inventory;
|
||||
[Inject(true)] private IEntityEquipmentContainer _equipmentContainer;
|
||||
|
||||
private IBasicItem _currentArmor;
|
||||
|
||||
public override void OnAwake()
|
||||
{
|
||||
base.OnAwake();
|
||||
_health.OnDamageFactory += OnDamageFactory;
|
||||
_inventory.OnUsedItem += OnUsedItem;
|
||||
|
||||
_equipmentContainer.OnEquip += OnEquip;
|
||||
_equipmentContainer.OnDeEquip += OnDeEquip;
|
||||
|
||||
_playerEquipSelector.TryEquipFactory += OnTryEquip;
|
||||
|
||||
if (_inventory is not null)
|
||||
_inventory.OnUsedItem += OnUsedItem;
|
||||
|
||||
if (_equipmentContainer is not null)
|
||||
{
|
||||
_equipmentContainer.OnEquip += OnEquip;
|
||||
_equipmentContainer.OnDeEquip += OnDeEquip;
|
||||
}
|
||||
|
||||
if (_playerEquipSelector is not null)
|
||||
_playerEquipSelector.TryEquipFactory += OnTryEquip;
|
||||
|
||||
}
|
||||
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
if (initialArmor.Allow)
|
||||
{
|
||||
Armor = initialArmor.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnTryEquip(IBasicItem arg)
|
||||
@@ -91,7 +113,7 @@ namespace BITFALL.Entities.Armor
|
||||
}
|
||||
private int OnDamageFactory(DamageMessage arg1, int damage)
|
||||
{
|
||||
if (_currentArmor is null) return damage;
|
||||
if (_currentArmor is null && initialArmor.Allow is false) return damage;
|
||||
if (Armor is 0) return damage;
|
||||
if (damage > Armor)
|
||||
{
|
||||
@@ -102,5 +124,18 @@ namespace BITFALL.Entities.Armor
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(EntityArmor))]
|
||||
public sealed class EntityArmorInspector:BITInspector<EntityArmor>
|
||||
{
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
FillDefaultInspector();
|
||||
var label = root.Create<Label>();
|
||||
|
||||
label.bindingPath = nameof(EntityArmor.currentArmor);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user