88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
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<TrainableEntry> trainables = new List<TrainableEntry>();
|
|
|
|
// 3. 全局开关:是否阻止所有技能衰减
|
|
public bool disableAllSkillDecay = false;
|
|
|
|
public CompProperties_AdvancedTraining()
|
|
{
|
|
this.compClass = typeof(CompAdvancedTraining);
|
|
}
|
|
}
|
|
|
|
public class SkillLevelEntry
|
|
{
|
|
public SkillDef skill;
|
|
public int level = 0;
|
|
public bool disableDecay = true;
|
|
}
|
|
|
|
// 新增:用于定义训练项目的条目
|
|
public class TrainableEntry
|
|
{
|
|
public TrainableDef trainable;
|
|
public bool trainInstantly = false; // 是否立即完成训练
|
|
public bool setWanted = false; // 是否默认启用
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- 2. 处理训练项目 (只在初次生成时) ---
|
|
if (!respawningAfterLoad && pawn.training != null && !Props.trainables.NullOrEmpty())
|
|
{
|
|
foreach (var entry in Props.trainables)
|
|
{
|
|
if (entry.trainable == null) continue;
|
|
|
|
// 2a. 立即完成训练
|
|
if (entry.trainInstantly && !pawn.training.HasLearned(entry.trainable))
|
|
{
|
|
pawn.training.Train(entry.trainable, null, complete: true);
|
|
}
|
|
|
|
// 2b. 设置为默认启用
|
|
if (entry.setWanted)
|
|
{
|
|
pawn.training.SetWantedRecursive(entry.trainable, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |