This commit is contained in:
CortexCore
2025-08-05 23:34:30 +08:00
parent 519c93d651
commit dbc223be46
14 changed files with 156 additions and 5 deletions

View File

@@ -4,7 +4,8 @@
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:677cd05ca06c46b4395470200b1acdad",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:d8b63aba1907145bea998dd612889d6b"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -22,13 +22,15 @@ namespace Net.Project.B.Inventory
public class PlayerEquipmentInventory : IPlayerEquipmentInventory
{
private readonly ILogger<PlayerEquipmentInventory> _logger;
private readonly IPlayerInventory _playerInventory;
public IReadOnlyDictionary<int, IRuntimeItem> Items => _items;
private readonly ConcurrentDictionary<int, IRuntimeItem> _items = new();
public PlayerEquipmentInventory(ILogger<PlayerEquipmentInventory> logger)
public PlayerEquipmentInventory(ILogger<PlayerEquipmentInventory> logger, IPlayerInventory playerInventory)
{
_logger = logger;
_playerInventory = playerInventory;
}
public event Action<int, IRuntimeItem> OnItemAdded;
@@ -69,12 +71,23 @@ namespace Net.Project.B.Inventory
try
{
OnItemConsumed?.Invoke(slot, item);
foreach (var (id, runtimeItem) in _playerInventory.Container.ItemDictionary)
{
if (runtimeItem.ScriptableId != item.ScriptableId) continue;
if (!_playerInventory.Container.Remove(id)) continue;
if (AddOrUpdate(slot, item))
{
break;
}
throw new InvalidOperationException("内部错误,无法从背包补充物品");
}
}
catch (Exception e)
{
_logger.LogCritical(e,e.Message);
}
return true;
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using Unity.Mathematics;
using UnityEngine;
namespace Net.Project.B.Inventory
{
public interface IPlayerPlateInventory
{
IReadOnlyDictionary<int, IRuntimeItem> Plates { get; }
IReadOnlyDictionary<int,int> PlateSlotProviders { get; }
public event Action<IRuntimeItem> OnPlateAdded;
public event Action<IRuntimeItem> OnPlateRemoved;
public event Action<IRuntimeItem> OnPlateDamaged ;
public event Action<IRuntimeItem> OnPlateDestroyed ;
public event Action<int2,int2> OnPlateSlotsUpdated;
public event Action<int2, int2> OnSlotsUpdated;
public event Action<int2, int2> OnArmorPointsUpdated;
int2 PlateSlots { get; }
int2 ArmorPoints { get; }
bool AddPlateSlotProvider(int key, int count);
bool RemovePlateSlotProvider(int key);
bool TryAddPlate(IRuntimeItem item);
bool TryRemovePlate(int id);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 791b19f96863f7d44b3f12374e2d3097
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -34,7 +34,18 @@ namespace Net.Project.B.Inventory
/// </summary>
/// <param name="itemId"></param>
void Drop(int itemId);
/// <summary>
/// 使用武器
/// </summary>
/// <param name="itemId"></param>
/// <param name="controller"></param>
/// <returns></returns>
bool Draw(int itemId,out IPlayerWeaponController controller);
/// <summary>
/// 使用主要武器
/// </summary>
/// <returns></returns>
bool DrawPrimaryWeapon();
}
}