401 lines
11 KiB
C#
401 lines
11 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace TcgEngine
|
|
{
|
|
public enum CardType
|
|
{
|
|
None = 0,
|
|
Hero = 5,
|
|
Character = 10,
|
|
Spell = 20,
|
|
Artifact = 30,
|
|
Secret = 40,
|
|
Equipment = 50,
|
|
}
|
|
|
|
public enum CardCamp
|
|
{
|
|
None = -1, // 无阵营限制
|
|
ZiYouRen = 0, // 自由人
|
|
YiYongJun = 5, // 义勇军
|
|
WangGuoJun = 10, // 王国军
|
|
DiGuoJun = 20, // 帝国军
|
|
ShouQun = 30, // 兽群
|
|
XieMo = 40, // 邪魔
|
|
}
|
|
|
|
/// <summary>
|
|
/// Defines all card data
|
|
/// </summary>
|
|
|
|
[CreateAssetMenu(fileName = "card", menuName = "TcgEngine/CardData", order = 5)]
|
|
public class CardData : ScriptableObject
|
|
{
|
|
public string id;
|
|
|
|
[Header("Display")]
|
|
public string title;
|
|
|
|
[Header("Dynamic Art Paths")]
|
|
public string art_full_path;
|
|
public string art_board_path;
|
|
public string art_horizontal_path;
|
|
public string art_vertical_path;
|
|
|
|
|
|
[Header("Stats")]
|
|
public CardType type;
|
|
public CardCamp camp;
|
|
public TeamData team;
|
|
public RarityData rarity;
|
|
public int mana;
|
|
public int attack;
|
|
public int hp;
|
|
|
|
[Header("Traits")]
|
|
public TraitData[] traits;
|
|
public TraitStat[] stats;
|
|
|
|
[Header("Abilities")]
|
|
public AbilityData[] abilities;
|
|
|
|
[Header("Card Text")]
|
|
[TextArea(3, 5)]
|
|
public string text;
|
|
|
|
[Header("Description")]
|
|
[TextArea(5, 10)]
|
|
public string desc;
|
|
|
|
[Header("FX")]
|
|
public GameObject spawn_fx;
|
|
public GameObject death_fx;
|
|
public GameObject attack_fx;
|
|
public GameObject damage_fx;
|
|
public GameObject idle_fx;
|
|
public AudioClip spawn_audio;
|
|
public AudioClip death_audio;
|
|
public AudioClip attack_audio;
|
|
public AudioClip damage_audio;
|
|
|
|
[Header("Availability")]
|
|
public bool deckbuilding = false;
|
|
public int cost = 100;
|
|
public PackData[] packs;
|
|
|
|
public static List<CardData> card_list = new List<CardData>(); //Faster access in loops
|
|
public static Dictionary<string, CardData> card_dict = new Dictionary<string, CardData>(); //Faster access in Get(id)
|
|
|
|
public static void Load(string folder = "")
|
|
{
|
|
if (card_list.Count == 0)
|
|
{
|
|
card_list.AddRange(Resources.LoadAll<CardData>(folder));
|
|
|
|
foreach (CardData card in card_list)
|
|
card_dict.Add(card.id, card);
|
|
}
|
|
}
|
|
|
|
public Sprite GetBoardArt(VariantData variant)
|
|
{
|
|
if (!string.IsNullOrEmpty(art_board_path))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(art_board_path);
|
|
if (dynamicSprite != null)
|
|
return dynamicSprite;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Sprite GetFullArt(VariantData variant)
|
|
{
|
|
if (!string.IsNullOrEmpty(art_full_path))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(art_full_path);
|
|
if (dynamicSprite != null)
|
|
{
|
|
return dynamicSprite;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} 图片加载失败: {art_full_path}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} art_full_path为空");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Sprite GetHorizontalArt()
|
|
{
|
|
if (!string.IsNullOrEmpty(art_horizontal_path))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(art_horizontal_path);
|
|
if (dynamicSprite != null)
|
|
{
|
|
return dynamicSprite;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} 图片加载失败: {art_horizontal_path}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} art_horizontal_path为空");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public Sprite GetVerticalArt()
|
|
{
|
|
if (!string.IsNullOrEmpty(art_vertical_path))
|
|
{
|
|
Sprite dynamicSprite = SpriteLoader.Get()?.LoadSprite(art_vertical_path);
|
|
if (dynamicSprite != null)
|
|
{
|
|
return dynamicSprite;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} 图片加载失败: {art_vertical_path}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"卡牌{id} art_vertical_path为空");
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public string GetTitle()
|
|
{
|
|
return title;
|
|
}
|
|
|
|
public string GetText()
|
|
{
|
|
return text;
|
|
}
|
|
|
|
public string GetDesc()
|
|
{
|
|
return desc;
|
|
}
|
|
|
|
public string GetTypeId()
|
|
{
|
|
if (type == CardType.Hero)
|
|
return "hero";
|
|
if (type == CardType.Character)
|
|
return "character";
|
|
if (type == CardType.Artifact)
|
|
return "artifact";
|
|
if (type == CardType.Spell)
|
|
return "spell";
|
|
if (type == CardType.Secret)
|
|
return "secret";
|
|
if (type == CardType.Equipment)
|
|
return "equipment";
|
|
return "";
|
|
}
|
|
|
|
public string GetAbilitiesDesc()
|
|
{
|
|
string txt = "";
|
|
foreach (AbilityData ability in abilities)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(ability.desc))
|
|
txt += "<b>" + ability.GetTitle() + ":</b> " + ability.GetDesc(this) + "\n";
|
|
}
|
|
return txt;
|
|
}
|
|
|
|
public bool IsCharacter()
|
|
{
|
|
return type == CardType.Character;
|
|
}
|
|
|
|
public bool IsSecret()
|
|
{
|
|
return type == CardType.Secret;
|
|
}
|
|
|
|
public bool IsBoardCard()
|
|
{
|
|
return type == CardType.Character || type == CardType.Artifact;
|
|
}
|
|
|
|
public bool IsRequireTarget()
|
|
{
|
|
return type == CardType.Equipment || IsRequireTargetSpell();
|
|
}
|
|
|
|
public bool IsRequireTargetSpell()
|
|
{
|
|
return type == CardType.Spell && HasAbility(AbilityTrigger.OnPlay, AbilityTarget.PlayTarget);
|
|
}
|
|
|
|
public bool IsEquipment()
|
|
{
|
|
return type == CardType.Equipment;
|
|
}
|
|
|
|
public bool IsDynamicManaCost()
|
|
{
|
|
// 检查通用法力值是否为动态消耗
|
|
if (mana > 99)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
public bool HasTrait(string trait)
|
|
{
|
|
foreach (TraitData t in traits)
|
|
{
|
|
if (t.id == trait)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool HasTrait(TraitData trait)
|
|
{
|
|
if (trait != null)
|
|
return HasTrait(trait.id);
|
|
return false;
|
|
}
|
|
|
|
public bool HasStat(string trait)
|
|
{
|
|
if (stats == null)
|
|
return false;
|
|
|
|
foreach (TraitStat stat in stats)
|
|
{
|
|
if (stat.trait.id == trait)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool HasStat(TraitData trait)
|
|
{
|
|
if (trait != null)
|
|
return HasStat(trait.id);
|
|
return false;
|
|
}
|
|
|
|
public int GetStat(string trait_id)
|
|
{
|
|
if (stats == null)
|
|
return 0;
|
|
|
|
foreach (TraitStat stat in stats)
|
|
{
|
|
if (stat.trait.id == trait_id)
|
|
return stat.value;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public int GetStat(TraitData trait)
|
|
{
|
|
if (trait != null)
|
|
return GetStat(trait.id);
|
|
return 0;
|
|
}
|
|
|
|
public bool HasAbility(AbilityData tability)
|
|
{
|
|
foreach (AbilityData ability in abilities)
|
|
{
|
|
if (ability && ability.id == tability.id)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool HasAbility(AbilityTrigger trigger)
|
|
{
|
|
foreach (AbilityData ability in abilities)
|
|
{
|
|
if (ability && ability.trigger == trigger)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public bool HasAbility(AbilityTrigger trigger, AbilityTarget target)
|
|
{
|
|
foreach (AbilityData ability in abilities)
|
|
{
|
|
if (ability && ability.trigger == trigger && ability.target == target)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public AbilityData GetAbility(AbilityTrigger trigger)
|
|
{
|
|
foreach (AbilityData ability in abilities)
|
|
{
|
|
if (ability && ability.trigger == trigger)
|
|
return ability;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public bool HasPack(PackData pack)
|
|
{
|
|
foreach (PackData apack in packs)
|
|
{
|
|
if (apack == pack)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static CardData Get(string id)
|
|
{
|
|
if (id == null)
|
|
return null;
|
|
bool success = card_dict.TryGetValue(id, out CardData card);
|
|
if (success)
|
|
return card;
|
|
return null;
|
|
}
|
|
|
|
public static List<CardData> GetAllDeckbuilding()
|
|
{
|
|
List<CardData> multi_list = new List<CardData>();
|
|
foreach (CardData acard in GetAll())
|
|
{
|
|
if (acard.deckbuilding)
|
|
multi_list.Add(acard);
|
|
}
|
|
return multi_list;
|
|
}
|
|
|
|
public static List<CardData> GetAll(PackData pack)
|
|
{
|
|
List<CardData> multi_list = new List<CardData>();
|
|
foreach (CardData acard in GetAll())
|
|
{
|
|
if (acard.HasPack(pack))
|
|
multi_list.Add(acard);
|
|
}
|
|
return multi_list;
|
|
}
|
|
|
|
public static List<CardData> GetAll()
|
|
{
|
|
return card_list;
|
|
}
|
|
}
|
|
} |