100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
// using System;
|
|
// using System.Collections;
|
|
// using System.Collections.Generic;
|
|
// using System.Linq;
|
|
// using BITFALL.Entities.Equipment;
|
|
// using BITFALL.Player.Inventory;
|
|
// using UnityEngine;
|
|
// using BITKit;
|
|
// using BITKit.Entities;
|
|
//
|
|
// namespace BITFALL
|
|
// {
|
|
//
|
|
// /// <summary>
|
|
// /// 玩家装备容器
|
|
// /// 支持,护甲,头盔和背包等
|
|
// /// </summary>
|
|
// [CustomType(typeof(IEntityEquipmentContainer))]
|
|
// public class PlayerEquipContainer : EntityComponent, IEntityEquipmentContainer
|
|
// {
|
|
// private Dictionary<IEquipmentSlot, IBasicItem> Equipment = new();
|
|
// [Inject]
|
|
// private IBasicItemContainer inventory;
|
|
// public override void OnAwake()
|
|
// {
|
|
// var health = entity.Get<IHealth>();
|
|
// health.OnSetAlive += OnSetAlive;
|
|
// }
|
|
//
|
|
// private void OnSetAlive(bool obj)
|
|
// {
|
|
// if (obj) return;
|
|
// foreach (var x in Equipment.ToArray())
|
|
// {
|
|
// OnDeEquip?.Invoke(x.Key, x.Value);
|
|
// inventory.Add(x.Value);
|
|
// }
|
|
// Equipment.Clear();
|
|
// }
|
|
//
|
|
// public override void OnStart()
|
|
// {
|
|
// base.OnStart();
|
|
// inventory = entity.Get<IBasicItemContainer>();
|
|
// var playerInventory = entity.Get<IPlayerInventory>();
|
|
// playerInventory.OnUseItem += TryExecute;
|
|
// }
|
|
//
|
|
// public Action<IEquipmentSlot, IBasicItem> OnEquip { get; set; }
|
|
// public Action<IEquipmentSlot, IBasicItem> OnDeEquip { get; set; }
|
|
//
|
|
// public bool TryDeEquip<T>(T slot) where T : IEquipmentSlot
|
|
// {
|
|
// if (!Equipment.TryGetValue(slot, out var equipable)) return false;
|
|
// if (inventory.Add(equipable))
|
|
// {
|
|
// DeEquip(slot, equipable);
|
|
// }
|
|
// return false;
|
|
// }
|
|
// private bool Equip(IEquipmentSlot slot, IBasicItem item)
|
|
// {
|
|
// Equipment.Add(slot, item);
|
|
// OnEquip?.Invoke(slot, item);
|
|
// return true;
|
|
// }
|
|
// private bool DeEquip(IEquipmentSlot slot, IBasicItem item)
|
|
// {
|
|
// Equipment.Remove(slot);
|
|
// OnDeEquip?.Invoke(slot, item);
|
|
// return true;
|
|
// }
|
|
// public int Priority => 0;
|
|
//
|
|
// public bool TryExecute(IBasicItem value)
|
|
// {
|
|
// var asset = value.GetAssetable();
|
|
// //尝试获取可装备信息
|
|
// if (!asset.TryGetProperty<EquipmentAsSlot>(out var equipable)) return false;
|
|
// //已装备物品
|
|
// if (Equipment.TryGetValue(equipable.slot, out var equipedItem))
|
|
// {
|
|
// //尝试将装配放回背包
|
|
// if (inventory.Add(equipedItem))
|
|
// {
|
|
// //移除已装备物品
|
|
// DeEquip(equipable.slot, value);
|
|
// }
|
|
// }
|
|
// //从库存中移除物品
|
|
// if (inventory.Remove(value))
|
|
// {
|
|
// //装配物品
|
|
// Equip(equipable.slot, value);
|
|
// }
|
|
// return false;
|
|
// }
|
|
// }
|
|
// }
|