示例#1
0
        public static void DeconstructDropStuff(Thing oldThing)
        {
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }

            ThingDef oldDef   = oldThing.def;
            ThingDef stuffDef = oldThing.Stuff;

            //preferably GenLeaving.DoLeavingsFor here, but don't want to drop non-stuff things.
            if (GenLeaving.CanBuildingLeaveResources(oldThing, DestroyMode.Deconstruct))
            {
                int count      = TotalStuffNeeded(oldDef, stuffDef);
                int leaveCount = GetBuildingResourcesLeaveCalculator(oldThing, DestroyMode.Deconstruct)(count);
                if (leaveCount > 0)
                {
                    Thing leftThing = ThingMaker.MakeThing(stuffDef);
                    leftThing.stackCount = leaveCount;
#pragma warning disable CS0618 // Type or member is obsolete
                    GenDrop.TryDropSpawn(leftThing, oldThing.Position, oldThing.Map, ThingPlaceMode.Near, out Thing dummyThing);
#pragma warning restore CS0618 // Type or member is obsolete
                }
            }
        }
示例#2
0
        //public static System.Reflection.MethodInfo removeRes = typeof(Thing).GetMethod("RemoveAllReservationsAndDesignationsOnThis", BindingFlags.Instance | BindingFlags.NonPublic);
        //public static System.Reflection.MethodInfo notifyMethod = typeof(RegionDirtyer).GetMethod("Notify_ThingAffectingRegionsDespawned", BindingFlags.Instance | BindingFlags.NonPublic);

        public static bool TakeDamage(Thing __instance, ref DamageWorker.DamageResult __result, DamageInfo dinfo)
        {
            if (__instance.Destroyed)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            if ((double)dinfo.Amount == 0.0)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            if (__instance.def.damageMultipliers != null)
            {
                for (int index = 0; index < __instance.def.damageMultipliers.Count; ++index)
                {
                    if (__instance.def.damageMultipliers[index].damageDef == dinfo.Def)
                    {
                        int num = UnityEngine.Mathf.RoundToInt(dinfo.Amount * __instance.def.damageMultipliers[index].multiplier);
                        dinfo.SetAmount((float)num);
                    }
                }
            }
            //__result = new DamageWorker.DamageResult();
            //if (__instance is Plant)
            if (true)
            {
                bool absorbed;
                __instance.PreApplyDamage(ref dinfo, out absorbed);

                if (absorbed)
                {
                    __result = new DamageWorker.DamageResult();
                    return(false);
                }

                bool anyParentSpawned = __instance.SpawnedOrAnyParentSpawned;
                Map  mapHeld          = __instance.MapHeld;

                DamageWorker.DamageResult damageResult = Apply(dinfo, __instance);
                if (dinfo.Def.harmsHealth & anyParentSpawned)
                {
                    mapHeld.damageWatcher.Notify_DamageTaken(__instance, damageResult.totalDamageDealt);
                }
                if (dinfo.Def.ExternalViolenceFor(__instance))
                {
                    GenLeaving.DropFilthDueToDamage(__instance, damageResult.totalDamageDealt);
                    if (dinfo.Instigator != null && dinfo.Instigator is Pawn instigator)
                    {
                        instigator.records.AddTo(RecordDefOf.DamageDealt, damageResult.totalDamageDealt);
                        instigator.records.AccumulateStoryEvent(StoryEventDefOf.DamageDealt);
                    }
                }

                __instance.PostApplyDamage(dinfo, damageResult.totalDamageDealt);
                __result = damageResult;
            }

            return(false);
        }
        public static void PostFix(ref Func <int, int> __result, Thing destroyedThing, ref DestroyMode mode)
        {
            if (destroyedThing.def.defName != "MSRecoveryPod" || mode != DestroyMode.Deconstruct ||
                !(destroyedThing.def.resourcesFractionWhenDeconstructed >= 1f))
            {
                return;
            }

            if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
            {
                __result = _ => 0;
                return;
            }

            if (mode == DestroyMode.Deconstruct && destroyedThing is Frame)
            {
                mode = DestroyMode.Cancel;
                return;
            }

            if (mode == DestroyMode.Deconstruct)
            {
                __result = count => count;
            }
        }
示例#4
0
            // Token: 0x06000003 RID: 3 RVA: 0x00002290 File Offset: 0x00000490
            public static Func <int, int> GBRLC(Thing t, DestroyMode d)
            {
                bool flag = !GenLeaving.CanBuildingLeaveResources(t, d);

                if (!flag)
                {
                    switch (d)
                    {
                    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(Mathf.Min((float)count * t.def.resourcesFractionWhenDeconstructed, (float)count)));

                    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);
                    }
                    throw new ArgumentException("Unknown destroy mode " + d + " (Deconstruct Return Fix error)");
                }
                return((int count) => 0);
            }
示例#5
0
            }//end DoLeavingsForPrefix

            public static Func <int, int> GBRLC(Thing t)
            {
                if (!GenLeaving.CanBuildingLeaveResources(t, DestroyMode.Deconstruct))
                {
                    return((int count) => 0);
                }
                return((int count) => GenMath.RoundRandom(Mathf.Min((float)count * t.def.resourcesFractionWhenDeconstructed, (float)(count)))); //other destroy modes deleted because I always know the mode
            }
示例#6
0
        public static void ThingDestroy(Thing __instance, DestroyMode mode = DestroyMode.Vanish)
        {
            if (!Thing.allowDestroyNonDestroyable && !__instance.def.destroyable)
            {
                Log.Error("Tried to destroy non-destroyable thing " + __instance);
                return;
            }

            if (__instance.Destroyed)
            {
                Log.Error("Tried to destroy already-destroyed thing " + __instance);
                return;
            }

            bool spawned = __instance.Spawned;
            Map  map     = __instance.Map;

            if (__instance.Spawned)
            {
                __instance.DeSpawn(mode);
            }

            mapIndexOrState(__instance) = -2;
            if (__instance.def.DiscardOnDestroyed)
            {
                __instance.Discard();
            }

            CompExplosive compExplosive = __instance.TryGetComp <CompExplosive>();

            if (spawned)
            {
                List <Thing> list = (compExplosive != null) ? new List <Thing>() : null;
                GenLeaving.DoLeavingsFor(__instance, map, mode, list);
                compExplosive?.AddThingsIgnoredByExplosion(list);
            }

            if (__instance.holdingOwner != null)
            {
                __instance.holdingOwner.Notify_ContainedItemDestroyed(__instance);
            }

            RemoveAllReservationsAndDesignationsOnThis(__instance);
            if (!(__instance is Pawn))
            {
                __instance.stackCount = 0;
            }

            if (mode != DestroyMode.QuestLogic)
            {
                QuestUtility.SendQuestTargetSignals(__instance.questTags, "Destroyed", __instance.Named("SUBJECT"));
            }

            if (mode == DestroyMode.KillFinalize)
            {
                QuestUtility.SendQuestTargetSignals(__instance.questTags, "Killed", __instance.Named("SUBJECT"));
            }
        }
示例#7
0
            public static bool Prefix(TerrainGrid __instance, IntVec3 c, bool doLeavings, Map ___map, ref TerrainDef[] ___underGrid)
            {
                try
                {
                    var ZTracker = ZUtils.ZTracker;
                    if (ZTracker.GetZIndexFor(___map) > 0)
                    {
                        int num = ___map.cellIndices.CellToIndex(c);
                        if (doLeavings)
                        {
                            GenLeaving.DoLeavingsFor(__instance.topGrid[num], c, ___map);
                        }
                        if (___underGrid[num] != null)
                        {
                            __instance.topGrid[num] = ___underGrid[num];
                            ___underGrid[num]       = null;
                            Traverse.Create(__instance).Method("DoTerrainChangedEffects", new object[]
                            {
                                c
                            }).GetValue();
                        }
                        if (c.GetTerrain(___map) == TerrainDefOf.Sand)
                        {
                            __instance.SetTerrain(c, ZLevelsDefOf.ZL_OutsideTerrain);
                        }

                        Map  lowerMap  = ZTracker.GetLowerLevel(___map.Tile, ___map);
                        bool firstTime = false;
                        if (lowerMap == null)
                        {
                            return(false);

                            //lowerMap = ZTracker.CreateLowerLevel(___map, c);
                            firstTime = true;
                        }

                        var thingList = c.GetThingList(___map);
                        if (thingList.Where(x => x is Blueprint || x is Frame).Count() == 0)
                        {
                            for (int i = thingList.Count - 1; i >= 0; i--)
                            {
                                if (!(thingList[i] is Mineable || thingList[i] is Blueprint || thingList[i] is Frame))
                                {
                                    //Log.Message(thingList[i] + " going down 1");
                                    ZTracker.SimpleTeleportThing(thingList[i], c, lowerMap, firstTime, 10);
                                }
                            }
                        }
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("[Z-Levels] DestroyedTerrain patch produced an error. That should not happen and will break things. Send a Hugslib log to the Z-Levels developers. Error message: " + ex, true);
                }
                return(true);
            }
示例#8
0
        private static Func <int, int> GetBuildingResourcesLeaveCalculator(Thing destroyedThing, DestroyMode mode)
        {
            if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
            {
                return(_ => 0);
            }

            if (mode == DestroyMode.Deconstruct && destroyedThing is Frame)
            {
                mode = DestroyMode.Cancel;
            }

            switch (mode)
            {
            case DestroyMode.Vanish:
            {
                return(_ => 0);
            }

            case DestroyMode.WillReplace:
            {
                return(_ => 0);
            }

            case DestroyMode.KillFinalize:
            {
                return(count => GenMath.RoundRandom(count * 0.5f));
            }

            case DestroyMode.Deconstruct:
            {
                return(count =>
                       GenMath.RoundRandom(Math.Min(count * destroyedThing.def.resourcesFractionWhenDeconstructed,
                                                    count - 1)));
            }

            case DestroyMode.FailConstruction:
            {
                return(count => GenMath.RoundRandom(count * 0.5f));
            }

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

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

            throw new ArgumentException(string.Concat("Unknown destroy mode ", mode));
        }
示例#9
0
        public static void DamagePart(Pawn p, int damage, BodyPartRecord part)
        {
            HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(DamageDefOf.SurgicalCut, p, part);

            Hediff_Injury injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, p, part);

            injury.Severity = damage;

            p.health.AddHediff(injury, part, new DamageInfo(DamageDefOf.SurgicalCut, damage, 999f, -1f, null, part));
            GenLeaving.DropFilthDueToDamage(p, damage);
        }
示例#10
0
        public static void SpawnBuildingAsPossible(Building building, Map map, bool respawningAfterLoad = false)
        {
            bool flag = false;

            foreach (IntVec3 item in building.OccupiedRect())
            {
                List <Thing> thingList = item.GetThingList(map);
                int          num       = 0;
                while (num < thingList.Count)
                {
                    if (!(thingList[num] is Pawn) || building.def.passability != Traversability.Impassable)
                    {
                        if ((thingList[num].def.category == ThingCategory.Building || thingList[num].def.category == ThingCategory.Item) && GenSpawn.SpawningWipes(building.def, thingList[num].def))
                        {
                            flag = true;
                            break;
                        }
                        num++;
                        continue;
                    }
                    flag = true;
                    break;
                }
                if (flag)
                {
                    break;
                }
            }
            if (flag)
            {
                bool flag2 = false;
                if (building.def.Minifiable)
                {
                    MinifiedThing minifiedThing = building.MakeMinified();
                    if (GenPlace.TryPlaceThing(minifiedThing, building.Position, map, ThingPlaceMode.Near, null))
                    {
                        flag2 = true;
                    }
                    else
                    {
                        minifiedThing.GetDirectlyHeldThings().Clear();
                        minifiedThing.Destroy(DestroyMode.Vanish);
                    }
                }
                if (!flag2)
                {
                    GenLeaving.DoLeavingsFor(building, map, DestroyMode.Refund, building.OccupiedRect());
                }
            }
            else
            {
                GenSpawn.Spawn(building, building.Position, map, building.Rotation, respawningAfterLoad);
            }
        }
示例#11
0
        public DamageWorker.DamageResult TakeDamage(DamageInfo dinfo)
        {
            if (this.Destroyed)
            {
                return(DamageWorker.DamageResult.MakeNew());
            }
            if (dinfo.Amount == 0)
            {
                return(DamageWorker.DamageResult.MakeNew());
            }
            if (this.def.damageMultipliers != null)
            {
                for (int i = 0; i < this.def.damageMultipliers.Count; i++)
                {
                    if (this.def.damageMultipliers[i].damageDef == dinfo.Def)
                    {
                        int amount = Mathf.RoundToInt((float)dinfo.Amount * this.def.damageMultipliers[i].multiplier);
                        dinfo.SetAmount(amount);
                    }
                }
            }
            bool flag = default(bool);

            this.PreApplyDamage(dinfo, out flag);
            if (flag)
            {
                return(DamageWorker.DamageResult.MakeNew());
            }
            bool spawnedOrAnyParentSpawned = this.SpawnedOrAnyParentSpawned;
            Map  mapHeld = this.MapHeld;

            DamageWorker.DamageResult result = dinfo.Def.Worker.Apply(dinfo, this);
            if (dinfo.Def.harmsHealth && spawnedOrAnyParentSpawned)
            {
                mapHeld.damageWatcher.Notify_DamageTaken(this, result.totalDamageDealt);
            }
            if (dinfo.Def.externalViolence)
            {
                GenLeaving.DropFilthDueToDamage(this, result.totalDamageDealt);
                if (dinfo.Instigator != null)
                {
                    Pawn pawn = dinfo.Instigator as Pawn;
                    if (pawn != null)
                    {
                        pawn.records.AddTo(RecordDefOf.DamageDealt, result.totalDamageDealt);
                        pawn.records.AccumulateStoryEvent(StoryEventDefOf.DamageDealt);
                    }
                }
            }
            this.PostApplyDamage(dinfo, result.totalDamageDealt);
            return(result);
        }
示例#12
0
        public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            if (!allowDestroyNonDestroyable && !def.destroyable)
            {
                Log.Error("Tried to destroy non-destroyable thing " + this);
                return;
            }
            if (Destroyed)
            {
                Log.Error("Tried to destroy already-destroyed thing " + this);
                return;
            }
            bool spawned = Spawned;
            Map  map     = Map;

            if (Spawned)
            {
                DeSpawn(mode);
            }
            mapIndexOrState = -2;
            if (def.DiscardOnDestroyed)
            {
                Discard();
            }
            CompExplosive compExplosive = this.TryGetComp <CompExplosive>();

            if (spawned)
            {
                List <Thing> list = ((compExplosive != null) ? new List <Thing>() : null);
                GenLeaving.DoLeavingsFor(this, map, mode, list);
                compExplosive?.AddThingsIgnoredByExplosion(list);
            }
            if (holdingOwner != null)
            {
                holdingOwner.Notify_ContainedItemDestroyed(this);
            }
            RemoveAllReservationsAndDesignationsOnThis();
            if (!(this is Pawn))
            {
                stackCount = 0;
            }
            if (mode != DestroyMode.QuestLogic)
            {
                QuestUtility.SendQuestTargetSignals(questTags, "Destroyed", this.Named("SUBJECT"));
            }
            if (mode == DestroyMode.KillFinalize)
            {
                QuestUtility.SendQuestTargetSignals(questTags, "Killed", this.Named("SUBJECT"));
            }
        }
示例#13
0
        public DamageWorker.DamageResult TakeDamage(DamageInfo dinfo)
        {
            if (Destroyed)
            {
                return(new DamageWorker.DamageResult());
            }
            if (dinfo.Amount == 0f)
            {
                return(new DamageWorker.DamageResult());
            }
            if (def.damageMultipliers != null)
            {
                for (int i = 0; i < def.damageMultipliers.Count; i++)
                {
                    if (def.damageMultipliers[i].damageDef == dinfo.Def)
                    {
                        int num = Mathf.RoundToInt(dinfo.Amount * def.damageMultipliers[i].multiplier);
                        dinfo.SetAmount(num);
                    }
                }
            }
            PreApplyDamage(ref dinfo, out var absorbed);
            if (absorbed)
            {
                return(new DamageWorker.DamageResult());
            }
            bool spawnedOrAnyParentSpawned = SpawnedOrAnyParentSpawned;
            Map  mapHeld = MapHeld;

            DamageWorker.DamageResult damageResult = dinfo.Def.Worker.Apply(dinfo, this);
            if (dinfo.Def.harmsHealth && spawnedOrAnyParentSpawned)
            {
                mapHeld.damageWatcher.Notify_DamageTaken(this, damageResult.totalDamageDealt);
            }
            if (dinfo.Def.ExternalViolenceFor(this))
            {
                GenLeaving.DropFilthDueToDamage(this, damageResult.totalDamageDealt);
                if (dinfo.Instigator != null)
                {
                    Pawn pawn = dinfo.Instigator as Pawn;
                    if (pawn != null)
                    {
                        pawn.records.AddTo(RecordDefOf.DamageDealt, damageResult.totalDamageDealt);
                        pawn.records.AccumulateStoryEvent(StoryEventDefOf.DamageDealt);
                    }
                }
            }
            PostApplyDamage(dinfo, damageResult.totalDamageDealt);
            return(damageResult);
        }
        public static void ChangeStuff(this Thing thing, ThingDef stuff)
        {
            thing.SetStuffDirect(stuff);
            thing.HitPoints = thing.MaxHitPoints;             //Deconstruction/construction implicitly repairs
            if (thing is Frame frame)
            {
                GenLeaving.DoLeavingsFor(thing, thing.Map, DestroyMode.Cancel);
                frame.workDone = 0;
            }

            thing.Notify_ColorChanged();

            thing.Map.reservationManager.ReleaseAllForTarget(thing);
        }
        public override void Generate(Map map, GenStepParams parms)
        {
            var decay         = this.decay.RandomInRange;
            var corpseChance  = this.corpseChance.RandomInRange;
            var maxItemValue  = this.maxItemValue.RandomInRange;
            var _currentThing = (Thing)null;

            foreach (var pos in map.cellsInRandomOrder.GetAll())
            {
                try {
                    var things = pos.GetThingList(map);
                    for (var i = things.Count - 1; i >= 0; i--)
                    {
                        var thing = things[i];
                        _currentThing = thing;
                        if ((thing.MarketValue > maxItemValue || ShouldDestroy(thing, decay)) && !thing.Destroyed)
                        {
                            if (thing is Pawn pawn && !pawn.Faction.IsPlayer && Rand.Chance(corpseChance))
                            {
                                pawn.equipment.DestroyAllEquipment();
                                foreach (var apparel in pawn.apparel.WornApparel)
                                {
                                    if (apparel.MarketValue > maxItemValue * 2)
                                    {
                                        pawn.apparel.Remove(apparel);
                                    }
                                }
                                pawn.Kill(null);
                                pawn.Corpse.timeOfDeath -= Rand.RangeInclusive(10, 500) * 1000;
                            }
                            else
                            {
                                thing.Destroy();
                            }
                            GenLeaving.DropFilthDueToDamage(thing, thing.MaxHitPoints);
                        }
                        else
                        {
                            if (thing is Building_Bed bed)
                            {
                                bed.SetFactionDirect(null);
                            }
                            if (Rand.Chance(decay * decay))
                            {
                                thing.HitPoints = (int)(thing.MaxHitPoints * (1 - Rand.Value * decay));
                            }
                        }
                    }
                }
示例#16
0
        public void RemoveTopLayer(IntVec3 c, bool doLeavings = true)
        {
            int num = this.map.cellIndices.CellToIndex(c);

            if (doLeavings)
            {
                GenLeaving.DoLeavingsFor(this.topGrid[num], c, this.map);
            }
            if (this.underGrid[num] != null)
            {
                this.topGrid[num]   = this.underGrid[num];
                this.underGrid[num] = null;
                this.DoTerrainChangedEffects(c);
            }
        }
示例#17
0
        public void RemoveTopLayer(IntVec3 c, bool doLeavings = true)
        {
            int index = this.map.cellIndices.CellToIndex(c);

            if (doLeavings)
            {
                GenLeaving.DoLeavingsFor(this.topGrid[index], c, this.map);
            }
            if (this.underGrid[index] == null)
            {
                return;
            }
            this.topGrid[index]   = this.underGrid[index];
            this.underGrid[index] = (TerrainDef)null;
            this.DoTerrainChangedEffects(c);
        }
        public new void FailConstruction(Pawn worker)
        {
            Log.Message($"Failed replace frame! work was {workDone}, Decon is {WorkToDeconstruct(def, oldStuff)}, total is {WorkToBuild}");

            workDone = Mathf.Min(workDone, WorkToDeconstruct(def, oldStuff));
            if (workDone < WorkToDeconstruct(def, oldStuff))
            {
                return;                                                           //Deconstruction doesn't fail
            }
            GenLeaving.DoLeavingsFor(this, Map, DestroyMode.FailConstruction);

            MoteMaker.ThrowText(this.DrawPos, Map, "TextMote_ConstructionFail".Translate());
            if (base.Faction == Faction.OfPlayer && this.WorkToReplace > 1400f)
            {
                Messages.Message("MessageConstructionFailed".Translate(this.LabelEntityToBuild, worker.LabelShort, worker.Named("WORKER")),
                                 new TargetInfo(base.Position, Map), MessageTypeDefOf.NegativeEvent);
            }
        }
示例#19
0
    public override void Destroy()
    {
        base.Destroy();

        GenLeaving.DoLeavingsFor(this, destroyMode);

        if (def.MakeFog)
        {
            Find.FogGrid.Notify_FogBlockerDestroyed(Position);
        }

        if (def.holdsRoof)
        {
            RoofCollapseChecker.Notify_RoofHolderDestroyed(this);
        }

        if (def.leaveTerrain != null && Map.Initialized)
        {
            foreach (IntVec3 loc in GenAdj.SquaresOccupiedBy(this))
            {
                Find.TerrainGrid.SetTerrain(loc, def.leaveTerrain);
            }
        }

        Find.ListerBuildings.Remove(this);

        if (TransmitsPower || def.ConnectToPower)
        {
            if (TransmitsPower)
            {
                PowerNetManager.Notify_TransmitterDespawned(this);
            }

            if (def.ConnectToPower)
            {
                PowerNetManager.Notify_ConnectorDespawned(this);
            }

            Find.MapDrawer.MapChanged(Position, MapChangeType.PowerGrid, true, false);
        }
    }
示例#20
0
        public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            if (!Thing.allowDestroyNonDestroyable && !this.def.destroyable)
            {
                Log.Error("Tried to destroy non-destroyable thing " + this);
                return;
            }
            if (this.Destroyed)
            {
                Log.Error("Tried to destroy already-destroyed thing " + this);
                return;
            }
            bool spawned = this.Spawned;
            Map  map     = this.Map;

            if (this.Spawned)
            {
                this.DeSpawn();
            }
            this.mapIndexOrState = -2;
            if (this.def.DiscardOnDestroyed)
            {
                this.Discard(false);
            }
            CompExplosive compExplosive = this.TryGetComp <CompExplosive>();
            bool          flag          = compExplosive != null && compExplosive.destroyedThroughDetonation;

            if (spawned && !flag)
            {
                GenLeaving.DoLeavingsFor(this, map, mode);
            }
            if (this.holdingOwner != null)
            {
                this.holdingOwner.Notify_ContainedItemDestroyed(this);
            }
            this.RemoveAllReservationsAndDesignationsOnThis();
            if (!(this is Pawn))
            {
                this.stackCount = 0;
            }
        }
示例#21
0
 public static void PostFix(ref Func <int, int> __result, Thing destroyedThing, DestroyMode mode)
 {
     if (destroyedThing.def.defName.StartsWith("MSMedicalMat") && mode == DestroyMode.Deconstruct && destroyedThing.def.resourcesFractionWhenDeconstructed >= 1f)
     {
         if (!GenLeaving.CanBuildingLeaveResources(destroyedThing, mode))
         {
             __result = ((int count) => 0);
             return;
         }
         if (mode == DestroyMode.Deconstruct && typeof(Frame).IsAssignableFrom(destroyedThing.GetType()))
         {
             mode = DestroyMode.Cancel;
             return;
         }
         if (mode == DestroyMode.Deconstruct)
         {
             __result = ((int count) => count);
             return;
         }
     }
 }
示例#22
0
文件: Thing.cs 项目: potsh/RimWorld
 public virtual void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     if (!allowDestroyNonDestroyable && !def.destroyable)
     {
         Log.Error("Tried to destroy non-destroyable thing " + this);
     }
     else if (Destroyed)
     {
         Log.Error("Tried to destroy already-destroyed thing " + this);
     }
     else
     {
         bool spawned = Spawned;
         Map  map     = Map;
         if (Spawned)
         {
             DeSpawn(mode);
         }
         mapIndexOrState = -2;
         if (def.DiscardOnDestroyed)
         {
             Discard();
         }
         bool flag = this.TryGetComp <CompExplosive>()?.destroyedThroughDetonation ?? false;
         if (spawned && !flag)
         {
             GenLeaving.DoLeavingsFor(this, map, mode);
         }
         if (holdingOwner != null)
         {
             holdingOwner.Notify_ContainedItemDestroyed(this);
         }
         RemoveAllReservationsAndDesignationsOnThis();
         if (!(this is Pawn))
         {
             stackCount = 0;
         }
     }
 }
示例#23
0
        public static void Refund(Thing thing, Map map, CellRect avoidThisRect)
        {
            bool flag = false;

            if (thing.def.Minifiable)
            {
                MinifiedThing minifiedThing = thing.MakeMinified();
                if (GenPlace.TryPlaceThing(minifiedThing, thing.Position, map, ThingPlaceMode.Near, null, (IntVec3 x) => !avoidThisRect.Contains(x)))
                {
                    flag = true;
                }
                else
                {
                    minifiedThing.GetDirectlyHeldThings().Clear();
                    minifiedThing.Destroy(DestroyMode.Vanish);
                }
            }
            if (!flag)
            {
                GenLeaving.DoLeavingsFor(thing, map, DestroyMode.Refund, thing.OccupiedRect(), (IntVec3 x) => !avoidThisRect.Contains(x));
                thing.Destroy(DestroyMode.Vanish);
            }
        }
示例#24
0
        // Token: 0x060000F0 RID: 240 RVA: 0x00008874 File Offset: 0x00006A74
        public static void Destroy_Prefix(Thing __instance, DestroyMode mode = DestroyMode.Vanish)
        {
            bool flag = !Thing.allowDestroyNonDestroyable && !__instance.def.destroyable;

            if (!flag)
            {
                bool destroyed = __instance.Destroyed;
                if (!destroyed)
                {
                    bool spawned  = __instance.Spawned;
                    Map  map      = __instance.Map;
                    bool spawned2 = __instance.Spawned;
                    if (spawned2)
                    {
                        __instance.DeSpawn(mode);
                    }
                    sbyte value = Traverse.Create(typeof(Thing)).Field("mapIndexOrState").GetValue <sbyte>();
                    bool  discardOnDestroyed = __instance.def.DiscardOnDestroyed;
                    if (discardOnDestroyed)
                    {
                        __instance.Discard(false);
                    }
                    CompExplosive compExplosive = __instance.TryGetComp <CompExplosive>();
                    bool          flag2         = compExplosive != null && compExplosive.destroyedThroughDetonation;
                    bool          flag3         = spawned && !flag2;
                    if (flag3)
                    {
                        GenLeaving.DoLeavingsFor(__instance, map, mode, null);
                    }
                    bool flag4 = __instance.holdingOwner != null;
                    if (flag4)
                    {
                        __instance.holdingOwner.Notify_ContainedItemDestroyed(__instance);
                    }
                    List <Map> maps = Find.Maps;
                    for (int i = 0; i < maps.Count; i++)
                    {
                        bool flag5 = __instance.def.category == ThingCategory.Mote;
                        if (flag5)
                        {
                            return;
                        }
                        bool flag6 = __instance.def.category != ThingCategory.Mote;
                        if (flag6)
                        {
                            maps[i].reservationManager.ReleaseAllForTarget(__instance);
                            maps[i].physicalInteractionReservationManager.ReleaseAllForTarget(__instance);
                            IAttackTarget attackTarget = __instance as IAttackTarget;
                            bool          flag7        = attackTarget != null;
                            if (flag7)
                            {
                                maps[i].attackTargetReservationManager.ReleaseAllForTarget(attackTarget);
                            }
                            maps[i].designationManager.RemoveAllDesignationsOn(__instance, false);
                        }
                    }
                    bool flag8 = !(__instance is Pawn);
                    if (flag8)
                    {
                        __instance.stackCount = 0;
                    }
                }
            }
        }
示例#25
0
 public static bool TakeDamage_Prefix(Thing __instance, DamageInfo dinfo, ref DamageWorker.DamageResult __result)
 {
     if (__instance as Pawn == null)
     {
         return(true);
     }
     else
     {
         //Log.Message("Own TakeDamage");
         //Log.Message("Log1");
         if (__instance.Destroyed)
         {
             __result = DamageWorker.DamageResult.MakeNew();
         }
         //Log.Message("Log2");
         if (dinfo.Amount == 0)
         {
             __result = DamageWorker.DamageResult.MakeNew();
         }
         //Log.Message("Log3");
         if (__instance.def.damageMultipliers != null)
         {
             for (int i = 0; i < __instance.def.damageMultipliers.Count; i++)
             {
                 if (__instance.def.damageMultipliers[i].damageDef == dinfo.Def)
                 {
                     int amount = Mathf.RoundToInt((float)dinfo.Amount * __instance.def.damageMultipliers[i].multiplier);
                     dinfo.SetAmount(amount);
                 }
             }
         }
         //Log.Message("Log4");
         bool flag;
         __instance.PreApplyDamage(dinfo, out flag);
         if (flag)
         {
             __result = DamageWorker.DamageResult.MakeNew();
         }
         //Log.Message("Log5");
         bool spawnedOrAnyParentSpawned = __instance.SpawnedOrAnyParentSpawned;
         Map  mapHeld = __instance.MapHeld;
         DamageWorker.DamageResult result = dinfo.Def.Worker.Apply(dinfo, __instance);
         if (dinfo.Def.harmsHealth && spawnedOrAnyParentSpawned)
         {
             mapHeld.damageWatcher.Notify_DamageTaken(__instance, result.totalDamageDealt);
         }
         //Log.Message("Log6");
         if (dinfo.Def.externalViolence)
         {
             GenLeaving.DropFilthDueToDamage(__instance, result.totalDamageDealt);
             if (dinfo.Instigator != null)
             {
                 Pawn pawn = dinfo.Instigator as Pawn;
                 if (pawn != null)
                 {
                     pawn.records.AddTo(RecordDefOf.DamageDealt, result.totalDamageDealt);
                     pawn.records.AccumulateStoryEvent(StoryEventDefOf.DamageDealt);
                 }
             }
         }
         //Log.Message("Log7");
         __instance.PostApplyDamage(dinfo, result.totalDamageDealt);
         __result = result;
         return(false);
         //return true;
     }
 }
示例#26
0
            public static bool DoLeavingsForPrefix(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null, List <Thing> listOfLeavingsOut = null)
            {
                bool flag = mode == DestroyMode.Deconstruct;
                bool result;

                if (flag)
                {
                    ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();
                    bool flag2 = GenLeaving.CanBuildingLeaveResources(diedThing, mode);
                    if (flag2)
                    {
                        Frame frame = diedThing as Frame;
                        bool  flag3 = frame != null;
                        if (flag3)
                        {
                            for (int i = frame.resourceContainer.Count - 1; i >= 0; i--)
                            {
                                int  num   = DeconstructReturnFix.CalcFix.GBRLC(diedThing, mode)(frame.resourceContainer[i].stackCount);
                                bool flag4 = num > 0;
                                if (flag4)
                                {
                                    frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[i], thingOwner, num, true);
                                }
                            }
                            frame.resourceContainer.ClearAndDestroyContents(mode);
                        }
                        else
                        {
                            List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                            for (int j = 0; j < list.Count; j++)
                            {
                                ThingDefCountClass thingDefCountClass = list[j];
                                int  num2  = DeconstructReturnFix.CalcFix.GBRLC(diedThing, mode)(thingDefCountClass.count);
                                bool flag5 = num2 > 0;
                                if (flag5)
                                {
                                    Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                                    thing.stackCount = num2;
                                    thingOwner.TryAdd(thing, true);
                                }
                            }
                        }
                    }
                    List <IntVec3> list2 = leavingsRect.Cells.InRandomOrder(null).ToList <IntVec3>();
                    int            num3  = 0;
                    for (;;)
                    {
                        bool flag6 = thingOwner.Count > 0;
                        if (!flag6)
                        {
                            goto IL_1B4;
                        }
                        ThingOwner <Thing> thingOwner2 = thingOwner;
                        Thing          thing2          = thingOwner[0];
                        IntVec3        dropLoc         = list2[num3];
                        ThingPlaceMode mode2           = ThingPlaceMode.Near;
                        Thing          thing3          = null;
                        bool           flag7           = thingOwner2.TryDrop(thing2, dropLoc, map, mode2, out thing3, null, nearPlaceValidator);
                        if (!flag7)
                        {
                            break;
                        }
                        num3++;
                        bool flag8 = num3 >= list2.Count;
                        if (flag8)
                        {
                            num3 = 0;
                        }
                    }
                    Log.Warning(string.Concat(new object[]
                    {
                        "Deconstruct Return Fix: Failed to place all leavings for destroyed thing ",
                        diedThing,
                        " at ",
                        leavingsRect.CenterCell
                    }), false);
                    return(false);

IL_1B4:
                    result = false;
                }
                else
                {
                    result = true;
                }
                return(result);
            }
示例#27
0
            public static bool DoLeavingsForPrefix(Thing diedThing, Map map, DestroyMode mode, CellRect leavingsRect, Predicate <IntVec3> nearPlaceValidator = null)
            {
                if (mode != DestroyMode.Deconstruct)
                {
                    return(true);                                 //just to make it more readable
                }
                ThingOwner <Thing> thingOwner = new ThingOwner <Thing>();

                if (GenLeaving.CanBuildingLeaveResources(diedThing, mode))
                {
                    Frame frame = diedThing as Frame;
                    if (frame != null)
                    {
                        for (int frameResCt = frame.resourceContainer.Count - 1; frameResCt >= 0; frameResCt--)
                        {
                            int gblrc;
                            if ((gblrc = GBRLC(diedThing)(frame.resourceContainer[frameResCt].stackCount)) > 0)
                            {
                                frame.resourceContainer.TryTransferToContainer(frame.resourceContainer[frameResCt], thingOwner, gblrc, true);
                            }
                        }
                        frame.resourceContainer.ClearAndDestroyContents(mode);
                    }
                    else
                    {
                        // TODO: ModExtension specifying drop rates per ThingDef. Needs to be relatively optimized.
                        List <ThingDefCountClass> list = diedThing.CostListAdjusted();
                        for (int l = 0; l < list.Count; l++)
                        {
                            ThingDefCountClass tdcc = list[l];
                            int gblrc;
                            if ((gblrc = GBRLC(diedThing)(tdcc.count)) > 0)
                            {
                                Thing thing = ThingMaker.MakeThing(tdcc.thingDef, null);
                                thing.stackCount = gblrc;
                                thingOwner.TryAdd(thing, true);
                            }
                        }
                    }
                }
                List <IntVec3> cellList = leavingsRect.Cells.InRandomOrder(null).ToList();
                int            cellInd  = 0;

                while (true)
                {
                    if (thingOwner.Count > 0)
                    {
                        ThingOwner <Thing> thingOwner2 = thingOwner;
                        Thing          thing           = thingOwner[0];
                        IntVec3        dropLoc         = cellList[cellInd];
                        ThingPlaceMode mode2           = ThingPlaceMode.Near;
                        Thing          thing4          = default(Thing);
                        if (thingOwner2.TryDrop(thing, dropLoc, map, mode2, out thing4, null, nearPlaceValidator))
                        {
                            cellInd++;
                            if (cellInd >= cellList.Count)
                            {
                                cellInd = 0;
                            }
                            continue;
                        }
                        break;
                    }
                    return(false);
                }
                ULog.Warning("Deconstruct Return Fix: Failed to place all leavings for destroyed thing " + diedThing + " at " + leavingsRect.CenterCell, false);
                return(false);
            }//end DoLeavingsForPrefix
示例#28
0
        public override void Resolve(ResolveParams rp)
        {
            SpawnDescriptor[] array = new SpawnDescriptor[30]
            {
                new SpawnDescriptor
                {
                    offset = new IntVec3(0, 0, 0),
                    def    = ThingDefOf.Ship_Reactor,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(0, 0, 12),
                    def    = ThingDefOf.Ship_Beam,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(0, 0, 6),
                    def    = ThingDefOf.Ship_Beam,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-4, 0, -2),
                    def    = ThingDefOf.Ship_Beam,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(4, 0, -2),
                    def    = ThingDefOf.Ship_Beam,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(0, 0, -7),
                    def    = ThingDefOf.Ship_Beam,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(0, 0, 16),
                    def    = ThingDefOf.Ship_SensorCluster,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(3, 0, -7),
                    def    = ThingDefOf.Ship_ComputerCore,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 15),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 13),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 11),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 9),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 7),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, 5),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-4, 0, 2),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-5, 0, 1),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 15),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 13),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 11),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 9),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 7),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(2, 0, 5),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(5, 0, 2),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(6, 0, 1),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.East
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-6, 0, -3),
                    def    = ThingDefOf.Ship_Engine,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(7, 0, -3),
                    def    = ThingDefOf.Ship_Engine,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(3, 0, -11),
                    def    = ThingDefOf.Ship_Engine,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-2, 0, -11),
                    def    = ThingDefOf.Ship_Engine,
                    rot    = Rot4.North
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, -8),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                },
                new SpawnDescriptor
                {
                    offset = new IntVec3(-1, 0, -6),
                    def    = ThingDefOf.Ship_CryptosleepCasket,
                    rot    = Rot4.West
                }
            };
            IntVec3 centerCell = rp.rect.CenterCell;
            IntVec3 b          = new IntVec3(-1, 0, -3);

            SpawnDescriptor[] array2 = array;
            for (int i = 0; i < array2.Length; i++)
            {
                SpawnDescriptor spawnDescriptor = array2[i];
                Thing           thing           = ThingMaker.MakeThing(spawnDescriptor.def, null);
                thing.SetFaction(rp.faction, null);
                if (rp.hpPercentRange.HasValue)
                {
                    thing.HitPoints = Mathf.Clamp(Mathf.RoundToInt((float)thing.MaxHitPoints * rp.hpPercentRange.Value.RandomInRange), 1, thing.MaxHitPoints);
                    GenLeaving.DropFilthDueToDamage(thing, (float)(thing.MaxHitPoints - thing.HitPoints));
                }
                CompHibernatable compHibernatable = thing.TryGetComp <CompHibernatable>();
                if (compHibernatable != null)
                {
                    compHibernatable.State = HibernatableStateDefOf.Hibernating;
                }
                GenSpawn.Spawn(thing, centerCell + b + spawnDescriptor.offset, BaseGen.globalSettings.map, spawnDescriptor.rot, false);
            }
        }
示例#29
0
        public static bool TakeDamage(Thing __instance, ref DamageWorker.DamageResult __result, DamageInfo dinfo)
        {
            //---START change---
            Map mapHeld = __instance.MapHeld; //moved

            if (mapHeld == null)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            //---END change---

            if (__instance.Destroyed)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            if ((double)dinfo.Amount == 0.0)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            if (__instance.def.damageMultipliers != null)
            {
                for (int index = 0; index < __instance.def.damageMultipliers.Count; ++index)
                {
                    if (__instance.def.damageMultipliers[index].damageDef == dinfo.Def)
                    {
                        int num = Mathf.RoundToInt(dinfo.Amount * __instance.def.damageMultipliers[index].multiplier);
                        dinfo.SetAmount((float)num);
                    }
                }
            }
            bool absorbed;

            __instance.PreApplyDamage(ref dinfo, out absorbed);
            if (absorbed)
            {
                __result = new DamageWorker.DamageResult();
                return(false);
            }
            bool anyParentSpawned = __instance.SpawnedOrAnyParentSpawned;

            // Map mapHeld = __instance.MapHeld; //moved
            DamageWorker.DamageResult damageResult = dinfo.Def.Worker.Apply(dinfo, __instance);
            if (dinfo.Def.harmsHealth & anyParentSpawned)
            {
                mapHeld.damageWatcher.Notify_DamageTaken(__instance, damageResult.totalDamageDealt);
            }
            if (dinfo.Def.ExternalViolenceFor(__instance))
            {
#if RW13
                if (dinfo.SpawnFilth)
#endif
                GenLeaving.DropFilthDueToDamage(__instance, damageResult.totalDamageDealt);
                if (dinfo.Instigator != null && dinfo.Instigator is Pawn instigator2)
                {
                    if (instigator2 != null)
                    {
                        instigator2.records.AddTo(RecordDefOf.DamageDealt, damageResult.totalDamageDealt);
#if RW12
                        instigator2.records.AccumulateStoryEvent(StoryEventDefOf.DamageDealt);
#endif
                    }
                }
            }
            __instance.PostApplyDamage(dinfo, damageResult.totalDamageDealt);
            __result = damageResult;
            return(false);
        }