93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
![]() |
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using BITKit;
|
||
|
using Net.Project.B.Damage;
|
||
|
using UnityEngine;
|
||
|
using Random = UnityEngine.Random;
|
||
|
|
||
|
namespace Project.B.Item
|
||
|
{
|
||
|
public class ScriptableItemDamage : IDamageType
|
||
|
{
|
||
|
public int ScriptableId { get; set; }
|
||
|
}
|
||
|
public class ScriptableItem : ScriptableObject,IScriptableItem
|
||
|
{
|
||
|
public static Color GetQualityColor(ItemQuality quality)
|
||
|
{
|
||
|
return quality switch
|
||
|
{
|
||
|
ItemQuality.Common => Color.white,
|
||
|
ItemQuality.Uncommon => Color.green,
|
||
|
ItemQuality.Rare => Color.cyan,
|
||
|
//紫色
|
||
|
ItemQuality.Epic => new Color(0.5f, 0, 1),
|
||
|
//橙色
|
||
|
ItemQuality.Legendary => new Color(1, 0.5f, 0),
|
||
|
ItemQuality.Mythical => Color.red,
|
||
|
ItemQuality.Develop => Color.gray,
|
||
|
_ => Color.white
|
||
|
};
|
||
|
}
|
||
|
|
||
|
[Header(Constant.Header.Settings)]
|
||
|
[SerializeField] internal int id;
|
||
|
[SerializeReference,SubclassSelector] internal IReference displayName;
|
||
|
[SerializeReference,SubclassSelector] internal IReference description;
|
||
|
[SerializeField] internal Sprite icon;
|
||
|
[SerializeField] internal Sprite rectangleIcon;
|
||
|
[SerializeField] internal ItemQuality quality;
|
||
|
|
||
|
[SerializeField,Range(1,64)] internal int maxStack;
|
||
|
[SerializeField] internal Transform model;
|
||
|
|
||
|
[SerializeField] internal int value;
|
||
|
/// <summary>
|
||
|
/// 是否为不可储存的即兴物品
|
||
|
/// </summary>
|
||
|
[SerializeField] internal bool isImprovised;
|
||
|
/// <summary>
|
||
|
/// 允许被击倒时使用
|
||
|
/// </summary>
|
||
|
[SerializeField] internal bool allowUseWhileKnocked;
|
||
|
|
||
|
[Header(nameof(Properties))]
|
||
|
[SerializeReference, SubclassSelector] internal IScriptableItemProperty[] properties;
|
||
|
[SerializeReference, SubclassSelector] internal IScriptableItemProperty[] factoryProperty;
|
||
|
|
||
|
[SerializeReference, SubclassSelector] internal IScriptableControllerClass controllerClass;
|
||
|
|
||
|
public int Id => id;
|
||
|
public string Name => displayName?.Value;
|
||
|
public string Description => description?.Value;
|
||
|
public int MaxStack => maxStack;
|
||
|
public ItemQuality Quality => quality;
|
||
|
public Transform Model => model;
|
||
|
public Sprite Icon => icon;
|
||
|
public Sprite RectangleIcon => rectangleIcon;
|
||
|
|
||
|
public IReadOnlyDictionary<Type, IScriptableItemProperty> Properties =>
|
||
|
factoryProperty.ToDictionary(p => p.GetType(), p => p);
|
||
|
|
||
|
public IScriptableControllerClass ControllerClass => controllerClass;
|
||
|
|
||
|
public virtual IRuntimeItem CreateRuntimeItem()
|
||
|
{
|
||
|
var item = RuntimeItem.Create();
|
||
|
item.Amount = MaxStack;
|
||
|
item.Id = Random.Range(int.MinValue, int.MaxValue);
|
||
|
item.ScriptableId = Id;
|
||
|
if (properties is {Length:>0})
|
||
|
{
|
||
|
item.RuntimeProperties = properties.ToDictionary(x => x.GetType(), x => x);
|
||
|
}
|
||
|
return item;
|
||
|
}
|
||
|
|
||
|
public int Value => value;
|
||
|
}
|
||
|
|
||
|
}
|