public static void DeregisterDroid(Droid droid) { if (listerDroids.allDroids.Contains(droid)) { listerDroids.allDroids.Remove(droid); } }
public CremationTarget(string label, Predicate<Thing> p, int naturalPriority, Droid c) { this.label = label; this.naturalPriority = naturalPriority; this.Accepts = p; this.crematorius = c; }
public override Job JobOnThing(Pawn pawn, Thing t) { JobDef jDef; Droid droid = pawn as Droid; if (droid == null) { return(null); } CremationTarget target = droid.work.specialist.GetWorker <CremationWorker>().AllTargets.First((CremationTarget ta) => ta.Accepts(t)); switch (target.Mode) { case CremationOperationMode.Butcher: { jDef = DefDatabase <JobDef> .GetNamed("MD2DroidButcherCorpse"); break; } case CremationOperationMode.Cremate: { jDef = DefDatabase <JobDef> .GetNamed("MD2DroidCremateCorpse"); break; } default: return(null); } return(new Job(jDef, t)); }
public CremationTarget(string label, Predicate <Thing> p, int naturalPriority, Droid c) { this.label = label; this.naturalPriority = naturalPriority; this.Accepts = p; this.crematorius = c; }
public override bool ShouldSkip(Pawn pawn) { Droid droid = pawn as Droid; bool flag = droid != null && droid.work.Contains(WorkPackageDef.Named("MD2CremationPackage")) && droid.work.specialist.GetWorker <CremationWorker>() != null; return(!flag); }
public static void RegisterDroid(Droid droid) { if (!listerDroids.allDroids.Contains(droid)) { listerDroids.allDroids.Add(droid); } }
public WorkManager(List<WorkPackageDef> workPackages, Droid droid) : this(droid) { specialist = new SpecialistManager(droid); foreach(var package in workPackages) { AddWorkPackage(package); } }
public WorkManager(List <WorkPackageDef> workPackages, Droid droid) : this(droid) { specialist = new SpecialistManager(droid); foreach (var package in workPackages) { AddWorkPackage(package); } }
private void PostDrawPawnRow(Rect rect, Droid p) { if (!p.Active) { GUI.color = new Color(1f, 1f, 0f, 0.5f); Widgets.DrawLineHorizontal(rect.x, rect.center.y, rect.width); GUI.color = Color.white; } }
protected override Job TryGiveTerminalJob(Pawn pawn) { if (!(pawn is ICharge)) { return(null); } ICharge chargee = (ICharge)pawn; Droid droid = (Droid)pawn; if (droid != null && !droid.Active) { return(null); } float chargeThreshold; float distance; switch (stage) { case 1: { chargeThreshold = chargee.PowerSafeThreshold; distance = 20f; break; } case 2: { chargeThreshold = chargee.PowerLowThreshold; distance = 50f; break; } case 3: { chargeThreshold = chargee.PowerCriticalThreshold; distance = 9999f; break; } default: { chargeThreshold = chargee.PowerLowThreshold; distance = 50f; break; } } if (chargee.TotalCharge <= chargee.MaxEnergy * chargeThreshold) { Thing target = ListerDroids.ClosestChargerFor(chargee, distance); if (target != null) { return(new Job(DefDatabase <JobDef> .GetNamed("MD2ChargeDroid"), new TargetInfo(target))); } } return(null); }
public override bool HasJobOnThing(Pawn pawn, Thing t) { Droid droid = pawn as Droid; if (droid == null) { return(false); } CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>(); Predicate <Thing> predicate1 = (Thing corpse) => !corpse.IsForbidden(Faction.OfColony) && droid.AwareOf(corpse) && droid.CanReserve(corpse); bool flag = t is Corpse && droid != null && predicate1(t) && worker.AllTargets.Any((CremationTarget target) => target.Accepts(t)); return(flag); }
public static List<WorkGiver> WorkGiversInOrderEmergency(Droid droid) { List<WorkGiver> list = new List<WorkGiver>(); foreach(var wg in droid.workSettings.WorkGiversInOrderEmergency) { if(droid.KindDef.allowedWorkTypeDefs.Contains(wg.def.workType)) { list.Add(wg); } } return list; }
protected virtual void DrawPawnRow(Rect r, Droid p) { float num = 175f; Text.Font = GameFont.Medium; for (int i = 0; i < OTab_Droid_Work.VisibleWorkTypeDefsInPriorityOrder.Count; i++) { WorkTypeDef workTypeDef = OTab_Droid_Work.VisibleWorkTypeDefsInPriorityOrder[i]; Vector2 topLeft = new Vector2(num, r.y + 2.5f); if (p.story != null && p.work.Contains(workTypeDef)) { WidgetsWork.DrawWorkBoxFor(topLeft, p, workTypeDef); } Rect rect2 = new Rect(topLeft.x, topLeft.y, 25f, 25f); TooltipHandler.TipRegion(rect2, WidgetsWork.TipForPawnWorker(p, workTypeDef)); num += this.workColumnSpacing; } }
public override IEnumerable <Gizmo> GetGizmos() { foreach (var g in base.GetGizmos()) { yield return(g); } Command_Action action = new Command_Action(); action.action = () => { Droid droid = Blueprint.GenerateDroid(Blueprint.Default, Faction.OfColony); droid.parts.ReplacePowerCell(ThingMaker.MakeThing(ThingDef.Named("MD2DroidPowerCell"))); GenSpawn.Spawn(droid, base.InteractionCell); }; action.defaultLabel = "click"; action.groupKey = 10008999; yield return(action); }
public void ReactivateDroid(bool dropDroid = false) { if (!IsAvailableForReactivation) { if (ReadyForReactivation) { Droid droid = InnerDroid.InnerDroid; droid.playerController.Drafted = false; droid.ShouldUsePower = true; GenSpawn.Spawn(droid, InteractionCell); Messages.Message("DroidReactivated".Translate(new object[] { droid.LabelBase }), MessageSound.Benefit); innerDroid.Destroy(); innerDroid = null; SetPowerUsage(); } else if (dropDroid) { DropDroid(); } } }
protected override IEnumerable <Toil> MakeNewToils() { //Set what will cause the job to fail: this.FailOnDestroyedOrForbidden(CorpseIndex); this.FailOnBurningImmobile(CorpseIndex); this.FailOn(() => !(pawn is Droid)); //Reserve the corpse yield return(Toils_Reserve.Reserve(CorpseIndex)); //Go to the corpse yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)); Toil toil = new Toil(); toil.initAction = () => { //Check if the pawn is set to strip bodies, if yes then strip it, otherwise skip this step Droid droid = (Droid)pawn; CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>(); if (worker.StripBodies) { Corpse corpse = (Corpse)TargetThingA; if (corpse.AnythingToStrip()) { corpse.Strip(); } } }; toil.defaultCompleteMode = ToilCompleteMode.Delay; toil.defaultDuration = 300; toil.WithEffect(() => DefDatabase <EffecterDef> .GetNamed("Cremate"), CorpseIndex); toil.WithSustainer(() => DefDatabase <SoundDef> .GetNamed("Recipe_Cremate")); toil.AddFinishAction(() => TargetA.Thing.Destroy()); toil.FailOnBurningImmobile(CorpseIndex); toil.FailOnDestroyedOrForbidden(CorpseIndex); toil.AddEndCondition(() => this.ticksLeftThisToil <= 0 ? JobCondition.Succeeded : JobCondition.Ongoing); yield return(toil); }
public void ReactivationTick() { if (InnerDroid != null) { Droid droid = InnerDroid.InnerDroid; if (droid.ShouldGetRepairs) { if (Find.TickManager.TicksGame % TicksPerRepairCycle == 0) { droid.Repair(this); } } float num = (Power != null) ? Power.props.basePowerConsumption * 2f : 400f; droid.Charge(num); InnerDroid.InnerDroid.health.HealthTick(); if (ReadyForReactivation) { ReactivateDroid(); } } }
public UtilityManager(Droid droid) { parent = droid; }
public MetaDataManager(Droid droid, Blueprint bp) : this(droid) { ExplodeOnDeath = bp.ExplodeOnDeath; ExplosionRadius = bp.ExplosionRadius; }
//public Thing ShieldGenerator; public PartsManager(Droid droid) { parent = droid; }
public SpecialistManager(Droid droid) { parent = droid; }
public MetaDataManager(Droid droid) { parent = droid; }
public WorkManager(Droid droid) { parent = droid; }
public SpecialistWorker(Droid droid) { parent = droid; }
//public bool emergency; protected override Job TryGiveTerminalJob(Pawn pawn) { if (!(pawn is Droid)) { return(null); } Droid droid = pawn as Droid; if (!droid.Active) { return(null); } List <WorkGiver> list = this.emergency ? droid.work.WorkGiversInOrderEmergency : droid.work.WorkGiversInOrder; int num = -999; TargetInfo targetInfo = TargetInfo.Invalid; WorkGiver_Scanner workGiver_Scanner = null; for (int i = 0; i < list.Count; i++) { WorkGiver workGiver = list[i]; if (workGiver.def.priorityInType != num && targetInfo.IsValid) { break; } if (workGiver.MissingRequiredCapacity(pawn) == null) { if (!workGiver.ShouldSkip(pawn)) { try { Job job = workGiver.NonScanJob(pawn); if (job != null) { Job result = job; return(result); } WorkGiver_Scanner scanner = workGiver as WorkGiver_Scanner; if (scanner != null) { if (workGiver.def.scanThings) { Predicate <Thing> predicate = (Thing t) => !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t); IEnumerable <Thing> enumerable = scanner.PotentialWorkThingsGlobal(pawn); Predicate <Thing> validator = predicate; Thing thing = GenClosest.ClosestThingReachable(pawn.Position, scanner.PotentialWorkThingRequest, scanner.PathEndMode, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, enumerable, scanner.LocalRegionsToScanFirst, enumerable != null); if (thing != null) { targetInfo = thing; workGiver_Scanner = scanner; } } if (workGiver.def.scanCells) { IntVec3 position = pawn.Position; float num2 = 99999f; foreach (IntVec3 current in scanner.PotentialWorkCellsGlobal(pawn)) { float lengthHorizontalSquared = (current - position).LengthHorizontalSquared; if (lengthHorizontalSquared < num2 && !current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current)) { targetInfo = current; workGiver_Scanner = scanner; num2 = lengthHorizontalSquared; } } } num = workGiver.def.priorityInType; } } catch (Exception ex) { Log.Error(string.Concat(new object[] { pawn, " threw exception in WorkGiver ", workGiver.def.defName, ": ", ex.ToString() })); } finally { } if (targetInfo.IsValid) { pawn.mindState.lastGivenWorkType = workGiver.def.workType; if (targetInfo.HasThing) { return(workGiver_Scanner.JobOnThing(pawn, targetInfo.Thing)); } return(workGiver_Scanner.JobOnCell(pawn, targetInfo.Cell)); } } } } return(null); }
public CremationWorker(Droid droid) : base(droid) { }
protected override IEnumerable <Toil> MakeNewToils() { //Set what will cause the job to fail: this.FailOnDestroyedOrForbidden(CorpseIndex); this.FailOnBurningImmobile(CorpseIndex); this.FailOn(() => !(pawn is Droid) || TargetA.Thing.TryGetComp <CompRottable>() != null && TargetA.Thing.TryGetComp <CompRottable>().Stage != RotStage.Fresh); Droid droid = pawn as Droid; CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>(); //Reserve the corpse yield return(Toils_Reserve.Reserve(CorpseIndex)); //Go to the corpse yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)); //If wanting to strip bodies, then strip it. if (worker.StripBodies) { yield return(Toils_General.Wait(80)); //Strip the body Toil t = new Toil(); t.initAction = () => { Corpse corpse = (Corpse)TargetA.Thing; if (corpse != null && corpse.AnythingToStrip()) { corpse.Strip(); } }; yield return(t); } //Wait the time to do the butchering Toil effecterWait = Toils_General.Wait(300); effecterWait.WithEffect(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <EffecterDef> .GetNamed("ButcherFlesh") : DefDatabase <EffecterDef> .GetNamed("ButcherMechanoid"), CorpseIndex); effecterWait.WithSustainer(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseFlesh") : DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseMechanoid")); yield return(effecterWait); Toil toil = new Toil(); toil.initAction = delegate { List <Thing> products; Corpse c = (Corpse)TargetA.Thing; if (c != null) { float efficiency = Rand.Range(0.9f, 1f); if (c.innerPawn.RaceProps.isFlesh) { products = TargetA.Thing.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList(); } else { products = c.innerPawn.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList(); } TargetA.Thing.Destroy(); foreach (var thing in products) { if (!GenPlace.TryPlaceThing(thing, pawn.Position, ThingPlaceMode.Near)) { Log.Error(string.Concat(new object[] { pawn, " could not drop butcher product ", thing, " near ", pawn.Position })); } } } else { Log.Error(string.Concat(new object[] { pawn, " tried to butcher ", TargetA.Thing, " at ", TargetA.Thing.Position, " which is not a corpse." })); return; } }; yield return(toil); }
public BackstoryManager(Droid droid) { this.parent = droid; }
public static IEnumerable <FloatMenuOption> ExtraFloatMenuOptions(this Droid droid, IntVec3 sq, IEnumerable <FloatMenuOption> options) { foreach (var thing in sq.GetThingList()) { CompMannable mannable = thing.TryGetComp <CompMannable>(); if (mannable != null && !mannable.MannedNow) { yield return(new FloatMenuOption("DroidManThing".Translate(thing.Label), delegate { droid.jobs.StartJob(new Job(JobDefOf.ManTurret, thing), JobCondition.InterruptForced); })); } if (droid.equipment != null && (thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon)) { yield return(new FloatMenuOption("Equip".Translate(thing.Label), delegate { CompForbiddable f = thing.TryGetComp <CompForbiddable>(); if (f != null && f.Forbidden) { f.Forbidden = false; } droid.jobs.StartJob(new Job(JobDefOf.Equip, thing), JobCondition.InterruptForced); })); } if (thing is Pawn) { Pawn p = thing as Pawn; if (p.RaceProps.intelligence >= Intelligence.Humanlike) { if (droid.playerController.Drafted && p.CanBeArrested() && droid.CanReserveAndReach(p, PathEndMode.Touch, Danger.Some)) { //Try to arrest yield return(new FloatMenuOption("TryToArrest".Translate(p.LabelCap), delegate { Building_Bed bed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where((Building_Bed b) => b.ForPrisoners && b.owner == null).FirstOrDefault(); if (bed != null) { Job job = new Job(JobDefOf.Arrest, p, bed); job.maxNumToCarry = 1; droid.jobs.StartJob(job, JobCondition.InterruptForced); } else { Messages.Message("DroidArrestNoBedsAvailable".Translate(), MessageSound.RejectInput); } })); } if (p.Downed) { if (droid.work.Contains(WorkTypeDefOf.Doctor) && droid.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { if (!p.HostileTo(Faction.OfColony) && p.def.race.intelligence >= Intelligence.Humanlike) { //Rescue a downed colonist or visitor yield return(new FloatMenuOption("Rescue".Translate(p.LabelCap), delegate { Building_Bed freeBed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where(b => (b.Medical || b.owner == p || b.owner == null) && b.CurOccupant == null && !b.ForPrisoners).OrderByDescending(b => (b.def.building != null) ? b.def.building.bed_medicalBonusFactor : 0f).FirstOrDefault(); if (freeBed != null) { Job job = new Job(JobDefOf.Rescue, p, freeBed); job.maxNumToCarry = 1; droid.jobs.StartJob(job, JobCondition.InterruptForced); } else { Messages.Message("DroidRescueNoMedicalBedsAvailable".Translate(), MessageSound.RejectInput); } })); } if (p.HostileTo(Faction.OfColony)) { //Capture a downed enemy or broken colonist yield return(new FloatMenuOption("Capture".Translate(p.LabelCap), delegate { Building_Bed freeBed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where(b => (b.Medical || b.owner == p || b.owner == null) && b.CurOccupant == null && b.ForPrisoners).OrderByDescending(b => (b.def.building != null) ? b.def.building.bed_medicalBonusFactor : 0f).FirstOrDefault(); if (freeBed != null) { Job job = new Job(JobDefOf.Capture, p, freeBed); job.maxNumToCarry = 1; droid.jobs.StartJob(job, JobCondition.InterruptForced); } else { Messages.Message("DroidArrestNoBedsAvailable".Translate(), MessageSound.RejectInput); } })); } } if (p.AnythingToStrip()) { yield return(new FloatMenuOption("Strip".Translate(p.LabelCap), delegate { droid.jobs.StartJob(new Job(JobDefOf.Strip, p), JobCondition.InterruptForced); })); } } } } if (thing is Corpse) { Corpse c = thing as Corpse; if (c.AnythingToStrip()) { yield return(new FloatMenuOption("Strip".Translate(c.LabelCap), delegate { droid.jobs.StartJob(new Job(JobDefOf.Strip, c), JobCondition.InterruptForced); })); } } } foreach (var o in options) { yield return(o); } }
private static bool ShouldDrawOverlayOnMap(Droid droid) { return(true); }
public DrawManager(Droid droid) { this.parent = droid; }
public static Droid GenerateDroid(Blueprint bp, Faction faction) { Droid droid = (Droid)ThingMaker.MakeThing(bp.KindDef.race); droid.SetFactionDirect(faction); droid.kindDef = bp.KindDef; droid.RaceProps.corpseDef = ThingDef.Named("MD2DroidCorpse"); #region Trackers droid.thinker = new Pawn_Thinker(droid); droid.playerController = new Pawn_PlayerController(droid); droid.inventory = new Pawn_InventoryTracker(droid); droid.pather = new Pawn_PathFollower(droid); droid.jobs = new Pawn_JobTracker(droid); droid.health = new Pawn_HealthTracker(droid); droid.ageTracker = new Pawn_AgeTracker(droid); droid.filth = new Pawn_FilthTracker(droid); droid.mindState = new Pawn_MindState(droid); droid.equipment = new Pawn_EquipmentTracker(droid); droid.apparel = new Pawn_ApparelTracker(droid); droid.natives = new Pawn_NativeVerbs(droid); droid.meleeVerbs = new Pawn_MeleeVerbs(droid); droid.carryHands = new Pawn_CarryHands(droid); droid.ownership = new Pawn_Ownership(droid); droid.skills = new Pawn_SkillTracker(droid); droid.story = new Pawn_StoryTracker(droid); droid.workSettings = new Pawn_WorkSettings(droid); droid.guest = new Pawn_GuestTracker(droid); droid.needs = new Pawn_NeedsTracker(droid); droid.stances = new Pawn_StanceTracker(droid); typeof(Pawn_NeedsTracker).GetMethod("AddNeed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(droid.needs, new object[] { DefDatabase <NeedDef> .GetNamed("Mood") }); #endregion droid.gender = droid.RaceProps.hasGenders ? Gender.Male : Gender.None; droid.ageTracker.SetChronologicalBirthDate(GenDate.CurrentYear, GenDate.DayOfMonth); droid.story.skinColor = PawnSkinColors.PaleWhiteSkin; droid.story.crownType = CrownType.Narrow; droid.story.headGraphicPath = GraphicDatabaseHeadRecords.GetHeadRandom(Gender.Male, droid.story.skinColor, droid.story.crownType).GraphicPath; droid.story.hairColor = PawnHairColors.RandomHairColor(droid.story.skinColor, droid.ageTracker.AgeBiologicalYears); droid.story.name = new PawnName() { first = "Droid", last = "Droid", nick = bp.Name }; #region Managers droid.meta = new MetaDataManager(droid, bp); droid.utilities = new UtilityManager(droid); WorkPackageDef maintenance = WorkPackageDef.Named("MD2MaintenancePackage"); WorkPackageDef firefighting = WorkPackageDef.Named("MD2FirefighterPackage"); List <WorkPackageDef> list = bp.WorkPackages; if (!list.Contains(maintenance)) { list.Add(maintenance); } if (!list.Contains(firefighting)) { list.Add(firefighting); } droid.work = new WorkManager(list, droid); droid.backstory = new BackstoryManager(droid); droid.backstory.SpawnSetup(); droid.drawManager = new DrawManager(bp.BodyGraphicDef, bp.HeadGraphicDef, droid); droid.drawManager.SpawnSetup(); droid.parts = new PartsManager(droid); #endregion foreach (SkillRecord sk in droid.skills.skills) { sk.level = (bp.StartingSkillLevel > 20) ? 20 : (bp.StartingSkillLevel <= 0) ? 1 : bp.StartingSkillLevel; sk.passion = bp.SkillPassion; } droid.workSettings.EnableAndInitialize(); foreach (var def in DefDatabase <WorkTypeDef> .AllDefs) { if (droid.work.Contains(def)) { droid.workSettings.SetPriority(def, 4); } else { droid.workSettings.SetPriority(def, 0); droid.workSettings.Disable(def); } } return(droid); }
public DroidUIOverlay(Droid droid) { this.droid = droid; }
public DrawManager(GraphicDef bodyGraphicPath, GraphicDef headGraphicPath, Droid droid) { this.bodyGraphicDef = bodyGraphicPath; this.headGraphicDef = headGraphicPath; this.parent = droid; }
public PartsManager(Thing powerCell, Droid droid) { parent = droid; PowerCell = powerCell; }
public static void DeregisterDroid(Droid droid) { if (listerDroids.allDroids.Contains(droid)) listerDroids.allDroids.Remove(droid); }
private static bool ShouldDrawOverlayOnMap(Droid droid) { return true; }
public static void RegisterDroid(Droid droid) { if (!listerDroids.allDroids.Contains(droid)) listerDroids.allDroids.Add(droid); }