76 lines
2.7 KiB
C#
76 lines
2.7 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using Continentis.MainGame;
|
||
using Continentis.MainGame.Card;
|
||
using SLSFramework.UModAssistance;
|
||
using UnityEngine;
|
||
|
||
namespace Continentis.Mods.Basic.Cards
|
||
{
|
||
public class CardLogicComponent_GenerateCards : CardLogicComponentBase
|
||
{
|
||
private Func<CardData, bool> cardFilter;
|
||
|
||
public override void Initialize(CardLogicBase card)
|
||
{
|
||
base.Initialize(card);
|
||
cardFilter = cardData => !cardData.HasKeyword("Unobtainable");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置卡牌过滤器
|
||
/// </summary>
|
||
public void SetFilter(Func<CardData, bool> filter)
|
||
{
|
||
List<Func<CardData, bool>> originalFilters = new List<Func<CardData, bool>>();
|
||
originalFilters.Add(cardData => !cardData.HasKeyword("Unobtainable"));
|
||
if (filter != null) originalFilters.Add(filter);
|
||
this.cardFilter = cardData => originalFilters.All(f => f(cardData));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从指定的cardDataID中,根据needFilter决定是否进行过滤,获取符合条件的卡牌数据列表
|
||
/// </summary>
|
||
/// <param name="needFilter">是否需要过滤</param>
|
||
/// <param name="cardDataIDs">指定的卡牌数据ID列表</param>
|
||
/// <returns>符合条件的卡牌数据列表</returns>
|
||
public List<CardData> GetDesignatedGlobalCardData(bool needFilter, params string[] cardDataIDs)
|
||
{
|
||
List<CardData> result = new List<CardData>();
|
||
|
||
foreach (string dataID in cardDataIDs)
|
||
{
|
||
if (ModManager.TryGetData(dataID, out CardData cardData))
|
||
{
|
||
if (needFilter && cardFilter(cardData))
|
||
{
|
||
result.Add(cardData);
|
||
}
|
||
else if (!needFilter)
|
||
{
|
||
result.Add(cardData);
|
||
}
|
||
}
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 在游戏全部的卡牌中,获取经过全局过滤器过滤后的所有卡牌数据列表
|
||
/// </summary>
|
||
public List<CardData> GetFilteredGlobalCardData()
|
||
{
|
||
return ModManager.Database[typeof(CardData)].Values.Cast<CardData>().Where(cardFilter).ToList();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 在游戏全部的卡牌中,获取经过指定过滤器过滤后的所有卡牌数据列表
|
||
/// </summary>
|
||
public List<CardData> GetFilteredGlobalCardData(Func<CardData, bool> filter)
|
||
{
|
||
return ModManager.Database[typeof(CardData)].Values.Cast<CardData>().Where(filter).ToList();
|
||
}
|
||
}
|
||
} |