This commit is contained in:
CortexCore
2025-02-24 23:02:49 +08:00
parent 9775bdd099
commit b07ae4fea7
82 changed files with 1021 additions and 386 deletions

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using BITKit;
using UnityEngine;
namespace Net.Project.B.Inventory
{
public interface IPlayerEquipmentInventory
{
IReadOnlyDictionary<int, IRuntimeItem> Items { get; }
public event Action<int, IRuntimeItem> OnItemAdded;
public event Action<int, IRuntimeItem> OnItemUpdated;
public event Action<int, IRuntimeItem> OnItemConsumed;
public event Action<int, IRuntimeItem> OnItemRemoved;
bool AddOrUpdate(int slot, IRuntimeItem item);
bool Remove(int slot);
bool Consume(int slot);
}
public class PlayerEquipmentInventory : IPlayerEquipmentInventory
{
public IReadOnlyDictionary<int, IRuntimeItem> Items => _items;
private readonly ConcurrentDictionary<int, IRuntimeItem> _items = new();
public event Action<int, IRuntimeItem> OnItemAdded;
public event Action<int, IRuntimeItem> OnItemUpdated;
public event Action<int, IRuntimeItem> OnItemConsumed;
public event Action<int, IRuntimeItem> OnItemRemoved;
public virtual bool AddOrUpdate(int slot, IRuntimeItem item)
{
if (_items.TryGetValue(slot, out var current))
{
if (current.Id != item.Id) return false;
_items[slot] = item;
OnItemUpdated?.Invoke(slot, item);
}
else
{
_items.TryAdd(slot, item);
OnItemAdded?.Invoke(slot, item);
}
return true;
}
public virtual bool Remove(int slot)
{
if (!_items.TryRemove(slot, out var item)) return false;
OnItemRemoved?.Invoke(slot, item);
return true;
}
public virtual bool Consume(int slot)
{
if (_items.TryRemove(slot, out _) is false) return false;
OnItemConsumed?.Invoke(slot, null);
return true;
}
}
}

View File

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

View File

@@ -6,76 +6,35 @@ using BITKit.StateMachine;
namespace Net.Project.B.Inventory
{
/// <summary>
/// 玩家武器槽
/// </summary>
public enum PlayerWeaponSlot
{
/// <summary>
/// 主武器
/// </summary>
Primary,
/// <summary>
/// 主武器2
/// </summary>
Secondary,
/// <summary>
/// 副武器,例如手枪,近战武器等
/// </summary>
Sidearm,
/// <summary>
/// 消耗品,通常是护甲,医疗包等
/// </summary>
Supplies,
/// <summary>
/// 战术道具
/// </summary>
Tactics,
/// <summary>
/// 致命道具
/// </summary>
Lethal,
/// <summary>
/// 连杀奖励,特别的武器
/// </summary>
KillStreak
}
/// <summary>
/// 玩家武器控制器
/// 玩家控制器
/// </summary>
public interface IPlayerWeaponController:IStateAsync{}
/// <summary>
/// 玩家枪支控制器
/// 玩家泛型控制器
/// </summary>
public interface IPlayerGunController:IPlayerWeaponController{}
/// <summary>
/// 玩家近战武器控制器
/// </summary>
public interface IPlayerMeleeController:IPlayerWeaponController{}
/// <typeparam name="T"></typeparam>
public interface IPlayerWeaponController<T>:IPlayerWeaponController{}
/// <summary>
/// 玩家武器库存,与背包不是一个东西
/// </summary>
public interface IPlayerWeaponInventory
{
/// <summary>
/// 武器
/// 允许使用武器
/// </summary>
public IReadOnlyDictionary<PlayerWeaponSlot,int> WeaponSlots { get; }
public ValidHandle AllowWeapon { get; }
/// <summary>
/// 武器控制器状态机
/// </summary>
public IStateMachine<IPlayerWeaponController> StateMachine { get; }
/// <summary>
/// 武器槽更新回调,参数为:slot,ItemId,IsAdd
/// </summary>
public event Action<PlayerWeaponSlot, int, bool> OnWeaponSlotChanged;
/// <summary>
/// 丢下武器
/// </summary>
/// <param name="slot"></param>
void Drop(PlayerWeaponSlot slot);
void Use(PlayerWeaponSlot slot);
void Use(int id);
/// <param name="itemId"></param>
void Drop(int itemId);
void Draw(int itemId);
}
}