1
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class MentalBreakWorker_BrokenPersonality : MentalBreakWorker
|
||||
{
|
||||
public override bool TryStart(Pawn pawn, string reason, bool causedByMood)
|
||||
{
|
||||
// 先尝试启动精神状态
|
||||
if (base.TryStart(pawn, reason, causedByMood))
|
||||
{
|
||||
// 成功启动后,执行附加逻辑
|
||||
var extension = def.mentalState.GetModExtension<MentalStateDefExtension_BrokenPersonality>();
|
||||
if (extension != null && extension.traitToAdd != null && !pawn.story.traits.HasTrait(extension.traitToAdd))
|
||||
{
|
||||
pawn.story.traits.GainTrait(new Trait(extension.traitToAdd));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class MentalStateDefExtension_BrokenPersonality : DefModExtension
|
||||
{
|
||||
public TraitDef traitToAdd;
|
||||
public FactionDef factionToJoin;
|
||||
public float skillLevelFactor = 1f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
using Verse.AI.Group;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class MentalState_BrokenPersonality : MentalState
|
||||
{
|
||||
public override void PostStart(string reason)
|
||||
{
|
||||
base.PostStart(reason);
|
||||
|
||||
// 发送信件
|
||||
if (PawnUtility.ShouldSendNotificationAbout(pawn))
|
||||
{
|
||||
// 手动实现备用逻辑:如果信件标题(beginLetterLabel)为空,则使用精神状态的通用标签(label)
|
||||
string labelText = def.beginLetterLabel;
|
||||
if (string.IsNullOrEmpty(labelText))
|
||||
{
|
||||
labelText = def.label;
|
||||
}
|
||||
TaggedString letterLabel = labelText.Formatted(pawn.LabelShort, pawn.Named("PAWN")).CapitalizeFirst();
|
||||
TaggedString letterText = def.beginLetter.Formatted(pawn.LabelShort, pawn.Named("PAWN")).CapitalizeFirst();
|
||||
if (reason != null)
|
||||
{
|
||||
letterText += "\n\n" + reason;
|
||||
}
|
||||
Find.LetterStack.ReceiveLetter(letterLabel, letterText, LetterDefOf.ThreatBig, pawn);
|
||||
}
|
||||
|
||||
var extension = def.GetModExtension<MentalStateDefExtension_BrokenPersonality>();
|
||||
if (extension != null)
|
||||
{
|
||||
bool alreadyBroken = pawn.story.traits.HasTrait(extension.traitToAdd);
|
||||
|
||||
if (!alreadyBroken)
|
||||
{
|
||||
// 移除所有技能热情
|
||||
foreach (SkillRecord skill in pawn.skills.skills)
|
||||
{
|
||||
skill.passion = Passion.None;
|
||||
}
|
||||
|
||||
// 所有技能等级减半
|
||||
foreach (SkillRecord skill in pawn.skills.skills)
|
||||
{
|
||||
int currentLevel = skill.Level;
|
||||
skill.Level = (int)(currentLevel * extension.skillLevelFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// 改变派系
|
||||
Faction newFaction = Find.FactionManager.FirstFactionOfDef(extension.factionToJoin);
|
||||
if (newFaction == null)
|
||||
{
|
||||
newFaction = Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile);
|
||||
}
|
||||
|
||||
if (newFaction != null)
|
||||
{
|
||||
pawn.SetFaction(newFaction, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 离开地图
|
||||
Lord lord = pawn.GetLord();
|
||||
if (lord == null)
|
||||
{
|
||||
LordJob_ExitMapBest lordJob = new LordJob_ExitMapBest(LocomotionUrgency.Jog, canDig: true, canDefendSelf: true);
|
||||
lord = LordMaker.MakeNewLord(pawn.Faction, lordJob, pawn.Map, Gen.YieldSingle(pawn));
|
||||
}
|
||||
else
|
||||
{
|
||||
lord.ReceiveMemo("PawnBroken");
|
||||
}
|
||||
|
||||
// 强制恢复以避免状态无限持续
|
||||
this.forceRecoverAfterTicks = 150;
|
||||
}
|
||||
|
||||
public override void MentalStateTick(int delta)
|
||||
{
|
||||
base.MentalStateTick(delta);
|
||||
// 确保在下一帧就恢复,因为所有效果都已经应用
|
||||
if (age > 0)
|
||||
{
|
||||
RecoverFromState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class MentalState_MechNoPilot : MentalState
|
||||
{
|
||||
public override void PostStart(string reason)
|
||||
{
|
||||
base.PostStart(reason);
|
||||
|
||||
// 停止所有工作和移动
|
||||
pawn.jobs?.StopAll();
|
||||
pawn.pather?.StopDead();
|
||||
|
||||
// 取消征召
|
||||
if (pawn.drafter != null && pawn.Drafted)
|
||||
{
|
||||
pawn.drafter.Drafted = false;
|
||||
}
|
||||
|
||||
// 清除当前敌人目标
|
||||
pawn.mindState.enemyTarget = null;
|
||||
}
|
||||
|
||||
public override void PostEnd()
|
||||
{
|
||||
base.PostEnd();
|
||||
}
|
||||
|
||||
public override void MentalStateTick(int delta)
|
||||
{
|
||||
// 使用父类的tick逻辑,但不允许自动恢复
|
||||
if (pawn.IsHashIntervalTick(30, delta))
|
||||
{
|
||||
age += 30;
|
||||
|
||||
// 只有在有驾驶员时才允许恢复
|
||||
// 检查会由 CompMechPilotHolder 处理
|
||||
// 这里不实现自动恢复逻辑
|
||||
}
|
||||
}
|
||||
|
||||
// 重写以禁用敌对行为
|
||||
public override bool ForceHostileTo(Thing t)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool ForceHostileTo(Faction f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 重写以禁用社交活动
|
||||
public override RandomSocialMode SocialModeMax()
|
||||
{
|
||||
return RandomSocialMode.Off;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user