This commit is contained in:
2025-09-25 14:42:35 +08:00
parent 94e1e2cd0c
commit 866c84df7f
4 changed files with 60 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
using Verse;
using RimWorld;
using System.Linq;
using System.Collections.Generic;
namespace ArachnaeSwarm
{
@@ -13,34 +13,40 @@ namespace ArachnaeSwarm
base.Apply(target, dest);
Pawn user = parent.pawn;
if (user == null) return;
if (user == null || user.skills == null) return;
// 1. 技能经验增益
int levelBefore = user.skills.GetSkill(Props.skill).GetLevel();
user.skills.Learn(Props.skill, Props.xpGainAmount, direct: true);
int levelAfter = user.skills.GetSkill(Props.skill).GetLevel();
// 2. 热情设置
SkillRecord targetSkillRecord = user.skills.GetSkill(Props.skill);
if (targetSkillRecord != null && !targetSkillRecord.TotallyDisabled)
// 遍历并应用所有技能变更
foreach (var change in Props.skillChanges)
{
if (targetSkillRecord.passion != Props.passionGained)
if (change.skill == null) continue;
// 1. 技能经验增益
int levelBefore = user.skills.GetSkill(change.skill).GetLevel();
user.skills.Learn(change.skill, change.xpGainAmount, direct: true);
int levelAfter = user.skills.GetSkill(change.skill).GetLevel();
// 2. 热情设置
SkillRecord targetSkillRecord = user.skills.GetSkill(change.skill);
if (targetSkillRecord != null && !targetSkillRecord.TotallyDisabled)
{
targetSkillRecord.passion = Props.passionGained;
if (targetSkillRecord.passion != change.passionGained)
{
targetSkillRecord.passion = change.passionGained;
}
}
}
// 发送通知
if (PawnUtility.ShouldSendNotificationAbout(user))
{
Messages.Message("AbilitySkillChanged".Translate(
user.LabelShort,
Props.skill.LabelCap,
levelBefore,
levelAfter,
user.Named("USER")),
user,
MessageTypeDefOf.PositiveEvent);
// 发送通知 (为每个技能变更发送一次)
if (PawnUtility.ShouldSendNotificationAbout(user))
{
Messages.Message("AbilitySkillChanged".Translate(
user.LabelShort,
change.skill.LabelCap,
levelBefore,
levelAfter,
user.Named("USER")),
user,
MessageTypeDefOf.PositiveEvent);
}
}
}
@@ -53,5 +59,4 @@ namespace ArachnaeSwarm
return base.Valid(target, throwMessages);
}
}
}

View File

@@ -1,13 +1,21 @@
using Verse;
using RimWorld;
using System.Collections.Generic;
namespace ArachnaeSwarm
{
public class CompProperties_AbilityAddExtraExp : CompProperties_AbilityEffect
// 定义一个类来封装单次技能的变更
public class SkillChange
{
public SkillDef skill;
public Passion passionGained = Passion.Major; // 可配置获得的热情等级,默认为大火
public float xpGainAmount = 50000f;
public Passion passionGained = Passion.None;
public float xpGainAmount;
}
// 修改 CompProperties 来使用 SkillChange 列表
public class CompProperties_AbilityAddExtraExp : CompProperties_AbilityEffect
{
public List<SkillChange> skillChanges = new List<SkillChange>();
public CompProperties_AbilityAddExtraExp()
{