157 lines
4.2 KiB
C#
157 lines
4.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace TcgEngine
|
||
{
|
||
/// <summary>
|
||
/// Defines all packs data
|
||
/// </summary>
|
||
|
||
[CreateAssetMenu(fileName = "PackData", menuName = "TcgEngine/PackData", order = 5)]
|
||
public class PackData : ScriptableObject
|
||
{
|
||
public string id;
|
||
|
||
[Header("Content")]
|
||
public PackType type;
|
||
public int cards = 5; //Cards per pack
|
||
public PackRarity[] rarities_1st; //Probability of each rarity, for first card
|
||
public PackRarity[] rarities; //Probability of each rarity, for other cards
|
||
public PackVariant[] variants; //Probability of each variant, for other cards
|
||
|
||
[Header("Display")]
|
||
public string title;
|
||
|
||
[Header("Dynamic Art Paths")]
|
||
public string pack_img_path;
|
||
public string cardback_img_path;
|
||
|
||
[TextArea(5, 10)]
|
||
public string desc;
|
||
public int sort_order;
|
||
|
||
[Header("Availability")]
|
||
public bool available = true;
|
||
public int cost = 100; //Cost to buy
|
||
|
||
public static List<PackData> pack_list = new List<PackData>();
|
||
|
||
public static void Load(string folder = "")
|
||
{
|
||
if (pack_list.Count == 0)
|
||
pack_list.AddRange(Resources.LoadAll<PackData>(folder));
|
||
|
||
pack_list.Sort((PackData a, PackData b) => {
|
||
if (a.sort_order == b.sort_order)
|
||
return a.id.CompareTo(b.id);
|
||
else
|
||
return a.sort_order.CompareTo(b.sort_order);
|
||
});
|
||
}
|
||
|
||
public string GetTitle()
|
||
{
|
||
return title;
|
||
}
|
||
|
||
public string GetDesc()
|
||
{
|
||
return desc;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取Pack图片,优先使用动态路径
|
||
/// </summary>
|
||
public Sprite GetPackImage()
|
||
{
|
||
if (!string.IsNullOrEmpty(pack_img_path))
|
||
{
|
||
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(pack_img_path);
|
||
if (dynamicSprite != null)
|
||
{
|
||
return dynamicSprite;
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"Pack {id} 图片加载失败: {pack_img_path}");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"Pack {id} pack_img_path为空");
|
||
}
|
||
return pack_img;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取卡背图片,优先使用动态路径
|
||
/// </summary>
|
||
public Sprite GetCardbackImage()
|
||
{
|
||
if (!string.IsNullOrEmpty(cardback_img_path))
|
||
{
|
||
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(cardback_img_path);
|
||
if (dynamicSprite != null)
|
||
{
|
||
return dynamicSprite;
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"Pack {id} 卡背图片加载失败: {cardback_img_path}");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.LogWarning($"Pack {id} cardback_img_path为空");
|
||
}
|
||
return cardback_img;
|
||
}
|
||
|
||
public static PackData Get(string id)
|
||
{
|
||
foreach (PackData pack in GetAll())
|
||
{
|
||
if (pack.id == id)
|
||
return pack;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public static List<PackData> GetAllAvailable()
|
||
{
|
||
List<PackData> valid_list = new List<PackData>();
|
||
foreach (PackData apack in GetAll())
|
||
{
|
||
if (apack.available)
|
||
valid_list.Add(apack);
|
||
}
|
||
return valid_list;
|
||
}
|
||
|
||
public static List<PackData> GetAll()
|
||
{
|
||
return pack_list;
|
||
}
|
||
}
|
||
|
||
public enum PackType
|
||
{
|
||
Random = 0,
|
||
Fixed = 10,
|
||
}
|
||
|
||
[System.Serializable]
|
||
public struct PackRarity
|
||
{
|
||
public RarityData rarity;
|
||
public int probability;
|
||
}
|
||
|
||
[System.Serializable]
|
||
public struct PackVariant
|
||
{
|
||
public VariantData variant;
|
||
public int probability;
|
||
}
|
||
} |