/// <summary> /// 生成卡片信息 /// </summary> public void Init(bool _isMy) { if (IsMonster()) { curAfk = afk; curDef = def; curLevel = level; curAttribute = attribute; cardAttackedTime = 0; } isMy = _isMy; duel = Duel.GetInstance(); if (ComVal.isInExtra(cardType)) { curArea = ComVal.Area_Extra; } else { curArea = ComVal.Area_MainDeck; } }
/// <summary> /// 排序 /// </summary> /// <param name="list"></param> /// <returns></returns> public static List <Card> SortCardList(List <Card> list) { List <Card> normalMonsterList = new List <Card>(); List <Card> monsterList = new List <Card>(); List <Card> spellList = new List <Card>(); List <Card> trapList = new List <Card>(); List <Card> xyzMonsterList = new List <Card>(); List <Card> fusionMonsterList = new List <Card>(); List <Card> synchroMonsterList = new List <Card>(); List <Card> resultList = new List <Card>(); for (int i = 0; i < list.Count; i++) { Card card = list[i]; if (card.IsMonster()) { if (!ComVal.isInExtra(card.cardType) && card.cardType != ComVal.CardType_Monster_Normal) { bool isInsert = false; for (int j = 0; j < monsterList.Count; j++)//有同名则插入其后面 { if (card.cardID == monsterList[j].cardID) { monsterList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { for (int x = 0; x < monsterList.Count; x++) { if (card.level < monsterList[x].level) { monsterList.Insert(x, card); isInsert = true; break; } } } if (!isInsert) { monsterList.Add(card); } } else if (card.cardType == ComVal.CardType_Monster_Normal) { bool isInsert = false; for (int j = 0; j < normalMonsterList.Count; j++)//有同名则插入其后面 { if (card.cardID == normalMonsterList[j].cardID) { normalMonsterList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { for (int x = 0; x < normalMonsterList.Count; x++) { if (card.level < normalMonsterList[x].level) { normalMonsterList.Insert(x, card); isInsert = true; break; } } } if (!isInsert) { normalMonsterList.Add(card); } } else if (card.cardType == ComVal.CardType_Monster_Fusion) { bool isInsert = false; for (int j = 0; j < fusionMonsterList.Count; j++)//有同名则插入其后面 { if (card.cardID == fusionMonsterList[j].cardID) { fusionMonsterList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { for (int x = 0; x < fusionMonsterList.Count; x++) { if (card.level < fusionMonsterList[x].level) { fusionMonsterList.Insert(x, card); isInsert = true; break; } } } if (!isInsert) { fusionMonsterList.Add(card); } } else if (card.cardType == ComVal.CardType_Monster_Synchro) { bool isInsert = false; for (int j = 0; j < synchroMonsterList.Count; j++)//有同名则插入其后面 { if (card.cardID == synchroMonsterList[j].cardID) { synchroMonsterList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { for (int x = 0; x < synchroMonsterList.Count; x++) { if (card.level < synchroMonsterList[x].level) { synchroMonsterList.Insert(x, card); isInsert = true; break; } } } if (!isInsert) { synchroMonsterList.Add(card); } } else if (card.cardType == ComVal.CardType_Monster_XYZ) { bool isInsert = false; for (int j = 0; j < xyzMonsterList.Count; j++)//有同名则插入其后面 { if (card.cardID == xyzMonsterList[j].cardID) { xyzMonsterList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { for (int x = 0; x < xyzMonsterList.Count; x++) { if (card.level < xyzMonsterList[x].level) { xyzMonsterList.Insert(x, card); isInsert = true; break; } } } if (!isInsert) { xyzMonsterList.Add(card); } } } else if (card.isSpell()) { bool isInsert = false; for (int j = 0; j < spellList.Count; j++)//有同名则插入其后面 { if (card.cardID == spellList[j].cardID) { spellList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { spellList.Add(card); } } else if (card.IsTrap()) { bool isInsert = false; for (int j = 0; j < trapList.Count; j++)//有同名则插入其后面 { if (card.cardID == trapList[j].cardID) { trapList.Insert(j, card); isInsert = true; break; } } if (!isInsert) { trapList.Add(card); } } } resultList.AddRange(normalMonsterList); resultList.AddRange(monsterList); resultList.AddRange(fusionMonsterList); resultList.AddRange(synchroMonsterList); resultList.AddRange(xyzMonsterList); resultList.AddRange(spellList); resultList.AddRange(trapList); return(resultList); }
/// <summary> /// 增加卡片 /// </summary> /// <param name="isMain">是否为主卡组</param> /// <param name="id">卡片id</param> public void AddCardToDeck(string id) { Card card = LoadXml.GetCard(id); bool isMain = !ComVal.isInExtra(card.cardType); int cardNum = 0; if (isMain) { foreach (var item in curDeck.mainDeck.cardList) { if (item.cardID == card.cardID) { cardNum++; } } } else { foreach (var item in curDeck.extraDeck.cardList) { if (item.cardID == card.cardID) { cardNum++; } } } if (cardNum >= 3) { return; } if (isMain) { if (curCard != null) { int val = GetObjVal(curCard.gameObject, isMain); AddToDeckFromPool(card, mainDeckGroup.transform, true); curDeck.mainDeck.InsertCard(card, val); for (int i = val; i < curDeck.mainDeck.GroupNum; i++) { mainDeckList[i].GetComponent <Card_Edit>().SetTexture(curDeck.mainDeck.GetCard(i).cardID, true); } UpdateText(); return; } if (mainDeckList.Count > curDeck.mainDeck.cardList.Count) { Card_Edit theCard_edit = mainDeckList[curDeck.mainDeck.cardList.Count].GetComponent <Card_Edit>(); theCard_edit.SetTexture(card.cardID, true); theCard_edit.SetActive(true); } else if (mainDeckList.Count == curDeck.mainDeck.cardList.Count) { AddToDeckFromPool(card, mainDeckGroup.transform, true); } else { Debug.Log("error"); } curDeck.mainDeck.AddCard(card); } else { if (curCard != null) { int val = GetObjVal(curCard.gameObject, isMain); AddToDeckFromPool(card, extraDeckGroup.transform, false); curDeck.extraDeck.InsertCard(card, val); for (int i = val; i < curDeck.extraDeck.GroupNum; i++) { extraDeckList[i].GetComponent <Card_Edit>().SetTexture(curDeck.extraDeck.GetCard(i).cardID, true); } UpdateText(); return; } if (extraDeckList.Count > curDeck.extraDeck.cardList.Count) { Card_Edit theCard_edit = extraDeckList[curDeck.extraDeck.cardList.Count].GetComponent <Card_Edit>(); theCard_edit.SetTexture(card.cardID, true); theCard_edit.SetActive(true); } else if (extraDeckList.Count == curDeck.extraDeck.cardList.Count) { AddToDeckFromPool(card, extraDeckGroup.transform, false); } else { Debug.Log("error"); } curDeck.extraDeck.AddCard(card); } UpdateText(); }