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

@@ -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;

View File

@@ -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)

View File

@@ -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);

View File

@@ -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)