Beispiel #1
0
 public ShipHandler()
 {
     if (handlers is null)
     {
         handlers = new ThingOwner <Pawn>(this, false, LookMode.Reference);
     }
 }
Beispiel #2
0
        public static int GetGoodwillChange(IEnumerable <IThingHolder> pods, Settlement giveTo)
        {
            float num = 0f;

            foreach (IThingHolder pod in pods)
            {
                ThingOwner directlyHeldThings = pod.GetDirectlyHeldThings();
                for (int i = 0; i < directlyHeldThings.Count; i++)
                {
                    float singlePrice;
                    if (directlyHeldThings[i].def == ThingDefOf.Silver)
                    {
                        singlePrice = directlyHeldThings[i].MarketValue;
                    }
                    else
                    {
                        float priceFactorSell_TraderPriceType      = (giveTo.TraderKind != null) ? giveTo.TraderKind.PriceTypeFor(directlyHeldThings[i].def, TradeAction.PlayerSells).PriceMultiplier() : 1f;
                        float tradePriceImprovementOffsetForPlayer = giveTo.TradePriceImprovementOffsetForPlayer;
                        singlePrice = TradeUtility.GetPricePlayerSell(directlyHeldThings[i], priceFactorSell_TraderPriceType, 1f, tradePriceImprovementOffsetForPlayer);
                    }
                    num += GetBaseGoodwillChange(directlyHeldThings[i], directlyHeldThings[i].stackCount, singlePrice, giveTo.Faction);
                }
            }
            return(PostProcessedGoodwillChange(num, giveTo.Faction));
        }
Beispiel #3
0
 private static void NotifyAddedAndMergedWith(ThingOwner <Thing> __instance, Thing item, int mergedCount)
 {
     if (!(__instance.Owner is CompTransporter owner))
     {
         return;
     }
     owner.Notify_ThingAddedAndMergedWith(item, mergedCount);
 }
 //Establishes that this building remains after reload and implements the tutor
 public override void SpawnSetup(Map map, bool respawningAfterLoad)
 {
     base.SpawnSetup(map, respawningAfterLoad);
     this.powerComp      = base.GetComp <CompPowerTrader>();
     this.innerContainer = new ThingOwner <Neurolink_Harddrive>(this);
     //LessonAutoActivator.TeachOpportunity(ConceptDefOf.BuildHarddrive, OpportunityType.GoodToKnow);
     LessonAutoActivator.TeachOpportunity(Neurolink_ConceptDefOf.Neurolink_UsingMainframe, OpportunityType.GoodToKnow);
 }
Beispiel #5
0
        public static bool PlayerOrQuestRewardHas(ThingDef thingDef)
        {
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                if (maps[i].listerThings.ThingsOfDef(thingDef).Count > 0)
                {
                    return(true);
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int j = 0; j < caravans.Count; j++)
            {
                if (caravans[j].IsPlayerControlled)
                {
                    List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravans[j]);
                    for (int k = 0; k < list.Count; k++)
                    {
                        if (list[k].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int l = 0; l < sites.Count; l++)
            {
                ItemStashContentsComp component = sites[l].GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int m = 0; m < contents.Count; m++)
                    {
                        if (contents[m].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
                DefeatAllEnemiesQuestComp component2 = sites[l].GetComponent <DefeatAllEnemiesQuestComp>();
                if (component2 != null)
                {
                    ThingOwner rewards = component2.rewards;
                    for (int n = 0; n < rewards.Count; n++)
                    {
                        if (rewards[n].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #6
0
        protected override Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator)
        {
            if (pawn.drugs == null)
            {
                return(null);
            }
            Predicate <Thing> predicate = delegate(Thing t)
            {
                if (!CanIngestForJoy(pawn, t))
                {
                    return(false);
                }
                if (extraValidator != null && !extraValidator(t))
                {
                    return(false);
                }
                return(true);
            };
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (predicate(innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            takeableDrugs.Clear();
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int j = 0; j < currentPolicy.Count; j++)
            {
                if (currentPolicy[j].allowedForJoy)
                {
                    takeableDrugs.Add(currentPolicy[j].drug);
                }
            }
            takeableDrugs.Shuffle();
            for (int k = 0; k < takeableDrugs.Count; k++)
            {
                List <Thing> list = pawn.Map.listerThings.ThingsOfDef(takeableDrugs[k]);
                if (list.Count > 0)
                {
                    IntVec3           position       = pawn.Position;
                    Map               map            = pawn.Map;
                    List <Thing>      searchSet      = list;
                    PathEndMode       peMode         = PathEndMode.OnCell;
                    TraverseParms     traverseParams = TraverseParms.For(pawn);
                    Predicate <Thing> validator      = predicate;
                    Thing             thing          = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator);
                    if (thing != null)
                    {
                        return(thing);
                    }
                }
            }
            return(null);
        }
 public VehicleHandlerGroup(Pawn newVehicle)
 {
     this.uniqueID = Find.UniqueIDsManager.GetNextThingID();
     this.vehicle  = newVehicle;
     if (this.handlers == null)
     {
         this.handlers = new ThingOwner <Pawn>(this, false, LookMode.Reference);
     }
 }
Beispiel #8
0
        public static void NotifyAddedAndMergedWithPostfix(ref ThingOwner __instance, Thing item, int mergedCount)
        {
            ShipBase ship = __instance.Owner as ShipBase;

            if (ship != null)
            {
                ship.compShip.NotifyItemAdded(item, mergedCount);
            }
        }
Beispiel #9
0
 public Caravan()
 {
     this.pawns      = new ThingOwner <Pawn>(this, false, LookMode.Reference);
     this.pather     = new Caravan_PathFollower(this);
     this.gotoMote   = new Caravan_GotoMoteRenderer();
     this.tweener    = new Caravan_Tweener(this);
     this.trader     = new Caravan_TraderTracker(this);
     this.storyState = new StoryState(this);
 }
Beispiel #10
0
 public VehicleHandler(VehiclePawn vehiclePawn)
 {
     uniqueID         = VehicleIdManager.Instance.GetNextHandlerId();
     this.vehiclePawn = vehiclePawn;
     if (handlers is null)
     {
         handlers = new ThingOwner <Pawn>(this, false, LookMode.Reference);
     }
 }
Beispiel #11
0
 private void MakeIntoContainer(ThingOwner container, ThingDef def, int count)
 {
     if (count > 0)
     {
         Thing thing = ThingMaker.MakeThing(def);
         thing.stackCount = count;
         container.TryAdd(thing);
     }
 }
Beispiel #12
0
        public static void NotifyAddedPostfix(ref ThingOwner __instance, Thing item)
        {
            ShipBase ship = __instance.Owner as ShipBase;

            if (ship != null)
            {
                ship.compShip.NotifyItemAdded(item, item.stackCount);
            }
        }
Beispiel #13
0
        private void SpawnCaravanAtDestinationTile()
        {
            PawnFlyersTraveling.tmpPawns.Clear();
            for (int i = 0; i < this.pods.Count; i++)
            {
                ThingOwner innerContainer = this.pods[i].innerContainer;
                for (int j = 0; j < innerContainer.Count; j++)
                {
                    Pawn      pawn      = innerContainer[j] as Pawn;
                    PawnFlyer pawnFlyer = innerContainer[j] as PawnFlyer;
                    if (pawn != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add(pawn);
                    }
                    else if (pawnFlyer != null)
                    {
                        PawnFlyersTraveling.tmpPawns.Add((Pawn)pawnFlyer);
                    }
                }
            }
            int startingTile;

            if (!GenWorldClosest.TryFindClosestPassableTile(this.destinationTile, out startingTile))
            {
                startingTile = this.destinationTile;
            }
            Caravan o = CaravanMaker.MakeCaravan(PawnFlyersTraveling.tmpPawns, Faction.OfPlayer, startingTile, true);

            o.AddPawn((Pawn)pawnFlyer, false);
            for (int k = 0; k < this.pods.Count; k++)
            {
                ThingOwner innerContainer2 = this.pods[k].innerContainer;
                for (int l = 0; l < innerContainer2.Count; l++)
                {
                    if (!(innerContainer2[l] is Pawn))
                    {
                        Pawn pawn2 = CaravanInventoryUtility.FindPawnToMoveInventoryTo(innerContainer2[l],
                                                                                       PawnFlyersTraveling.tmpPawns, null, null);
                        pawn2.inventory.innerContainer.TryAdd(innerContainer2[l], true);
                    }
                    else
                    {
                        Pawn pawn3 = innerContainer2[l] as Pawn;
                        if (!pawn3.IsPrisoner)
                        {
                            if (pawn3.Faction != pawnFlyer.Faction)
                            {
                                pawn3.SetFaction(pawnFlyer.Faction);
                            }
                        }
                    }
                }
            }
            this.RemoveAllPods();
            Find.WorldObjects.Remove(this);
            Messages.Message("MessageTransportPodsArrived".Translate(), o, MessageTypeDefOf.PositiveEvent);
        }
Beispiel #14
0
 public SlotLoadable(SlotLoadableDef xmlDef, Thing newOwner)
 {
     //Log.Message("Slot Loaded");
     def = xmlDef;
     slottableThingDefs = xmlDef.slottableThingDefs;
     owner = newOwner;
     ThingIDMaker.GiveIDTo(this);
     slot = new ThingOwner <Thing>(this, false, LookMode.Deep);
 }
Beispiel #15
0
 public ShipHandler(Pawn newShip)
 {
     uniqueID = Find.UniqueIDsManager.GetNextThingID();
     shipPawn = newShip;
     if (handlers is null)
     {
         handlers = new ThingOwner <Pawn>(this, false, LookMode.Reference);
     }
 }
Beispiel #16
0
        public static void TryUpdateInventory(ThingOwner owner)
        {
            Pawn pawn = owner?.Owner?.ParentHolder as Pawn;

            if (pawn != null)
            {
                TryUpdateInventory(pawn);
            }
        }
Beispiel #17
0
 private void AddItemsFromTransferablesToRandomInventories(List <Pawn> pawns)
 {
     transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn);
     if (ListPlayerPawnsInventorySeparately)
     {
         for (int i = 0; i < pawns.Count; i++)
         {
             if (CanListInventorySeparately(pawns[i]))
             {
                 ThingOwner <Thing> innerContainer = pawns[i].inventory.innerContainer;
                 for (int num = innerContainer.Count - 1; num >= 0; num--)
                 {
                     RemoveCarriedItemFromTransferablesOrDrop(innerContainer[num], pawns[i], transferables);
                 }
             }
         }
         for (int j = 0; j < transferables.Count; j++)
         {
             if (transferables[j].things.Any((Thing x) => !x.Spawned))
             {
                 transferables[j].things.SortBy((Thing x) => x.Spawned);
             }
         }
     }
     for (int k = 0; k < transferables.Count; k++)
     {
         if (!(transferables[k].AnyThing is Corpse))
         {
             TransferableUtility.Transfer(transferables[k].things, transferables[k].CountToTransfer, delegate(Thing splitPiece, IThingHolder originalHolder)
             {
                 Thing item2 = splitPiece.TryMakeMinified();
                 CaravanInventoryUtility.FindPawnToMoveInventoryTo(item2, pawns, null).inventory.innerContainer.TryAdd(item2);
             });
         }
     }
     for (int l = 0; l < transferables.Count; l++)
     {
         if (!(transferables[l].AnyThing is Corpse))
         {
             continue;
         }
         TransferableUtility.TransferNoSplit(transferables[l].things, transferables[l].CountToTransfer, delegate(Thing originalThing, int numToTake)
         {
             if (AutoStripSpawnedCorpses)
             {
                 Corpse corpse = originalThing as Corpse;
                 if (corpse != null && corpse.Spawned)
                 {
                     corpse.Strip();
                 }
             }
             Thing item = originalThing.SplitOff(numToTake);
             CaravanInventoryUtility.FindPawnToMoveInventoryTo(item, pawns, null).inventory.innerContainer.TryAdd(item);
         });
     }
 }
Beispiel #18
0
        static bool Prefix(Pawn ___pawn, ThingOwner <Apparel> ___wornApparel, DestroyMode mode)
        {
            DestroyApparelExtension mod = ___pawn.kindDef.GetModExtension <DestroyApparelExtension>() ?? DestroyApparelExtension.defaultValues;

            if (mod.destroyOnlyWeapon)
            {
                return(false);
            }
            return(true);
        }
        public SlotLoadable(Thing newOwner)
        {
            Log.Message("Slot started");
            SlotLoadableDef def = this.def as SlotLoadableDef;

            this.slottableThingDefs = def.slottableThingDefs;
            owner = newOwner;
            ThingIDMaker.GiveIDTo(this);
            slot = new ThingOwner <Thing>(this, false, LookMode.Deep);
        }
Beispiel #20
0
        public void Notify_Installed(Pawn installer, Thing target)
        {
            this.uninstalled = false;

            //Installed on a character
            if (target is Pawn targetPawn)
            {
                if (this.parent.def != null)
                {
                    //Add apparel
                    if (this.parent.def.IsApparel)
                    {
                        if (targetPawn.apparel != null)
                        {
                            this.parent.DeSpawn();
                            targetPawn.apparel.Wear((Apparel)this.parent);
                        }
                    }
                    //Add equipment
                    if (this.parent.def.IsWeapon)
                    {
                        if (targetPawn.equipment != null)
                        {
                            if (targetPawn.equipment.Primary != null)
                            {
                                CompInstalledPart otherPart = targetPawn.equipment.Primary.GetComp <CompInstalledPart>();
                                if (otherPart != null)
                                {
                                    Notify_Uninstalled(installer, targetPawn);
                                }
                            }
                            this.parent.DeSpawn();
                            targetPawn.equipment.MakeRoomFor(this.parent);
                            targetPawn.equipment.AddEquipment(this.parent);
                        }
                    }
                }
            }
            else
            {
                ThingOwner addableSource = target.TryGetInnerInteractableThingOwner();
                if (addableSource != null)
                {
                    this.parent.DeSpawn();
                    addableSource.TryAdd(this.parent);
                }
            }

            Messages.Message("CompInstalledPart_Installed".Translate(new object[]
            {
                installer.LabelShort,
                this.parent.LabelShort,
                target.LabelShort
            }), MessageSound.Benefit);
        }
Beispiel #21
0
        } //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
Beispiel #22
0
        protected override Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator)
        {
            if (pawn.drugs == null)
            {
                return(null);
            }
            Predicate <Thing> predicate = delegate(Thing t)
            {
                if (!CanIngestForJoy(pawn, t))
                {
                    return(false);
                }
                return((extraValidator == null || extraValidator(t)) ? true : false);
            };
            ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;

            for (int i = 0; i < innerContainer.Count; i++)
            {
                if (predicate(innerContainer[i]))
                {
                    return(innerContainer[i]);
                }
            }
            bool flag = false;

            if (pawn.story != null && (pawn.story.traits.DegreeOfTrait(TraitDefOf.DrugDesire) > 0 || pawn.InMentalState))
            {
                flag = true;
            }
            takeableDrugs.Clear();
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int j = 0; j < currentPolicy.Count; j++)
            {
                if (flag || currentPolicy[j].allowedForJoy)
                {
                    takeableDrugs.Add(currentPolicy[j].drug);
                }
            }
            takeableDrugs.Shuffle();
            for (int k = 0; k < takeableDrugs.Count; k++)
            {
                List <Thing> list = pawn.Map.listerThings.ThingsOfDef(takeableDrugs[k]);
                if (list.Count > 0)
                {
                    Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, list, PathEndMode.OnCell, TraverseParms.For(pawn), 9999f, predicate);
                    if (thing != null)
                    {
                        return(thing);
                    }
                }
            }
            return(null);
        }
Beispiel #23
0
        public void Notify_BoardedCaravan(Pawn pawnToBoard, ThingOwner handler)
        {
            if (!pawnToBoard.IsWorldPawn())
            {
                Log.Warning("Tried boarding Caravan with non-worldpawn");
            }

            if (!(pawnToBoard.holdingOwner is null))
            {
                pawnToBoard.holdingOwner.TryTransferToContainer(pawnToBoard, handler);
            }
Beispiel #24
0
        public static void TickTheInteractionWorkers(Caravan __instance)
        {
            // Foreach pawn
            ThingOwner <Pawn> cache = __instance.pawns;

            for (int i = 0; i < cache.Count; i++)
            {
                Pawn target = cache[i];
                //target.interactions.InteractionsTrackerTick();
            }
        }
Beispiel #25
0
        private void MakeIntoContainer(ThingOwner container, ThingDef def, int count)
        {
            if (count <= 0)
            {
                return;
            }
            Thing thing = ThingMaker.MakeThing(def, null);

            thing.stackCount = count;
            container.TryAdd(thing, true);
        }
        // Token: 0x06000016 RID: 22 RVA: 0x000035D8 File Offset: 0x000017D8
        private static void MakeIntoContainer(ThingOwner container, ThingDef def, int count)
        {
            bool flag = def == null || count <= 0;

            if (!flag)
            {
                Thing thing = ThingMaker.MakeThing(def, null);
                thing.stackCount = count;
                container.TryAdd(thing, true);
            }
        }
        private void TryLaunch(GlobalTargetInfo target, PawnsArrivalModeDef arriveMode, bool attackOnArrival)
        {
            Cthulhu.Utility.DebugReport("TryLaunch Called");
            if (!this.parent.Spawned)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's unspawned.");
                return;
            }
            List <CompTransporterPawn> transportersInGroup = this.TransportersInGroup;

            if (transportersInGroup == null)
            {
                Log.Error("Tried to launch " + this.parent + ", but it's not in any group.");
                return;
            }
            if (!this.LoadingInProgressOrReadyToLaunch)
            {
                Cthulhu.Utility.DebugReport("TryLaunch Failed");
                return;
            }
            Map map = this.parent.Map;
            int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, target.Tile);

            if (num > this.MaxLaunchDistance)
            {
                Cthulhu.Utility.DebugReport("TryLaunch Failed #2");
                return;
            }
            this.Transporter.TryRemoveLord(map);
            int groupID = this.Transporter.groupID;

            for (int i = 0; i < transportersInGroup.Count; i++)
            {
                Cthulhu.Utility.DebugReport("Transporter Outspawn Attempt");
                CompTransporterPawn compTransporter = transportersInGroup[i];
                Cthulhu.Utility.DebugReport("Transporter Outspawn " + compTransporter.parent.Label);
                PawnFlyersLeaving pawnFlyerLeaving = (PawnFlyersLeaving)ThingMaker.MakeThing(PawnFlyerDef.leavingDef, null);
                pawnFlyerLeaving.groupID         = groupID;
                pawnFlyerLeaving.pawnFlyer       = this.parent as PawnFlyer;
                pawnFlyerLeaving.destinationTile = target.Tile;
                pawnFlyerLeaving.destinationCell = target.Cell;
                pawnFlyerLeaving.arriveMode      = arriveMode;
                pawnFlyerLeaving.attackOnArrival = attackOnArrival;
                ThingOwner innerContainer = compTransporter.GetDirectlyHeldThings();
                pawnFlyerLeaving.Contents = new ActiveDropPodInfo();
                innerContainer.TryTransferAllToContainer(pawnFlyerLeaving.Contents.innerContainer);
                //pawnFlyerLeaving.Contents.innerContainer. //TryAddMany(innerContainer);
                innerContainer.Clear();
                compTransporter.CleanUpLoadingVars(map);
                compTransporter.parent.DeSpawn();
                pawnFlyerLeaving.Contents.innerContainer.TryAdd(compTransporter.parent);
                GenSpawn.Spawn(pawnFlyerLeaving, compTransporter.parent.Position, map);
            }
        }
Beispiel #28
0
        public override void Initialize(CompProperties props)
        {
            base.Initialize(props);
            Pawn pawn = this.parent as Pawn;

            if (initialize)
            {
                this.innerContainer = new ThingOwner <Thing>();
                this.initialize     = false;
            }
        }
 public static void MakepawnInfos(ThingOwner container)
 {
     foreach (Thing t in container)
     {
         Pawn pawn = t as Pawn;
         if (pawn != null)
         {
             Log.Message(TravelingShipsUtility.PawnInfoString(pawn));
         }
     }
 }
Beispiel #30
0
        private static void TryToReplaceChunk(Thing thing, ThingOwner container)
        {
            if (thing?.def?.defName != "ShipChunk" || !IsRandomSuccess())
            {
                return;
            }

            container.Remove(thing);
            container.TryAdd(ThingMaker.MakeThing(ThingDef.Named("THU_XenoShipChunk")));

            Log.Message("replaced a chunk (" + replacementPercent + "% chance)");
        }