public static void LaunchThingsOfType(ThingDef resDef, int debt, TradeShip trader)
        {
            while (debt > 0)
            {
                Thing thing = null;
                foreach (Building_OrbitalTradeBeacon current in Building_OrbitalTradeBeacon.AllPowered())
                {
                    foreach (IntVec3 current2 in current.TradeableCells)
                    {
                        foreach (Thing current3 in Find.ThingGrid.ThingsAt(current2))
                        {
                            if (current3.def == resDef)
                            {
                                thing = current3;
                                goto IL_C4;
                            }
                        }
                    }
                }
IL_C4:
                if (thing == null)
                {
                    Log.Error("Could not find any " + resDef + " to transfer to trader.");
                    break;
                }
                int   num    = Math.Min(debt, thing.stackCount);
                Thing thing2 = thing.SplitOff(num);
                if (trader != null)
                {
                    trader.AddToStock(thing2);
                }
                debt -= num;
            }
        }
        public override void DoEffect(Pawn user)
        {
            base.DoEffect(user);
            Map map = user.MapHeld;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                Messages.Message("PolarisOrbitalTraderCouldNotArrival".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }
            TraderKindDef traderKindDef = base.parent.TryGetComp <CompOrbitalTraderCaller>().traderKindDef;
            TradeShip     tradeShip     = new TradeShip(traderKindDef);

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
            {
                Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(new object[]
                {
                    tradeShip.name,
                    tradeShip.def.label
                }), LetterDefOf.PositiveEvent, null);
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return;
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return(false);
            }
            TraderKindDef def;

            if ((from x in DefDatabase <TraderKindDef> .AllDefs
                 where x.orbital
                 select x).TryRandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality, out def))
            {
                TradeShip tradeShip = new TradeShip(def);
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                {
                    var text = "TraderArrival".Translate(tradeShip.name, tradeShip.def.label);

                    if (Quote != null)
                    {
                        text += "\n\n";
                        text += Quote;
                    }

                    Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, text, LetterDefOf.PositiveEvent, null);
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
                return(true);
            }
            throw new InvalidOperationException();
        }
Exemple #4
0
            private static bool Prefix(TradeShip __instance, Thing toGive, int countToGive, Pawn playerNegotiator, List <Pawn> ___soldPrisoners)
            {
                if (__instance.Map != null)
                {
                    MapParent_PocketDimension mapParent = __instance.Map.info.parent as MapParent_PocketDimension;
                    if (mapParent != null)
                    {
                        Map containingMap = PocketDimensionUtility.GetHighestContainingMap(__instance.Map);

                        // If there was no containing map found (should mean box is in a caravan; could mean the box was nested inside itself, it which case, oh well, give them their goods anyway :P)
                        if (containingMap == __instance.Map)
                        {
                            Building_PocketDimensionExit exit = PocketDimensionUtility.GetExit(mapParent.dimensionSeed);
                            if (exit != null && exit.SpawnedOrAnyParentSpawned)
                            {
                                Thing thing = toGive.SplitOff(countToGive);
                                thing.PreTraded(TradeAction.PlayerBuys, playerNegotiator, __instance);
                                Pawn pawn = thing as Pawn;
                                if (pawn != null)
                                {
                                    ___soldPrisoners.Remove(pawn);
                                }

                                IntVec3 positionHeld = exit.PositionHeld;
                                Map     mapHeld      = exit.MapHeld;
                                GenPlace.TryPlaceThing(thing, positionHeld, mapHeld, ThingPlaceMode.Near);
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }
        // this is a weird amalgamation between CompDoEffect and IncidentWorker_OrbitalTraderArrival
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);

            Map map = usedBy.Map;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return;
            }

            if (DefDatabase <TraderKindDef> .AllDefs
                .Where(x => x.orbital)
                .TryRandomElementByWeight(traderDef => traderDef.commonality, out TraderKindDef def))
            {
                TradeShip tradeShip = new TradeShip(def);
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                {
                    Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(
                                                       tradeShip.name,
                                                       tradeShip.def.label,
                                                       "TraderArrivalNoFaction".Translate()
                                                       ), LetterDefOf.PositiveEvent, null);
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
        public static void Postfix(TradeShip __instance)
        {
            Thing thing = ThingMaker.MakeThing(BankDefOf.BankNote);

            thing.stackCount = Rand.Range(8, 16);
            ((ThingOwner)AccessTools.Field(typeof(TradeShip), "things").GetValue(__instance)).TryAdd(thing);
        }
        // Token: 0x06003C5E RID: 15454 RVA: 0x0013ED34 File Offset: 0x0013CF34
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                return(false);
            }
            //	Log.Message("TraderKindDefs with RecruiterExt: " + DefDatabase<TraderKindDef>.AllDefs.Where(x=> x.HasModExtension<RecruiterExt>()).Count());
            TraderKindDef traderKindDef;

            if ((from x in DefDatabase <TraderKindDef> .AllDefs.Where(x => x.stockGenerators.Any(y => y is StockGenerator_Recruits))
                 where this.CanSpawn(map, x)
                 select x).TryRandomElement(out traderKindDef))
            {
                TradeShip tradeShip = new TradeShip(traderKindDef, this.GetFaction(traderKindDef));
                if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
                {
                    base.SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid, Array.Empty <NamedArgument>());
                }
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
                return(true);
            }
            throw new InvalidOperationException();
        }
Exemple #8
0
        static void addOptions(Map map, List <FloatMenuOption> opts)
        {
            if (orbitalTraders.Count == 0)
            {
                foreach (var d in DefDatabase <TraderKindDef> .AllDefsListForReading)
                {
                    if (d.orbital)
                    {
                        orbitalTraders.Add(d);
                    }
                }
                orbitalTraders.Sort(delegate(TraderKindDef d1, TraderKindDef d2)
                {
                    return(d1.label.CompareTo(d2.label));
                });
            }

            if (Settings.Cost > 0)
            {
                int found = 0;
                foreach (Thing t in TradeUtility.AllLaunchableThingsForTrade(map))
                {
                    if (t.def == ThingDefOf.Silver)
                    {
                        found += t.stackCount;
                        if (found > Settings.Cost)
                        {
                            break;
                        }
                    }
                }
                if (found < Settings.Cost)
                {
                    opts.Add(new FloatMenuOption("CallTradeShips.NotEnoughSilver".Translate(found, Settings.Cost), null));
                    return;
                }
            }

            foreach (var d in orbitalTraders)
            {
                opts.Add(new FloatMenuOption(getMenuLabel(d), delegate()
                {
                    TradeShip tradeShip = new TradeShip(d);
                    if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && b.GetComp <CompPowerTrader>().PowerOn))
                    {
                        TradeUtility.LaunchSilver(map, Settings.Cost);
                        Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(
                                                           tradeShip.name,
                                                           tradeShip.def.label,
                                                           "TraderArrivalNoFaction".Translate()
                                                           ), LetterDefOf.PositiveEvent, null);
                    }
                    map.passingShipManager.AddShip(tradeShip);
                    tradeShip.GenerateThings();
                }, MenuOptionPriority.Low));
            }
        }
 public static void Postfix(TradeShip __instance, Thing toGive, int countToGive, Pawn playerNegotiator)
 {
     if (__instance.def.HasModExtension <RecruiterExt>())
     {
         Pawn pawn = toGive as Pawn;
         if (pawn != null)
         {
             pawn.SetFaction(playerNegotiator.Faction, playerNegotiator);
         }
     }
 }
Exemple #10
0
 public static bool PassingShipTick(TradeShip __instance)
 {
     --__instance.ticksUntilDeparture;
     if (__instance.Departed)
     {
         __instance.Depart();
     }
     RimThreaded.TradeShipThings = things(__instance);
     RimThreaded.TradeShipTicks  = things(__instance).Count;
     return(false);
 }
Exemple #11
0
 public static void GenerateShip(Def shipDef, Map map, TradeShip tradeShip, Faction fac, Lord lord, out Building core)
 {
     core = null;
     if (inaccessible || methodGenerateShip == null)
     {
         return;
     }
     //core = (Building)
     methodGenerateShip.Invoke(null, new object[] {
         shipDef, map, tradeShip, fac, lord, null
     });
 }
        public static bool PassingShipTick(TradeShip __instance)
        {
            --__instance.ticksUntilDeparture;
            if (__instance.Departed)
            {
                __instance.Depart();
            }
            int        index       = Interlocked.Increment(ref totalTradeShipsCount) - 1;
            ThingOwner thingsOwner = __instance.things;

            tradeShips[index].TradeShipThings = thingsOwner;
            Interlocked.Add(ref totalTradeShipTicks, thingsOwner.Count);
            tradeShips[index].TradeShipTicks = totalTradeShipTicks;
            return(false);
        }
        public static void SummonTradeShip()
        {
            Map map = Find.CurrentMap;

            if (map == null)
            {
                return;
            }
            if (DefDatabase <TraderKindDef> .AllDefs.Where((TraderKindDef x) => CanSpawn(map, x)).TryRandomElementByWeight((TraderKindDef traderDef) => traderDef.CalculatedCommonality, out var result))
            {
                TradeShip tradeShip = new TradeShip(result, GetFaction(result));
                Messages.Message(new Message("Debug: Trade ship arrived: " + tradeShip.def.LabelCap, MessageTypeDefOf.PositiveEvent));
                //SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid);
                map.passingShipManager.AddShip(tradeShip);
                tradeShip.GenerateThings();
            }
        }
Exemple #14
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            var map = (Map)parms.target;

            if (map.passingShipManager.passingShips.Count >= MaxShips)
            {
                return(false);
            }

            var tradeShip = new TradeShip(RSDefOf.RSSRSTradeShip);

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
            {
                base.SendStandardLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, parms, LookTargets.Invalid, Array.Empty <NamedArgument>());
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return(true);
        }
Exemple #15
0
    /// <summary>
    /// Assigns the specified ship to this trade route.
    /// </summary>

    public void AssignShip(AvailableShips.Owned ship)
    {
        if (ship.tradeRoute != this)
        {
            if (ship.tradeRoute != null)
            {
                ship.tradeRoute.UnassignShip(ship);
            }
            ship.tradeRoute = this;
            ships.Add(ship);

            if (ship.prefab != null)
            {
                Vector3    start = mOriginal.Sample(0f, SplineV.SampleType.Linear);
                Vector3    next  = mOriginal.Sample(1f, SplineV.SampleType.Linear);
                GameObject go    = Instantiate(ship.prefab.prefab, start, Quaternion.LookRotation(next - start)) as GameObject;

                if (go != null)
                {
                    // Replace the possible multiple colliders with a single one residing at root
                    Collider[] cols = go.GetComponentsInChildren <Collider>();

                    if (cols.Length > 1)
                    {
                        foreach (Collider col in cols)
                        {
                            Destroy(col);
                        }
                        go.AddComponent <BoxCollider>();
                    }

                    ship.asset = go;
                    go.AddComponent <Highlightable>();
                    TradeShip script = go.AddComponent <TradeShip>();
                    script.tradeRoute = this;
                    script.prefab     = ship.prefab;
                    script.speed      = ship.prefab.speed;
                }
            }
        }
    }
        public override void DoEffect(Pawn user)
        {
            base.DoEffect(user);
            Map map = user.MapHeld;

            if (map.passingShipManager.passingShips.Count >= 5)
            {
                Messages.Message("PolarisOrbitalTraderCouldNotArrival".Translate(), MessageTypeDefOf.NegativeEvent);
                return;
            }
            TraderKindDef traderKindDef = base.parent.TryGetComp <CompOrbitalTraderCaller>().traderKindDef;
            TradeShip     tradeShip     = new TradeShip(traderKindDef, this.GetFaction(traderKindDef));

            if (map.listerBuildings.allBuildingsColonist.Any((Building b) => b.def.IsCommsConsole && (b.GetComp <CompPowerTrader>() == null || b.GetComp <CompPowerTrader>().PowerOn)))
            {
                //Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label), LetterDefOf.PositiveEvent, null);
                //Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, "TraderArrivalNoFaction".Translate()), LetterDefOf.PositiveEvent, null);
                Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, (tradeShip.Faction == null) ? "TraderArrivalNoFaction".Translate() : "TraderArrivalFromFaction".Translate(tradeShip.Faction.Named("FACTION"))), LetterDefOf.PositiveEvent, null);
            }
            map.passingShipManager.AddShip(tradeShip);
            tradeShip.GenerateThings();
            return;
        }
 static void Postfix(TradeShip __instance, ref IEnumerable <Thing> __result)
 {
     if (__instance.Map.listerBuildings.allBuildingsColonist.Any(b => b.def.HasComp(typeof(Comp_EnhancedBeacon))))
     {
         List <Thing> things     = new List <Thing>();
         List <Zone>  tradeZones = __instance.Map.zoneManager.AllZones.Where(z => z is Zone_Stockpile).ToList();
         //IEnumerable<Thing> enumerable = from thing in __instance.Map.listerThings.AllThings
         //                                where thing.def.category == ThingCategory.Item
         //                                && TradeUtility.PlayerSellableNow(thing)
         //                                && !thing.Position.Fogged(thing.Map)
         //                                && (thing.Map.areaManager.Home[thing.Position] || thing.IsInAnyStorage())
         //                                select thing;
         //foreach (Thing thing in enumerable)
         //{
         //    things.Add(thing);
         //}
         foreach (Zone zone in tradeZones)
         {
             things.AddRange(zone.AllContainedThings);
         }
         __result = things.AsEnumerable <Thing>();
     }
 }
Exemple #18
0
        private List <Thing> GenThingList(out string tradeShipKind)
        {
            //Thing tmp;
            //int i;
            tradeShipKind = string.Empty;
            List <Thing> list = new List <Thing>();

            if ((from x in DefDatabase <TraderKindDef> .AllDefs
                 where x.orbital
                 select x).TryRandomElement(out TraderKindDef def))
            {
                TradeShip tradeShip = new TradeShip(def);
                tradeShipKind = def.LabelCap;
                ThingSetMakerParams Trader = default(ThingSetMakerParams);
                Trader.traderDef = tradeShip.def;
                list             = ThingSetMakerDefOf.TraderStock.root.Generate(Trader);
                List <Thing> tempList = new List <Thing>();
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    bool flag = true;
                    if (list[i] is Pawn pawn)
                    {
                        if (Rand.Chance(0.6f))
                        {
                            list.Remove(list[i]);
                            flag = false;
                        }
                        else
                        {
                            HealthUtility.DamageUntilDowned(pawn);
                        }
                    }
                    else
                    {
                        if (list[i].stackCount == 1)
                        {
                            if (Rand.Chance(0.6f))
                            {
                                list.Remove(list[i]);
                                //list[i].Destroy();
                                flag = false;
                            }
                        }
                        else
                        {
                            list[i].stackCount = Mathf.RoundToInt(list[i].stackCount * 0.3f);
                            if (list[i].stackCount < 1)
                            {
                                list.Remove(list[i]);
                                //list[i].Destroy();
                                flag = false;
                            }
                        }
                    }
                    if (flag)
                    {
                        for (int j = list[i].stackCount; j > list[i].def.stackLimit; j -= list[i].def.stackLimit)
                        {
                            list[i].stackCount -= list[i].def.stackLimit;
                            Thing tempThing = ThingMaker.MakeThing(list[i].def);
                            tempThing.stackCount = list[i].def.stackLimit;
                            if (tempThing is MinifiedThing && (tempThing as MinifiedThing).InnerThing == null)
                            {
                                continue;
                            }
                            tempList.Add(tempThing);
                        }
                    }
                }

                /*foreach (Thing thing in list)
                 * {
                 *  if (thing is Pawn pawn)
                 *      HealthUtility.DamageUntilDowned(pawn);
                 *  else
                 *  {
                 *      thing.stackCount = Mathf.FloorToInt(thing.stackCount * 0.3f);
                 *      if (thing.stackCount <= 0)
                 *          thing.Destroy();
                 *  }
                 *  for (int i = thing.stackCount; i > thing.def.stackLimit; i -= thing.def.stackLimit)
                 *  {
                 *      thing.stackCount -= thing.def.stackLimit;
                 *      Thing tempThing = ThingMaker.MakeThing(thing.def);
                 *      tempThing.stackCount = thing.def.stackLimit;
                 *      if (tempThing is MinifiedThing && (tempThing as MinifiedThing).InnerThing == null) continue;
                 *      tempList.Add(tempThing);
                 *
                 *  }
                 * }*/
                list.AddRange(tempList);
            }
            return(list);
        }
 public static bool LaunchThingsOfTypePrefix(ThingDef resDef, int debt, Map map, TradeShip trader)
 {
     return(false);
 }
            public static void LaunchThingsOfTypePostfix(ThingDef resDef, int debt, Map map, TradeShip trader)
            {
                while (debt > 0)
                {
                    Thing thing = null;
                    foreach (IntVec3 current2 in AllTradeableCells(map))
                    {
                        foreach (Thing current3 in map.thingGrid.ThingsAt(current2))
                        {
                            if (current3.def == resDef)
                            {
                                thing = current3;
                                goto IL_CC;
                            }
                        }
                    }
IL_CC:
                    if (thing == null)
                    {
                        Log.Error("[OrbitalTradeHook] Could not find any " + resDef + " to transfer to trader.", false);
                        break;
                    }
                    int num = Math.Min(debt, thing.stackCount);
                    if (trader != null)
                    {
                        trader.GiveSoldThingToTrader(thing, num, TradeSession.playerNegotiator);
                    }
                    else
                    {
                        thing.SplitOff(num).Destroy(DestroyMode.Vanish);
                    }
                    debt -= num;
                }
            }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    var job = this.job as Job_CallTradeShip;
                    if (job == null)
                    {
                        Log.Error("CallTradeShips: Job is not of type Job_CallTradeShip.");
                        return;
                    }

                    ThingWithComps twc = job.targetA.Thing as ThingWithComps;
                    if (twc?.def?.IsCommsConsole == false)
                    {
                        Log.Error("CallTradeShips: Target is not a CommsConsole");
                        return;
                    }

                    if (!Util.HasEnoughSilver(twc.Map, out int found))
                    {
                        Log.Warning("Not enough silver");
                        return;
                    }
                    TradeUtility.LaunchSilver(twc.Map, Settings.Cost);

                    if (job.TraderKind == TraderKindEnum.Orbital)
                    {
                        if (twc.GetComp <CompPowerTrader>()?.PowerOn == true)
                        {
                            TradeShip tradeShip = new TradeShip(job.TraderKindDef);
                            twc.Map.passingShipManager.AddShip(tradeShip);
                            tradeShip.GenerateThings();
                            Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap, "TraderArrival".Translate(tradeShip.name, tradeShip.def.label, "TraderArrivalNoFaction".Translate()), LetterDefOf.PositiveEvent, null);
                        }
                    }
                    else if (job.TraderKind == TraderKindEnum.Lander)
                    {
                        foreach (var id in DefDatabase <IncidentDef> .AllDefsListForReading)
                        {
                            if (id.Worker is IncidentWorker_OrbitalTraderArrival)
                            {
                                if (id.Worker.TryExecute(new IncidentParms()
                                {
                                    target = twc.Map
                                }))
                                {
                                    return;
                                }
                                break;
                            }
                        }
                        Log.Error("CallTradShips failed to create trade ship from mod TraderShips");
                        return;
                    }
                    else
                    {
                        Log.Error("CallTradeShips: Unknown TraderKindEnum: " + job.TraderKind);
                        return;
                    }
                }
            });
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if ((from x in DefDatabase <TraderKindDef> .AllDefs
                 where x.orbital
                 select x).TryRandomElement(out TraderKindDef def))
            {
                TradeShip           tradeShip = new TradeShip(def);
                List <Thing>        list      = new List <Thing>();
                ThingSetMakerParams Trader    = default(ThingSetMakerParams);
                Trader.traderDef = tradeShip.def;
                Trader.tile      = map.Tile;
                list             = ThingSetMakerDefOf.TraderStock.root.Generate(Trader);
                List <Thing> tempList = new List <Thing>();
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    bool flag = true;
                    if (list[i] is Pawn pawn)
                    {
                        if (Rand.Chance(0.6f))
                        {
                            list.Remove(list[i]);
                            flag = false;
                        }
                        else
                        {
                            HealthUtility.DamageUntilDowned(pawn);
                        }
                    }
                    else
                    {
                        if (list[i].stackCount == 1)
                        {
                            if (Rand.Chance(0.6f))
                            {
                                list.Remove(list[i]);
                                //list[i].Destroy();
                                flag = false;
                            }
                        }
                        else
                        {
                            list[i].stackCount = Mathf.RoundToInt(list[i].stackCount * 0.3f);
                            if (list[i].stackCount < 1)
                            {
                                list.Remove(list[i]);
                                //list[i].Destroy();
                                flag = false;
                            }
                        }
                    }
                    if (flag)
                    {
                        for (int j = list[i].stackCount; j > list[i].def.stackLimit; j -= list[i].def.stackLimit)
                        {
                            list[i].stackCount -= list[i].def.stackLimit;
                            Thing tempThing = ThingMaker.MakeThing(list[i].def);
                            tempThing.stackCount = list[i].def.stackLimit;
                            if (tempThing is MinifiedThing && (tempThing as MinifiedThing).InnerThing == null)
                            {
                                continue;
                            }
                            tempList.Add(tempThing);
                        }
                    }
                }

                /*foreach (Thing thing in list)
                 * {
                 *  if (thing is Pawn pawn)
                 *      HealthUtility.DamageUntilDowned(pawn);
                 *  for (int i = thing.stackCount; i > thing.def.stackLimit; i -= thing.def.stackLimit)
                 *  {
                 *      thing.stackCount -= thing.def.stackLimit;
                 *      Thing tempThing = ThingMaker.MakeThing(thing.def);
                 *      tempThing.stackCount = thing.def.stackLimit;
                 *      if (tempThing is MinifiedThing && (tempThing as MinifiedThing).InnerThing == null) continue;
                 *      tempList.Add(tempThing);
                 *
                 *  }
                 * }*/
                list.AddRange(tempList);

                IntVec3 intVec = DropCellFinder.RandomDropSpot(map);
                DropPodUtility.DropThingsNear(intVec, map, list, 110, false, true, true);
                Find.LetterStack.ReceiveLetter(tradeShip.def.LabelCap + " " + "PolarisTitleTradeShipPodCrash".Translate(), "PolarisTradeShipPodCrash".Translate(new object[]
                {
                    tradeShip.name,
                    tradeShip.def.label
                }), LetterDefOf.PositiveEvent, new TargetInfo(intVec, map, false), null);
                return(true);
            }
            throw new InvalidOperationException();
        }