// Token: 0x06003124 RID: 12580 RVA: 0x00170240 File Offset: 0x0016E640
        public static Func <int, int> AAA_GetBuildingResourcesLeaveCalculator(Thing diedThing, DestroyMode mode)
        {
            if (!AAA_GenLeavingAll.AAA_CanBuildingLeaveResources(diedThing, mode))
            {
                return((int count) => 0);
            }
            switch (mode)
            {
            case DestroyMode.Vanish:
                return((int count) => 0);

            case DestroyMode.KillFinalize:
                return((int count) => GenMath.RoundRandom((float)count /* 0.5f*/));

            case DestroyMode.Deconstruct:
                return((int count) => GenMath.RoundRandom((float)count /** diedThing.def.resourcesFractionWhenDeconstructed*/));

            case DestroyMode.FailConstruction:
                return((int count) => GenMath.RoundRandom((float)count /* 0.5f*/));

            case DestroyMode.Cancel:
                return((int count) => GenMath.RoundRandom((float)count * 1f));

            case DestroyMode.Refund:
                return((int count) => count);

            default:
                throw new ArgumentException("Unknown destroy mode " + mode);
            }
        }
        // Token: 0x06003121 RID: 12577 RVA: 0x0016FD48 File Offset: 0x0016E148
        public static void AAA_DoLeavingsFor(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect)
        {
            if ((Current.ProgramState != ProgramState.Playing && mode != DestroyMode.Refund) || mode == DestroyMode.Vanish)
            {
                return;
            }

            ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

            if (mode == DestroyMode.KillFinalize && diedThing.def.killedLeavings != null)
            {
                for (int k = 0; k < diedThing.def.killedLeavings.Count; k++)
                {
                    Thing thing = ThingMaker.MakeThing(diedThing.def.killedLeavings[k].thingDef, null);
                    thing.stackCount = diedThing.def.killedLeavings[k].count;
                    thingOwner.TryAdd(thing, true);
                }
            }
            if (AAA_GenLeavingAll.AAA_CanBuildingLeaveResources(diedThing, mode))
            {
                RimWorld.Frame frame = diedThing as RimWorld.Frame;
                if (frame != null)
                {
                    for (int l = frame.resourceContainer.Count - 1; l >= 0; l--)
                    {
                        int num = AAA_GenLeavingAll.AAA_GetBuildingResourcesLeaveCalculator(diedThing, mode)(frame.resourceContainer[l].stackCount);
                        if (num > 0)
                        {
                            frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[l], thingOwner, num, true);
                        }
                    }
                    frame.resourceContainer.ClearAndDestroyContents(DestroyMode.Vanish);
                }
                else
                {
                    List <ThingDefCountClass> list = diedThing.AAA_CostListAdjusted();

                    for (int m = 0; m < list.Count; m++)
                    {
                        ThingDefCountClass thingCountClass = list[m];
                        int num2 = AAA_GenLeavingAll.AAA_GetBuildingResourcesLeaveCalculator(diedThing, mode)(thingCountClass.count);
                        if (num2 > 0 && mode == DestroyMode.KillFinalize && thingCountClass.thingDef.slagDef != null)
                        {
                            int count = thingCountClass.thingDef.slagDef.smeltProducts.First((ThingDefCountClass pro) => pro.thingDef == RimWorld.ThingDefOf.Steel).count;
                            int num3  = num2 / 2 / 8;
                            for (int n = 0; n < num3; n++)
                            {
                                thingOwner.TryAdd(ThingMaker.MakeThing(thingCountClass.thingDef.slagDef, null), true);
                            }
                            num2 -= num3 * count;
                        }
                        if (num2 > 0)
                        {
                            Thing thing2 = ThingMaker.MakeThing(thingCountClass.thingDef, null);
                            thing2.stackCount = num2;
                            thingOwner.TryAdd(thing2, true);
                        }
                    }
                }
            }
            List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
            int            num4  = 0;

            while (thingOwner.Count > 0)
            {
                if (mode == DestroyMode.KillFinalize && !map.areaManager.Home[list2[num4]])
                {
                    // thingOwner[0].SetForbidden(true, false);
                }
                Thing thing3;
                if (!thingOwner.TryDrop(thingOwner[0], list2[num4], map, ThingPlaceMode.Near, out thing3, null))
                {
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }));
                    return;
                }
                num4++;
                if (num4 >= list2.Count)
                {
                    num4 = 0;
                }
            }
        }