diff --git a/.kilocode/mcp.json b/.kilocode/mcp.json index 44d11942..5d65c878 100644 --- a/.kilocode/mcp.json +++ b/.kilocode/mcp.json @@ -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" + ] } } } diff --git a/.kilocode/rules/rimworld.md b/.kilocode/rules/rimworld.md index 8c816e2a..11395210 100644 --- a/.kilocode/rules/rimworld.md +++ b/.kilocode/rules/rimworld.md @@ -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. \ No newline at end of file +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` 项目文件中的相应 `` 条目,否则会导致编译失败。 \ No newline at end of file diff --git a/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/Assemblies/WulaFallenEmpire.dll index ef4872e6..4b985b38 100644 Binary files a/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/Defs/HediffDefs/Hediffs_PsychicTest.xml b/1.6/Defs/HediffDefs/Hediffs_PsychicTest.xml new file mode 100644 index 00000000..1ba1100f --- /dev/null +++ b/1.6/Defs/HediffDefs/Hediffs_PsychicTest.xml @@ -0,0 +1,38 @@ + + + + + + WULA_Hediff_PsychicSensitivityPlus + + 用于测试的心灵敏感度增益效果。 + HediffWithComps + (0.8, 0.35, 0.35) + false + +
  • + + 1 + +
  • +
    +
    + + + + WULA_Hediff_PsychicSensitivityMinus + + 用于测试的心灵敏感度减益效果。 + HediffWithComps + (0.6, 0.6, 0.6) + true + +
  • + + -1 + +
  • +
    +
    + +
    \ No newline at end of file diff --git a/1.6/Defs/ThingDefs_Misc/Weapons/WULA_Test_Weapon.xml b/1.6/Defs/ThingDefs_Misc/Weapons/WULA_Test_Weapon.xml new file mode 100644 index 00000000..889a18fd --- /dev/null +++ b/1.6/Defs/ThingDefs_Misc/Weapons/WULA_Test_Weapon.xml @@ -0,0 +1,51 @@ + + + + WULA_TestWeapon_PsychicScaling + + 一个用于测试心灵敏感度伤害缩放的武器。 + + Things/Item/Equipment/WeaponRanged/Autopistol + Graphic_Single + + Interact_Autopistol + + 1 + 1 + + None + true + +
  • + Verb_Shoot + true + Bullet_TestWeapon_PsychicScaling + 1.0 + 30 + Shot_Autopistol + GunTail_Light + 9 +
  • +
    + +
  • + 1.0 + 1.0 +
  • +
    +
    + + + Bullet_TestWeapon_PsychicScaling + + + Things/Projectile/Bullet_Small + Graphic_Single + + + Bullet + 10 + 50 + + +
    \ No newline at end of file diff --git a/Source/WulaFallenEmpire/CompPsychicScaling.cs b/Source/WulaFallenEmpire/CompPsychicScaling.cs index e4d2a045..097761d7 100644 --- a/Source/WulaFallenEmpire/CompPsychicScaling.cs +++ b/Source/WulaFallenEmpire/CompPsychicScaling.cs @@ -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倍伤害。 diff --git a/Source/WulaFallenEmpire/HarmonyPatches/DamageInfo_Constructor_Patch.cs b/Source/WulaFallenEmpire/HarmonyPatches/DamageInfo_Constructor_Patch.cs new file mode 100644 index 00000000..9214ac06 --- /dev/null +++ b/Source/WulaFallenEmpire/HarmonyPatches/DamageInfo_Constructor_Patch.cs @@ -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(); + 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); + } + } +} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/HarmonyPatches/HealthTracker_PreApplyDamage_Patch.cs b/Source/WulaFallenEmpire/HarmonyPatches/HealthTracker_PreApplyDamage_Patch.cs deleted file mode 100644 index 47229321..00000000 --- a/Source/WulaFallenEmpire/HarmonyPatches/HealthTracker_PreApplyDamage_Patch.cs +++ /dev/null @@ -1,69 +0,0 @@ -using HarmonyLib; -using RimWorld; -using Verse; - -namespace WulaFallenEmpire.HarmonyPatches -{ - [HarmonyPatch(typeof(Pawn_HealthTracker), "PreApplyDamage")] - public static class HealthTracker_PreApplyDamage_Patch - { - /// - /// 在伤害应用到Pawn之前执行的补丁。 - /// - /// 伤害信息,可以被修改。 - /// 输出参数,如果伤害被完全吸收则为true。 - 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(); - 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); - } - } -} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/VerbPropertiesExplosiveBeam.cs b/Source/WulaFallenEmpire/VerbPropertiesExplosiveBeam.cs deleted file mode 100644 index 0cbbc66f..00000000 --- a/Source/WulaFallenEmpire/VerbPropertiesExplosiveBeam.cs +++ /dev/null @@ -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); - } - } -} diff --git a/Source/WulaFallenEmpire/Verb_ShootBeamExplosive.cs b/Source/WulaFallenEmpire/Verb_ShootBeamExplosive.cs deleted file mode 100644 index b75e18a3..00000000 --- a/Source/WulaFallenEmpire/Verb_ShootBeamExplosive.cs +++ /dev/null @@ -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); - } - } -} diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj index a443348f..f8269d67 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj +++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj @@ -68,61 +68,62 @@ - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - + + + - + + - - - - - - + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + +