How is frostbite damage handle in code

Started by johndoe1652, April 17, 2022, 08:55:50 AM

Previous topic - Next topic

johndoe1652

How exactly does frostbite damage get applied? Is it coupled to Hypothermia somehow. I've being scrounging through the rimworld files using dnSpy without much luck.

In short, I want to make a mod that uses the same mechanics that frostbite uses to apply a hypoxia damage to organs when bloodloss reaches severe.

I've never modded before, so this is a learning curve for me.

Canute

Hi,
sorry i can't answer your question, just can give you some hint's how you find the answer yourself.

I highly think these gamemechanic is at some of the core files and not at the XML code.
That mean's you should grab a "c# disassembler" (search for that if you don't know any) and look at the code itself.
But you see that require knowledge of c# to understand it.

johndoe1652

I've worked with c# for a couple of years now, so it isn't hassle. I did look through the core files using dnSpy, but didn't have much luck deciphering it.

I might be able to retrofit the fire.cs file given with the rimworld source. Maybe look through modded source code. Really which rimworld had some documentation at this point.

johndoe1652

Haha! Found it:

// Verse.HediffGiver_Hypothermia
using System.Linq;
using RimWorld;
using UnityEngine;
using Verse;

public class HediffGiver_Hypothermia : HediffGiver
{
public HediffDef hediffInsectoid;

public override void OnIntervalPassed(Pawn pawn, Hediff cause)
{
float ambientTemperature = pawn.AmbientTemperature;
FloatRange floatRange = pawn.ComfortableTemperatureRange();
FloatRange floatRange2 = pawn.SafeTemperatureRange();
HediffSet hediffSet = pawn.health.hediffSet;
HediffDef hediffDef = ((pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid) ? hediffInsectoid : hediff);
Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef);
if (ambientTemperature < floatRange2.min)
{
float a = Mathf.Abs(ambientTemperature - floatRange2.min) * 6.45E-05f;
a = Mathf.Max(a, 0.00075f);
HealthUtility.AdjustSeverity(pawn, hediffDef, a);
if (pawn.Dead)
{
return;
}
}
if (firstHediffOfDef == null)
{
return;
}
if (ambientTemperature > floatRange.min)
{
float value = firstHediffOfDef.Severity * 0.027f;
value = Mathf.Clamp(value, 0.0015f, 0.015f);
firstHediffOfDef.Severity -= value;
}
else if (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid && ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f)
{
float num = 0.025f * firstHediffOfDef.Severity;
if (Rand.Value < num && pawn.RaceProps.body.AllPartsVulnerableToFrostbite.Where((BodyPartRecord x) => !hediffSet.PartIsMissing(x)).TryRandomElementByWeight((BodyPartRecord x) => x.def.frostbiteVulnerability, out var result))
{
int num2 = Mathf.CeilToInt((float)result.def.hitPoints * 0.5f);
DamageInfo dinfo = new DamageInfo(DamageDefOf.Frostbite, num2, 0f, -1f, null, result);
pawn.TakeDamage(dinfo);
}
}
}
}