This commit is contained in:
2025-11-21 15:43:54 +08:00
parent 2ea2c33059
commit a0ee1164bf
10 changed files with 352 additions and 75 deletions

View File

@@ -64,45 +64,74 @@ namespace WulaFallenEmpire
private bool IsValidTarget(Thing thing)
{
// 检查是否有生命值
if (thing.def.useHitPoints == false || thing.HitPoints <= 0)
return false;
// 检查物体类型过滤
if (thing is Building && !Props.affectBuildings)
return false;
if (thing is Pawn && !Props.affectPawns)
return false;
if (thing is Plant && !Props.affectPlants)
return false;
// 检查阵营关系(如果是生物)
// 检查是否为 PawnPawn 有独立的健康系统)
if (thing is Pawn pawn)
{
Faction targetFaction = pawn.Faction;
Faction parentFaction = parent.Faction;
if (pawn.Dead || pawn.Downed)
return false;
if (targetFaction == null)
// 检查是否影响生物
if (!Props.affectPawns)
return false;
// 如果父物体没有派系,则只检查目标派系
if (parentFaction == null)
{
if (!Props.affectNeutral)
if (targetFaction == null && !Props.affectNeutral)
return false;
}
else if (targetFaction == parentFaction)
{
if (!Props.affectFriendly)
if (targetFaction != null && targetFaction.IsPlayer && !Props.affectFriendly)
return false;
}
else if (targetFaction.HostileTo(parentFaction))
{
if (!Props.affectHostile)
if (targetFaction != null && !targetFaction.IsPlayer && !Props.affectHostile)
return false;
}
else
{
if (!Props.affectNeutral)
return false;
// 正常阵营关系检查
if (targetFaction == null)
{
if (!Props.affectNeutral)
return false;
}
else if (targetFaction == parentFaction)
{
if (!Props.affectFriendly)
return false;
}
else if (targetFaction.HostileTo(parentFaction))
{
if (!Props.affectHostile)
return false;
}
else
{
if (!Props.affectNeutral)
return false;
}
}
}
else
{
// 对于非 Pawn 物体,检查生命值系统
if (thing.def.useHitPoints == false || thing.HitPoints <= 0)
return false;
// 检查物体类型过滤
if (thing is Building && !Props.affectBuildings)
return false;
if (thing is Plant && !Props.affectPlants)
return false;
}
// 如果设置为影响所有物体,跳过后续检查
if (Props.affectEverything)
return true;
// 如果忽略阵营关系,跳过阵营检查
if (Props.ignoreFactionRelations)
return true;
return true;
}
@@ -119,7 +148,7 @@ namespace WulaFallenEmpire
DamageInfo damageInfo = new DamageInfo(
Props.damageDef,
finalDamageAmount,
armorPenetration: 0f,
armorPenetration: Props.armorPenetration,
instigator: parent,
hitPart: null,
weapon: null,
@@ -128,6 +157,9 @@ namespace WulaFallenEmpire
// 应用伤害
target.TakeDamage(damageInfo);
// 特殊效果处理
HandleSpecialEffects(target, damageInfo);
}
/// <summary>
@@ -172,35 +204,29 @@ namespace WulaFallenEmpire
}
// 返回心灵敏感度作为伤害倍率
// 例如敏感度0.5 = 0.5倍伤害敏感度1.5 = 1.5倍伤害
return psychicSensitivity;
}
/// <summary>
/// 处理特殊效果(如伤害类型特定的效果)
/// </summary>
private void HandleSpecialEffects(Thing target, DamageInfo damageInfo)
{
// 如果是 Pawn可以添加额外的效果
if (target is Pawn pawn)
{
// 显示伤害数值(调试用)
if (Props.showDamageNumbers)
{
MoteMaker.ThrowText(target.DrawPos, target.Map, damageInfo.Amount.ToString());
}
}
}
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(ref ticksUntilNextDamage, "ticksUntilNextDamage", Props.damageIntervalTicks);
}
/// <summary>
/// 调试方法:显示伤害计算信息
/// </summary>
public string GetDamageDebugInfo(Thing target)
{
if (target is Pawn pawn)
{
float psychicSensitivity = pawn.GetStatValue(StatDefOf.PsychicSensitivity);
float damageFactor = CalculatePsychicSensitivityFactor(pawn);
int finalDamage = CalculateFinalDamage(target);
return $"目标: {pawn.Label}\n" +
$"心灵敏感度: {psychicSensitivity:F2}\n" +
$"伤害倍率: {damageFactor:F2}\n" +
$"基础伤害: {Props.damageAmount}\n" +
$"最终伤害: {finalDamage}";
}
return $"目标: {target.Label}\n基础伤害: {Props.damageAmount}";
}
}
}

View File

@@ -9,6 +9,7 @@ namespace WulaFallenEmpire
public int damageIntervalTicks = 60; // B: 伤害间隔(帧数)
public DamageDef damageDef; // C: 伤害类型
public int damageAmount = 10; // 基础伤害量
public float armorPenetration = 0f; // 护甲穿透
// 伤害缩放设置
public bool scaleWithPsychicSensitivity = false; // 是否随心灵敏感度缩放
@@ -24,6 +25,13 @@ namespace WulaFallenEmpire
public bool affectBuildings = true; // 是否影响建筑
public bool affectPawns = true; // 是否影响生物
public bool affectPlants = false; // 是否影响植物
// 特殊设置
public bool ignoreFactionRelations = false; // 忽略所有阵营关系检查(用于无派系实体)
public bool affectEverything = false; // 影响范围内所有有生命值的物体
// 特殊效果
public bool showDamageNumbers = false; // 显示伤害数值(调试用)
public CompProperties_AreaDamage()
{

View File

@@ -0,0 +1,162 @@
using RimWorld;
using UnityEngine;
using Verse;
namespace WulaFallenEmpire
{
public class CompPeriodicGameCondition : ThingComp
{
private int ticksUntilNextCondition;
public CompProperties_PeriodicGameCondition Props => (CompProperties_PeriodicGameCondition)props;
public override void Initialize(CompProperties props)
{
base.Initialize(props);
ticksUntilNextCondition = GetIntervalTicks();
}
public override void CompTick()
{
base.CompTick();
if (!parent.Spawned || parent.Map == null)
return;
ticksUntilNextCondition--;
if (ticksUntilNextCondition <= 0)
{
TryMakeGameCondition();
ticksUntilNextCondition = GetIntervalTicks();
}
}
private int GetIntervalTicks()
{
return Mathf.RoundToInt(Props.intervalDays * 60000f); // 1天 = 60000 ticks
}
private int GetDurationTicks()
{
return Mathf.RoundToInt(Props.durationDays * 60000f);
}
private void TryMakeGameCondition()
{
Map map = parent.Map;
if (map == null)
return;
// 检查是否可以触发
if (!CanMakeGameCondition(map))
return;
// 创建游戏条件
GameCondition condition = GameConditionMaker.MakeCondition(Props.gameConditionDef, GetDurationTicks());
map.gameConditionManager.RegisterCondition(condition);
// 发送通知
if (Props.sendLetter)
{
TrySendLetter(map, condition);
}
}
private bool CanMakeGameCondition(Map map)
{
if (Props.gameConditionDef == null)
return false;
GameConditionManager conditionManager = map.gameConditionManager;
if (conditionManager == null)
return false;
// 检查是否被其他条件阻止
if (Props.checkPreventIncidents)
{
foreach (GameCondition activeCondition in conditionManager.ActiveConditions)
{
if (activeCondition.def.preventIncidents)
{
return false;
}
}
}
// 检查是否已存在相同条件
if (Props.checkAlreadyActive && conditionManager.ConditionIsActive(Props.gameConditionDef))
{
return false;
}
// 检查是否可以共存
if (Props.checkCanCoexist)
{
foreach (GameCondition activeCondition in conditionManager.ActiveConditions)
{
if (!Props.gameConditionDef.CanCoexistWith(activeCondition.def))
{
return false;
}
}
}
// 特殊条件:检查水域是否有鱼
if (Props.requireFish && ModsConfig.OdysseyActive)
{
if (map.waterBodyTracker == null || !map.waterBodyTracker.AnyBodyContainsFish)
{
return false;
}
}
return true;
}
private void TrySendLetter(Map map, GameCondition condition)
{
if (condition.HiddenByOtherCondition(map))
return;
// 检查是否有地图会受到这个条件影响
bool anyMapAffected = false;
foreach (Map currentMap in Find.Maps)
{
if (condition.CanApplyOnMap(currentMap))
{
anyMapAffected = true;
break;
}
}
if (!anyMapAffected)
return;
}
public override void PostExposeData()
{
base.PostExposeData();
Scribe_Values.Look(ref ticksUntilNextCondition, "ticksUntilNextCondition", GetIntervalTicks());
}
/// <summary>
/// 手动触发一次游戏条件(用于调试或特殊事件)
/// </summary>
public void TriggerNow()
{
ticksUntilNextCondition = 0;
}
/// <summary>
/// 获取下一次触发的时间信息
/// </summary>
public string GetNextTriggerInfo()
{
if (!parent.Spawned)
return "Not spawned";
float daysUntilNext = ticksUntilNextCondition / 60000f;
return $"Next trigger in: {daysUntilNext:F1} days";
}
}
}

View File

@@ -0,0 +1,30 @@
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
public class CompProperties_PeriodicGameCondition : CompProperties
{
public GameConditionDef gameConditionDef; // 要创建的游戏条件
public float intervalDays = 1f; // 触发间隔(天)
public float durationDays = 1f; // 游戏条件持续时间(天)
// 条件检查设置
public bool checkCanCoexist = true; // 检查是否与其他条件共存
public bool checkAlreadyActive = true; // 检查是否已存在相同条件
public bool checkPreventIncidents = true; // 检查是否被其他条件阻止
// 通知设置
public bool sendLetter = true; // 是否发送信件通知
public string letterLabel; // 信件标题(如为空则使用游戏条件的默认标题)
public LetterDef letterDef; // 信件类型
// 特殊条件
public bool requireFish = false; // 是否需要水域有鱼仅限Odyssey DLC
public CompProperties_PeriodicGameCondition()
{
compClass = typeof(CompPeriodicGameCondition);
}
}
}