(Solved) Set trap to only target legs?

Started by Incantation, October 13, 2017, 12:50:43 PM

Previous topic - Next topic

Incantation

Hey guys, I'm having some issue with a simple trap mod I've cooked up introducing bear traps into Rimworld. They're basically an offshoot of the standard deadfall traps. My issue is that I only want them to hit legs and feet, but they're regularly taking torsos and heads. Can anyone point me in the right direction here please? Thank you.

Here is the mod for references sake

<?xml version="1.0" encoding="utf-8" ?>
<ThingDefs>

  <ThingDef ParentName="BuildingBase">
    <defName>Beartrap</defName>
    <label>bear trap</label>
    <thingClass>Building_TrapRearmable</thingClass>
    <graphicData>
      <texPath>Things/Building/Security/beartraparmed</texPath>
      <graphicClass>Graphic_Single</graphicClass>
      <damageData>
        <rect>(1,1,0,0)</rect>
      </damageData>
    </graphicData>
    <altitudeLayer>Building</altitudeLayer>
    <drawerType>RealtimeOnly</drawerType>
    <rotatable>false</rotatable>
    <tickerType>Normal</tickerType>
    <stealable>false</stealable>
    <statBases>
      <MaxHitPoints>60</MaxHitPoints>
      <WorkToBuild>1750</WorkToBuild>
      <Beauty>-6</Beauty>
      <TrapMeleeDamage>65</TrapMeleeDamage>
      <TrapSpringChance>1.0</TrapSpringChance>
    </statBases>
    <description>A set of jagged metal jaws attached to a pressure plate. Snaps shut with brutal force once triggered resulting in violent bone crushing trauma. </description>
    <stuffCategories>
      <li>Metallic</li>
    </stuffCategories>
    <costStuffCount>50</costStuffCount>
    <designationCategory>Security</designationCategory>
    <designationHotKey>Misc9</designationHotKey>
    <building>
      <isTrap>true</isTrap>
      <trapDamageCategory>Blunt</trapDamageCategory>
      <trapUnarmedGraphicData>
        <texPath>Things/Building/Security/beartrapunarmed</texPath>
        <graphicClass>Graphic_Single</graphicClass>
        <shaderType>Cutout</shaderType>
      </trapUnarmedGraphicData>
    </building>
  </ThingDef>

</ThingDefs>

DrMrEd

I think you'll need a custom ThingClass to define the exact damage behavior when the trap is hit. From a brief exploration of the code (RimWorld.Building_TrapRearmable), you'd want to implement a new DamagePawn method, setting the DamageInfo object's SetBodyRegion to only act on legs.


Incantation

#2
Thanks for the push in the right direction. So this is gonna sound stupid- I get what you're saying, but I have no idea on as to how to implement it.

So research shows me that I need to make a C# script based off of the original Deadfall traps and just edit "damageInfo.SetBodyRegion(bodyPartHeight, 3); to damageInfo.SetBodyRegion(bodyPartHeight, 2);" right? After I do that how do I save it as a .dll for the assemblies folder? Visual studio eludes my comprehension.  ???

CannibarRechter

If the interface to visual studio is a bit too complex, you can just open the .csproj file and edit the xml in there directly. The tags all correspond to things you can do in the UI, but 6 one way, half a dozen the other.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

DrMrEd

You are on the right track. You'll need to compile an assemply to put in the \Assemblies folder. Then add

<thingClass>Building_BearTrap</thingClass>

to your BuildingDef XML.

There are some issues I see in your C#, but that's probably from the way it was decompiled. Like there shouldn't be O.get_x() method calls, but  instead O.x property references. But when you get to the IDE step, that stuff should be cleared up for you.

On the DamageInfo piece, I think it'd be better to use:

damageInfo.SetBodyRegion(BodyPartHeight.Bottom, BodyPartDepth.Outside);

This is better practice than using (1, 2) even if they're literally the same to the compiler.

I don't know if you need to SetBodyRegion for the damageInfo2 (stun damage) or not. Might be worth testing out both ways.

CannibarRechter

Was the latest version of ILSpy used? It does a good job of decompiling RimWorld, and doesn't mess up getters and setters, AFAICT.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

Incantation

Thanks for the help guys, I've managed to solve the problem.  :D

Albion

Are you willing to post your solution or give a link to the finished mod later? It would help future modders running into the same issue.