213 lines
7.2 KiB
C#
213 lines
7.2 KiB
C#
using Invector;
|
|
using Sirenix.OdinInspector;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
[System.Serializable]
|
|
public partial class bItem : ScriptableObject
|
|
{
|
|
#region SerializedProperties in customEditor
|
|
|
|
[HideInInspector]
|
|
public int id;
|
|
|
|
[HideInInspector]
|
|
public string secondaryName = "secondary Name";
|
|
|
|
[HideInInspector]
|
|
public string description = "Item Description";
|
|
|
|
[HideInInspector]
|
|
public string secondaryDescription = "Secondary Description";
|
|
|
|
[HideInInspector]
|
|
public bItemType type;
|
|
|
|
// --- NEW TRINKET FIELD ---
|
|
// Removed [HideInInspector] so you can see it in default inspector
|
|
// If you have a custom Editor script for bItem, you may need to add a line there to draw this property.
|
|
public TrinketColor trinketColor;
|
|
// -------------------------
|
|
[FoldoutGroup("Magic Settings")]
|
|
[InfoBox("Assign the Spell Definition here. If null, this item is not a spell.")]
|
|
[InlineEditor]
|
|
public SpellDefinition spellDefinition;
|
|
|
|
[HideInInspector]
|
|
public Sprite icon, secondaryIcon, teriaryIcon;
|
|
|
|
[HideInInspector]
|
|
public string iconPath, secondaryIconPath, teriaryIconPath;
|
|
|
|
[HideInInspector]
|
|
public bool stackable = true;
|
|
|
|
[HideInInspector]
|
|
public int maxStack;
|
|
|
|
[HideInInspector]
|
|
public int amount;
|
|
|
|
[HideInInspector]
|
|
public GameObject originalObject;
|
|
|
|
[HideInInspector]
|
|
public GameObject dropObject;
|
|
|
|
[HideInInspector]
|
|
public List<bItemAttribute> attributes = new List<bItemAttribute>();
|
|
|
|
[HideInInspector]
|
|
public bool isInEquipArea;
|
|
|
|
public Color checkColor = Color.cyan;
|
|
|
|
[HideInInspector]
|
|
public bool isEquiped;
|
|
|
|
#endregion SerializedProperties in customEditor
|
|
|
|
#region Properties in defaultInspector
|
|
|
|
public bool destroyAfterUse = true;
|
|
public bool canBeUsed = true;
|
|
public bool canBeDroped = true;
|
|
public bool canBeDestroyed = true;
|
|
|
|
[Header("Animation Settings")]
|
|
[vHelpBox("Triggers a animation when Equipping a Weapon or enabling item.\nYou can also trigger an animation if the ItemType is a Consumable")]
|
|
public string EnableAnim = "LowBack";
|
|
|
|
[vHelpBox("Triggers a animation when Unequipping a Weapon or disable item")]
|
|
public string DisableAnim = "LowBack";
|
|
|
|
[vHelpBox("Delay to enable the Weapon/Item object when Equipping\n If ItemType is a Consumable use this to delay the item usage.")]
|
|
public float enableDelayTime = 0.5f;
|
|
|
|
[vHelpBox("Delay to hide the Weapon/Item object when Unequipping")]
|
|
public float disableDelayTime = 0.5f;
|
|
|
|
[vHelpBox("If the item is equippable use this to set a custom handler to instantiate the SpawnObject")]
|
|
public string customHandler;
|
|
|
|
[vHelpBox("If the item is equippable and need to use two hand\n<color=yellow><b>This option makes it impossible to equip two items</b></color>")]
|
|
public bool twoHandWeapon;
|
|
|
|
[HideInInspector]
|
|
public OnHandleItemEvent onDestroy;
|
|
|
|
#endregion Properties in defaultInspector
|
|
|
|
public void OnDestroy()
|
|
{
|
|
onDestroy.Invoke(this);
|
|
}
|
|
|
|
public Texture2D iconTexture
|
|
{
|
|
get
|
|
{
|
|
if (!icon) return null;
|
|
try
|
|
{
|
|
if (icon.rect.width != icon.texture.width || icon.rect.height != icon.texture.height)
|
|
{
|
|
Texture2D newText = new Texture2D((int)icon.textureRect.width, (int)icon.textureRect.height);
|
|
newText.name = icon.name;
|
|
Color[] newColors = icon.texture.GetPixels((int)icon.textureRect.x, (int)icon.textureRect.y, (int)icon.textureRect.width, (int)icon.textureRect.height);
|
|
newText.SetPixels(newColors);
|
|
newText.Apply();
|
|
return newText;
|
|
}
|
|
else
|
|
return icon.texture;
|
|
}
|
|
catch
|
|
{
|
|
Debug.LogWarning("Icon texture of the " + name + " is not Readable", icon.texture);
|
|
return icon.texture;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bItemAttribute GetItemAttribute(bItemAttributes attribute)
|
|
{
|
|
if (attributes != null) return attributes.Find(_attribute => _attribute.name == attribute);
|
|
return null;
|
|
}
|
|
|
|
public bItemAttribute GetItemAttribute(string name)
|
|
{
|
|
if (attributes != null)
|
|
return attributes.Find(attribute => attribute.name.ToString().Equals(name));
|
|
return null;
|
|
}
|
|
|
|
public string GetItemAttributesText(List<bItemAttributes> ignore = null)
|
|
{
|
|
System.Text.StringBuilder text = new System.Text.StringBuilder();
|
|
for (int i = 0; i < attributes.Count; i++)
|
|
{
|
|
if (ignore == null || !ignore.Contains(attributes[i].name))
|
|
text.AppendLine(GetItemAttributeText(i));
|
|
}
|
|
return text.ToString();
|
|
}
|
|
|
|
protected string GetItemAttributeText(int i)
|
|
{
|
|
if (attributes.Count > 0 && i < attributes.Count)
|
|
{
|
|
return attributes[i].GetDisplayText();
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
protected string GetItemAttributeText(int i, string customFormat)
|
|
{
|
|
if (attributes.Count > 0 && i < attributes.Count)
|
|
{
|
|
return attributes[i].GetDisplayText(customFormat);
|
|
}
|
|
return string.Empty;
|
|
}
|
|
|
|
public string ItemTypeText()
|
|
{
|
|
return ItemTypeText(type.DisplayFormat());
|
|
}
|
|
|
|
public string ItemTypeText(string format)
|
|
{
|
|
var _text = format;
|
|
var value = type.ToString().InsertSpaceBeforeUpperCase().RemoveUnderline();
|
|
if (string.IsNullOrEmpty(_text))
|
|
return value;
|
|
else if (_text.Contains("(NAME)")) _text.Replace("(NAME)", value);
|
|
return _text;
|
|
}
|
|
|
|
public string GetFullItemDescription(string format = null, List<bItemAttributes> ignoreAttributes = null)
|
|
{
|
|
string text = "";
|
|
if (string.IsNullOrEmpty(format))
|
|
{
|
|
text += (name);
|
|
text += "\n" + (ItemTypeText());
|
|
text += "\n" + (description);
|
|
text += "\n" + (GetItemAttributesText());
|
|
}
|
|
else
|
|
{
|
|
text = format;
|
|
if (text.Contains("(NAME)")) text = text.Replace("(NAME)", name);
|
|
if (text.Contains("(TYPE)")) text = text.Replace("(TYPE)", ItemTypeText());
|
|
if (text.Contains("(DESC)")) text = text.Replace("(DESC)", description);
|
|
if (text.Contains("(ATTR)")) text = text.Replace("(ATTR)", GetItemAttributesText(ignoreAttributes));
|
|
}
|
|
return text;
|
|
}
|
|
}
|
|
} |