修改版灵能

This commit is contained in:
2025-08-03 14:55:46 +08:00
parent 236b52765d
commit 6bbd328e2f
11 changed files with 221 additions and 260 deletions

View File

@@ -9,7 +9,10 @@
"env": {
"PYTHONUNBUFFERED": "1"
},
"disabled": false
"disabled": false,
"alwaysAllow": [
"get_context"
]
}
},
"tools": {
@@ -25,7 +28,9 @@
"description": "关于RimWorld开发的问题应包含代码或XML中的关键词。"
}
},
"required": ["question"]
"required": [
"question"
]
}
}
}

View File

@@ -18,4 +18,8 @@ Always remember these critical paths for your work:
2. Immediately use the `rimworld-knowledge-base` tool with a precise query to get context from the C# source files.
3. Analyze the retrieved context.
4. Perform code modifications within the user's mod project directory.
5. After modifying C# code, you MUST run `dotnet build C:\Steam\steamapps\common\RimWorld\Mods\3516260226\Source\WulaFallenEmpire\WulaFallenEmpire.csproj` to check for errors. A successful build is required for task completion.
5. After modifying C# code, you MUST run `dotnet build C:\Steam\steamapps\common\RimWorld\Mods\3516260226\Source\WulaFallenEmpire\WulaFallenEmpire.csproj` to check for errors. A successful build is required for task completion.
## Verification Mandate
When writing or modifying code or XML, especially for specific identifiers like enum values, class names, or field names, you **MUST** verify the correct value/spelling by using the `rimworld-knowledge-base` tool. Do not rely on memory.
- **同步项目文件:** 当重命名、移动或删除C#源文件时**必须**同步更新 `.csproj` 项目文件中的相应 `<Compile Include="..." />` 条目,否则会导致编译失败。

Binary file not shown.

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<!-- 增加心灵敏感度的 Hediff -->
<HediffDef>
<defName>WULA_Hediff_PsychicSensitivityPlus</defName>
<label>心灵敏感度增益 (测试)</label>
<description>用于测试的心灵敏感度增益效果。</description>
<hediffClass>HediffWithComps</hediffClass>
<defaultLabelColor>(0.8, 0.35, 0.35)</defaultLabelColor>
<isBad>false</isBad>
<stages>
<li>
<statOffsets>
<PsychicSensitivity>1</PsychicSensitivity>
</statOffsets>
</li>
</stages>
</HediffDef>
<!-- 减少心灵敏感度的 Hediff -->
<HediffDef>
<defName>WULA_Hediff_PsychicSensitivityMinus</defName>
<label>心灵敏感度减益 (测试)</label>
<description>用于测试的心灵敏感度减益效果。</description>
<hediffClass>HediffWithComps</hediffClass>
<defaultLabelColor>(0.6, 0.6, 0.6)</defaultLabelColor>
<isBad>true</isBad>
<stages>
<li>
<statOffsets>
<PsychicSensitivity>-1</PsychicSensitivity>
</statOffsets>
</li>
</stages>
</HediffDef>
</Defs>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<ThingDef ParentName="BaseHumanMakeableGun">
<defName>WULA_TestWeapon_PsychicScaling</defName>
<label>心灵缩放测试枪</label>
<description>一个用于测试心灵敏感度伤害缩放的武器。</description>
<graphicData>
<texPath>Things/Item/Equipment/WeaponRanged/Autopistol</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<soundInteract>Interact_Autopistol</soundInteract>
<statBases>
<Mass>1</Mass>
<RangedWeapon_Cooldown>1</RangedWeapon_Cooldown>
</statBases>
<tradeability>None</tradeability>
<destroyOnDrop>true</destroyOnDrop>
<verbs>
<li>
<verbClass>Verb_Shoot</verbClass>
<hasStandardCommand>true</hasStandardCommand>
<defaultProjectile>Bullet_TestWeapon_PsychicScaling</defaultProjectile>
<warmupTime>1.0</warmupTime>
<range>30</range>
<soundCast>Shot_Autopistol</soundCast>
<soundCastTail>GunTail_Light</soundCastTail>
<muzzleFlashScale>9</muzzleFlashScale>
</li>
</verbs>
<comps>
<li Class="WulaFallenEmpire.CompProperties_PsychicScaling">
<damageMultiplierPerSensitivityPoint>1.0</damageMultiplierPerSensitivityPoint>
<damageReductionMultiplierPerSensitivityPoint>1.0</damageReductionMultiplierPerSensitivityPoint>
</li>
</comps>
</ThingDef>
<ThingDef ParentName="BaseBullet">
<defName>Bullet_TestWeapon_PsychicScaling</defName>
<label>测试弹</label>
<graphicData>
<texPath>Things/Projectile/Bullet_Small</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<projectile>
<damageDef>Bullet</damageDef>
<damageAmountBase>10</damageAmountBase>
<speed>50</speed>
</projectile>
</ThingDef>
</Defs>

View File

@@ -9,7 +9,7 @@ namespace WulaFallenEmpire
public class CompProperties_PsychicScaling : CompProperties
{
// 每点心灵敏感度超出100%的部分)提供的伤害【增伤】乘数。
public float damageMultiplierPerSensitivityPoint = 0.25f;
public float damageMultiplierPerSensitivityPoint = 1f;
// 每点心灵敏感度低于100%的部分)提供的伤害【减伤】乘数。
// 例如系数为1时50%敏感度将造成 1 - (1 - 0.5) * 1 = 0.5倍伤害。

View File

@@ -0,0 +1,74 @@
using HarmonyLib;
using RimWorld;
using Verse;
using UnityEngine;
namespace WulaFallenEmpire.HarmonyPatches
{
// ==========================================================================================
// FINAL CORRECTED PATCH: Targets the DamageInfo constructor.
//
// REASONING: This is the universal "catch-all" solution. Almost all damage inflicted
// in the game must first create a DamageInfo instance. By patching the constructor
// with a Postfix, we can modify the damage value right at its source, immediately
// after it's created. This ensures our logic applies universally (to melee, all
// projectile types, abilities, etc.) and is not bypassed by specific implementations
// like the one found in `Bullet.Impact`.
// ==========================================================================================
[HarmonyPatch(typeof(DamageInfo), MethodType.Constructor)]
[HarmonyPatch(new[] {
typeof(DamageDef),
typeof(float),
typeof(float),
typeof(float),
typeof(Thing),
typeof(BodyPartRecord),
typeof(ThingDef),
typeof(DamageInfo.SourceCategory),
typeof(Thing),
typeof(bool),
typeof(bool),
typeof(QualityCategory),
typeof(bool),
typeof(bool)
})]
public static class DamageInfo_Constructor_Patch // Renamed class for ultimate clarity
{
public static void Postfix(ref DamageInfo __instance, Thing instigator, ThingDef weapon)
{
if (weapon == null)
{
return;
}
var psychicCompProps = weapon.GetCompProperties<CompProperties_PsychicScaling>();
if (psychicCompProps == null)
{
return;
}
if (!(instigator is Pawn instigatorPawn))
{
return;
}
float psychicSensitivity = instigatorPawn.GetStatValue(StatDefOf.PsychicSensitivity);
float damageMultiplier = 1f;
if (psychicSensitivity > 1f)
{
damageMultiplier = 1f + (psychicSensitivity - 1f) * psychicCompProps.damageMultiplierPerSensitivityPoint;
}
else if (psychicSensitivity < 1f)
{
damageMultiplier = 1f - (1f - psychicSensitivity) * psychicCompProps.damageReductionMultiplierPerSensitivityPoint;
}
float originalAmount = __instance.Amount;
float finalMultiplier = Mathf.Max(0f, damageMultiplier);
float newAmount = originalAmount * finalMultiplier;
__instance.SetAmount(newAmount);
}
}
}

View File

@@ -1,69 +0,0 @@
using HarmonyLib;
using RimWorld;
using Verse;
namespace WulaFallenEmpire.HarmonyPatches
{
[HarmonyPatch(typeof(Pawn_HealthTracker), "PreApplyDamage")]
public static class HealthTracker_PreApplyDamage_Patch
{
/// <summary>
/// 在伤害应用到Pawn之前执行的补丁。
/// </summary>
/// <param name="dinfo">伤害信息,可以被修改。</param>
/// <param name="absorbed">输出参数如果伤害被完全吸收则为true。</param>
public static void Prefix(ref DamageInfo dinfo, out bool absorbed)
{
// 必须为out参数赋默认值
absorbed = false;
// 检查伤害来源是否是一个Pawn
Pawn instigatorPawn = dinfo.Instigator as Pawn;
if (instigatorPawn == null)
{
return;
}
// 检查这个Pawn是否装备了武器
if (instigatorPawn.equipment?.Primary == null)
{
return;
}
// 检查武器上是否有我们的心灵增幅组件
var psychicComp = instigatorPawn.equipment.Primary.GetComp<CompPsychicScaling>();
if (psychicComp == null)
{
return;
}
// 获取心灵敏感度属性值
float psychicSensitivity = instigatorPawn.GetStatValue(StatDefOf.PsychicSensitivity);
// 根据心灵敏感度是否大于100%,使用不同的计算逻辑
float damageMultiplier;
if (psychicSensitivity > 1f)
{
// 增伤伤害会根据XML中的增伤系数获得额外加成
damageMultiplier = 1 + ((psychicSensitivity - 1) * psychicComp.Props.damageMultiplierPerSensitivityPoint);
}
else if (psychicSensitivity < 1f)
{
// 减伤伤害会根据XML中的减伤系数降低
damageMultiplier = 1 - ((1 - psychicSensitivity) * psychicComp.Props.damageReductionMultiplierPerSensitivityPoint);
}
else
{
// 敏感度正好为100%,伤害不变
damageMultiplier = 1f;
}
// 获取当前伤害值并应用乘数
float originalAmount = dinfo.Amount;
float newAmount = originalAmount * damageMultiplier;
// 更新伤害信息中的伤害值
dinfo.SetAmount(newAmount);
}
}
}

View File

@@ -1,50 +0,0 @@
using RimWorld;
using Verse;
using Verse.Sound;
namespace WulaFallenEmpire
{
public class VerbPropertiesExplosiveBeam : VerbProperties
{
// 爆炸开关
public bool enableExplosion = false;
// 每x个shotcount触发一次爆炸
public int explosionShotInterval = 1;
// 爆炸基础属性
public float explosionRadius = 2.9f;
public DamageDef explosionDamageDef = null; // null时使用默认的Bomb
public int explosionDamage = -1; // -1时使用武器默认伤害
public float explosionArmorPenetration = -1f; // -1时使用武器默认穿甲
// 爆炸音效和特效
public SoundDef explosionSound = null;
public EffecterDef explosionEffecter = null;
// 爆炸后生成物品
public ThingDef postExplosionSpawnThingDef = null;
public float postExplosionSpawnChance = 0f;
public int postExplosionSpawnThingCount = 1;
// 爆炸前生成物品
public ThingDef preExplosionSpawnThingDef = null;
public float preExplosionSpawnChance = 0f;
public int preExplosionSpawnThingCount = 1;
// 气体效果
public GasType? postExplosionGasType = null;
// 其他爆炸属性
public bool applyDamageToExplosionCellsNeighbors = true;
public float chanceToStartFire = 0f;
public bool damageFalloff = true;
public float screenShakeFactor = 0f; // 新增:屏幕震动因子
public VerbPropertiesExplosiveBeam()
{
// 设置默认值
verbClass = typeof(Verb_ShootBeamExplosive);
}
}
}

View File

@@ -1,93 +0,0 @@
using System.Collections.Generic;
using RimWorld;
using UnityEngine;
using Verse;
using Verse.Sound;
namespace WulaFallenEmpire
{
public class Verb_ShootBeamExplosive : Verse.Verb_ShootBeam
{
private int explosionShotCounter = 0;
protected override bool TryCastShot()
{
bool result = base.TryCastShot();
if (result && verbProps is VerbPropertiesExplosiveBeam explosiveProps && explosiveProps.enableExplosion)
{
explosionShotCounter++;
if (explosionShotCounter >= explosiveProps.explosionShotInterval)
{
explosionShotCounter = 0;
TriggerExplosion(explosiveProps);
}
}
return result;
}
private void TriggerExplosion(VerbPropertiesExplosiveBeam explosiveProps)
{
Vector3 explosionPos = InterpolatedPosition;
IntVec3 explosionCell = explosionPos.ToIntVec3();
if (!explosionCell.InBounds(caster.Map))
return;
// 播放爆炸音效
if (explosiveProps.explosionSound != null)
{
explosiveProps.explosionSound.PlayOneShot(new TargetInfo(explosionCell, caster.Map));
}
// 生成爆炸
GenExplosion.DoExplosion(
center: explosionCell,
map: caster.Map,
radius: explosiveProps.explosionRadius,
damType: explosiveProps.explosionDamageDef ?? DamageDefOf.Bomb,
instigator: caster,
damAmount: explosiveProps.explosionDamage > 0 ? explosiveProps.explosionDamage : verbProps.defaultProjectile?.projectile?.GetDamageAmount(EquipmentSource) ?? 20,
armorPenetration: explosiveProps.explosionArmorPenetration >= 0 ? explosiveProps.explosionArmorPenetration : verbProps.defaultProjectile?.projectile?.GetArmorPenetration(EquipmentSource) ?? 0.3f,
explosionSound: null, // 我们已经手动播放了音效
weapon: base.EquipmentSource?.def,
projectile: null,
intendedTarget: currentTarget.Thing,
postExplosionSpawnThingDef: explosiveProps.postExplosionSpawnThingDef,
postExplosionSpawnChance: explosiveProps.postExplosionSpawnChance,
postExplosionSpawnThingCount: explosiveProps.postExplosionSpawnThingCount,
postExplosionGasType: explosiveProps.postExplosionGasType,
applyDamageToExplosionCellsNeighbors: explosiveProps.applyDamageToExplosionCellsNeighbors,
preExplosionSpawnThingDef: explosiveProps.preExplosionSpawnThingDef,
preExplosionSpawnChance: explosiveProps.preExplosionSpawnChance,
preExplosionSpawnThingCount: explosiveProps.preExplosionSpawnThingCount,
chanceToStartFire: explosiveProps.chanceToStartFire,
damageFalloff: explosiveProps.damageFalloff,
direction: null,
ignoredThings: null,
affectedAngle: null,
doVisualEffects: true,
propagationSpeed: 0.6f,
excludeRadius: 0f,
doSoundEffects: false, // 我们手动处理音效
screenShakeFactor: explosiveProps.screenShakeFactor // 新增:屏幕震动因子
);
// 生成额外的视觉效果
if (explosiveProps.explosionEffecter != null)
{
Effecter effecter = explosiveProps.explosionEffecter.Spawn(explosionCell, caster.Map);
effecter.Trigger(new TargetInfo(explosionCell, caster.Map), TargetInfo.Invalid);
effecter.Cleanup();
}
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look(ref explosionShotCounter, "explosionShotCounter", 0);
}
}
}

View File

@@ -68,61 +68,62 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Building_Wula_DarkEnergy_Engine.cs" />
<Compile Include="MechanitorPatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="CompApparelInterceptor.cs" />
<Compile Include="SectionLayer_WulaHull.cs" />
<Compile Include="HediffComp_RegenerateBackstory.cs" />
<Compile Include="Verb\ShootArc.cs" />
<Compile Include="WulaFallenEmpireMod.cs" />
<Compile Include="Need_WulaEnergy.cs" />
<Compile Include="NeedDefExtension_Energy.cs" />
<Compile Include="WorkGiver_FeedWulaPatient.cs" />
<Compile Include="WorkGiverDefExtension_FeedWula.cs" />
<Compile Include="WorkGiver_Warden_FeedWula.cs" />
<Compile Include="WorkGiver_Warden_DeliverEnergy.cs" />
<Compile Include="ThingDefExtension_EnergySource.cs" />
<Compile Include="IngestPatch.cs" />
<Compile Include="JobDriver_IngestWulaEnergy.cs" />
<Compile Include="JobDriver_FeedWulaPatient.cs" />
<Compile Include="WulaStatDefOf.cs" />
<Compile Include="CompUseEffect_WulaSkillTrainer.cs" />
<Compile Include="CompUseEffect_PassionTrainer.cs" />
<Compile Include="CompPsychicScaling.cs" />
<Compile Include="CompUseEffect_FixAllHealthConditions.cs" />
<Compile Include="Recipe_AdministerWulaMechRepairKit.cs" />
<Compile Include="Verb_ShootBeamExplosive.cs" />
<Compile Include="VerbPropertiesExplosiveBeam.cs" />
<Compile Include="HediffComp_WulaCharging.cs" />
<Compile Include="JobGiver_WulaGetEnergy.cs" />
<Compile Include="JobGiver_WulaPackEnergy.cs" />
<Compile Include="JobGiverDefExtension_WulaPackEnergy.cs" />
<Compile Include="WulaCaravanEnergyDef.cs" />
<Compile Include="HarmonyPatches\Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs" />
<Compile Include="HarmonyPatches\FloatMenuOptionProvider_Ingest_Patch.cs" />
<Compile Include="HarmonyPatches\Projectile_Launch_Patch.cs" />
<Compile Include="HarmonyPatches\MechanitorUtility_InMechanitorCommandRange_Patch.cs" />
<Compile Include="MentalState_BrokenPersonality.cs" />
<Compile Include="MentalStateDefExtension_BrokenPersonality.cs" />
<Compile Include="MentalBreakWorker_BrokenPersonality.cs" />
<Compile Include="EventSystem\DebugActions.cs" />
<Compile Include="CompUseEffect_PassionTrainer.cs" />
<Compile Include="CompUseEffect_WulaSkillTrainer.cs" />
<Compile Include="EventSystem\CompOpenCustomUI.cs" />
<Compile Include="EventSystem\Condition.cs" />
<Compile Include="EventSystem\EventDef.cs" />
<Compile Include="EventSystem\DebugActions.cs" />
<Compile Include="EventSystem\Dialog_CustomDisplay.cs" />
<Compile Include="EventSystem\Effect.cs" />
<Compile Include="EventSystem\EventContext.cs" />
<Compile Include="EventSystem\EventDef.cs" />
<Compile Include="EventSystem\EventUIConfigDef.cs" />
<Compile Include="EventSystem\CompOpenCustomUI.cs" />
<Compile Include="EventSystem\QuestNode_Root_EventLetter.cs" />
<Compile Include="EventSystem\Letter_EventChoice.cs" />
<Compile Include="Verb\ProperShotgun.cs" />
<Compile Include="Verb\Trackingbullet.cs" />
<Compile Include="Verb\Projectile_ConfigurableHellsphereCannon.cs" />
<Compile Include="TimedExplosion.cs" />
<Compile Include="EventSystem\QuestNode_Root_EventLetter.cs" />
<Compile Include="HarmonyPatches\Caravan_NeedsTracker_TrySatisfyPawnNeeds_Patch.cs" />
<Compile Include="HarmonyPatches\DamageInfo_Constructor_Patch.cs" />
<Compile Include="HarmonyPatches\FloatMenuOptionProvider_Ingest_Patch.cs" />
<Compile Include="HarmonyPatches\MechanitorUtility_InMechanitorCommandRange_Patch.cs" />
<Compile Include="HarmonyPatches\Projectile_Launch_Patch.cs" />
<Compile Include="HediffComp_RegenerateBackstory.cs" />
<Compile Include="HediffComp_WulaCharging.cs" />
<Compile Include="IngestPatch.cs" />
<Compile Include="JobDriver_FeedWulaPatient.cs" />
<Compile Include="JobDriver_IngestWulaEnergy.cs" />
<Compile Include="JobGiver_WulaGetEnergy.cs" />
<Compile Include="JobGiver_WulaPackEnergy.cs" />
<Compile Include="JobGiverDefExtension_WulaPackEnergy.cs" />
<Compile Include="MechanitorPatch.cs" />
<Compile Include="MentalBreakWorker_BrokenPersonality.cs" />
<Compile Include="MentalState_BrokenPersonality.cs" />
<Compile Include="MentalStateDefExtension_BrokenPersonality.cs" />
<Compile Include="Need_WulaEnergy.cs" />
<Compile Include="NeedDefExtension_Energy.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PsychicRitual_TechOffering.cs" />
<Compile Include="CompPsychicScaling.cs" />
<Compile Include="HarmonyPatches\HealthTracker_PreApplyDamage_Patch.cs" />
<Compile Include="PsychicRitualDef_AddHediff.cs" />
<Compile Include="PsychicRitualToil_AddHediff.cs" />
<Compile Include="Recipe_AdministerWulaMechRepairKit.cs" />
<Compile Include="SectionLayer_WulaHull.cs" />
<Compile Include="ThingDefExtension_EnergySource.cs" />
<Compile Include="TimedExplosion.cs" />
<Compile Include="Verb\ExplosionParameters.cs" />
<Compile Include="Verb\Projectile_ConfigurableHellsphereCannon.cs" />
<Compile Include="Verb\ProperShotgun.cs" />
<Compile Include="Verb\ShootArc.cs" />
<Compile Include="Verb\Trackingbullet.cs" />
<Compile Include="Verb\Verb_ShootBeamExplosive.cs" />
<Compile Include="Verb\VerbPropertiesExplosiveBeam.cs" />
<Compile Include="WorkGiver_FeedWulaPatient.cs" />
<Compile Include="WorkGiver_Warden_DeliverEnergy.cs" />
<Compile Include="WorkGiver_Warden_FeedWula.cs" />
<Compile Include="WorkGiverDefExtension_FeedWula.cs" />
<Compile Include="WulaCaravanEnergyDef.cs" />
<Compile Include="WulaFallenEmpireMod.cs" />
<Compile Include="WulaStatDefOf.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 自定义清理任务删除obj文件夹中的临时文件 -->