internal static bool TryTransferEquipmentToContainer(this Pawn_EquipmentTracker _this, ThingWithComps eq, ThingContainer container, out ThingWithComps resultingEq) { // Fetch private fields Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this); if (!_this.AllEquipment.Contains(eq)) { Log.Warning(pawn.LabelCap + " tried to transfer equipment he didn't have: " + eq); resultingEq = null; return(false); } if (container.TryAdd(eq, true)) { resultingEq = null; } else { resultingEq = eq; } _this.Remove(eq); CE_Utility.TryUpdateInventory(pawn); // Equipment was stored away, update inventory // Cancel current job (use verb, etc.) if (pawn.Spawned) { pawn.stances.CancelBusyStanceSoft(); } return(resultingEq == null); }
public bool AddItem([NotNull] Thing t, int initialCounter = 0) { if (!_container.TryAdd(t)) { return false; } _thingCounter[t] = initialCounter; return true; }
public virtual void BoardOn(Pawn pawn) { if (mountableComp.IsMounted && (storage.Count(x => x is Pawn) >= maxNumBoarding || //No Space (Faction != null && Faction != pawn.Faction))) //Not your vehicle { return; } if (pawn.Faction == Faction.OfPlayer && (pawn.needs.food.CurCategory == HungerCategory.Starving || pawn.needs.rest.CurCategory == RestCategory.Exhausted)) { Messages.Message(pawn.LabelCap + "cannot board on " + LabelCap + ": " + pawn.LabelCap + "is starving or exhausted", MessageSound.RejectInput); return; } Job jobNew = new Job(HaulJobDefOf.StandBy, mountableComp.Driver.Position, 4800); mountableComp.Driver.jobs.StartJob(jobNew, JobCondition.Incompletable); storage.TryAdd(pawn); pawn.holder = GetContainer(); pawn.holder.owner = this; pawn.jobs.StartJob(new Job(JobDefOf.WaitCombat)); }
internal static bool TryTransferEquipmentToContainer(this Pawn_EquipmentTracker _this, ThingWithComps eq, ThingContainer container, out ThingWithComps resultingEq) { // Fetch private fields Pawn pawn = (Pawn)pawnFieldInfo.GetValue(_this); ThingWithComps primaryInt = (ThingWithComps)primaryIntFieldInfo.GetValue(_this); if (!_this.AllEquipment.Contains(eq)) { Log.Warning(pawn.LabelCap + " tried to transfer equipment he didn't have: " + eq); resultingEq = null; return(false); } if (container.TryAdd(eq)) { resultingEq = null; } else { resultingEq = eq; } if (primaryInt == eq) { primaryIntFieldInfo.SetValue(_this, null); // Changed assignment to SetValue() since we're fetching a private variable through reflection } pawn.meleeVerbs.Notify_EquipmentLost(); Utility.TryUpdateInventory(pawn); // Equipment was stored away, update inventory // Cancel current job (use verb, etc.) if (pawn.Spawned) { pawn.stances.CancelBusyStanceSoft(); } return(resultingEq == null); }
internal static bool TryAdd(this ThingContainer _this, Thing item, bool canMergeWithExistingStacks = true) { if (item == null) { Log.Warning("Tried to add null item to ThingContainer."); return(false); } if (_this.Contains(item)) { Log.Warning("Tried to add " + item + " to ThingContainer but this item is already here."); return(false); } if (item.stackCount > _this.AvailableStackSpace) { return(_this.TryAdd(item, _this.AvailableStackSpace) > 0); } List <Thing> innerList = (List <Thing>)innerListFieldInfo.GetValue(_this); // Fetch innerList through reflection SlotGroupUtility.Notify_TakingThing(item); if (canMergeWithExistingStacks && item.def.stackLimit > 1) { for (int i = 0; i < innerList.Count; i++) { if (innerList[i].def == item.def) { int num = item.stackCount; if (num > _this.AvailableStackSpace) { num = _this.AvailableStackSpace; } Thing other = item.SplitOff(num); if (!innerList[i].TryAbsorbStack(other, false)) { Log.Error("ThingContainer did TryAbsorbStack " + item + " but could not absorb stack."); } } if (item.Destroyed) { //CR PART!!! CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker); // Item has been added, notify CompInventory return(true); } } } int maxStacks = (int)maxStacksFieldInfo.GetValue(_this); // Fetch maxStacks through reflection if (innerList.Count >= maxStacks) { return(false); } if (item.Spawned) { item.DeSpawn(); } if (item.HasAttachment(ThingDefOf.Fire)) { item.GetAttachment(ThingDefOf.Fire).Destroy(DestroyMode.Vanish); } item.holdingContainer = _this; innerList.Add(item); CR_Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker); // Item has been added, notify CompInventory return(true); }
internal static bool TryAdd(this ThingContainer _this, Thing item) { if (item.stackCount > _this.AvailableStackSpace) { Log.Error(string.Concat(new object[] { "Add item with stackCount=", item.stackCount, " with only ", _this.AvailableStackSpace, " in container. Splitting and adding..." })); return(_this.TryAdd(item, _this.AvailableStackSpace)); } List <Thing> innerList = (List <Thing>)innerListFieldInfo.GetValue(_this); // Fetch innerList through reflection SlotGroupUtility.Notify_TakingThing(item); if (item.def.stackLimit > 1) { for (int i = 0; i < innerList.Count; i++) { if (innerList[i].def == item.def) { int num = item.stackCount; if (num > _this.AvailableStackSpace) { num = _this.AvailableStackSpace; } Thing other = item.SplitOff(num); if (!innerList[i].TryAbsorbStack(other, false)) { Log.Error("ThingContainer did TryAbsorbStack " + item + " but could not absorb stack."); } } if (item.Destroyed) { Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker); // Item has been added, notify CompInventory return(true); } } } int maxStacks = (int)maxStacksFieldInfo.GetValue(_this); // Fetch maxStacks through reflection if (innerList.Count >= maxStacks) { return(false); } if (item.Spawned) { item.DeSpawn(); } if (item.HasAttachment(ThingDefOf.Fire)) { item.GetAttachment(ThingDefOf.Fire).Destroy(DestroyMode.Vanish); } item.holder = _this; innerList.Add(item); Utility.TryUpdateInventory(_this.owner as Pawn_InventoryTracker); // Item has been added, notify CompInventory return(true); }