155 lines
3.7 KiB
C#
155 lines
3.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using BITKit;
|
|
using BITKit.Modification;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Guns.Modify
|
|
{
|
|
[Serializable]
|
|
public sealed class GunModifyOptional:ICloneable
|
|
{
|
|
[SerializeReference,SubclassSelector] private GunModifyElement index;
|
|
[SerializeField] private AssetableItem value;
|
|
public bool HasValue => value is not null;
|
|
public IModifyElement Index => index;
|
|
public AssetableItem Value
|
|
{
|
|
get => value;
|
|
set => this.value = value;
|
|
}
|
|
|
|
public object Clone()
|
|
{
|
|
return new GunModifyOptional
|
|
{
|
|
index = index,
|
|
value = value
|
|
};
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 基本武器改装容器
|
|
/// </summary>
|
|
[CustomType(typeof(IModifyManager))]
|
|
[Serializable]
|
|
public sealed class GunModify : ModifyManager,IProperty,ICloneable
|
|
{
|
|
[SerializeField] private GunModifyOptional[] elements=Array.Empty<GunModifyOptional>();
|
|
|
|
public override IDictionary<IModifyElement, object> Modifies =>
|
|
new Dictionary<IModifyElement, object>(elements.Select(
|
|
x=>new KeyValuePair<IModifyElement, object>(x.Index,x.Value)
|
|
));
|
|
|
|
public override void Add(IModifyElement modify, object obj)
|
|
{
|
|
base.Add(modify, obj);
|
|
foreach (var x in elements.Where(x=>x.Index.Equals(modify)))
|
|
{
|
|
x.Value = obj.As<AssetableItem>();
|
|
}
|
|
}
|
|
|
|
public override void Remove(IModifyElement modify, out object obj)
|
|
{
|
|
base.Remove(modify, out obj);
|
|
foreach (var x in elements.Where(x=>x.Index.Equals(modify)))
|
|
{
|
|
obj = x.Value;
|
|
x.Value = null;
|
|
return;
|
|
}
|
|
throw new InvalidOperationException($"没有找到对应的改装:{modify}");
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
var stringBuilder = new System.Text.StringBuilder();
|
|
foreach (var x in elements)
|
|
{
|
|
stringBuilder.AppendLine(x.HasValue ? $"{x.Index}:{x.Value.Name}" : $"{x.Index}:empty");
|
|
}
|
|
return stringBuilder.ToString();
|
|
}
|
|
|
|
public object Clone()
|
|
{
|
|
var clone = new GunModify();
|
|
if (elements is null) return clone;
|
|
|
|
clone.elements = elements.Select(x => x.Clone().As<GunModifyOptional>()).ToArray();
|
|
|
|
return clone;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 抽象武器改装元素
|
|
/// </summary>
|
|
public abstract class GunModifyElement : IModifyElement
|
|
{
|
|
public override bool Equals(object obj)
|
|
{
|
|
return GetType() == obj?.GetType();
|
|
}
|
|
public override int GetHashCode() => GetType().GetHashCode();
|
|
|
|
[SerializeReference,SubclassSelector] private GunModifyElement[] requires;
|
|
[SerializeReference,SubclassSelector] private GunModifyElement[] incompatibles;
|
|
public virtual IModifyElement[] Require=>requires;
|
|
public virtual IModifyElement[] Incompatible => incompatibles;
|
|
}
|
|
/// <summary>
|
|
/// 枪口,例如消音器,枪口制退器,枪口补偿器
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Muzzle:GunModifyElement
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 枪管,例如重型枪管,短枪管和T50前线之类的
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Barrel:GunModifyElement
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 弹匣,例如扩容弹匣,快速弹匣,9mm改装弹匣和弹鼓等
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Magazine:GunModifyElement
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 瞄具,例如全息瞄准镜,红点瞄准镜,狙击镜和夜视仪等
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Sights:GunModifyElement
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 下挂,例如快速握把,垂直握把和榴弹发射器等
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Underbarrel:GunModifyElement
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 战术侧挂,例如战术灯,激光瞄准器和红外线瞄准器等
|
|
/// </summary>
|
|
[Serializable]
|
|
public sealed class Tactical:GunModifyElement
|
|
{
|
|
|
|
}
|
|
}
|