public static void Postfix(Thing item, IThingHolder ___owner) { if (item != last && ___owner is Building_BookStore bookStore && !bookStore.borrowed.Contains(item)) { bookStore.CheckBookIn(item); last = item; }
public Pawn GetEquippedPawn(ThingWithComps thing) { IThingHolder holder = thing.ParentHolder; if (holder == null) { return(null); } Pawn pawn = null; if (thing is Apparel apparel) { pawn = apparel.Wearer; } else if (holder is Pawn_ApparelTracker apparelTracker) { pawn = apparelTracker.pawn; } else if (holder is Pawn_EquipmentTracker equipTracker) { pawn = equipTracker.pawn; } return(pawn); }
public static void Transfer(List <Thing> things, int count, Action <Thing, IThingHolder> transferred) { if (count > 0) { tmpThings.Clear(); tmpThings.AddRange(things); int num = count; for (int i = 0; i < tmpThings.Count; i++) { Thing thing = tmpThings[i]; int num2 = Mathf.Min(num, thing.stackCount); if (num2 > 0) { IThingHolder parentHolder = thing.ParentHolder; Thing thing2 = thing.SplitOff(num2); num -= num2; if (thing2 == thing) { things.Remove(thing); } transferred(thing2, parentHolder); if (num <= 0) { break; } } } tmpThings.Clear(); if (num > 0) { Log.Error("Can't transfer things because there is nothing left."); } } }
private static void InterfaceDrop(ITab_Pawn_Gear __instance, Thing t) { if (t.def.IsMeleeWeapon || t.def.IsRangedWeapon) { ThingWithComps thingWithComps = t as ThingWithComps; ThingOwner thingOwner = thingWithComps.holdingOwner; IThingHolder actualOwner = thingOwner.Owner; if (actualOwner is Pawn_InventoryTracker) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn((actualOwner as Pawn_InventoryTracker).pawn); if (pawnMemory == null) { return; } pawnMemory.DropSidearm(thingWithComps.def, true); } else if (actualOwner is Pawn_EquipmentTracker) { GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn((actualOwner as Pawn_EquipmentTracker).ParentHolder as Pawn); if (pawnMemory == null) { return; } pawnMemory.DropPrimary(true); } } }
public static Thing GetFirstSpawnedParentThing(Thing thing) { Thing result; if (thing.Spawned) { result = thing; } else { for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { return(thing2); } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { return(thingComp.parent); } } result = null; } return(result); }
public static bool TryGetFixedTemperature(IThingHolder holder, Thing forThing, out float temperature) { if (holder is Pawn_InventoryTracker) { if (forThing.TryGetComp <CompHatcher>() != null) { temperature = 14f; return(true); } } bool result; if (holder is CompLaunchable || holder is ActiveDropPodInfo || holder is TravelingTransportPods) { temperature = 14f; result = true; } else if (holder is SettlementBase_TraderTracker || holder is TradeShip) { temperature = 14f; result = true; } else { temperature = 21f; result = false; } return(result); }
public static void InterfaceDrop(ITab_Pawn_Gear __instance, Thing t) { if (t.def.IsMeleeWeapon || t.def.IsRangedWeapon) { ThingWithComps thingWithComps = t as ThingWithComps; ThingOwner thingOwner = thingWithComps.holdingOwner; IThingHolder actualOwner = thingOwner.Owner; if (actualOwner is Pawn_InventoryTracker) { CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn((actualOwner as Pawn_InventoryTracker).pawn); if (pawnMemory == null) { return; } pawnMemory.InformOfDroppedSidearm(thingWithComps, true); } else if (actualOwner is Pawn_EquipmentTracker) { CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn((actualOwner as Pawn_EquipmentTracker).ParentHolder as Pawn); if (pawnMemory == null) { return; } pawnMemory.InformOfDroppedSidearm(thingWithComps, true); } } }
public static List <Thing> GetAllThingsRecursively(IThingHolder holder, bool allowUnreal = true) { List <Thing> list = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(holder, list, allowUnreal); return(list); }
public static void GetAllThingsRecursively(IThingHolder holder, List <Thing> outThings, bool allowUnreal = true) { outThings.Clear(); ThingOwnerUtility.tmpStack.Clear(); ThingOwnerUtility.tmpStack.Push(holder); while (ThingOwnerUtility.tmpStack.Count != 0) { IThingHolder thingHolder = ThingOwnerUtility.tmpStack.Pop(); if (allowUnreal || ThingOwnerUtility.AreImmediateContentsReal(thingHolder)) { ThingOwner directlyHeldThings = thingHolder.GetDirectlyHeldThings(); if (directlyHeldThings != null) { outThings.AddRange(directlyHeldThings); } } ThingOwnerUtility.tmpHolders.Clear(); thingHolder.GetChildHolders(ThingOwnerUtility.tmpHolders); for (int i = 0; i < ThingOwnerUtility.tmpHolders.Count; i++) { ThingOwnerUtility.tmpStack.Push(ThingOwnerUtility.tmpHolders[i]); } } ThingOwnerUtility.tmpStack.Clear(); ThingOwnerUtility.tmpHolders.Clear(); }
public static bool get_FreeColonistsSpawnedOrInPlayerEjectablePodsCount(MapPawns __instance, ref int __result) { int num = 0; lock (pawnsSpawned(__instance)) { for (int index = 0; index < pawnsSpawned(__instance).Count; ++index) { if (pawnsSpawned(__instance)[index].IsFreeColonist) { ++num; } } } List <Thing> thingList = map(__instance).listerThings.ThingsInGroup(ThingRequestGroup.ThingHolder); for (int index1 = 0; index1 < thingList.Count; ++index1) { if (thingList[index1] is Building_CryptosleepCasket cryptosleepCasket && cryptosleepCasket.def.building.isPlayerEjectable || (thingList[index1] is IActiveDropPod || thingList[index1] is PawnFlyer) || thingList[index1].TryGetComp <CompTransporter>() != null) { IThingHolder holder = (IThingHolder)thingList[index1].TryGetComp <CompTransporter>() ?? (IThingHolder)thingList[index1]; List <Thing> tmpThings = new List <Thing>(); ThingOwnerUtility.GetAllThingsRecursively(holder, tmpThings, true, (Predicate <IThingHolder>)null); for (int index2 = 0; index2 < tmpThings.Count; ++index2) { if (tmpThings[index2] is Pawn tmpThing && !tmpThing.Dead && tmpThing.IsFreeColonist) { ++num; } } } } __result = num; return(false); }
private static bool GetAllHeldPawns(IThingHolder holder, List <Pawn> outThings, Stack <IThingHolder> tmpStack, List <IThingHolder> tmpHolders) { tmpStack.Clear(); tmpStack.Push(holder); while (tmpStack.Count != 0) { IThingHolder thingHolder = tmpStack.Pop(); ThingOwner directlyHeldThings = thingHolder.GetDirectlyHeldThings(); if (directlyHeldThings != null) { for (int i = 0; i < directlyHeldThings.Count; i++) { Pawn pawn = directlyHeldThings[i] as Pawn; if (pawn != null && ThingRequest.ForGroup(ThingRequestGroup.Pawn).Accepts(pawn) && !pawn.Dead) { outThings.Add(pawn); } } } tmpHolders.Clear(); thingHolder.GetChildHolders(tmpHolders); for (int i = 0; i < tmpHolders.Count; i++) { tmpStack.Push(tmpHolders[i]); } } return(false); }
public static bool GetAllThingsRecursively(IThingHolder holder, List <Thing> outThings, bool allowUnreal = true, Predicate <IThingHolder> passCheck = null) { outThings.Clear(); if (passCheck != null && !passCheck(holder)) { return(false); } Stack <IThingHolder> tmpStack = new Stack <IThingHolder>(); tmpStack.Push(holder); while (tmpStack.Count != 0) { IThingHolder thingHolder = tmpStack.Pop(); if (allowUnreal || ThingOwnerUtility.AreImmediateContentsReal(thingHolder)) { ThingOwner directlyHeldThings = thingHolder.GetDirectlyHeldThings(); if (directlyHeldThings != null) { outThings.AddRange(directlyHeldThings); } } List <IThingHolder> tmpHolders = new List <IThingHolder>(); thingHolder.GetChildHolders(tmpHolders); for (int i = 0; i < tmpHolders.Count; i++) { if (passCheck == null || passCheck(tmpHolders[i])) { tmpStack.Push(tmpHolders[i]); } } } //tmpStack.Clear(); //tmpHolders.Clear(); return(false); }
public static void Prefix(Thing item, IThingHolder ___owner) { if (___owner is Building_BookStore) { Act = true; } }
public void GetChildHolders(List <IThingHolder> outChildren) { ThingOwnerUtility.AppendThingHoldersFromThings(outChildren, GetDirectlyHeldThings()); List <WorldObject> allWorldObjects = worldObjects.AllWorldObjects; for (int i = 0; i < allWorldObjects.Count; i++) { IThingHolder thingHolder = allWorldObjects[i] as IThingHolder; if (thingHolder != null) { outChildren.Add(thingHolder); } List <WorldObjectComp> allComps = allWorldObjects[i].AllComps; for (int j = 0; j < allComps.Count; j++) { IThingHolder thingHolder2 = allComps[j] as IThingHolder; if (thingHolder2 != null) { outChildren.Add(thingHolder2); } } } for (int k = 0; k < components.Count; k++) { IThingHolder thingHolder3 = components[k] as IThingHolder; if (thingHolder3 != null) { outChildren.Add(thingHolder3); } } }
public static void AppendThingHoldersFromThings(List <IThingHolder> outThingsHolders, ThingOwner container) { if (container == null) { return; } int i = 0; int count = container.Count; while (i < count) { IThingHolder thingHolder = container[i] as IThingHolder; if (thingHolder != null) { outThingsHolders.Add(thingHolder); } ThingWithComps thingWithComps = container[i] as ThingWithComps; if (thingWithComps != null) { List <ThingComp> allComps = thingWithComps.AllComps; for (int j = 0; j < allComps.Count; j++) { IThingHolder thingHolder2 = allComps[j] as IThingHolder; if (thingHolder2 != null) { outThingsHolders.Add(thingHolder2); } } } i++; } }
public static GlobalTargetInfo GetAdjustedTarget(GlobalTargetInfo target) { if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { return(thing); } GlobalTargetInfo result = GlobalTargetInfo.Invalid; for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { result = thing2; break; } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { result = thingComp.parent; break; } WorldObject worldObject = parentHolder as WorldObject; if (worldObject != null && worldObject.Spawned) { result = worldObject; break; } } if (result.IsValid) { return(result); } if (thing.Tile >= 0) { return(new GlobalTargetInfo(thing.Tile)); } } else if (target.Cell.IsValid && target.Tile >= 0 && target.Map != null && !Find.Maps.Contains(target.Map)) { MapParent parent = target.Map.info.parent; if (parent != null && parent.Spawned) { return(parent); } if (parent != null && parent.Tile >= 0) { return(new GlobalTargetInfo(target.Map.Tile)); } return(GlobalTargetInfo.Invalid); } else if (target.HasWorldObject && !target.WorldObject.Spawned && target.WorldObject.Tile >= 0) { return(new GlobalTargetInfo(target.WorldObject.Tile)); } return(target); }
public bool ParentIsNotContained(IThingHolder holder) { if (holder is Map) { return(true); } return(false); }
public static bool AreImmediateContentsReal(IThingHolder holder) { if (!(holder is Corpse)) { return(!(holder is MinifiedThing)); } return(false); }
public static bool ShouldAutoRemoveDestroyedThings(IThingHolder holder) { if (!(holder is Corpse)) { return(!(holder is Caravan)); } return(false); }
public static bool IsEnclosingContainer(this IThingHolder holder) { if (holder != null && !(holder is Pawn_CarryTracker) && !(holder is Corpse) && !(holder is Map) && !(holder is Caravan) && !(holder is Settlement_TraderTracker)) { return(!(holder is TradeShip)); } return(false); }
public static void Postfix(Thing item, IThingHolder ___owner) { if (___owner is Building_BookStore bookStore && item.Stuff != null && item.Stuff.IsWithinCategory(TechDefOf.Knowledge)) { ResearchProjectDef project = ModBaseHumanResources.unlocked.techByStuff[item.Stuff]; bookStore.CompStorageGraphic.UpdateGraphics(); project.CarefullyFinishProject(bookStore); } }
public static bool Prefix(Thing item, IThingHolder ___owner) { if (item.def.IsWeapon && ___owner is Pawn_EquipmentTracker gear) { Pawn pawn = (Pawn)pawnInfo.GetValue(gear); return(HarmonyPatches.CheckKnownWeapons(pawn, item)); } return(true); }
public static Thing ReplacedThing(ThingWithComps original) { bool actionRequired = original.GetType() != original.def.thingClass; if (actionRequired) { // Log.Message("original.GetType("+ original.GetType()+ ") != original.def.thingClass("+ original.def.thingClass+")"); bool act = original.def.modContentPack != null && original.def.modContentPack.Name.Contains("Adeptus Mechanicus"); if (act) { try { // Log.Message("act"); // Log.Warning(original.LabelCap + "'s ThingClass doesnt match its Defs ThingClass, trying to fix"); Thing thing = ThingMaker.MakeThing(original.def, original.Stuff); thing.Position = original.Position; CompQuality quality = original.TryGetCompFast <CompQuality>(); if (quality != null) { quality.parent = thing as ThingWithComps; } CompArt art = original.TryGetCompFast <CompArt>(); if (art != null) { art.parent = thing as ThingWithComps; } thing.thingIDNumber = original.thingIDNumber; IThingHolder holder = original.ParentHolder; CompEquippable equippable = original.TryGetCompFast <CompEquippable>(); if (equippable != null) { Thing user = equippable.VerbTracker.PrimaryVerb.Caster; Pawn p = user as Pawn; if (p != null) { p.equipment.Remove(original); p.equipment.AddEquipment(thing as ThingWithComps); } } else if (holder != null) { holder.GetDirectlyHeldThings().Remove(original); holder.GetDirectlyHeldThings().TryAdd(thing); } return(thing); } catch (Exception) { Log.Warning("Something went wrong trying to replace " + original.LabelCap + "'s ThingClass from " + original.GetType().Name + " to " + original.def.thingClass.Name); return(original); } } } return(original); }
public static void RecordPlayerAddedMapThings(IThingHolder owner, Map onMap) { var state = GetStateForMap(onMap); var knownOrInvalidThingIds = new HashSet <int>(state.PlayerAddedThingIds.Union(state.ScenarioGeneratedThingIds)); var nonColonistThings = ThingOwnerUtility.GetAllThingsRecursively(owner, false) .Where(t => !(t is Pawn) && !(t is Building) && !knownOrInvalidThingIds.Contains(t.thingIDNumber)); //Logger.Message("Player added things to map: " + nonColonistThings.ListElements()); state.PlayerAddedThingIds.AddRange(nonColonistThings.Select(t => t.thingIDNumber)); }
private static bool <CalculateWealthItems> m__0(IThingHolder x) { if (x is PassingShip || x is MapComponent) { return(false); } Pawn pawn = x as Pawn; return(pawn == null || pawn.Faction == Faction.OfPlayer); }
private Pawn CurrentWearerOf(Thing t) { IThingHolder parentHolder = t.ParentHolder; if (!(parentHolder is Pawn_EquipmentTracker) && !(parentHolder is Pawn_ApparelTracker)) { return(null); } return((Pawn)parentHolder.ParentHolder); }
/// <summary> /// Walks the linked list from a Thing's holdingOwner.Owner back up to a Pawn, or null, and returns the result. /// </summary> /// <param name="container">IThingHolder type which can be a container of some sort or a pawn.</param> /// <returns>Pawn type which can be null if we didn't end up with a pawn at the top.</returns> private Pawn RootHolder(IThingHolder container) { IThingHolder holder = container; while (holder != null && (holder as Pawn) == null) { holder = holder.ParentHolder; } return(holder as Pawn); }
} //end FindClosestIngForBill public static Thing FindClosestIngToBillGiver(Bill theBill, IngredientCount curIng) { IBillGiver billGiver = theBill.billStack.billGiver; IThingHolder holder = billGiver as IThingHolder; Thing building = billGiver as Thing; ThingOwner vatStoredIngredients = holder?.GetDirectlyHeldThings(); if (billGiver == null || building == null || billGiver == null || vatStoredIngredients == null) { return(null); } int storedCount = vatStoredIngredients.FirstOrDefault(thing => thing.def == curIng.FixedIngredient)?.stackCount ?? 0; int countNeededFromRecipe = (int)(curIng.CountRequiredOfFor(curIng.FixedIngredient, theBill.recipe) * QEESettings.instance.organTotalResourcesFloat); int countNeededForCrafting = countNeededFromRecipe - storedCount; countNeededForCrafting = countNeededForCrafting < 0 ? 0 : countNeededForCrafting; //only check the map for Things if the vat still needs some of this ingredient if (countNeededForCrafting > 0) { //find the closest accessible Thing of that ThingDef on the map ThingRequest tRequest = ThingRequest.ForDef(curIng.FixedIngredient); IEnumerable <Thing> searchSet = billGiver.Map.listerThings.ThingsMatching(tRequest); Thing result = GenClosest.ClosestThing_Global(building.Position, searchSet, validator : delegate(Thing testThing) { if (testThing.def.defName != curIng.FixedIngredient.defName) { return(false); } if (testThing.IsForbidden(building.Faction)) { return(false); } return(true); }); //return the Thing, if we found one if (result != null) { //QEEMod.TryLog("Ingredient found: " + curIng.FixedIngredient.label + " | stackCount: " + result.stackCount + " | recipe: " // + countNeededFromRecipe); return(result); } } return(null); } //end function FindClosestIngToBillGiver
public static void Postfix(Thing item, IThingHolder ___owner) { if (item != last && ___owner is Building_BookStore bookStore) { bookStore.CheckBookOut(item); last = item; } else if (item == last) { last = null; } }
public static bool ContentsSuspended(IThingHolder holder) { while (holder != null) { if (holder is Building_CryptosleepCasket || holder is ImportantPawnComp) { return(true); } holder = holder.ParentHolder; } return(false); }