You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.5 KiB
93 lines
2.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CardStore : MonoBehaviour
|
|
{
|
|
public TextAsset cardData;
|
|
public List<Card> cardList = new List<Card> ();
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//LoadCardData();
|
|
//TestLoad();
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
public void LoadCardData()
|
|
{
|
|
string[] dateRow = cardData.text.Split('\n');
|
|
foreach (var row in dateRow)
|
|
{
|
|
string[] rowArray = row.Split(',');
|
|
if (rowArray[0]=="#")
|
|
{
|
|
continue;
|
|
}
|
|
else if (rowArray[0]=="monster")
|
|
{
|
|
//新建怪兽卡
|
|
int id = int.Parse(rowArray[1]);
|
|
string name = rowArray[2];
|
|
int atk = int.Parse(rowArray[3]);
|
|
int health = int.Parse(rowArray[4]);
|
|
MonsterCard monsterCard = new MonsterCard(id,name,atk,health);
|
|
cardList.Add(monsterCard);
|
|
|
|
//Debug.Log("Save Card:" + monsterCard.CardName);
|
|
}
|
|
else if (rowArray[0]=="spell")
|
|
{
|
|
//新建魔法卡
|
|
int id = int.Parse(rowArray[1]);
|
|
string name = rowArray[2];
|
|
string effect = rowArray[3];
|
|
int effectvalue = int.Parse(rowArray[4]);
|
|
SpellCard spellCard = new SpellCard(id,name,effect,effectvalue);
|
|
cardList.Add(spellCard);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void TestLoad()
|
|
{
|
|
foreach (var card in cardList)
|
|
{
|
|
Debug.Log("Card:"+card.id.ToString()+card.CardName);
|
|
}
|
|
}
|
|
|
|
public Card RandomCard()//随机抽卡,待改进为概率抽卡
|
|
{
|
|
Card card = cardList[Random.Range(0,cardList.Count)];
|
|
return card;
|
|
}
|
|
|
|
public Card CopyCard(int _id)
|
|
{
|
|
Card copyCard = new Card(_id, cardList[_id].CardName);
|
|
if (cardList[_id] is MonsterCard)
|
|
{
|
|
var monstercard = cardList[_id] as MonsterCard;
|
|
copyCard = new MonsterCard(_id, monstercard.CardName, monstercard.attack, monstercard.healthPointMax);
|
|
}
|
|
else if (cardList[_id] is SpellCard)
|
|
{
|
|
var spellcard = cardList[_id] as SpellCard;
|
|
copyCard = new SpellCard(_id, spellcard.CardName, spellcard.effect, spellcard.effectvalue);
|
|
}
|
|
//其他卡牌类型
|
|
|
|
return copyCard;
|
|
}
|
|
|
|
|
|
}
|