Esempio n. 1
0
        public static void DestroyOrPassToWorld(this Thing t, DestroyMode mode = DestroyMode.Vanish)
        {
            Pawn pawn = t as Pawn;

            if (pawn != null)
            {
                if (!Find.WorldPawns.Contains(pawn))
                {
                    Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
                }
            }
            else
            {
                t.Destroy(mode);
            }
        }
 private void RegisterInCell(Thing t, IntVec3 c)
 {
     if (!c.InBounds(this.map))
     {
         Log.Warning(string.Concat(new object[]
         {
             t,
             " tried to register out of bounds at ",
             c,
             ". Destroying."
         }), false);
         t.Destroy(DestroyMode.Vanish);
         return;
     }
     this.thingGrid[this.map.cellIndices.CellToIndex(c)].Add(t);
 }
Esempio n. 3
0
 public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, bool respawningAfterLoad = false)
 {
     if (map == null)
     {
         Log.Error("Tried to spawn " + newThing + " in a null map.");
         return(null);
     }
     if (!loc.InBounds(map))
     {
         Log.Error(string.Concat(new object[]
         {
             "Tried to spawn ",
             newThing,
             " out of bounds at ",
             loc,
             "."
         }));
         return(null);
     }
     if (newThing.Spawned)
     {
         Log.Error("Tried to spawn " + newThing + " but it's already spawned.");
         return(newThing);
     }
     GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
     if (newThing.def.randomizeRotationOnSpawn)
     {
         newThing.Rotation = Rot4.Random;
     }
     else
     {
         newThing.Rotation = rot;
     }
     newThing.Position = loc;
     if (newThing.holdingOwner != null)
     {
         newThing.holdingOwner.Remove(newThing);
     }
     newThing.SpawnSetup(map, respawningAfterLoad);
     if (newThing.Spawned && newThing.stackCount == 0)
     {
         Log.Error("Spawned thing with 0 stackCount: " + newThing);
         newThing.Destroy(DestroyMode.Vanish);
         return(null);
     }
     return(newThing);
 }
Esempio n. 4
0
 protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell)
 {
     if (t.def.category != ThingCategory.Mote && !damagedThings.Contains(t))
     {
         damagedThings.Add(t);
         if (this.def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed)
         {
             t.Destroy(DestroyMode.Vanish);
         }
         else
         {
             float      num            = (!(t.Position == explosion.Position)) ? (t.Position - explosion.Position).AngleFlat : ((float)Rand.RangeInclusive(0, 359));
             DamageDef  damageDef      = this.def;
             int        damageAmountAt = explosion.GetDamageAmountAt(cell);
             float      angle          = num;
             Thing      instigator     = explosion.instigator;
             ThingDef   weapon         = explosion.weapon;
             DamageInfo dinfo          = new DamageInfo(damageDef, damageAmountAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown);
             if (this.def.explosionAffectOutsidePartsOnly)
             {
                 dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
             }
             if (t.def.category == ThingCategory.Building)
             {
                 int num2 = Mathf.RoundToInt((float)dinfo.Amount * this.def.explosionBuildingDamageFactor);
                 damageDef      = this.def;
                 damageAmountAt = num2;
                 angle          = dinfo.Angle;
                 instigator     = explosion.instigator;
                 weapon         = dinfo.Weapon;
                 dinfo          = new DamageInfo(damageDef, damageAmountAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown);
             }
             BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null;
             if (t is Pawn)
             {
                 battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, this.def);
                 Find.BattleLog.Add(battleLogEntry_ExplosionImpact);
             }
             t.TakeDamage(dinfo).InsertIntoLog(battleLogEntry_ExplosionImpact);
         }
     }
 }
Esempio n. 5
0
        public virtual bool TryAbsorbStack(Thing other, bool respectStackLimit)
        {
            if (!this.CanStackWith(other))
            {
                return(false);
            }
            int num = ThingUtility.TryAbsorbStackNumToTake(this, other, respectStackLimit);

            if (this.def.useHitPoints)
            {
                this.HitPoints = Mathf.CeilToInt((float)(this.HitPoints * this.stackCount + other.HitPoints * num) / (float)(this.stackCount + num));
            }
            this.stackCount  += num;
            other.stackCount -= num;
            StealAIDebugDrawer.Notify_ThingChanged(this);
            if (other.stackCount <= 0)
            {
                other.Destroy(DestroyMode.Vanish);
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
 protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell)
 {
     if (t.def.category != ThingCategory.Mote && t.def.category != ThingCategory.Ethereal && !damagedThings.Contains(t))
     {
         damagedThings.Add(t);
         if (def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed)
         {
             t.Destroy();
         }
         else
         {
             float      num                = (!(t.Position == explosion.Position)) ? (t.Position - explosion.Position).AngleFlat : ((float)Rand.RangeInclusive(0, 359));
             DamageDef  damageDef          = def;
             float      amount             = (float)explosion.GetDamageAmountAt(cell);
             float      armorPenetrationAt = explosion.GetArmorPenetrationAt(cell);
             float      angle              = num;
             Thing      instigator         = explosion.instigator;
             ThingDef   weapon             = explosion.weapon;
             DamageInfo dinfo              = new DamageInfo(damageDef, amount, armorPenetrationAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown, explosion.intendedTarget);
             if (def.explosionAffectOutsidePartsOnly)
             {
                 dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
             }
             BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null;
             Pawn pawn = t as Pawn;
             if (pawn != null)
             {
                 battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, def);
                 Find.BattleLog.Add(battleLogEntry_ExplosionImpact);
             }
             DamageResult damageResult = t.TakeDamage(dinfo);
             damageResult.AssociateWithLog(battleLogEntry_ExplosionImpact);
             if (pawn != null && damageResult.wounded && pawn.stances != null)
             {
                 pawn.stances.StaggerFor(95);
             }
         }
     }
 }
Esempio n. 7
0
        public static bool TryDropSpawn(Thing thing, IntVec3 dropCell, Map map, ThingPlaceMode mode, out Thing resultingThing, Action <Thing, int> placedAction = null, Predicate <IntVec3> nearPlaceValidator = null)
        {
            bool result;

            if (map == null)
            {
                Log.Error("Dropped " + thing + " in a null map.", false);
                resultingThing = null;
                result         = false;
            }
            else if (!dropCell.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Dropped ",
                    thing,
                    " out of bounds at ",
                    dropCell
                }), false);
                resultingThing = null;
                result         = false;
            }
            else if (thing.def.destroyOnDrop)
            {
                thing.Destroy(DestroyMode.Vanish);
                resultingThing = null;
                result         = true;
            }
            else
            {
                if (thing.def.soundDrop != null)
                {
                    thing.def.soundDrop.PlayOneShot(new TargetInfo(dropCell, map, false));
                }
                result = GenPlace.TryPlaceThing(thing, dropCell, map, mode, out resultingThing, placedAction, nearPlaceValidator);
            }
            return(result);
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
 public virtual void ConsumeIngredient(Thing ingredient, RecipeDef recipe, Map map)
 {
     ingredient.Destroy();
 }
Esempio n. 10
0
        public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            if (map == null)
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe <Thing>() + " in a null map.", false);
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    "."
                }), false);
                return(null);
            }
            if (newThing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }
            CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to spawn ",
                    newThing.ToStringSafe <Thing>(),
                    " out of bounds at ",
                    loc,
                    " (out of bounds because size is ",
                    newThing.def.Size,
                    ")."
                }), false);
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error("Tried to spawn " + newThing + " but it's already spawned.", false);
                return(newThing);
            }
            if (wipeMode == WipeMode.Vanish)
            {
                GenSpawn.WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
            }
            else if (wipeMode == WipeMode.FullRefund)
            {
                GenSpawn.WipeAndRefundExistingThings(loc, rot, newThing.def, map);
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 current in occupiedRect)
                {
                    foreach (Thing current2 in current.GetThingList(map).ToList <Thing>())
                    {
                        if (current2 != newThing)
                        {
                            if (current2.def.category == ThingCategory.Item)
                            {
                                current2.DeSpawn(DestroyMode.Vanish);
                                if (!GenPlace.TryPlaceThing(current2, current, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                                {
                                    current2.Destroy(DestroyMode.Vanish);
                                }
                            }
                        }
                    }
                }
            }
            newThing.Rotation = rot;
            newThing.Position = loc;
            if (newThing.holdingOwner != null)
            {
                newThing.holdingOwner.Remove(newThing);
            }
            newThing.SpawnSetup(map, respawningAfterLoad);
            if (newThing.Spawned && newThing.stackCount == 0)
            {
                Log.Error("Spawned thing with 0 stackCount: " + newThing, false);
                newThing.Destroy(DestroyMode.Vanish);
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 current3 in occupiedRect)
                {
                    foreach (Thing current4 in current3.GetThingList(map).ToList <Thing>())
                    {
                        if (current4 != newThing)
                        {
                            Pawn pawn = current4 as Pawn;
                            if (pawn != null)
                            {
                                pawn.pather.TryRecoverFromUnwalkablePosition(false);
                            }
                        }
                    }
                }
            }
            return(newThing);
        }
Esempio n. 11
0
        public static Thing Spawn(Thing newThing, IntVec3 loc, Map map, Rot4 rot, WipeMode wipeMode = WipeMode.Vanish, bool respawningAfterLoad = false)
        {
            if (map == null)
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe() + " in a null map.");
                return(null);
            }
            if (!loc.InBounds(map))
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe() + " out of bounds at " + loc + ".");
                return(null);
            }
            if (newThing.def.randomizeRotationOnSpawn)
            {
                rot = Rot4.Random;
            }
            CellRect occupiedRect = GenAdj.OccupiedRect(loc, rot, newThing.def.Size);

            if (!occupiedRect.InBounds(map))
            {
                Log.Error("Tried to spawn " + newThing.ToStringSafe() + " out of bounds at " + loc + " (out of bounds because size is " + newThing.def.Size + ").");
                return(null);
            }
            if (newThing.Spawned)
            {
                Log.Error("Tried to spawn " + newThing + " but it's already spawned.");
                return(newThing);
            }
            switch (wipeMode)
            {
            case WipeMode.Vanish:
                WipeExistingThings(loc, rot, newThing.def, map, DestroyMode.Vanish);
                break;

            case WipeMode.FullRefund:
                WipeAndRefundExistingThings(loc, rot, newThing.def, map);
                break;
            }
            if (newThing.def.category == ThingCategory.Item)
            {
                foreach (IntVec3 item in occupiedRect)
                {
                    foreach (Thing item2 in item.GetThingList(map).ToList())
                    {
                        if (item2 != newThing && item2.def.category == ThingCategory.Item)
                        {
                            item2.DeSpawn();
                            if (!GenPlace.TryPlaceThing(item2, item, map, ThingPlaceMode.Near, null, (IntVec3 x) => !occupiedRect.Contains(x)))
                            {
                                item2.Destroy();
                            }
                        }
                    }
                }
            }
            newThing.Rotation = rot;
            newThing.Position = loc;
            if (newThing.holdingOwner != null)
            {
                newThing.holdingOwner.Remove(newThing);
            }
            newThing.SpawnSetup(map, respawningAfterLoad);
            if (newThing.Spawned && newThing.stackCount == 0)
            {
                Log.Error("Spawned thing with 0 stackCount: " + newThing);
                newThing.Destroy();
                return(null);
            }
            if (newThing.def.passability == Traversability.Impassable)
            {
                foreach (IntVec3 item3 in occupiedRect)
                {
                    foreach (Thing item4 in item3.GetThingList(map).ToList())
                    {
                        if (item4 != newThing)
                        {
                            (item4 as Pawn)?.pather.TryRecoverFromUnwalkablePosition(error: false);
                        }
                    }
                }
                return(newThing);
            }
            return(newThing);
        }
Esempio n. 12
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef != null)
            {
                if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        List <Thing> thingList = c.GetThingList(map);
                        for (int j = thingList.Count - 1; j >= 0; j--)
                        {
                            Thing thing = thingList[j];
                            RoofCollapserImmediate.TryAddToCrushedThingsList(thing, outCrushedThings);
                            Pawn       pawn = thing as Pawn;
                            DamageInfo dinfo;
                            if (pawn != null)
                            {
                                DamageDef      crush            = DamageDefOf.Crush;
                                float          amount           = 99999f;
                                float          armorPenetration = 999f;
                                BodyPartRecord brain            = pawn.health.hediffSet.GetBrain();
                                dinfo = new DamageInfo(crush, amount, armorPenetration, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse, null);
                            }
                            else
                            {
                                dinfo = new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null);
                                dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                            if (i == 0 && pawn != null)
                            {
                                battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken);
                            }
                            thing.TakeDamage(dinfo).AssociateWithLog(battleLogEntry_DamageTaken);
                            if (!thing.Destroyed && thing.def.destroyable)
                            {
                                thing.Destroy(DestroyMode.Vanish);
                            }
                        }
                    }
                }
                else
                {
                    List <Thing> thingList2 = c.GetThingList(map);
                    for (int k = thingList2.Count - 1; k >= 0; k--)
                    {
                        Thing thing2 = thingList2[k];
                        if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                        {
                            RoofCollapserImmediate.TryAddToCrushedThingsList(thing2, outCrushedThings);
                            float num = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange;
                            if (thing2.def.building != null)
                            {
                                num *= thing2.def.building.roofCollapseDamageMultiplier;
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                            if (thing2 is Pawn)
                            {
                                battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken((Pawn)thing2, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                            }
                            DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, (float)GenMath.RoundRandom(num), 0f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null);
                            dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            thing2.TakeDamage(dinfo2).AssociateWithLog(battleLogEntry_DamageTaken2);
                        }
                    }
                }
                if (roofDef.collapseLeavingThingDef != null)
                {
                    Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map, WipeMode.Vanish);
                    if (thing3.def.rotatable)
                    {
                        thing3.Rotation = Rot4.Random;
                    }
                }
                for (int l = 0; l < 1; l++)
                {
                    Vector3 vector = c.ToVector3Shifted();
                    vector += Gen.RandomHorizontalVector(0.6f);
                    MoteMaker.ThrowDustPuff(vector, map, 2f);
                }
            }
        }
        public override void PostLoadSavegame(string loadingVersion)
        {
            oldCrashedShipParts.Clear();
            foreach (UpgradedCrashedShipPart upgradedCrashedShipPart in upgradedCrashedShipParts)
            {
                Thing   thing   = upgradedCrashedShipPart.thing;
                IntVec3 invalid = IntVec3.Invalid;
                Map     map     = null;
                if (thing.Spawned)
                {
                    invalid = thing.Position;
                    map     = thing.Map;
                }
                else
                {
                    Skyfaller obj = thing.ParentHolder as Skyfaller;
                    if (obj == null)
                    {
                        thing.Destroy();
                    }
                    invalid = obj.Position;
                    map     = obj.Map;
                }
                if (!(invalid == IntVec3.Invalid))
                {
                    invalid = new IntVec3(invalid.x - Mathf.CeilToInt((float)thing.def.size.x / 2f), invalid.y, invalid.z);
                    Thing item = null;
                    if (upgradedCrashedShipPart.originalDefName == "CrashedPoisonShipPart" || upgradedCrashedShipPart.originalDefName == "PoisonSpreaderShipPart")
                    {
                        item = ThingMaker.MakeThing(ThingDefOf.DefoliatorShipPart);
                    }
                    else if (upgradedCrashedShipPart.originalDefName == "CrashedPsychicEmanatorShipPart")
                    {
                        item = ThingMaker.MakeThing(ThingDefOf.PsychicDronerShipPart);
                    }
                    ActiveDropPodInfo activeDropPodInfo = new ActiveDropPodInfo();
                    activeDropPodInfo.innerContainer.TryAdd(item, 1);
                    activeDropPodInfo.openDelay = 60;
                    activeDropPodInfo.leaveSlag = false;
                    activeDropPodInfo.despawnPodBeforeSpawningThing = true;
                    activeDropPodInfo.spawnWipeMode = WipeMode.Vanish;
                    DropPodUtility.MakeDropPodAt(invalid, map, activeDropPodInfo);
                }
            }
            upgradedCrashedShipParts.Clear();
            List <Site> sites = Find.WorldObjects.Sites;
            int         l;

            for (l = 0; l < sites.Count; l++)
            {
                if (!Find.QuestManager.QuestsListForReading.Any((Quest x) => x.QuestLookTargets.Contains(sites[l])))
                {
                    Quest quest = Quest.MakeRaw();
                    QuestUtility.GenerateBackCompatibilityNameFor(quest);
                    quest.SetInitiallyAccepted();
                    quest.appearanceTick = sites[l].creationGameTicks;
                    TimeoutComp component = sites[l].GetComponent <TimeoutComp>();
                    if (component != null && component.Active && !sites[l].HasMap)
                    {
                        QuestPartUtility.MakeAndAddQuestTimeoutDelay(quest, component.TicksLeft, sites[l]);
                        component.StopTimeout();
                    }
                    QuestPartUtility.MakeAndAddEndCondition <QuestPart_NoWorldObject>(quest, quest.InitiateSignal, QuestEndOutcome.Unknown).worldObject = sites[l];
                    ChoiceLetter choiceLetter = Find.Archive.ArchivablesListForReading.OfType <ChoiceLetter>().FirstOrDefault((ChoiceLetter x) => x.lookTargets != null && x.lookTargets.targets.Contains(sites[l]));
                    if (choiceLetter != null)
                    {
                        quest.description = choiceLetter.text;
                    }
                    Find.QuestManager.Add(quest);
                }
            }
            List <WorldObject> worldObjects = Find.WorldObjects.AllWorldObjects;
            int k;

            for (k = 0; k < worldObjects.Count; k++)
            {
                if (worldObjects[k].def == WorldObjectDefOf.EscapeShip && !Find.QuestManager.QuestsListForReading.Any((Quest x) => x.PartsListForReading.Any((QuestPart y) => y is QuestPart_NoWorldObject && ((QuestPart_NoWorldObject)y).worldObject == worldObjects[k])))
                {
                    MakeAndAddWorldObjectQuest(worldObjects[k], null);
                }
            }
            int j;

            for (j = 0; j < worldObjects.Count; j++)
            {
                if (worldObjects[j] is PeaceTalks && !Find.QuestManager.QuestsListForReading.Any((Quest x) => x.PartsListForReading.Any((QuestPart y) => y is QuestPart_NoWorldObject && ((QuestPart_NoWorldObject)y).worldObject == worldObjects[j])))
                {
                    Quest        quest2        = MakeAndAddWorldObjectQuest(worldObjects[j], null);
                    ChoiceLetter choiceLetter2 = Find.Archive.ArchivablesListForReading.OfType <ChoiceLetter>().FirstOrDefault((ChoiceLetter x) => x.lookTargets != null && x.lookTargets.targets.Contains(worldObjects[j]));
                    if (choiceLetter2 != null)
                    {
                        quest2.description = choiceLetter2.text;
                    }
                }
            }
            int i;

            for (i = 0; i < worldObjects.Count; i++)
            {
                TradeRequestComp component2 = worldObjects[i].GetComponent <TradeRequestComp>();
                if (component2 != null && component2.ActiveRequest && !Find.QuestManager.QuestsListForReading.Any((Quest x) => x.PartsListForReading.Any((QuestPart y) => y is QuestPart_NoWorldObject && ((QuestPart_NoWorldObject)y).worldObject == worldObjects[i])))
                {
                    Quest        quest3        = MakeAndAddTradeRequestQuest(worldObjects[i], null, component2);
                    ChoiceLetter choiceLetter3 = Find.Archive.ArchivablesListForReading.OfType <ChoiceLetter>().FirstOrDefault((ChoiceLetter x) => x.lookTargets != null && x.lookTargets.targets.Contains(worldObjects[i]));
                    if (choiceLetter3 != null)
                    {
                        quest3.description = choiceLetter3.text;
                    }
                }
            }
        }
Esempio n. 14
0
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef != null)
            {
                if (roofDef.collapseLeavingThingDef != null && roofDef.collapseLeavingThingDef.passability == Traversability.Impassable)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        List <Thing> thingList = c.GetThingList(map);
                        for (int num = thingList.Count - 1; num >= 0; num--)
                        {
                            Thing thing = thingList[num];
                            map.roofCollapseBuffer.Notify_Crushed(thing);
                            Pawn       pawn  = thing as Pawn;
                            DamageInfo dinfo = default(DamageInfo);
                            if (pawn != null)
                            {
                                DamageDef      crush  = DamageDefOf.Crush;
                                int            amount = 99999;
                                BodyPartRecord brain  = pawn.health.hediffSet.GetBrain();
                                dinfo = new DamageInfo(crush, amount, -1f, null, brain, null, DamageInfo.SourceCategory.Collapse);
                            }
                            else
                            {
                                dinfo = new DamageInfo(DamageDefOf.Crush, 99999, -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                                dinfo.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken = null;
                            if (i == 0 && pawn != null)
                            {
                                battleLogEntry_DamageTaken = new BattleLogEntry_DamageTaken(pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken);
                            }
                            thing.TakeDamage(dinfo).InsertIntoLog(battleLogEntry_DamageTaken);
                            if (!thing.Destroyed && thing.def.destroyable)
                            {
                                thing.Destroy(DestroyMode.Vanish);
                            }
                        }
                    }
                }
                else
                {
                    List <Thing> thingList2 = c.GetThingList(map);
                    for (int num2 = thingList2.Count - 1; num2 >= 0; num2--)
                    {
                        Thing thing2 = thingList2[num2];
                        if (thing2.def.category == ThingCategory.Item || thing2.def.category == ThingCategory.Plant || thing2.def.category == ThingCategory.Building || thing2.def.category == ThingCategory.Pawn)
                        {
                            map.roofCollapseBuffer.Notify_Crushed(thing2);
                            float num3 = (float)RoofCollapserImmediate.ThinRoofCrushDamageRange.RandomInRange;
                            if (thing2.def.building != null)
                            {
                                num3 *= thing2.def.building.roofCollapseDamageMultiplier;
                            }
                            BattleLogEntry_DamageTaken battleLogEntry_DamageTaken2 = null;
                            if (thing2 is Pawn)
                            {
                                battleLogEntry_DamageTaken2 = new BattleLogEntry_DamageTaken(thing2 as Pawn, RulePackDefOf.DamageEvent_Ceiling, null);
                                Find.BattleLog.Add(battleLogEntry_DamageTaken2);
                            }
                            DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Crush, GenMath.RoundRandom(num3), -1f, null, null, null, DamageInfo.SourceCategory.Collapse);
                            dinfo2.SetBodyRegion(BodyPartHeight.Top, BodyPartDepth.Outside);
                            thing2.TakeDamage(dinfo2).InsertIntoLog(battleLogEntry_DamageTaken2);
                        }
                    }
                }
                if (roofDef.collapseLeavingThingDef != null)
                {
                    Thing thing3 = GenSpawn.Spawn(roofDef.collapseLeavingThingDef, c, map);
                    if (thing3.def.rotatable)
                    {
                        thing3.Rotation = Rot4.Random;
                    }
                }
                for (int j = 0; j < 1; j++)
                {
                    Vector3 a = c.ToVector3Shifted();
                    a += Gen.RandomHorizontalVector(0.6f);
                    MoteMaker.ThrowDustPuff(a, map, 2f);
                }
            }
        }
        protected virtual void ExplosionDamageThing(Explosion explosion, Thing t, List <Thing> damagedThings, IntVec3 cell)
        {
            if (t.def.category == ThingCategory.Mote || t.def.category == ThingCategory.Ethereal)
            {
                return;
            }
            if (damagedThings.Contains(t))
            {
                return;
            }
            damagedThings.Add(t);
            if (this.def == DamageDefOf.Bomb && t.def == ThingDefOf.Fire && !t.Destroyed)
            {
                t.Destroy(DestroyMode.Vanish);
                return;
            }
            float num;

            if (t.Position == explosion.Position)
            {
                num = (float)Rand.RangeInclusive(0, 359);
            }
            else
            {
                num = (t.Position - explosion.Position).AngleFlat;
            }
            DamageDef  damageDef          = this.def;
            float      amount             = (float)explosion.GetDamageAmountAt(cell);
            float      armorPenetrationAt = explosion.GetArmorPenetrationAt(cell);
            float      angle      = num;
            Thing      instigator = explosion.instigator;
            ThingDef   weapon     = explosion.weapon;
            DamageInfo dinfo      = new DamageInfo(damageDef, amount, armorPenetrationAt, angle, instigator, null, weapon, DamageInfo.SourceCategory.ThingOrUnknown, explosion.intendedTarget);

            if (this.def.explosionAffectOutsidePartsOnly)
            {
                dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
            }
            if (t.def.category == ThingCategory.Building)
            {
                int num2 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionBuildingDamageFactor);
                dinfo.SetAmount((float)num2);
            }
            else if (t.def.category == ThingCategory.Plant)
            {
                int num3 = Mathf.RoundToInt(dinfo.Amount * this.def.explosionPlantDamageFactor);
                dinfo.SetAmount((float)num3);
            }
            BattleLogEntry_ExplosionImpact battleLogEntry_ExplosionImpact = null;
            Pawn pawn = t as Pawn;

            if (pawn != null)
            {
                battleLogEntry_ExplosionImpact = new BattleLogEntry_ExplosionImpact(explosion.instigator, t, explosion.weapon, explosion.projectile, this.def);
                Find.BattleLog.Add(battleLogEntry_ExplosionImpact);
            }
            DamageWorker.DamageResult damageResult = t.TakeDamage(dinfo);
            damageResult.AssociateWithLog(battleLogEntry_ExplosionImpact);
            if (pawn != null && damageResult.wounded && pawn.stances != null)
            {
                pawn.stances.StaggerFor(95);
            }
        }