Hello Everybody,
I would like to have help on remaking the commsconsole code,
I am truly stuck on my medicine cabinet mod.
I've attached the medicinecabinet source so you can see.
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UI;
using AI;
using Sound;
namespace ttm
{
public class Building_MedicineCabinet : Building
{
public static int CollectDuration = 150;
public override void ExposeData()
{
base.ExposeData();
}
public override void SpawnSetup()
{
base.SpawnSetup();
}
//Checking if there is Medicine in Hopper
private Thing MedsinHopper
{
get
{
Thing result;
foreach (IntVec3 current in GenAdj.AdjacentSquaresCardinal(this))
{
Thing thing = null;
Thing thing2 = null;
ThingDef thingDef = ThingDef.Named("Medicine");
ThingDef thingDef2 = ThingDef.Named("Hopper");
foreach (Thing current2 in Find.Grids.ThingsAt(current))
{
if (current2.def == thingDef)
{
thing = current2;
}
if(current2.def == thingDef2)
{
thing2 = current2;
}
}
if(thing != null && thing2 != null)
{
result = thing;
return result;
}
}
result = null;
return result;
}
}
//Use a Medicine in hopper
public Thing useMeds()
{
Thing result;
int num = 1;
int num2 = 0;
System.Collections.Generic.List<ThingDef> list = new System.Collections.Generic.List<ThingDef>();
Thing MedsinHopper = this.MedsinHopper;
do
{
int num3 = Mathf.Min(MedsinHopper.stackCount, num);
num2 += num3;
list.Add(MedsinHopper.def);
MedsinHopper.SplitOff(num3);
if (num2 >= num)
{
break;
}
MedsinHopper = this.MedsinHopper;
}
while (MedsinHopper != null);
result = null;
return result;
}
public bool CanuseMeds
{
get
{
return this.MedsinHopper != null;
}
}
//Salvaged Comms Console Code
public override IEnumerable<FloatMenuOption> GetFloatMenuChoicesFor(Pawn myPawn)
{
if (!myPawn.CanReach(this, PathMode.InteractionSquare))
{
FloatMenuOption item = new FloatMenuOption("Cannot use (no Path)", null);
return new List<FloatMenuOption>
{
item
};
}
if (!CanuseMeds)
{
FloatMenuOption item2 = new FloatMenuOption("There's no Medicine in Hopper.", null);
return new List<FloatMenuOption>
{
item2
};
}
else
{
Action action = delegate {
Job job = new Job(JobDefOf.UseCommsConsole, new TargetPack(this));
myPawn.playerController.TakeOrderedJob(job);
this.useMeds();
int amount = myPawn.healthTracker.MaxHealth - UnityEngine.Random.Range(10, 35);
myPawn.TakeDamage(new DamageInfo(DamageTypeDefOf.Healing, amount, null));
this.def.building.soundDispense.Play(base.Position);
};
List<FloatMenuOption> list = new List<FloatMenuOption>();
list.Add(new FloatMenuOption("Heal " + myPawn.Name.nick, action));
return list;
}
}
}
}
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
I want to know how the jobdriver works and make a pawn stop on the building within the interaction square. ILSPY messes up the jobdriver_useCommsConsole and WorkGiver code.
also I would like to ask how to use ,
if (Find.ResearchManager.IsFinished(ResearchProjectDef.Named("")))
{
DefDatabase<ThingDef>.GetNamed("").comps<CompPowerTrader>.();
}
Im trying to mod a building research upgrade to reduce consumption of power, and I don't know how to get Comppowertrader
<compClass>CompPowerTrader</compClass>
<basePowerConsumption>350</basePowerConsumption>
in the code.
or is that even possible?
Lastly, what better way to search for a building? and count how many there are. I am doing this
List<Building_OrbitalTradeBeacon> list = (
from Building_OrbitalTradeBeacon d in Find.ListerBuildings.AllBuildingsColonistOfType(EntityType.BuildingComplex)
where d.def.defName == "OrbitalTradeBeacon"
select d).ToList<Building_OrbitalTradeBeacon>();
Building building = list.RandomListElement<Building_OrbitalTradeBeacon>();
but it returns an object is not set to instance error.
Heres the source where im using this code.
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UI;
namespace ttm
{
class IncidentWorker_BrokenOTB : IncidentWorker
{
public override bool TryExecute(IncidentParms parms)
{
List<Building_OrbitalTradeBeacon> list = (
from Building_OrbitalTradeBeacon d in Find.ListerBuildings.AllBuildingsColonistOfType(EntityType.BuildingComplex)
where d.def.defName == "OrbitalTradeBeacon"
select d).ToList<Building_OrbitalTradeBeacon>();
{
Building building = list.RandomListElement<Building_OrbitalTradeBeacon>();
Find.LetterStack.ReceiveLetter(new Letter("An Orbital trade beacon has stumbled, turns out it got broken.", LetterUrgency.Medium));
building.TakeDamage(new DamageInfo(DamageTypeDefOf.Bullet, 100, null));
return true;
}
}
}
}
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
Heres a source that works with using the code, I really don't know why this works though, maybe its got something to do with it being EntityType.Building_PowerPlantGeothermal specifically. I haven't really studied it that much though and moved on.
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UI;
namespace ttm
{
public class IncidentWorker_BrokenBuildingGeothermal : IncidentWorker
{
public override bool TryExecute(IncidentParms parms)
{
List<Building_PowerPlant> list = (
from Building_PowerPlant g in Find.ListerBuildings.AllBuildingsColonistOfType(EntityType.Building_PowerPlantGeothermal)
where g.GetComp<CompPowerTrader>().powerOutput > 3000
select g).ToList<Building_PowerPlant>();
{
Building building = list.RandomListElement<Building_PowerPlant>();
Explosion.DoExplosion(building.Position, 5f, DamageTypeDefOf.Flame, null);
Find.LetterStack.ReceiveLetter(new Letter("A geothermal reactor's engine has been severely damaged and destroyed from a strong steam propulsion inside the planet core, due to an uncharted planet core these things happen on rimworlds.", LetterUrgency.Medium));
building.TakeDamage(new DamageInfo(DamageTypeDefOf.Bomb, 1000, null));
return true;
}
}
}
}
//Rimworld
//Rimworld TechTreeMinami Mod by: minami26
//Rimworld
Thats all thankyou! More power to rimworld!
if (Find.ResearchManager.IsFinished(ResearchProjectDef.Named("")))
{
DefDatabase<ThingDef>.GetNamed("").comps<CompPowerTrader>.();
}
If you want to change it the same ammount for a class try
if (Find.get_ResearchManager().IsFinished(ResearchProjectDef.Named("NameOfResearch")))
{
this.powerComp.powerOutput = 1f;
}