1
This commit is contained in:
@@ -15,5 +15,6 @@ namespace BITFALL.Entities.Inventory
|
||||
bool TryUseItem(IBasicItem item);
|
||||
event Func<IBasicItem,bool> TryUseItemFactory;
|
||||
void UseItem(IBasicItem item);
|
||||
bool TrySetItem(IBasicItem item);
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -19,7 +19,8 @@
|
||||
"GUID:48ef04d98836e2640bf90b524bdff904",
|
||||
"GUID:1eb13dc7c3cb5a444877a995967ed591",
|
||||
"GUID:ea5474181b324dd49a5976cd68f44f18",
|
||||
"GUID:87bea3a21c744b1478660b70494160ba"
|
||||
"GUID:87bea3a21c744b1478660b70494160ba",
|
||||
"GUID:fd0a768fe19798b48a5e0fe3568c874f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
@@ -10,9 +10,13 @@ using System.Security.Permissions;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using BITFALL;
|
||||
using BITFALL.Entities.Equipment;
|
||||
using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Guns.Modify;
|
||||
using BITFALL.Player.Equip;
|
||||
using BITFALL.Props;
|
||||
using BITKit.Entities.Melee;
|
||||
using BITKit.Entities.VFX;
|
||||
using BITKit.UX;
|
||||
using Cinemachine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Mathematics;
|
||||
@@ -34,14 +38,20 @@ namespace BITKit.Entities
|
||||
[SerializeField] protected EntityAnimator entityAnimator;
|
||||
[SerializeField] private Renderer[] renderers;
|
||||
[SerializeField] protected Transform cameraTransform;
|
||||
|
||||
[SerializeField] protected Prop_Modify _modify;
|
||||
[Header(Constant.Header.Services)]
|
||||
[SerializeReference,SubclassSelector] protected IMeleeService meleeService;
|
||||
[SerializeReference,SubclassSelector,Inject] private IUXPopup _popup;
|
||||
|
||||
public Entities.IEntity Entity { get; set; }
|
||||
public Entity UnityEntity=>Entity as Entity;
|
||||
public IBasicItem Item { get; set; }
|
||||
|
||||
|
||||
public IBasicItem Item
|
||||
{
|
||||
get => _item;
|
||||
set=>OnApply?.Invoke(_item = value);
|
||||
}
|
||||
private IBasicItem _item;
|
||||
public IDictionary<string,float> AnimationProperties => animationProperties.ToDictionary(x=>x.Key,x=>x.Value.Value);
|
||||
|
||||
public readonly InputActionGroup inputActionGroup = new()
|
||||
@@ -53,9 +63,12 @@ namespace BITKit.Entities
|
||||
protected virtual Vector3 meleeForce => Transform.forward;
|
||||
public bool IsEntered { get; set; }
|
||||
private Quaternion _initialCameraRotation;
|
||||
|
||||
protected event Action<IBasicItem> OnApply;
|
||||
|
||||
[Inject] protected IEntityOverride _entityOverride;
|
||||
|
||||
[Inject(true)] protected IEntityInventory _inventory;
|
||||
[Inject(true)] protected IUXPopup _uxPopup;
|
||||
public virtual void Entry()
|
||||
{
|
||||
if (animator)
|
||||
@@ -74,6 +87,7 @@ namespace BITKit.Entities
|
||||
var animName = animator.animator.GetCurrentAnimatorStateInfo(0).shortNameHash;
|
||||
animator.animator.Play(animName, -1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public virtual UniTask EntryAsync()
|
||||
@@ -120,7 +134,12 @@ namespace BITKit.Entities
|
||||
|
||||
public virtual void OnAwake()
|
||||
{
|
||||
AllowRendering.AddListener(x => renderers.ForEach(y => { y.enabled = x; }));
|
||||
AllowRendering.AddListener(x =>
|
||||
{
|
||||
renderers.ForEach(y => { y.enabled = x; });
|
||||
if (_modify)
|
||||
_modify.AllowModify.SetDisableElements(this,!x);
|
||||
});
|
||||
if (animator)
|
||||
animator.enabled = false;
|
||||
AllowRendering.Invoke();
|
||||
@@ -133,6 +152,21 @@ namespace BITKit.Entities
|
||||
vfxPlayer.enabled = false;
|
||||
|
||||
_entityOverride.OnOverride += OnOverride;
|
||||
|
||||
OnApply += (x) =>
|
||||
{
|
||||
if (!_modify) return;
|
||||
if (x is not null && x.TryGetProperty<GunModify>(out var modify))
|
||||
{
|
||||
_modify.Modify(modify);
|
||||
}
|
||||
else
|
||||
{
|
||||
_modify.ClearModify();
|
||||
}
|
||||
};
|
||||
if (_modify)
|
||||
_modify.ClearModify();
|
||||
}
|
||||
|
||||
private void OnOverride(bool obj)
|
||||
|
@@ -76,6 +76,14 @@ namespace BITFALL
|
||||
dictionary.TryRemove(item.Id);
|
||||
}
|
||||
|
||||
public bool TrySetItem(IBasicItem item)
|
||||
{
|
||||
if (dictionary.TryGetValue(item.Id, out var currentItem) is false) return false;
|
||||
dictionary[item.Id] = item;
|
||||
OnSet?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
[Inject]
|
||||
protected IHealth _health;
|
||||
[Inject]
|
||||
@@ -147,7 +155,7 @@ namespace BITFALL
|
||||
}
|
||||
public bool TryGetItem(Func<IBasicItem, bool> func, out IBasicItem item)
|
||||
{
|
||||
return dictionary.Values.TryGetAny(func, out item);
|
||||
return dictionary.Values.OrderBy(x=>x.TryGetProperty<ICount>(out var count)?count.Count:0).Reverse().TryGetAny(func, out item);
|
||||
}
|
||||
|
||||
public bool Drop(int _Id)
|
||||
@@ -167,9 +175,8 @@ namespace BITFALL
|
||||
{
|
||||
OnDrop?.Invoke(item);
|
||||
var prefab = item.GetAssetable();
|
||||
var _transform = transform;
|
||||
var position = _transform.position;
|
||||
var rotation = _transform.rotation;
|
||||
var position = Transform.position + Vector3.up;
|
||||
var rotation = Transform.rotation;
|
||||
if (_modelSlots.Slots.TryGetValue(prefab.AddressablePath, out var anchor))
|
||||
{
|
||||
position = anchor.position;
|
||||
|
@@ -4,6 +4,7 @@ using BITFALL.Entities.Inventory;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.UX;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
@@ -25,7 +26,9 @@ namespace BITFALL
|
||||
[Inject(true)]
|
||||
private IEntityInventory _inventory;
|
||||
[Inject(true)]
|
||||
private IEntityEquipmentContainer playerEquipContainer;
|
||||
private IEntityEquipmentContainer playerEquipContainer;
|
||||
|
||||
[Inject(true)] private IUXPopup _popup;
|
||||
public override void OnStart()
|
||||
{
|
||||
_container.AddFactory += AddFactory;
|
||||
@@ -36,7 +39,6 @@ namespace BITFALL
|
||||
{
|
||||
_inventory.OnUsedItem += OnRemove;
|
||||
}
|
||||
|
||||
if (playerEquipContainer is not null)
|
||||
{
|
||||
playerEquipContainer.OnEquip += OnEquip;
|
||||
@@ -48,7 +50,14 @@ namespace BITFALL
|
||||
{
|
||||
var asset = item.GetAssetable();
|
||||
if (!asset.TryGetProperty<ItemWeight>(out var itemWeight)) return true;
|
||||
return currentWeight + itemWeight <= maxWeight;
|
||||
|
||||
var result = currentWeight + itemWeight <= maxWeight;
|
||||
if (result is false)
|
||||
{
|
||||
_popup.Popup("<color=yellow>背包已满</color>");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void OnAdd(IBasicItem item)
|
||||
|
@@ -6,6 +6,7 @@ using BITFALL.Entities.Inventory;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.UX;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Items
|
||||
@@ -37,12 +38,19 @@ namespace BITFALL.Items
|
||||
[Inject] private IHealth _health;
|
||||
|
||||
[Inject(true)] private IKnockdown _knockdown;
|
||||
|
||||
[Inject(true)] private IUXPopup _popup;
|
||||
public override bool TryUse(IBasicItem item)
|
||||
{
|
||||
if(_health.IsAlive is false) return false;
|
||||
if (_health.HealthPoint == _health.MaxHealthPoint) return false;
|
||||
if (_health.HealthPoint >= _health.MaxHealthPoint)
|
||||
{
|
||||
_popup?.Popup("<color=yellow>生命值已满</color>");
|
||||
return false;
|
||||
}
|
||||
if (_knockdown is not null && _knockdown.IsKnockdown)
|
||||
{
|
||||
_popup?.Popup("<color=yellow>你被击倒了</color>");
|
||||
return false;
|
||||
}
|
||||
return base.TryUse(item);
|
||||
|
@@ -12,6 +12,7 @@ using BITFALL.Entities;
|
||||
using BITFALL.Entities.Improvised;
|
||||
using BITFALL.Player.Inventory;
|
||||
using BITKit.Selection;
|
||||
using BITKit.UX;
|
||||
|
||||
namespace BITFALL
|
||||
{
|
||||
@@ -24,6 +25,8 @@ namespace BITFALL
|
||||
private ImprovisedServiceInterface _improvisedService;
|
||||
[Inject(true)]
|
||||
private IKnockdown _knockdown;
|
||||
|
||||
[Inject(true)] private IUXPopup _popup;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
@@ -32,6 +35,22 @@ namespace BITFALL
|
||||
{
|
||||
_improvisedService.OnUnEquipImprovisedItem += OnUnEquipImprovisedItem;
|
||||
}
|
||||
OnAdd += OnAddItem;
|
||||
OnRemove += OnRemoveItem;
|
||||
OnUsedItem += OnUseItem;
|
||||
}
|
||||
|
||||
private void OnUseItem(IBasicItem obj)
|
||||
{
|
||||
_popup?.Popup($"使用了[{obj.Name}]");
|
||||
}
|
||||
private void OnRemoveItem(IBasicItem obj)
|
||||
{
|
||||
_popup?.Popup($"移除了[{obj.Name}]");
|
||||
}
|
||||
private void OnAddItem(IBasicItem obj)
|
||||
{
|
||||
_popup?.Popup($"捡起了[{obj.Name}]");
|
||||
}
|
||||
|
||||
protected override void OnSetAlive(bool alive)
|
||||
|
Reference in New Issue
Block a user