示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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 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));
                            }
                        }
                    }
                }
示例#6
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);
            }
        }
示例#7
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;
     }
 }
示例#8
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);
        }