1
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class StorytellerCompProperties_ImportantQuestWithFactionFilter : StorytellerCompProperties_ImportantQuest
|
||||
{
|
||||
// 派系类型白名单 - 只有这些派系类型的殖民地会触发任务
|
||||
public List<FactionDef> factionTypeWhitelist;
|
||||
|
||||
// 派系类型黑名单 - 这些派系类型的殖民地不会触发任务
|
||||
public List<FactionDef> factionTypeBlacklist;
|
||||
|
||||
// 是否启用派系过滤
|
||||
public bool useFactionFilter = false;
|
||||
|
||||
// 默认行为(当派系不在白名单中时的处理方式)
|
||||
public FactionFilterDefaultBehavior defaultBehavior = FactionFilterDefaultBehavior.Allow;
|
||||
|
||||
public StorytellerCompProperties_ImportantQuestWithFactionFilter()
|
||||
{
|
||||
compClass = typeof(StorytellerComp_ImportantQuestWithFactionFilter);
|
||||
}
|
||||
}
|
||||
|
||||
// 派系过滤的默认行为枚举
|
||||
public enum FactionFilterDefaultBehavior
|
||||
{
|
||||
Allow, // 允许不在列表中的派系
|
||||
Deny // 拒绝不在列表中的派系
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using RimWorld.Planet;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class StorytellerComp_ImportantQuestWithFactionFilter : StorytellerComp
|
||||
{
|
||||
private StorytellerCompProperties_ImportantQuestWithFactionFilter FilterProps =>
|
||||
(StorytellerCompProperties_ImportantQuestWithFactionFilter)props;
|
||||
|
||||
// 重新实现基类的私有属性
|
||||
private static int IntervalsPassed => Find.TickManager.TicksGame / 1000;
|
||||
|
||||
private bool BeenGivenQuest => Find.QuestManager.QuestsListForReading.Any((Quest q) => q.root == FilterProps.questDef);
|
||||
|
||||
public override IEnumerable<FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
|
||||
{
|
||||
// 先检查基础条件(天数、是否已给任务等)
|
||||
if (IntervalsPassed <= FilterProps.fireAfterDaysPassed * 60 || BeenGivenQuest)
|
||||
yield break;
|
||||
|
||||
// 检查派系过滤条件
|
||||
if (!PassesFactionFilter(target))
|
||||
yield break;
|
||||
|
||||
IncidentDef questIncident = FilterProps.questIncident;
|
||||
if (questIncident.TargetAllowed(target))
|
||||
{
|
||||
yield return new FiringIncident(questIncident, this, GenerateParms(questIncident.category, target));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查目标是否符合派系过滤条件
|
||||
/// </summary>
|
||||
private bool PassesFactionFilter(IIncidentTarget target)
|
||||
{
|
||||
// 如果不启用派系过滤,直接通过
|
||||
if (!FilterProps.useFactionFilter)
|
||||
return true;
|
||||
|
||||
// 获取目标的派系
|
||||
Faction faction = GetTargetFaction(target);
|
||||
if (faction == null)
|
||||
return false;
|
||||
|
||||
// 检查黑名单
|
||||
if (FilterProps.factionTypeBlacklist != null &&
|
||||
FilterProps.factionTypeBlacklist.Contains(faction.def))
|
||||
{
|
||||
Log.Message($"[FactionFilter] Quest blocked: {faction.def.defName} is in blacklist");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查白名单
|
||||
if (FilterProps.factionTypeWhitelist != null &&
|
||||
FilterProps.factionTypeWhitelist.Count > 0)
|
||||
{
|
||||
bool inWhitelist = FilterProps.factionTypeWhitelist.Contains(faction.def);
|
||||
|
||||
switch (FilterProps.defaultBehavior)
|
||||
{
|
||||
case FactionFilterDefaultBehavior.Allow:
|
||||
// 白名单模式:在白名单中或默认允许
|
||||
if (!inWhitelist)
|
||||
{
|
||||
Log.Message($"[FactionFilter] Quest allowed: {faction.def.defName} not in whitelist, but default behavior is Allow");
|
||||
}
|
||||
return true;
|
||||
|
||||
case FactionFilterDefaultBehavior.Deny:
|
||||
// 白名单模式:只有在白名单中才允许
|
||||
if (inWhitelist)
|
||||
{
|
||||
Log.Message($"[FactionFilter] Quest allowed: {faction.def.defName} is in whitelist");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Message($"[FactionFilter] Quest blocked: {faction.def.defName} not in whitelist and default behavior is Deny");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有设置白名单,根据默认行为决定
|
||||
switch (FilterProps.defaultBehavior)
|
||||
{
|
||||
case FactionFilterDefaultBehavior.Allow:
|
||||
Log.Message($"[FactionFilter] Quest allowed: No whitelist, default behavior is Allow");
|
||||
return true;
|
||||
case FactionFilterDefaultBehavior.Deny:
|
||||
Log.Message($"[FactionFilter] Quest blocked: No whitelist, default behavior is Deny");
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取目标的派系
|
||||
/// </summary>
|
||||
private Faction GetTargetFaction(IIncidentTarget target)
|
||||
{
|
||||
if (target is Map map)
|
||||
{
|
||||
return map.ParentFaction ?? Faction.OfPlayer;
|
||||
}
|
||||
else if (target is World world)
|
||||
{
|
||||
return Faction.OfPlayer;
|
||||
}
|
||||
else if (target is Caravan caravan)
|
||||
{
|
||||
return caravan.Faction;
|
||||
}
|
||||
|
||||
return Faction.OfPlayer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调试方法:显示当前过滤状态
|
||||
/// </summary>
|
||||
public string GetFactionFilterStatus(IIncidentTarget target)
|
||||
{
|
||||
if (!FilterProps.useFactionFilter)
|
||||
return "Faction filter: DISABLED";
|
||||
|
||||
Faction faction = GetTargetFaction(target);
|
||||
if (faction == null)
|
||||
return "Faction filter: NO FACTION";
|
||||
|
||||
StringBuilder status = new StringBuilder();
|
||||
status.AppendLine($"Faction filter: {faction.def.defName}");
|
||||
|
||||
// 黑名单检查
|
||||
if (FilterProps.factionTypeBlacklist != null &&
|
||||
FilterProps.factionTypeBlacklist.Contains(faction.def))
|
||||
{
|
||||
status.AppendLine("❌ BLACKLISTED");
|
||||
return status.ToString();
|
||||
}
|
||||
|
||||
// 白名单检查
|
||||
if (FilterProps.factionTypeWhitelist != null &&
|
||||
FilterProps.factionTypeWhitelist.Count > 0)
|
||||
{
|
||||
bool inWhitelist = FilterProps.factionTypeWhitelist.Contains(faction.def);
|
||||
|
||||
if (inWhitelist)
|
||||
{
|
||||
status.AppendLine("✅ WHITELISTED");
|
||||
}
|
||||
else
|
||||
{
|
||||
status.AppendLine(FilterProps.defaultBehavior == FactionFilterDefaultBehavior.Allow ?
|
||||
"⚠️ NOT IN WHITELIST (Allowed by default)" :
|
||||
"❌ NOT IN WHITELIST (Denied by default)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status.AppendLine(FilterProps.defaultBehavior == FactionFilterDefaultBehavior.Allow ?
|
||||
"✅ NO WHITELIST (Allowed by default)" :
|
||||
"❌ NO WHITELIST (Denied by default)");
|
||||
}
|
||||
|
||||
return status.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class StorytellerComp_SingleOnceFixed_FactionFilter : StorytellerComp_SingleOnceFixed
|
||||
{
|
||||
private StorytellerCompProperties_SingleOnceFixed_FactionFilter PropsFilter => (StorytellerCompProperties_SingleOnceFixed_FactionFilter)props;
|
||||
|
||||
public override IEnumerable<FiringIncident> MakeIntervalIncidents(IIncidentTarget target)
|
||||
{
|
||||
// 检查派系过滤条件
|
||||
if (!CheckFactionFilter())
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 调用父类的逻辑
|
||||
foreach (var incident in base.MakeIntervalIncidents(target))
|
||||
{
|
||||
yield return incident;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckFactionFilter()
|
||||
{
|
||||
if (Faction.OfPlayer == null)
|
||||
return false;
|
||||
|
||||
var playerFactionDef = Faction.OfPlayer.def;
|
||||
|
||||
// 优先检查白名单:如果白名单有内容,只有白名单内的派系才能触发
|
||||
if (PropsFilter.allowedFactionTypes != null && PropsFilter.allowedFactionTypes.Count > 0)
|
||||
{
|
||||
return PropsFilter.allowedFactionTypes.Contains(playerFactionDef);
|
||||
}
|
||||
|
||||
// 然后检查黑名单:如果黑名单有内容,黑名单内的派系不能触发
|
||||
if (PropsFilter.excludedFactionTypes != null && PropsFilter.excludedFactionTypes.Count > 0)
|
||||
{
|
||||
return !PropsFilter.excludedFactionTypes.Contains(playerFactionDef);
|
||||
}
|
||||
|
||||
// 如果既没有白名单也没有黑名单,所有派系都能触发
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class StorytellerCompProperties_SingleOnceFixed_FactionFilter : StorytellerCompProperties_SingleOnceFixed
|
||||
{
|
||||
// 黑名单:这些派系类型不会触发事件
|
||||
public List<FactionDef> excludedFactionTypes;
|
||||
|
||||
// 白名单:只有这些派系类型会触发事件(优先级高于黑名单)
|
||||
public List<FactionDef> allowedFactionTypes;
|
||||
|
||||
public StorytellerCompProperties_SingleOnceFixed_FactionFilter()
|
||||
{
|
||||
compClass = typeof(StorytellerComp_SingleOnceFixed_FactionFilter);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user