Files
ArachnaeSwarm/Source/ArachnaeSwarm/CompAdvancedTraining.cs
2025-09-03 11:57:11 +08:00

77 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using Verse;
using RimWorld;
namespace ArachnaeSwarm
{
public class CompProperties_AdvancedTraining : CompProperties
{
// 1. 用于设置固定技能等级
public List<SkillLevelEntry> skillLevels = new List<SkillLevelEntry>();
// 2. 用于指定生成时立即完成的训练
public List<TrainableDef> instantTrainables = new List<TrainableDef>();
// 3. 全局开关:是否阻止所有技能衰减
public bool disableAllSkillDecay = false;
public CompProperties_AdvancedTraining()
{
this.compClass = typeof(CompAdvancedTraining);
}
}
public class SkillLevelEntry
{
public SkillDef skill;
public int level = 0;
// 这里的 disableDecay 字段现在是冗余的,因为我们有全局的 disableAllSkillDecay
// 但为了兼容性或未来可能的需求,可以保留。
// 在当前方案中,它的值将被忽略。
public bool disableDecay = true;
}
public class CompAdvancedTraining : ThingComp
{
public CompProperties_AdvancedTraining Props => (CompProperties_AdvancedTraining)this.props;
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
Pawn pawn = this.parent as Pawn;
if (pawn == null) return;
// --- 1. 设置固定技能等级 ---
if (pawn.skills != null && !Props.skillLevels.NullOrEmpty())
{
foreach (var entry in Props.skillLevels)
{
if (entry.skill != null)
{
var skillRecord = pawn.skills.GetSkill(entry.skill);
if (skillRecord != null)
{
skillRecord.Level = entry.level;
// 注意: 激情 (passion) 影响学习速度,不直接阻止衰减。
// 实际的衰减阻止逻辑在 TrainingSystem_Patcher.cs 中处理。
// 默认情况下,我们不改变 passion除非有特殊需求。
}
}
}
}
// --- 2. 执行瞬间训练 (只在初次生成时) ---
if (!respawningAfterLoad && pawn.training != null && !Props.instantTrainables.NullOrEmpty())
{
foreach (var trainable in Props.instantTrainables)
{
if (trainable != null && !pawn.training.HasLearned(trainable))
{
pawn.training.Train(trainable, null, complete: true);
}
}
}
}
}
}