feat(Card): 卡牌基本框架,尚未测试
This commit is contained in:
@@ -4,10 +4,23 @@ namespace Card
|
||||
{
|
||||
public class Card
|
||||
{
|
||||
private CardConfig cardConfig;
|
||||
|
||||
public Sprite Sprite => cardConfig.CardIcon;
|
||||
public string CardName => cardConfig.CardName;
|
||||
public string CardDescription => cardConfig.CardDescription;
|
||||
private CardData _cardData;
|
||||
public Texture Texture => _cardData.CardTexture;
|
||||
public string CardName => _cardData.CardName;
|
||||
public string CardDescription => _cardData.CardDescription;
|
||||
public EffectData[] Effects => _cardData.Effects;
|
||||
|
||||
public Card(CardData cardData)
|
||||
{
|
||||
_cardData = cardData;
|
||||
}
|
||||
|
||||
public void PlayCard(CardContext context)
|
||||
{
|
||||
foreach (var effect in Effects)
|
||||
{
|
||||
EffectHandler.Execute(effect, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Card
|
||||
{
|
||||
public class CardConfig : ScriptableObject
|
||||
{
|
||||
public string CardName;
|
||||
public string CardDescription;
|
||||
public Sprite CardIcon;
|
||||
}
|
||||
|
||||
}
|
16
Assets/Script/Card/CardData.cs
Normal file
16
Assets/Script/Card/CardData.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Card
|
||||
{
|
||||
[CreateAssetMenu(fileName = "NewCard", menuName = "Card/CardData")]
|
||||
public class CardData : ScriptableObject
|
||||
{
|
||||
public string CardName;
|
||||
public string CardDescription;
|
||||
public Texture CardTexture;
|
||||
public EffectData[] Effects;
|
||||
}
|
||||
|
||||
}
|
10
Assets/Script/Card/CardEffect/CardContext.cs
Normal file
10
Assets/Script/Card/CardEffect/CardContext.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using UnityEngine;
|
||||
using Share;
|
||||
namespace Card
|
||||
{
|
||||
public class CardContext
|
||||
{
|
||||
public ICharacter Player;
|
||||
public ICharacter Target;
|
||||
}
|
||||
}
|
3
Assets/Script/Card/CardEffect/CardContext.cs.meta
Normal file
3
Assets/Script/Card/CardEffect/CardContext.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7279b5677f724ab4b93bd1028542d110
|
||||
timeCreated: 1760420712
|
28
Assets/Script/Card/CardEffect/EffectData.cs
Normal file
28
Assets/Script/Card/CardEffect/EffectData.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Card
|
||||
{
|
||||
[System.Serializable]
|
||||
public class EffectData
|
||||
{
|
||||
public EffectType type; // 效果类型,例如攻击、治疗、抽卡
|
||||
public int value; // 参数值
|
||||
public TargetType target; // 可选参数:目标类型("self", "enemy", "all")
|
||||
}
|
||||
|
||||
public enum TargetType
|
||||
{
|
||||
Self,
|
||||
Enemy,
|
||||
All,
|
||||
None
|
||||
}
|
||||
|
||||
public enum EffectType
|
||||
{
|
||||
Damage,
|
||||
Heal,
|
||||
DrawCard,
|
||||
AddBuff,
|
||||
}
|
||||
}
|
3
Assets/Script/Card/CardEffect/EffectData.cs.meta
Normal file
3
Assets/Script/Card/CardEffect/EffectData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5790e0b2fbce41c99a775bbacca0e2bc
|
||||
timeCreated: 1760420527
|
33
Assets/Script/Card/CardEffect/EffectHandler.cs
Normal file
33
Assets/Script/Card/CardEffect/EffectHandler.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Card
|
||||
{
|
||||
public static class EffectHandler
|
||||
{
|
||||
public static void Execute(EffectData effect, CardContext context)
|
||||
{
|
||||
switch (effect.type)
|
||||
{
|
||||
case EffectType.Damage:
|
||||
context.Target.TakeDamage(effect.value);
|
||||
break;
|
||||
|
||||
case EffectType.Heal:
|
||||
context.Target.Heal(effect.value);
|
||||
break;
|
||||
|
||||
case EffectType.DrawCard:
|
||||
context.Player.Draw(effect.value);
|
||||
break;
|
||||
|
||||
case EffectType.AddBuff:
|
||||
//TODO:context.Target.AddBuff(effect.value);
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.LogWarning($"未知效果类型: {effect.type}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Script/Card/CardEffect/EffectHandler.cs.meta
Normal file
3
Assets/Script/Card/CardEffect/EffectHandler.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 032e368e3d5846d78caf5f3239de979f
|
||||
timeCreated: 1760420695
|
@@ -1,7 +0,0 @@
|
||||
namespace Card
|
||||
{
|
||||
public interface ICardEffect
|
||||
{
|
||||
public void DoEffect();
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2f68930f8eb498aabe29d66e5740753
|
||||
timeCreated: 1760405389
|
@@ -8,14 +8,14 @@ namespace Card
|
||||
{
|
||||
public Card Card;
|
||||
|
||||
[SerializeField] private SpriteRenderer spriteRenderer;
|
||||
[SerializeField] private MeshRenderer meshRenderer;
|
||||
[SerializeField] private Text cardNameText;
|
||||
[SerializeField] private Text cardDescriptionText;
|
||||
|
||||
public void Setup(Card card)
|
||||
{
|
||||
Card = card;
|
||||
spriteRenderer.sprite = card.Sprite;
|
||||
meshRenderer.material.mainTexture = card.Texture;
|
||||
cardNameText.text = card.CardName;
|
||||
cardDescriptionText.text = card.CardDescription;
|
||||
}
|
||||
|
15
Assets/Script/Share/ICharacter.cs
Normal file
15
Assets/Script/Share/ICharacter.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Share
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色接口,可受伤害、治疗和添加Buff
|
||||
/// </summary>
|
||||
public interface ICharacter
|
||||
{
|
||||
public void TakeDamage(int damage);
|
||||
public void Heal(int heal);
|
||||
public void AddBuff(string buffName, int duration);
|
||||
public void Draw(int count);
|
||||
}
|
||||
}
|
3
Assets/Script/Share/ICharacter.cs.meta
Normal file
3
Assets/Script/Share/ICharacter.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0f41a6a18dd4801a9d6ba995cf09376
|
||||
timeCreated: 1760420819
|
Reference in New Issue
Block a user