protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnBurningImmobile(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); Toil toil = new Toil(); toil.initAction = delegate { ThingWithComps thingWithComps = (ThingWithComps)job.targetA.Thing; ThingWithComps thingWithComps2 = null; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(); } pawn.equipment.MakeRoomFor(thingWithComps2); pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map)); } }; toil.defaultCompleteMode = ToilCompleteMode.Instant; yield return(toil); }
public void Equip(Pawn equipper, ThingWithComps thingWithComps) { var flag = false; ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; flag = true; } equipper.equipment.MakeRoomFor(thingWithComps2); equipper.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(equipper.Position, equipper.Map, false)); } if (flag) { thingWithComps.DeSpawn(); } }
public void Equip(Pawn equipper, ThingWithComps thingWithComps) { if (thingWithComps.def.IsApparel) { var apparel = (Apparel)thingWithComps; equipper.apparel.Wear(apparel); if (equipper.outfits != null) { equipper.outfits.forcedHandler.SetForced(apparel, true); } } else { ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(); } equipper.equipment.MakeRoomFor(thingWithComps2); equipper.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(equipper.Position, equipper.Map)); } } }
protected override IEnumerable <Toil> MakeNewToils() { yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null)); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); yield return(new Toil { initAction = delegate { ThingWithComps thingWithComps = (ThingWithComps)this.job.targetA.Thing; ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { if (thingWithComps.Spawned) { thingWithComps.DeSpawn(DestroyMode.Vanish); } if (thingWithComps.holdingOwner != null) { thingWithComps.holdingOwner.Remove(thingWithComps); } thingWithComps2 = thingWithComps; } bool success = this.pawn.inventory.innerContainer.TryAdd(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false)); } if (success) { CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(this.pawn); if (pawnMemory == null) { return; } if (MemorizeOnPickup) { pawnMemory.InformOfAddedSidearm(thingWithComps2); } } }, defaultCompleteMode = ToilCompleteMode.Instant }); Toil onFinish = OnFinish(); if (onFinish != null) { yield return(onFinish); } }
// RimWorld.CharacterCardUtility public static void DrawCard(Rect rect, ThingWithComps selectedThing) { GUI.BeginGroup(rect); var compToggleDef = selectedThing.GetComp <CompToggleDef>(); if (compToggleDef != null) { var ts = Text.CalcSize(selectedThing.LabelCap).x; var y = rect.y; var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize); y += rect2.height; Text.Font = GameFont.Medium; Widgets.Label(rect2, selectedThing.LabelCap); Text.Font = GameFont.Small; Widgets.ListSeparator(ref y, rect2.width, "Select one of the following:"); // add all the buttons for the toggle defs foreach (var td in compToggleDef.toggleDefs) { var rect3 = new Rect(0f, y, rect.width, 20f); var isactive = false; if (selectedThing.def == td) { isactive = true; } if (Widgets.RadioButtonLabeled(rect3, td.LabelCap, isactive)) { //Log.Message(".. change location to "+td.LabelCap); // CHange def then give it a new id. Hopefully nothing index on the id var map = selectedThing.Map; var loc = selectedThing.Position; var rot = selectedThing.Rotation; selectedThing.DeSpawn(); selectedThing.def = td; selectedThing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(selectedThing); // necessary CompColorable colorable = selectedThing.TryGetComp <CompColorable>(); if (colorable != null) { colorable.Color = selectedThing.def.colorGenerator.NewRandomizedColor(); } // selectedThing.DrawColor = selectedThing.def.colorGenerator.NewRandomizedColor(); Graphic graphic = selectedThing.def.graphicData.GraphicColoredFor(selectedThing); GenSpawn.Spawn(selectedThing, loc, map, rot); FieldInfo subgraphic = typeof(Thing).GetField("graphicInt", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField); Traverse traverse = Traverse.Create(selectedThing); subgraphic.SetValue(selectedThing, graphic); Find.Selector.Select(selectedThing); break; } y += 25f; } } GUI.EndGroup(); }
// RimWorld.CharacterCardUtility public static void DrawCard(Rect rect, ThingWithComps selectedThing) { GUI.BeginGroup(rect); var compToggleDef = selectedThing.GetComp <CompToggleDef>(); if (compToggleDef != null) { var ts = Text.CalcSize(selectedThing.LabelCap).x; var y = rect.y; var rect2 = new Rect(rect.width / 2 - ts + SpacingOffset, y, rect.width, HeaderSize); y += rect2.height; Text.Font = GameFont.Medium; Widgets.Label(rect2, selectedThing.LabelCap); Text.Font = GameFont.Small; Widgets.ListSeparator(ref y, rect2.width, "Select one of the following:"); // add all the buttons for the toggle defs foreach (var td in compToggleDef.toggleDefs) { var rect3 = new Rect(0f, y, rect.width, 20f); var isactive = false; if (selectedThing.def == td) { isactive = true; } if (Widgets.RadioButtonLabeled(rect3, td.LabelCap, isactive)) { //Log.Message(".. change location to "+td.LabelCap); // CHange def then give it a new id. Hopefully nothing index on the id var map = selectedThing.Map; var loc = selectedThing.Position; var rot = selectedThing.Rotation; selectedThing.DeSpawn(); selectedThing.def = td; selectedThing.thingIDNumber = -1; ThingIDMaker.GiveIDTo(selectedThing); // necessary GenSpawn.Spawn(selectedThing, loc, map, rot); break; } y += 25f; } } GUI.EndGroup(); }
/// <summary> /// Make detailed instruction on how to do the job. /// </summary> /// <returns> Instructions on what to do. </returns> protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); yield return(new Toil() { initAction = () => { ThingWithComps thingWithComps = (ThingWithComps)job.targetA.Thing; ThingWithComps thingWithComps2 = null; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(); } // put away equiped weapon first if (pawn.equipment.Primary != null) { if (!pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.inventory.innerContainer)) { // if failed, drop the weapon pawn.equipment.MakeRoomFor(thingWithComps2); } } // There is a chance, albeit minor, even MakeRommFor can fail. if (pawn.equipment.Primary == null) { // unregister new weapon in the inventory list and register it in equipment list. pawn.equipment.GetDirectlyHeldThings().TryAddOrTransfer(thingWithComps2); } else { Messages.Message("CannotEquip".Translate(thingWithComps2.LabelShort), MessageTypeDefOf.RejectInput, false); } }, }); }
/*internal void AddWeapons(IEnumerable<ThingWithComps> weapons) * { * if (weapons == null) * return; * * foreach (ThingWithComps w in weapons) * { * this.AddWeapon(w); * } * }*/ internal bool AddWeapon(ThingWithComps weapon) { if (this.CanAdd(weapon)) { if (weapon.Spawned) { weapon.DeSpawn(); } if (CombatExtendedUtil.AddAmmo(weapon)) { return(true); } this.AddToSortedList(weapon, (CompBiocodable.IsBiocoded(weapon)) ? this.StoredBioEncodedWeapons : this.StoredWeapons); return(true); } return(false); }
protected override IEnumerable <Toil> MakeNewToils() { this.FailOnDestroyedOrNull(TargetIndex.A); this.FailOnBurningImmobile(TargetIndex.A); //Goto equipment { yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch) .FailOnDespawnedNullOrForbidden(TargetIndex.A)); } //Take equipment { Toil takeEquipment = new Toil(); takeEquipment.initAction = () => { ThingWithComps eq = ((ThingWithComps)job.targetA.Thing); ThingWithComps toEquip = null; if (eq.def.stackLimit > 1 && eq.stackCount > 1) { toEquip = (ThingWithComps)eq.SplitOff(1); } else { toEquip = eq; toEquip.DeSpawn(); } pawn.equipment.MakeRoomFor(toEquip); pawn.equipment.AddEquipment(toEquip); if (eq.def.soundInteract != null) { eq.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map)); } }; takeEquipment.defaultCompleteMode = ToilCompleteMode.Instant; yield return(takeEquipment); } }
private static void SwapThing(ThingWithComps thing, ThingDef newDef) { var map = thing.Map; var loc = thing.Position; var rot = thing.Rotation; var eqTracker = thing.ParentHolder as Pawn_EquipmentTracker; if (eqTracker != null) { eqTracker.Remove(thing); } else { thing.DeSpawn(); } thing.def = newDef; // Refresh verbs. foreach (var comp in thing.AllComps) { if (comp is IVerbOwner verbOwner && verbOwner.VerbTracker is VerbTracker verbTracker) { VerbsNeedReinitOnLoad(verbTracker); _ = verbTracker.AllVerbs; } } // Refresh graphics. thing.Notify_ColorChanged(); if (eqTracker != null) { eqTracker.AddEquipment(thing); } else if (GenSpawn.Spawn(thing, loc, map, rot) != null) { Find.Selector.Select(thing, playSound: false); } }
private void EquipWeapon() { ThingWithComps thingWithComps = (ThingWithComps)job.targetA.Thing; ThingWithComps thingWithComps2 = null; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(); } pawn.equipment.MakeRoomFor(thingWithComps2); pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map)); } }
static void Postfix(ref bool __state, ref CompTemperatureRuinable __instance) { if (Settings.convert_ruined_eggs && !__state && __instance.Ruined) // Thing is ruined after this tick { ThingWithComps thing = __instance.parent; Map map = thing.Map; foreach (var item in thing.AllComps) { if (item.props.GetType() == typeof(CompProperties_Hatcher)) { thing.DeSpawn(); thing.def = DefDatabase <ThingDef> .GetNamed("EggChickenUnfertilized"); thing.AllComps.Remove(__instance); thing.AllComps.Remove(item); thing.SpawnSetup(map, true); break; } } } }
public override IEnumerable <Toil> MakeNewToils() { this.FailOnIncapable(PawnCapacityDefOf.Manipulation); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)); if (_Necron == null) { Log.Warning("ERROR!!!! _Necron null"); yield break; } if (!DamagedNecron.Spawned && !DamagedNecron.Corpse.Spawned) { Log.Warning("ERROR!!!! DamagedNecron despawned"); yield break; } if (DamagedNecron == null) { Log.Warning("ERROR!!!! DamagedNecron null"); yield break; } if (!_Necron.PawnHediffs.NullOrEmpty()) { // Log.Message("CHECKING!!!! _Necron Damage"); foreach (Hediff hd in _Necron.PawnHediffs) { if (hd.def.hediffClass == typeof(Hediff_Injury)) { // Log.Message("INJURY!!!!"); this.useDuration += (int)(((hd.Severity * DamagedNecron.BodySize)) * (_Necron.UnhealableHediffs.Contains(hd) ? 3 : 1)); } else if (hd.def.hediffClass == typeof(Hediff_MissingPart) && !DamagedNecron.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(hd.Part)) { // Log.Message("MISSING PART!!!!"); this.useDuration += (int)(((300 * DamagedNecron.BodySize) * hd.Severity) * (_Necron.UnhealableHediffs.Contains(hd) ? 3 : 1)); } else { // Log.Message("STILL CHECKING!!!!"); if (hd.def.hediffClass != typeof(Hediff_Implant) && hd.def.hediffClass != typeof(Hediff_MissingPart)) { // Log.Message("NOT IMPLANT OR MISSINGPART!!!!"); } // Log.Message(string.Format("Missed {0} {1} on {2}", hd.LabelCap, hd.def.hediffClass, hd.Part.LabelCap)); } } } else { // Log.Warning("ERROR!!!! DamagedNecron null"); } if (DamagedNecron.Dead) { this.useDuration = (int)(500 * DamagedNecron.BodySize); } Toil prepare = Toils_General.Wait(this.useDuration, TargetIndex.A); prepare.NPCWithProgressBarToilDelay(TargetIndex.A, false, -0.5f); prepare.FailOnDespawnedNullOrForbidden(TargetIndex.A); prepare.WithEffect(EffecterDefOf.ConstructMetal, TargetIndex.A); prepare.PlaySustainerOrSound(() => SoundDefOf.Crunch); if (DamagedNecron.Dead) { yield return(prepare); Toil use = new Toil(); use.initAction = delegate() { Pawn Spyder = use.actor; _Necron.TryRevive(true); }; use.defaultCompleteMode = ToilCompleteMode.Instant; yield return(use); } else { if (DamagedNecron.Downed) { yield return(prepare); Toil use = new Toil(); use.initAction = delegate() { Pawn Spyder = use.actor; foreach (Hediff hd in _Necron.PawnHediffs) { DamagedNecron.health.RemoveHediff(hd); } }; use.defaultCompleteMode = ToilCompleteMode.Instant; yield return(use); if (_Necron.originalWeapon != null) { ThingWithComps thing = _Necron.originalWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (DamagedNecron.inventory.innerContainer.Contains(thing)) { DamagedNecron.inventory.innerContainer.Remove(thing); } DamagedNecron.equipment.AddEquipment(thing); } if (_Necron.secondryWeapon != null) { ThingWithComps thing = _Necron.secondryWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (DamagedNecron.inventory.innerContainer.Contains(thing)) { DamagedNecron.inventory.innerContainer.Remove(thing); } // DamagedNecron.equipment.AdMechAddOffHandEquipment(thing); } } } yield break; }
public void TryRevive(bool ForcedRevive = false) { reviveIntervalTicks = -1; reviveTried = true; Rand.PushState(); if (Rand.Chance(ReanimateChance) || ForcedRevive) { List <Hediff> hediffs = unhealableHediffs; ResurrectionUtility.Resurrect(Pawn); if (originalWeapon == null && Pawn.kindDef.weaponTags.Count > 0) { ThingDef thingDef = ThingDef.Named(Pawn.kindDef.weaponTags[0]); Thing thing2 = GenClosest.ClosestThingReachable(Pawn.Position, Pawn.Map, ThingRequest.ForDef(thingDef), PathEndMode.InteractionCell, TraverseParms.For(Pawn, Danger.Deadly, TraverseMode.ByPawn, false)); this.originalWeapon = (ThingWithComps)thing2; } if (originalWeapon != null) { ThingWithComps thing = originalWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (Pawn.inventory.innerContainer.Contains(thing)) { Pawn.inventory.innerContainer.Remove(thing); } Pawn.equipment.AddEquipment(thing); } if (secondryWeapon != null) { ThingWithComps thing = secondryWeapon; if (thing.Spawned) { thing.DeSpawn(); } if (Pawn.inventory.innerContainer.Contains(thing)) { Pawn.inventory.innerContainer.Remove(thing); } // pawn.equipment.AdMechAddOffHandEquipment(thing); } if (!ForcedRevive) { // bool revives = true; foreach (Hediff item in hediffs) { if (!Pawn.health.hediffSet.PartIsMissing(item.Part)) { if (Pawn.health.WouldDieAfterAddingHediff(item)) { // revives = false; } if (Pawn.health.WouldBeDownedAfterAddingHediff(item)) { // revives = false; } Pawn.health.AddHediff(item); } } } ThrowNecronGlow(Pos.ToVector3(), Map, 5f); FleckMaker.Static(Pos, Map, FleckDefOf.ExplosionFlash, 3f); // log.message(string.Format("{0} revive {1}",pawn, str)); } else { // log.message(string.Format("{0} revive {1}", pawn, str)); } Rand.PopState(); }