This commit is contained in:
CortexCore
2023-10-20 22:46:14 +08:00
parent a160813262
commit 325f63d6bc
42 changed files with 1602 additions and 79 deletions

View File

@@ -13,7 +13,9 @@
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:30cdc242b1ac6a944a460f4ab0b77b88"
"GUID:30cdc242b1ac6a944a460f4ab0b77b88",
"GUID:7efac18f239530141802fb139776f333",
"GUID:ef0bb553b58b90b488bdbe8672e3be0b"
],
"includePlatforms": [],
"excludePlatforms": [],

View File

@@ -1,20 +0,0 @@
{
"name": "BITFALL.Entities.Equipment",
"rootNamespace": "",
"references": [
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:677cd05ca06c46b4395470200b1acdad",
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -1,17 +0,0 @@
using BITKit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace BITFALL
{
public interface IEquipmentAsArms : IProperty { }
[System.Serializable]
public record EquipmentAsWeapon: IEquipmentAsArms { }
[System.Serializable]
public record EquipmentUseItem: IEquipmentAsArms { }
}

View File

@@ -1,38 +0,0 @@
using BITKit;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITFALL
{
public interface IEquipmentSlot
{
}
public abstract record EquipmentSlot: IEquipmentSlot
{
public override int GetHashCode() => GetType().GetHashCode();
}
[System.Serializable]
public sealed record EquipmentAsHead: EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsBody : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsArmor : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsHeal : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsBackpack : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsArmorPlates : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsTactics : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsThrow : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsEquip : EquipmentSlot { }
[System.Serializable]
public sealed record EquipmentAsSlot : IProperty
{
[SerializeReference, SubclassSelector] public IEquipmentSlot slot;
}
}

View File

@@ -1,27 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Core.Entites;
using UnityEngine;
namespace BITFALL.Entities.Equipment
{
public interface IEntityEquipment
{
event Action<IBasicItem> OnEquip;
event Action<IBasicItem> OnDeEquip;
bool IsSupportItem(IBasicItem item);
void EntryEquip(int index);
void EntryEquip(Func<string,bool> item);
void EntryEquip(IBasicItem item);
}
public interface IEquipBase : IEntryElement, IAwake, IStart, IUpdate
{
string AddressablePath { get; }
IEntity Entity { get; set; }
IBasicItem Item { get; set; }
bool IsSupportItem(IBasicItem item);
void PlayAudio(string name);
}
}

View File

@@ -36,14 +36,15 @@ namespace BITKit.Entities
allowGlobalActivation = true
};
protected readonly ValidHandle AllowRendering = new();
public virtual string AddressablePath => throw new System.NotImplementedException();
public virtual string AddressablePath => item.AddressablePath;
protected virtual Vector3 meleeForce => Transform.forward;
public bool IsEntered { get; set; }
public virtual void Entry()
{
AllowRendering.AddElement(this);
inputActionGroup.allowInput.AddElement(this);
animator.animator.enabled = true;
animator.animator.Update(0);
}
public virtual UniTask EntryAsync()
{
@@ -52,7 +53,7 @@ namespace BITKit.Entities
public virtual void Exit()
{
inputActionGroup.allowInput.AddElement(this);
inputActionGroup.allowInput.RemoveElement(this);
}
public virtual UniTask ExitAsync()
{
@@ -61,8 +62,13 @@ 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;
animator.animator.enabled = x;
}));
AllowRendering.Invoke();
Initialize();
}

View File

@@ -0,0 +1,99 @@
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 EntityEquipmentContainer : EntityComponent, IEntityEquipmentContainer
{
private readonly Dictionary<IEquipmentSlot, IBasicItem> dictionary = 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 dictionary.ToArray())
{
OnDeEquip?.Invoke(x.Key, x.Value);
inventory.Add(x.Value);
}
dictionary.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 (!dictionary.TryGetValue(slot, out var equipable)) return false;
if (inventory.Add(equipable))
{
DeEquip(slot, equipable);
}
return false;
}
private bool Equip(IEquipmentSlot slot, IBasicItem item)
{
dictionary.Add(slot, item);
OnEquip?.Invoke(slot, item);
return true;
}
private bool DeEquip(IEquipmentSlot slot, IBasicItem item)
{
dictionary.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 (dictionary.TryGetValue(equipable.slot, out var equipedItem))
{
//尝试将装配放回背包
if (inventory.Add(equipedItem))
{
//移除已装备物品
DeEquip(equipable.slot, value);
}
}
//从库存中移除物品
if (inventory.Remove(value))
{
//装配物品
Equip(equipable.slot, value);
}
return false;
}
}
}