Add diseases with a dll?

Started by Ykara, March 09, 2015, 02:52:36 PM

Previous topic - Next topic

Ykara

Hi guys, I was browsing the rimworld dlls and was wondering if it's possible to add specific diseases with a dll. I want my pawns to become sick if they get a new body part. I'm very new to dll modding, so please go easy with me, and please answer if you know the answer, I'm really interested if and how this works.

Illusion Distort

#1
Quote from: Ykara on March 09, 2015, 02:52:36 PM
Hi guys, I was browsing the rimworld dlls and was wondering if it's possible to add specific diseases with a dll. I want my pawns to become sick if they get a new body part. I'm very new to dll modding, so please go easy with me, and please answer if you know the answer, I'm really interested if and how this works.

I dont know if one needs to use a dll for it, i think xml will sufice.
Using the BodyPartDefs and Hediif you can make something "similar", i am not to familiar with the infection/bodydef/ code, but im sure you can change the bodypartdef to give the colonist a debuff:
(sickDebuff (give them a hediif_infection) or moodDebuff). Hope this helps,

if you need further help plz let me know. :D

mrofa

#2
https://ludeon.com/forums/index.php?topic=12159.0

Check this example mod, its still a10 but there isnt much change in a11 to it, so most methods should work.
There should be comments in source files,if i remmber right.
PA_Bullet.cs contains a method how to add a disies to pawn, im not sure if i did implement the specific body part there, so if i find my healing pots code i will like you the source.

Edit:
This is ny drugs thing with targeting specific body parts.
Dont worry about the drugtrafficer and mapcomponent they are not working and are not needed.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse.AI;
using Verse;
using Verse.Sound;
using RimWorld;

namespace ClutterModule
{
    class ItemThingClass : ThingWithComps
    {
        private Pawn OwnerPawn;
        private HediffDef HediffToAdd = null;
        private float HediffSeverityStage = 0;
        private BodyPartDef BodyPartToHediff = null;
       
       

        public override void SpawnSetup()
        {
            base.SpawnSetup();
            ReadFormXML();
        }

       
        private void ReadFormXML()
        {
            ItemThingDefs newThingDefs = (ItemThingDefs)this.def;
            if (newThingDefs != null)
            {
                HediffToAdd = newThingDefs.HediffToAdd;
                BodyPartToHediff = newThingDefs.BodyPartToHediff;
                HediffSeverityStage = newThingDefs.HediffSeverityStage;
            }
        }

        public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {

            List<FloatMenuOption> list = new List<FloatMenuOption>();
            {
                if (!myPawn.CanReserve(this, 1))
                {

                    FloatMenuOption item = new FloatMenuOption("CannotUseReserved", null);
                    return new List<FloatMenuOption>
                {
                    item
                };
                }
                if (!myPawn.CanReach(this, PathEndMode.Touch, Danger.Some))
                {
                    FloatMenuOption item2 = new FloatMenuOption("CannotUseNoPath", null);
                    return new List<FloatMenuOption>
                {
                    item2
                };
                }
                Action action3 = delegate
                {
                    Job job = new Job(DefDatabase<JobDef>.GetNamed("ClutterGoAndPickUpItem", true), this, this.Position);
                    myPawn.playerController.TakeOrderedJob(job);
                    OwnerPawn = myPawn;
                };
                list.Add(new FloatMenuOption("Pick Up" + this.def.LabelCap, action3));
                Action action2 = delegate
                {
                    Job job = new Job(DefDatabase<JobDef>.GetNamed("ClutterUseItem", true), this, this.Position);
                    myPawn.playerController.TakeOrderedJob(job);
                    OwnerPawn = myPawn;
                   
                };
                list.Add(new FloatMenuOption("Use" + this.def.LabelCap, action2));
            }
            return list;
        }
       
        public void AddHediffToPawn(Pawn pawn)
        {
            for(int i=0; i<Find.Map.components.Count;i++)
            {
                if(Find.Map.components.ElementAt(i).GetType() == typeof(Clutter.MapComponent_ResearchUpdates))
                {
                    Clutter.MapComponent_ResearchUpdates CustomMC = Find.Map.components.ElementAt(i) as Clutter.MapComponent_ResearchUpdates;
                    DrugTrafficer Dtrafficer = new DrugTrafficer();
                    Dtrafficer.DrugHediff=HediffToAdd;
                    Dtrafficer.DrugSkill = SkillDefOf.Cooking;
                    Dtrafficer.SkillAmmount=5;
                    Dtrafficer.DrugTime=1000;
                    Dtrafficer.PawnUser = pawn;
                    Dtrafficer.NewAdded=true;
                    CustomMC.DrugList.Add(Dtrafficer);
                    break;
                }
            }

            List<BodyPartRecord> list = new List<BodyPartRecord>();
            foreach (BodyPartRecord current in pawn.RaceProps.body.AllParts)
            {
                list.Add(current);
            }
            BodyPartRecord BodyPartToAffect = null;
            for (int i = 0; i < list.Count; i++)
            {
                if (list.ElementAt(i).def == BodyPartToHediff)
                {
                    BodyPartToAffect = list.ElementAt(i);
                    break;
                }
            }
            if (HediffToAdd == null)
            {
                HediffToAdd = HediffDefOf.WoundInfection;
            }



            if (!pawn.health.hediffSet.HasHediff(HediffToAdd))
            {
                int num = UnityEngine.Random.Range(1, 100);
                if (BodyPartToAffect == null)
                {
                    BodyPartToAffect = list.RandomElement();
                }

                HediffDef infection = HediffToAdd;
                infection.initialSeverity = HediffSeverityStage;
                pawn.health.AddHediff(infection, BodyPartToAffect, null);
                this.Destroy(DestroyMode.Vanish);
            }
            }
          }
    }

All i do is clutter all around.