123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
-
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using ET;
- using UnityEngine;
- namespace GFGGame
- {
- public class CardDataManager
- {
- private static Dictionary<int, Dictionary<int, CardData>> _cardDicByType = new Dictionary<int, Dictionary<int, CardData>>();
- public static Dictionary<int, Dictionary<int, int>> _selectList = new Dictionary<int, Dictionary<int, int>>();
- private static Dictionary<int, List<CardStoryCfg>> _cardStoryCfgDic = new Dictionary<int, List<CardStoryCfg>>();
- public static void Clear()
- {
- _cardDicByType.Clear();
- }
- public static void Add(CardInfoProto cardInfoProto)
- {
- CardData cardData = new CardData();
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(cardInfoProto.CardId);
- cardData.id = cardInfoProto.CardId;
- cardData.lv = cardInfoProto.Lvl;
- cardData.exp = cardInfoProto.Exp;
- cardData.star = cardInfoProto.Star;
- cardData.itemCfg = itemCfg;
- cardData.resIndex = cardInfoProto.ResIndex;
- cardData.scores = new Dictionary<int, int>();
- for (int j = 0; j < cardInfoProto.KsAttribute.Count; j++)
- {
- cardData.scores.Add(cardInfoProto.KsAttribute[j], cardInfoProto.VsAttribute[j]);
- }
- cardData.mainScore = itemCfg.mainScore;
- cardData.resources = CardDataManager.GetCardResources(itemCfg);
- if (_cardDicByType.ContainsKey(0) == false)
- {
- _cardDicByType[0] = new Dictionary<int, CardData>();
- }
- if (_cardDicByType.ContainsKey(cardData.itemCfg.mainScore) == false)
- {
- _cardDicByType[cardData.itemCfg.mainScore] = new Dictionary<int, CardData>();
- }
- _cardDicByType[0][cardData.id] = cardData;
- _cardDicByType[cardData.itemCfg.mainScore][cardData.id] = cardData;
- }
- private static List<string> GetCardResources(ItemCfg itemCfg)
- {
- List<string> resources = new List<string>();
- resources.Add(itemCfg.res);
- if (itemCfg.cardRes != "")
- {
- resources.Add(itemCfg.cardRes);
- }
- return resources;
- }
- private static List<CardData> SortItemList(List<CardData> arrayList)
- {
- arrayList.Sort((CardData a, CardData b) =>
- {
- int rarityA = a.itemCfg.rarity;
- int rarityB = b.itemCfg.rarity;
- if (rarityA < rarityB)
- {
- return 1;
- }
- else if (rarityA > rarityB)
- {
- return -1;
- }
- return string.Compare(a.itemCfg.res, b.itemCfg.res);
- });
- return arrayList;
- }
- /// <summary>
- /// 根据卡牌Id获取卡牌升级升星数据,无数据返回null
- /// </summary>
- /// <param name="cardId"></param>
- /// <returns></returns>
- public static CardData GetCardDataById(int cardId)
- {
- return _cardDicByType[0].ContainsKey(cardId) ? _cardDicByType[0][cardId] : null;
- }
- /// <summary>
- /// 根据男主类型获取卡牌列表
- /// </summary>
- public static List<CardData> GetCardListByRarity(int mainScore)
- {
- if (_cardDicByType.ContainsKey(mainScore))
- {
- Dictionary<int, CardData> cardDic = _cardDicByType[mainScore];
- CardData[] cardArray = new CardData[cardDic.Count];
- cardDic.Values.CopyTo(cardArray, 0);
- List<CardData> cardList = new List<CardData>(cardArray);
- cardList = CardDataManager.SortItemList(cardList);
- return cardList;
- }
- return new List<CardData>();
- }
- public static bool isFullLv(int cardId, int lv, bool showTips = true)
- {
- CardData cardData = _cardDicByType[0][cardId];
- if (lv >= CardRarityCfgArray.Instance.GetCfg(cardData.itemCfg.rarity).maxCardLvl && cardData.exp >= CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(lv, cardData.itemCfg.rarity).needExp)
- {
- if (showTips == true)
- {
- PromptController.Instance.ShowFloatTextPrompt("已达到最大等级");
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool isFullStar(int cardId, int star, bool showTips = true)
- {
- CardData cardData = _cardDicByType[0][cardId];
- if (CardStarCfgArray.Instance.GetCfgBycardTypeAndcardRarityAndstarLvl(cardData.itemCfg.subType, cardData.itemCfg.rarity, star + 1) == null)
- {
- if (showTips == true)
- {
- PromptController.Instance.ShowFloatTextPrompt("已达到最大星级");
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- public static void GetPreViewLvAndExp(int rarity, int curLv, int curExp, int hasExp, out int showLv, out int showExp)
- {
- showLv = curLv;
- showExp = curExp + hasExp;
- int maxLv = CardRarityCfgArray.Instance.GetCfg(rarity).maxCardLvl;
- CardLvlCfg tCurCfg = CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(showLv, rarity);
- while (showExp >= tCurCfg.needExp && showLv <= maxLv)
- {
- showExp -= tCurCfg.needExp;
- if (showLv + 1 > maxLv)
- {
- //满级
- // showLv = showLv - 1;
- showExp = tCurCfg.needExp;
- break;
- }
- showLv++;
- tCurCfg = CardLvlCfgArray.Instance.GetCfgBycardLvlAndcardRarity(showLv, rarity);
- // if (showExp < tCurCfg.needExp)
- // {
- // showLv = showLv - 1;
- // break;
- // }
- }
- }
- public static List<CardData> FilterCardList(List<CardData> cardList, Dictionary<int, Dictionary<int, int>> selectList)
- {
- List<CardData> _cardList = new List<CardData>();
- if (selectList.ContainsKey((int)EnumCardFilterType.SubType) == true && selectList[(int)EnumCardFilterType.SubType].Keys.Count > 0)
- {
- for (int i = cardList.Count - 1; i >= 0; i--)
- {
- if (selectList[(int)EnumCardFilterType.SubType].ContainsKey(cardList[i].itemCfg.subType) == false)
- {
- //稀有度
- cardList.RemoveAt(i);
- continue;
- }
- }
- }
- if (selectList.ContainsKey((int)EnumCardFilterType.PROPERTY) == true && selectList[(int)EnumCardFilterType.PROPERTY].Keys.Count > 0)
- {
- for (int i = cardList.Count - 1; i >= 0; i--)
- {
- if (selectList[(int)EnumCardFilterType.PROPERTY].ContainsKey(cardList[i].mainScore) == false)
- {
- cardList.RemoveAt(i);
- continue;
- }
- }
- }
- //属性
- if (selectList.ContainsKey((int)EnumCardFilterType.FOSTER) == true && selectList[(int)EnumCardFilterType.FOSTER].Keys.Count > 0)
- {
- for (int i = 0; i < cardList.Count; i++)
- {
- //培养度
- int maxLv = CardRarityCfgArray.Instance.GetCfg(cardList[i].itemCfg.rarity).maxCardLvl;
- ICollection keys = selectList[(int)EnumCardFilterType.FOSTER].Keys;
- foreach (int key in keys)
- {
- if (key == ConstCardState.STATE_FULL_LV && cardList[i].lv == maxLv ||
- key == ConstCardState.STATE_LV && cardList[i].lv < maxLv ||
- key == ConstCardState.STATE_FULL_STAR && isFullStar(cardList[i].id, cardList[i].star, false) ||
- key == ConstCardState.STATE_STAR && !isFullStar(cardList[i].id, cardList[i].star, false))
- {
- if (_cardList.IndexOf(cardList[i]) >= 0) continue;//一张卡片同时满足星级和等级条件时,不能重复添加
- _cardList.Add(cardList[i]);
- continue;
- }
- //if ()
- //{
- //技能相关留空
- //}
- }
- }
- return _cardList;
- }
- else
- {
- return cardList;
- }
- }
- public static List<CardStoryCfg> GetStoryCfgsById(int cardId)
- {
- if (_cardStoryCfgDic.Keys.Count == 0)
- {
- CardStoryCfg[] cardStoryCfgs = CardStoryCfgArray.Instance.dataArray;
- for (int i = 0; i < cardStoryCfgs.Length; i++)
- {
- int _cardId = cardStoryCfgs[i].cardId;
- if (_cardStoryCfgDic.ContainsKey(_cardId) == false)
- {
- _cardStoryCfgDic.Add(_cardId, new List<CardStoryCfg>());
- }
- _cardStoryCfgDic[_cardId].Add(cardStoryCfgs[i]);
- }
- }
- return _cardStoryCfgDic.ContainsKey(cardId) ? _cardStoryCfgDic[cardId] : new List<CardStoryCfg>();
- }
- }
- }
|