This commit is contained in:
CortexCore
2023-12-03 17:35:43 +08:00
parent ba342d6627
commit ba9f4eda80
702 changed files with 162078 additions and 21050 deletions

View File

@@ -8,6 +8,7 @@ using UnityEngine.InputSystem;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BITFALL.Entities;
using BITFALL.Entities.Improvised;
@@ -60,8 +61,6 @@ namespace BITFALL.Entities.Equipment
[Inject]
private IEquipService _equipService;
private readonly DoubleBuffer<IBasicItem> _cachedItem=new();
private readonly List<int> _blockList=new();
[Inject(true)] private InputActionGroup _inputActionGroup;
@@ -141,19 +140,11 @@ namespace BITFALL.Entities.Equipment
private void OnUnEquipImprovisedItem(IBasicItem obj)
{
Equip(null);
if (_cachedItem.TryGetRelease(out var item))
{
Equip(item);
}
Cancel();
}
private void OnEquipImprovisedItem(IBasicItem obj)
{
if (currentEquip is not null)
{
_cachedItem.Release(currentEquip);
}
Equip(obj);
}
@@ -245,10 +236,6 @@ namespace BITFALL.Entities.Equipment
if (TryEquipFactory?.CastAsFunc().Any(x => x.Invoke(value)) is false) return false;
_equipment.EntryEquip(value);
_improvisedService?.TryUnEquipImprovised(out _);
if (currentEquip is not null)
{
_cachedItem.Release(currentEquip);
}
currentEquip = value;
return true;
case var _ when asset.TryGetProperty<EquipmentAsSlot>(out var equipAsSlot):
@@ -257,35 +244,45 @@ namespace BITFALL.Entities.Equipment
}
return false;
}
public async void OnAdd(IBasicItem item)
{
if (_blockList.Contains(item.Id)) return;
if(currentEquip is not null && currentEquip.AddressablePath == item.AddressablePath)
if (_equipment.IsSupportItem(item) is false)
{
UpdateEquip();
}
if (currentEquip is not null && currentEquip.AddressablePath == item.AddressablePath)
{
if (equips.TryGetAny(x => x.Value.AddressablePath == item.AddressablePath, out var pair))
{
if(equips.TryGetAny(x=>x.Value.AddressablePath == item.AddressablePath,out var pair))
{
equips.Remove(pair.Key);
UpdateEquip();
}
currentEquip = null;
_equipment.EntryEquip((IBasicItem)null);
equips.Remove(pair.Key);
UpdateEquip();
}
else
currentEquip = null;
_equipment.EntryEquip((IBasicItem)null);
}
else
{
try
{
try
for (var i = 0; i < 8; i++)
{
for (var i = 0; i < 8; i++)
{
await UniTask.NextFrame();
}
if (_equipment.IsSupportItem(item) && item.GetAssetable().TryGetProperty<EquipmentAsWeapon>(out _))
{
_inventory.TryUseItem(item);
}
await UniTask.NextFrame();
}
if (_equipment.IsSupportItem(item) && item.GetAssetable().TryGetProperty<EquipmentAsWeapon>(out _))
{
_inventory.TryUseItem(item);
}
catch(OperationCanceledException){}
}
catch (OperationCanceledException)
{
}
}
}
private void OnTactics(InputAction.CallbackContext obj)
{
@@ -322,13 +319,11 @@ namespace BITFALL.Entities.Equipment
}
public void OnRemove(IBasicItem item)
{
_blockList.Add(item.Id);
if (_equipment.IsSupportItem(item) is false)
{
UpdateEquip();
}
_blockList.Add(item.Id);
}
private void OnEquip(IBasicItem obj)
{
@@ -337,7 +332,6 @@ namespace BITFALL.Entities.Equipment
private void UpdateEquip()
{
OnUpdateEquip?.Invoke(new Dictionary<int, IBasicItem>(equips));
_cachedItem.Clear();
}
public IDictionary<int, IBasicItem> Equipped => new Dictionary<int, IBasicItem>(equips);
@@ -349,6 +343,11 @@ namespace BITFALL.Entities.Equipment
var index = equips.First(x=>x.Value.AddressablePath==item.AddressablePath).Key;
if (equips.TryRemove(index) is false) return false;
if (!_inventory.Add(item)) return false;
if (currentEquip?.AddressablePath == item.AddressablePath)
{
Equip(null);
playerChoose.Clear();
}
UpdateEquip();
return true;
}