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)); yield return(new Toil { initAction = delegate() { ThingWithComps equipmentStack = (ThingWithComps)job.targetA.Thing; ThingWithComps equippedThing; if (equipmentStack.def.stackLimit > 1 && equipmentStack.stackCount > 1) { equippedThing = (ThingWithComps)equipmentStack.SplitOff(1); } else { equippedThing = equipmentStack; equippedThing.DeSpawn(DestroyMode.Vanish); } ShieldUtility.MakeRoomForShield(pawn, equippedThing); pawn.apparel.Wear((Apparel)equippedThing); if (equipmentStack.def.soundInteract != null) { equipmentStack.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } }, defaultCompleteMode = ToilCompleteMode.Instant }); }
private void TrySwitchToWeapon(ThingWithComps newEq, Pawn pawn) { if (newEq == null || pawn.equipment == null || !pawn.inventory.innerContainer.Contains(newEq)) { return; } if (newEq.def.stackLimit > 1 && newEq.stackCount > 1) { newEq = (ThingWithComps)newEq.SplitOff(1); } if (pawn.equipment.Primary != null) { if (MassUtility.FreeSpace(pawn) > 0) { pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.inventory.innerContainer); } else { pawn.equipment.MakeRoomFor(newEq); } } pawn.equipment.GetDirectlyHeldThings().TryAddOrTransfer(newEq); if (newEq.def.soundInteract != null) { newEq.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.MapHeld, false)); } }
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)); yield return(new Toil { initAction = delegate { ThingWithComps thingWithComps = (ThingWithComps)this.$this.job.targetA.Thing; ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(DestroyMode.Vanish); } this.$this.pawn.equipment.MakeRoomFor(thingWithComps2); this.$this.pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.$this.pawn.Position, this.$this.pawn.Map, false)); } }, defaultCompleteMode = ToilCompleteMode.Instant }); }
public Toil CreateEquipToil(TargetIndex index) { LocalTargetInfo equipment = pawn.jobs.curJob.GetTarget(index); Toil toil = new Toil { initAction = delegate { ThingWithComps weaponPile = (ThingWithComps)(Thing)equipment; ThingWithComps weapon; if (weaponPile.def.stackLimit > 1 && weaponPile.stackCount > 1) { weapon = (ThingWithComps)weaponPile.SplitOff(1); } else { weapon = weaponPile; weapon.DeSpawn(); } if (pawn.equipment.Primary != null) { //TODO FIX storedPrimaryWeapon = equipped = null pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.inventory.innerContainer); } pawn.equipment.AddEquipment(weapon); }, defaultCompleteMode = ToilCompleteMode.Instant }; toil.FailOnDespawnedNullOrForbidden(index); return(toil); }
protected void Equip(TargetIndex target, bool saveCurrent) { if (saveCurrent && pawn.equipment?.Primary != null) { pawn.CurJob.targetC = new LocalTargetInfo(pawn.equipment.Primary); pawn.equipment.TryTransferEquipmentToContainer(pawn.equipment.Primary, pawn.inventory.innerContainer); } ThingWithComps targetThing = (ThingWithComps)job.GetTarget(target).Thing; ThingWithComps isolatedThing; if (targetThing.def.stackLimit > 1 && targetThing.stackCount > 1) { isolatedThing = (ThingWithComps)targetThing.SplitOff(1); } else { isolatedThing = targetThing; if (targetThing.Spawned) { isolatedThing.DeSpawn(DestroyMode.Vanish); } } pawn.equipment.MakeRoomFor(isolatedThing); ThingOwner equipment = (ThingOwner)equipmentInfo.GetValue(pawn.equipment); if (!equipment.TryAddOrTransfer(isolatedThing)) { pawn.equipment.AddEquipment(isolatedThing); } if (targetThing.def.soundInteract != null) { targetThing.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } }
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)); } } }
/* * Returns a toil that equips the target index weapon */ private Toil CreateEquipToil(TargetIndex index) { LocalTargetInfo equipment = pawn.jobs.curJob.GetTarget(index); Toil equipToil = new Toil { initAction = delegate() { ThingWithComps thingWithComps = (ThingWithComps)equipment; ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(DestroyMode.Vanish); } this.pawn.equipment.MakeRoomFor(thingWithComps2); this.pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false)); } }, defaultCompleteMode = ToilCompleteMode.Instant }; equipToil.FailOnDespawnedNullOrForbidden(index); return(equipToil); }
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(); } }
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); } }
public static bool equipSpecificWeapon(Pawn pawn, ThingWithComps weapon, bool dropCurrent, bool intentionalDrop) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn); if (pawn == null || pawn.Dead || pawnMemory == null || pawn.equipment == null || pawn.inventory == null) { return(false); } if (weapon == pawn.equipment.Primary) //attepmpting to equip already-equipped weapon { Log.Warning("attepmpting to equip already-equipped weapon"); return(false); } //drop current on the ground if (dropCurrent && pawn.equipment.Primary != null) { pawnMemory.InformOfDroppedSidearm(weapon, intentionalDrop); ThingWithComps discarded; pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out discarded, pawn.Position, false); } //or put it in inventory else if (pawn.equipment.Primary != null) { ThingWithComps oldPrimary = pawn.equipment.Primary; pawn.equipment.Remove(oldPrimary); pawn.inventory.innerContainer.TryAdd(oldPrimary, true); } if (weapon == null) { } else { if (weapon.stackCount > 1) { weapon = weapon.SplitOff(1) as ThingWithComps; //if this cast doesnt work the world has gone mad } Pawn_EquipmentTracker_AddEquipment_Postfix.sourcedBySimpleSidearms = true; pawn.equipment.AddEquipment(weapon as ThingWithComps); Pawn_EquipmentTracker_AddEquipment_Postfix.sourcedBySimpleSidearms = false; if (weapon.def.soundInteract != null) { weapon.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } } //avoid hunting stackoverflowexception if (pawn.jobs != null && pawn.jobs.curJob != null && pawn.jobs.curJob.def == JobDefOf.Hunt) { pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true); } return(true); }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: this.FailOnDestroyedOrNull(TargetIndex.A); this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A); if (!this.$disposing) { this.$PC = 1; } return(true); case 1u: { Toil takeEquipment = new Toil(); takeEquipment.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 { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(DestroyMode.Vanish); } this.pawn.equipment.MakeRoomFor(thingWithComps2); this.pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false)); } }; takeEquipment.defaultCompleteMode = ToilCompleteMode.Instant; this.$current = takeEquipment; if (!this.$disposing) { this.$PC = 2; } return(true); } case 2u: this.$PC = -1; break; } return(false); }
public static bool equipSpecificWeaponFromInventory(Pawn pawn, ThingWithComps weapon, bool dropCurrent, bool intentionalDrop) { if (weapon != null) { if (weapon.stackCount > 1) { weapon = weapon.SplitOff(1) as ThingWithComps; //if this cast doesnt work the world has gone mad } else { pawn.inventory.innerContainer.Remove(weapon); } } return(equipSpecificWeapon(pawn, weapon, dropCurrent, intentionalDrop)); }
/// <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); } }, }); }
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 { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(); } //this.pawn.equipment.MakeRoomFor(thingWithComps2); //this.pawn.equipment.AddEquipment(thingWithComps2); 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) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(this.pawn); if (pawnMemory == null) { return; } pawnMemory.AddSidearm(thingWithComps2.def); } }, defaultCompleteMode = ToilCompleteMode.Instant }); yield return(Toils_Goto.Goto(TargetIndex.B, PathEndMode.OnCell)); }
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 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)); } }
public static bool TryEquipWeapon(Pawn pawn, ThingWithComps weapon, bool makeSound = true) { if (pawn == null || weapon == null) { return(false); } ThingWithComps currentWeapon = pawn.equipment.Primary; bool transferSuccess = true; if (currentWeapon != null) { transferSuccess = pawn.inventory.innerContainer.TryAddOrTransfer(currentWeapon); } if (transferSuccess) { if (weapon.stackCount > 1) { weapon = (ThingWithComps)weapon.SplitOff(1); } if (weapon.holdingOwner != null) { weapon.holdingOwner.Remove(weapon); } pawn.equipment.AddEquipment(weapon); if (makeSound) { weapon.def.soundInteract?.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map)); } return(true); } else { Log.Warning("CM_Grab_Your_Tool: Unable to transfer equipped weapon to inventory"); } return(false); }
public static bool ShouldReload(Pawn p) { //For mechanoids replace the check of is p.RaceProps.HumanLike by custom logic if (p.RaceProps.IsMechanoid && p.IsHacked()) { Log.Message("mech should reload called"); //return true when a mechanoid is hacked and does not have much ammo. ThingComp inventory = TryGetCompByTypeName(p, "CompInventory", "CombatExtended"); ThingWithComps eq = p.equipment.Primary; bool shouldTransfer = false; if (eq == null) { eq = p.inventory.GetDirectlyHeldThings().FirstOrDefault() as ThingWithComps; shouldTransfer = eq == null ? false : true; } if (inventory != null && eq != null) { //Everything is done using reflection, so we don't need to include a dependency ThingComp ammoUser = TryGetCompByTypeName(eq, "CompAmmoUser", "CombatExtended"); if (ammoUser != null) { var currentAmmo = Traverse.Create(ammoUser).Property("CurrentAmmo").GetValue(); int ammoCount = Traverse.Create(inventory).Method("AmmoCountOfDef", new object[] { currentAmmo }).GetValue <int>(); var props = Traverse.Create(ammoUser).Property("Props").GetValue(); int magazineSize = Traverse.Create(props).Field("magazineSize").GetValue <int>(); int minAmmo = magazineSize == 0 ? 10 : magazineSize; //No magic numbers? if (ammoCount < minAmmo) { if (shouldTransfer) { p.equipment.AddEquipment(eq.SplitOff(1) as ThingWithComps); } Log.Message("mech should reload returning true"); return(true); } } } } return(p.RaceProps.Humanlike); }
private void TryEquipDraggedItem(Pawn p) { droppedDraggedItem = false; if (!EquipmentUtility.CanEquip_NewTmp(draggedItem, p, out var cantReason)) { Messages.Message("MessageCantEquipCustom".Translate(cantReason.CapitalizeFirst()), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } if (draggedItem.def.IsWeapon) { if (p.guest.IsPrisoner) { Messages.Message("MessageCantEquipCustom".Translate("MessagePrisonerCannotEquipWeapon".Translate(p.Named("PAWN"))), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } if (p.WorkTagIsDisabled(WorkTags.Violent)) { Messages.Message("MessageCantEquipIncapableOfViolence".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } if (!p.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { Messages.Message("MessageCantEquipIncapableOfManipulation".Translate(), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } } Apparel apparel = draggedItem as Apparel; ThingWithComps thingWithComps = draggedItem as ThingWithComps; if (apparel != null && p.apparel != null) { if (!ApparelUtility.HasPartsToWear(p, apparel.def)) { Messages.Message("MessageCantWearApparelMissingBodyParts".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } if (CurrentWearerOf(apparel) != null && CurrentWearerOf(apparel).apparel.IsLocked(apparel)) { Messages.Message("MessageCantUnequipLockedApparel".Translate(), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } if (p.apparel.WouldReplaceLockedApparel(apparel)) { Messages.Message("MessageWouldReplaceLockedApparel".Translate(p.LabelShort, p), p, MessageTypeDefOf.RejectInput, historical: false); draggedItem = null; return; } tmpExistingApparel.Clear(); tmpExistingApparel.AddRange(p.apparel.WornApparel); for (int i = 0; i < tmpExistingApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(apparel.def, tmpExistingApparel[i].def, p.RaceProps.body)) { p.apparel.Remove(tmpExistingApparel[i]); Pawn pawn = CaravanInventoryUtility.FindPawnToMoveInventoryTo(tmpExistingApparel[i], Pawns, null); if (pawn != null) { pawn.inventory.innerContainer.TryAdd(tmpExistingApparel[i]); continue; } Log.Warning(string.Concat("Could not find any pawn to move ", tmpExistingApparel[i], " to.")); tmpExistingApparel[i].Destroy(); } } p.apparel.Wear((Apparel)apparel.SplitOff(1), dropReplacedApparel: false); if (p.outfits != null) { p.outfits.forcedHandler.SetForced(apparel, forced: true); } } else if (thingWithComps != null && p.equipment != null) { string personaWeaponConfirmationText = EquipmentUtility.GetPersonaWeaponConfirmationText(draggedItem, p); if (!personaWeaponConfirmationText.NullOrEmpty()) { _ = draggedItem; Find.WindowStack.Add(new Dialog_MessageBox(personaWeaponConfirmationText, "Yes".Translate(), delegate { AddEquipment(); }, "No".Translate())); draggedItem = null; return; } AddEquipment(); } else { Log.Warning(string.Concat("Could not make ", p, " equip or wear ", draggedItem)); } draggedItem = null; void AddEquipment() { tmpExistingEquipment.Clear(); tmpExistingEquipment.AddRange(p.equipment.AllEquipmentListForReading); for (int j = 0; j < tmpExistingEquipment.Count; j++) { p.equipment.Remove(tmpExistingEquipment[j]); Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(tmpExistingEquipment[j], Pawns, null); if (pawn2 != null) { pawn2.inventory.innerContainer.TryAdd(tmpExistingEquipment[j]); } else { Log.Warning(string.Concat("Could not find any pawn to move ", tmpExistingEquipment[j], " to.")); tmpExistingEquipment[j].Destroy(); } } p.equipment.AddEquipment((ThingWithComps)thingWithComps.SplitOff(1)); } }
private void TryEquipDraggedItem(Pawn p) { this.droppedDraggedItem = false; if (this.draggedItem.def.IsWeapon) { if (p.story != null && p.story.WorkTagIsDisabled(WorkTags.Violent)) { Messages.Message("MessageCantEquipIncapableOfViolence".Translate(p.LabelShort), p, MessageTypeDefOf.RejectInput); this.draggedItem = null; return; } if (!p.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)) { Messages.Message("MessageCantEquipIncapableOfManipulation".Translate(), p, MessageTypeDefOf.RejectInput); this.draggedItem = null; return; } } Apparel apparel = this.draggedItem as Apparel; ThingWithComps thingWithComps = this.draggedItem as ThingWithComps; if (apparel != null && p.apparel != null) { WITab_Caravan_Gear.tmpExistingApparel.Clear(); WITab_Caravan_Gear.tmpExistingApparel.AddRange(p.apparel.WornApparel); for (int i = 0; i < WITab_Caravan_Gear.tmpExistingApparel.Count; i++) { if (!ApparelUtility.CanWearTogether(apparel.def, WITab_Caravan_Gear.tmpExistingApparel[i].def, p.RaceProps.body)) { p.apparel.Remove(WITab_Caravan_Gear.tmpExistingApparel[i]); Pawn pawn = CaravanInventoryUtility.FindPawnToMoveInventoryTo(WITab_Caravan_Gear.tmpExistingApparel[i], this.Pawns, null, null); if (pawn != null) { pawn.inventory.innerContainer.TryAdd(WITab_Caravan_Gear.tmpExistingApparel[i], true); } else { Log.Warning("Could not find any pawn to move " + WITab_Caravan_Gear.tmpExistingApparel[i] + " to."); WITab_Caravan_Gear.tmpExistingApparel[i].Destroy(DestroyMode.Vanish); } } } p.apparel.Wear((Apparel)apparel.SplitOff(1), false); if (p.outfits != null) { p.outfits.forcedHandler.SetForced(apparel, true); } } else if (thingWithComps != null && p.equipment != null) { WITab_Caravan_Gear.tmpExistingEquipment.Clear(); WITab_Caravan_Gear.tmpExistingEquipment.AddRange(p.equipment.AllEquipmentListForReading); for (int j = 0; j < WITab_Caravan_Gear.tmpExistingEquipment.Count; j++) { p.equipment.Remove(WITab_Caravan_Gear.tmpExistingEquipment[j]); Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(WITab_Caravan_Gear.tmpExistingEquipment[j], this.Pawns, null, null); if (pawn2 != null) { pawn2.inventory.innerContainer.TryAdd(WITab_Caravan_Gear.tmpExistingEquipment[j], true); } else { Log.Warning("Could not find any pawn to move " + WITab_Caravan_Gear.tmpExistingEquipment[j] + " to."); WITab_Caravan_Gear.tmpExistingEquipment[j].Destroy(DestroyMode.Vanish); } } p.equipment.AddEquipment((ThingWithComps)thingWithComps.SplitOff(1)); } else { Log.Warning("Could not make " + p + " equip or wear " + this.draggedItem); } this.draggedItem = null; }
public static bool equipSpecificWeapon(Pawn pawn, ThingWithComps weapon, bool dropCurrent, bool intentionalDrop) { if (!pawn.IsValidSidearmsCarrier()) { return(false); } CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn); if (pawnMemory == null) { return(false); } if (weapon == pawn.equipment.Primary) //attepmpting to equip already-equipped weapon { Log.Warning("attepmpting to equip already-equipped weapon"); return(false); } if (!Settings.AllowBlockedWeaponUse && !StatCalculator.canUseSidearmInstance(weapon, pawn, out string reason)) { Log.Warning($"blocked equip of {weapon.Label} at equip-time because of: {reason}"); return(false); } var currentPrimary = pawn.equipment.Primary; //drop current on the ground if (dropCurrent && pawn.equipment.Primary != null) { if (!intentionalDrop) { DoFumbleMote(pawn); } pawnMemory.InformOfDroppedSidearm(weapon, intentionalDrop); Pawn_EquipmentTracker_TryDropEquipment.dropEquipmentSourcedBySimpleSidearms = true; pawn.equipment.TryDropEquipment(pawn.equipment.Primary, out ThingWithComps droppedItem, pawn.Position, false); Pawn_EquipmentTracker_TryDropEquipment.dropEquipmentSourcedBySimpleSidearms = false; } //or put it in inventory else if (pawn.equipment.Primary != null) { ThingWithComps oldPrimary = pawn.equipment.Primary; bool addedToInventory = pawn.inventory.innerContainer.TryAddOrTransfer(oldPrimary, true); //pawn.equipment.Remove(oldPrimary); //bool addedToInventory = pawn.inventory.innerContainer.TryAdd(oldPrimary, true); if (!addedToInventory) { Log.Warning(String.Format("Failed to place primary equipment {0} (initially was {1}) into inventory when swapping to {2} on pawn {3} (colonist: {4}) (dropping: {5}, current drop mode: {6}). Aborting swap. Please report this!", pawn.equipment.Primary != null ? pawn.equipment.Primary.LabelCap : "NULL", currentPrimary != null ? currentPrimary.LabelCap : "NULL", weapon != null ? weapon.LabelCap : "NULL", pawn?.LabelCap, pawn?.IsColonist, dropCurrent, Settings.FumbleMode )); } } if (pawn.equipment.Primary != null) { Log.Warning(String.Format("Failed to remove current primary equipment {0} (initially was {1}) when swapping to {2} on pawn {3} (colonist: {4}) (dropping: {5}, current drop mode: {6}). Aborting swap. Please report this!", pawn.equipment.Primary != null ? pawn.equipment.Primary.LabelCap : "NULL", currentPrimary != null ? currentPrimary.LabelCap : "NULL", weapon != null ? weapon.LabelCap : "NULL", pawn?.LabelCap, pawn?.IsColonist, dropCurrent, Settings.FumbleMode )); return(false); } if (weapon == null) { } else { if (weapon.stackCount > 1) { weapon = weapon.SplitOff(1) as ThingWithComps; //if this cast doesnt work the world has gone mad } if (weapon.holdingOwner != null) { weapon.holdingOwner.Remove(weapon); } Pawn_EquipmentTracker_AddEquipment.addEquipmentSourcedBySimpleSidearms = true; pawn.equipment.AddEquipment(weapon as ThingWithComps); Pawn_EquipmentTracker_AddEquipment.addEquipmentSourcedBySimpleSidearms = false; if (weapon.def.soundInteract != null) { weapon.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } } //avoid hunting stackoverflowexception if (pawn.jobs != null && pawn.jobs.curJob != null && pawn.jobs.curJob.def == JobDefOf.Hunt) { pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true); } return(true); }
protected override IEnumerable <Toil> MakeNewToils() { Bill bill = job.bill; AddEndCondition(delegate { Thing thing = GetActor().jobs.curJob.GetTarget(TargetIndex.A).Thing; if (thing is Building && !thing.Spawned) { return(JobCondition.Incompletable); } return(JobCondition.Ongoing); }); this.FailOnBurningImmobile(TargetIndex.A); this.FailOn(delegate() { IBillGiver billGiver = job.GetTarget(TargetIndex.A).Thing as IBillGiver; if (billGiver != null) { if (job.bill.DeletedOrDereferenced) { return(true); } if (!billGiver.CurrentlyUsableForBills()) { return(true); } } return(false); }); AddFinishAction(delegate() { //Log.Message("LearnWeapon: finishing"); ThingWithComps thingWithComps = (ThingWithComps)job.targetB.Thing; if (pawn.equipment.Primary != null) { pawn.equipment.TryDropEquipment(thingWithComps, out thingWithComps, pawn.Position, false); } }); Toil gotoBillGiver = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell); yield return(Toils_Jump.JumpIf(gotoBillGiver, () => job.GetTargetQueue(TargetIndex.B).NullOrEmpty <LocalTargetInfo>())); Toil extract = Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.B, true); yield return(extract); Toil getToHaulTarget = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B); yield return(getToHaulTarget); //temporary equip yield return(new Toil { initAction = delegate() { ThingWithComps thingWithComps = (ThingWithComps)job.targetB.Thing; ThingWithComps thingWithComps2; if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1) { thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1); } else { thingWithComps2 = thingWithComps; thingWithComps2.DeSpawn(DestroyMode.Vanish); } pawn.equipment.MakeRoomFor(thingWithComps2); pawn.equipment.AddEquipment(thingWithComps2); if (thingWithComps.def.soundInteract != null) { thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } }, defaultCompleteMode = ToilCompleteMode.Instant }); yield return(Toils_Jump.JumpIfHaveTargetInQueue(TargetIndex.B, extract)); yield return(gotoBillGiver); yield return(Toils_Combat.TrySetJobToUseAttackVerb(TargetIndex.A)); Toil train = new Toil(); train.initAction = delegate() { Pawn actor = train.actor; Job curJob = actor.jobs.curJob; ThingDef weapon = job.targetB.Thing.def; workLeft = curJob.bill.recipe.WorkAmountTotal(null); billStartTick = Find.TickManager.TicksGame; ticksSpentDoingRecipeWork = 0; curJob.bill.Notify_DoBillStarted(actor); //sound: if (weapon.soundInteract != null) { weapon.soundInteract.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } }; train.tickAction = delegate() { Pawn actor = train.actor; Job curJob = actor.jobs.curJob; ThingDef weapon = job.targetB.Thing.def; ticksSpentDoingRecipeWork++; curJob.bill.Notify_PawnDidWork(actor); IBillGiverWithTickAction billGiverWithTickAction = train.actor.CurJob.GetTarget(TargetIndex.A).Thing as IBillGiverWithTickAction; if (billGiverWithTickAction != null) { billGiverWithTickAction.UsedThisTick(); } float num = (curJob.RecipeDef.workSpeedStat != null) ? actor.GetStatValue(curJob.RecipeDef.workSpeedStat, true) : 1f; if (curJob.RecipeDef.workTableSpeedStat != null) { Building_WorkTable building_WorkTable = BillGiver as Building_WorkTable; if (building_WorkTable != null) { num *= building_WorkTable.GetStatValue(curJob.RecipeDef.workTableSpeedStat, true); } } if (DebugSettings.fastCrafting) { num *= 30f; } workLeft -= num; actor.GainComfortFromCellIfPossible(); if (workLeft <= 0f) { ReadyForNextToil(); } //pawn posture Verb verbToUse = actor.jobs.curJob.verbToUse; LocalTargetInfo target = actor.jobs.curJob.GetTarget(TargetIndex.A); pawn.stances.SetStance(new Stance_Warmup(1, target, verbToUse)); //sound: if (verbToUse.verbProps != null && verbToUse.verbProps.warmupTime > 0) { if ((ticksSpentDoingRecipeWork % verbToUse.verbProps.AdjustedFullCycleTime(verbToUse, actor).SecondsToTicks()) == 0) { if (verbToUse.verbProps.soundCast != null) { verbToUse.verbProps.soundCast.PlayOneShot(new TargetInfo(pawn.Position, pawn.Map, false)); } if (verbToUse.verbProps.soundCastTail != null) { verbToUse.verbProps.soundCastTail.PlayOneShotOnCamera(pawn.Map); } } } if (job.RecipeDef.workSkill != null) { //float xpDelta = techComp.proficientWeapons.Contains(job.targetB.Thing.def) ? 1f : 0.1f; float xp = 0.1f * job.RecipeDef.workSkillLearnFactor; actor.skills.GetSkill(job.RecipeDef.workSkill).Learn(xp, false); } }; train.defaultCompleteMode = ToilCompleteMode.Never; train.WithEffect(() => train.actor.CurJob.bill.recipe.effectWorking, TargetIndex.A); train.PlaySustainerOrSound(() => train.actor.CurJob.bill.recipe.soundWorking); train.WithProgressBar(TargetIndex.A, delegate { Pawn actor = train.actor; Job curJob = actor.CurJob; //return 1f - ((JobDriver_DoBill)actor.jobs.curDriver).workLeft / curJob.bill.recipe.WorkAmountTotal(null); return(1f - (workLeft / curJob.bill.recipe.WorkAmountTotal(null))); }, false, -0.5f); train.FailOn(() => train.actor.CurJob.bill.suspended); train.activeSkill = () => train.actor.CurJob.bill.recipe.workSkill; yield return(train.FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell)); Toil finalizeTraining = new Toil(); finalizeTraining.initAction = delegate { Pawn actor = finalizeTraining.actor; CompKnowledge techComp = actor.TryGetComp <CompKnowledge>(); if (!techComp.proficientWeapons.Contains(job.targetB.Thing.def)) { techComp.proficientWeapons.Add(TargetThingB.def); } job.bill.Notify_IterationCompleted(actor, new List <Thing> { }); actor.jobs.EndCurrentJob(JobCondition.Succeeded, false); }; finalizeTraining.defaultCompleteMode = ToilCompleteMode.Instant; finalizeTraining.FailOnDespawnedOrNull(TargetIndex.A); yield return(finalizeTraining); //testing yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null)); Toil findPlaceTarget = Toils_Haul.CarryHauledThingToCell(TargetIndex.B); yield return(findPlaceTarget); yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, findPlaceTarget, true, true)); yield break; }