Ludeon Forums

Ludeon Forums

  • August 17, 2022, 03:26:43 AM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How is frostbite damage handle in code  (Read 469 times)

johndoe1652

  • Muffalo
  • *
  • Posts: 4
  • Refugee
    • View Profile
How is frostbite damage handle in code
« on: April 17, 2022, 08:55:50 AM »

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.
Logged

Canute

  • Transcendent
  • *****
  • Posts: 9999
  • Refugee
    • View Profile
Re: How is frostbite damage handle in code
« Reply #1 on: April 18, 2022, 07:56:22 AM »

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

  • Muffalo
  • *
  • Posts: 4
  • Refugee
    • View Profile
Re: How is frostbite damage handle in code
« Reply #2 on: April 20, 2022, 10:01:28 AM »

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.
Logged

johndoe1652

  • Muffalo
  • *
  • Posts: 4
  • Refugee
    • View Profile
Re: How is frostbite damage handle in code
« Reply #3 on: April 21, 2022, 04:19:22 PM »

Haha! Found it:

Code: [Select]
// 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);
}
}
}
}
Logged