public static void DropRoofInCells(List <IntVec3> cells, Map map, List <Thing> outCrushedThings = null)
        {
            if (cells.NullOrEmpty <IntVec3>())
            {
                return;
            }
            IntVec3 cell = IntVec3.Invalid;

            for (int i = 0; i < cells.Count; i++)
            {
                if (cells[i].Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseOne(cells[i], map, outCrushedThings);
                }
            }
            for (int j = 0; j < cells.Count; j++)
            {
                if (cells[j].Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseTwo(cells[j], map);
                    cell = cells[j];
                }
            }
            if (cell.IsValid)
            {
                SoundDefOf.Roof_Collapse.PlayOneShot(new TargetInfo(cell, map, false));
            }
        }
Exemplo n.º 2
0
 public static void DropRoofInCells(IntVec3 c, Map map, List <Thing> outCrushedThings = null)
 {
     if (c.Roofed(map))
     {
         RoofCollapserImmediate.DropRoofInCellPhaseOne(c, map, outCrushedThings);
         RoofCollapserImmediate.DropRoofInCellPhaseTwo(c, map);
         SoundDefOf.Roof_Collapse.PlayOneShot(new TargetInfo(c, map, false));
     }
 }
Exemplo n.º 3
0
 public static void DropRoofInCells(IntVec3 c, Map map)
 {
     if (c.Roofed(map))
     {
         RoofCollapserImmediate.DropRoofInCellPhaseOne(c, map);
         RoofCollapserImmediate.DropRoofInCellPhaseTwo(c, map);
         SoundDefOf.RoofCollapse.PlayOneShot(new TargetInfo(c, map, false));
     }
 }
Exemplo n.º 4
0
 private void ImpactSomething()
 {
     if (base.def.projectile.flyOverhead)
     {
         RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
         if (roofDef != null)
         {
             if (roofDef.isThickRoof)
             {
                 base.def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
                 this.Destroy(DestroyMode.Vanish);
                 return;
             }
             if (base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full)
             {
                 RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map);
             }
         }
     }
     if (this.assignedTarget != null)
     {
         Pawn pawn = this.assignedTarget as Pawn;
         if (pawn != null && pawn.GetPosture() != 0 && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25 && Rand.Value > 0.20000000298023224)
         {
             this.Impact(null);
         }
         else
         {
             this.Impact(this.assignedTarget);
         }
     }
     else
     {
         Projectile.cellThingsFiltered.Clear();
         List <Thing> thingList = base.Position.GetThingList(base.Map);
         for (int i = 0; i < thingList.Count; i++)
         {
             Thing thing = thingList[i];
             if (thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant)
             {
                 Projectile.cellThingsFiltered.Add(thing);
             }
         }
         Projectile.cellThingsFiltered.Shuffle();
         for (int j = 0; j < Projectile.cellThingsFiltered.Count; j++)
         {
             Thing t = Projectile.cellThingsFiltered[j];
             if (Rand.Value < Projectile.ImpactSomethingHitThingChance(t))
             {
                 this.Impact(Projectile.cellThingsFiltered.RandomElement());
                 return;
             }
         }
         this.Impact(null);
     }
 }
Exemplo n.º 5
0
 private static void TryAddToCrushedThingsList(Thing t, List <Thing> outCrushedThings)
 {
     if (outCrushedThings != null)
     {
         if (!outCrushedThings.Contains(t) && RoofCollapserImmediate.WorthMentioningInCrushLetter(t))
         {
             outCrushedThings.Add(t);
         }
     }
 }
Exemplo n.º 6
0
        public void CollapseRoofsMarkedToCollapse()
        {
            RoofCollapseBuffer roofCollapseBuffer = map.roofCollapseBuffer;

            if (!roofCollapseBuffer.CellsMarkedToCollapse.Any())
            {
                return;
            }
            tmpCrushedThings.Clear();
            RoofCollapserImmediate.DropRoofInCells(roofCollapseBuffer.CellsMarkedToCollapse, map, tmpCrushedThings);
            if (tmpCrushedThings.Any())
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("RoofCollapsed".Translate());
                stringBuilder.AppendLine();
                stringBuilder.AppendLine("TheseThingsCrushed".Translate());
                tmpCrushedNames.Clear();
                for (int i = 0; i < tmpCrushedThings.Count; i++)
                {
                    Thing  thing = tmpCrushedThings[i];
                    Corpse corpse;
                    if ((corpse = thing as Corpse) == null || !corpse.Bugged)
                    {
                        string item = thing.LabelShortCap;
                        if (thing.def.category == ThingCategory.Pawn)
                        {
                            item = thing.LabelCap;
                        }
                        if (!tmpCrushedNames.Contains(item))
                        {
                            tmpCrushedNames.Add(item);
                        }
                    }
                }
                foreach (string tmpCrushedName in tmpCrushedNames)
                {
                    stringBuilder.AppendLine("    -" + tmpCrushedName);
                }
                Find.LetterStack.ReceiveLetter("LetterLabelRoofCollapsed".Translate(), stringBuilder.ToString().TrimEndNewlines(), LetterDefOf.NegativeEvent, new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], map));
            }
            else
            {
                Messages.Message("RoofCollapsed".Translate(), new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], map), MessageTypeDefOf.SilentInput);
            }
            tmpCrushedThings.Clear();
            roofCollapseBuffer.Clear();
        }
Exemplo n.º 7
0
        public void CollapseRoofsMarkedToCollapse()
        {
            RoofCollapseBuffer roofCollapseBuffer = this.map.roofCollapseBuffer;

            if (roofCollapseBuffer.CellsMarkedToCollapse.Any <IntVec3>())
            {
                this.tmpCrushedThings.Clear();
                RoofCollapserImmediate.DropRoofInCells(roofCollapseBuffer.CellsMarkedToCollapse, this.map, this.tmpCrushedThings);
                if (this.tmpCrushedThings.Any <Thing>())
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("RoofCollapsed".Translate());
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("TheseThingsCrushed".Translate());
                    this.tmpCrushedNames.Clear();
                    for (int i = 0; i < this.tmpCrushedThings.Count; i++)
                    {
                        Thing  thing = this.tmpCrushedThings[i];
                        string item  = thing.LabelShort.CapitalizeFirst();
                        if (thing.def.category == ThingCategory.Pawn)
                        {
                            item = thing.LabelCap;
                        }
                        if (!this.tmpCrushedNames.Contains(item))
                        {
                            this.tmpCrushedNames.Add(item);
                        }
                    }
                    foreach (string str in this.tmpCrushedNames)
                    {
                        stringBuilder.AppendLine("    -" + str);
                    }
                    Find.LetterStack.ReceiveLetter("LetterLabelRoofCollapsed".Translate(), stringBuilder.ToString().TrimEndNewlines(), LetterDefOf.NegativeEvent, new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], this.map, false), null, null);
                }
                else
                {
                    string text = "RoofCollapsed".Translate();
                    Messages.Message(text, new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], this.map, false), MessageTypeDefOf.SilentInput, true);
                }
                this.tmpCrushedThings.Clear();
                roofCollapseBuffer.Clear();
            }
        }
Exemplo n.º 8
0
        public void CollapseRoofsMarkedToCollapse()
        {
            RoofCollapseBuffer roofCollapseBuffer = this.map.roofCollapseBuffer;

            if (roofCollapseBuffer.CellsMarkedToCollapse.Count > 0)
            {
                RoofCollapserImmediate.DropRoofInCells(roofCollapseBuffer.CellsMarkedToCollapse, this.map);
                if (roofCollapseBuffer.CrushedThingsForLetter.Count > 0)
                {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("RoofCollapsed".Translate());
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine("TheseThingsCrushed".Translate());
                    HashSet <string> hashSet = new HashSet <string>();
                    foreach (Thing item2 in roofCollapseBuffer.CrushedThingsForLetter)
                    {
                        string item = item2.LabelShort.CapitalizeFirst();
                        if (item2.def.category == ThingCategory.Pawn)
                        {
                            item = item2.LabelCap;
                        }
                        if (!hashSet.Contains(item))
                        {
                            hashSet.Add(item);
                        }
                    }
                    foreach (string item3 in hashSet)
                    {
                        stringBuilder.AppendLine("    -" + item3);
                    }
                    Find.LetterStack.ReceiveLetter("LetterLabelRoofCollapsed".Translate(), stringBuilder.ToString(), LetterDefOf.NegativeEvent, new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], this.map, false), null);
                }
                else
                {
                    string text = "RoofCollapsed".Translate();
                    Messages.Message(text, new TargetInfo(roofCollapseBuffer.CellsMarkedToCollapse[0], this.map, false), MessageTypeDefOf.NegativeHealthEvent);
                }
                roofCollapseBuffer.Clear();
            }
        }
        public static void DropRoofInCells(IEnumerable <IntVec3> cells, Map map, List <Thing> outCrushedThings = null)
        {
            IntVec3 cell = IntVec3.Invalid;

            foreach (IntVec3 current in cells)
            {
                if (current.Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseOne(current, map, outCrushedThings);
                }
            }
            foreach (IntVec3 current2 in cells)
            {
                if (current2.Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseTwo(current2, map);
                    cell = current2;
                }
            }
            if (cell.IsValid)
            {
                SoundDefOf.Roof_Collapse.PlayOneShot(new TargetInfo(cell, map, false));
            }
        }
Exemplo n.º 10
0
        public static void DropRoofInCells(IEnumerable <IntVec3> cells, Map map)
        {
            IntVec3 cell = IntVec3.Invalid;

            foreach (IntVec3 cell2 in cells)
            {
                if (cell2.Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseOne(cell2, map);
                }
            }
            foreach (IntVec3 cell3 in cells)
            {
                if (cell3.Roofed(map))
                {
                    RoofCollapserImmediate.DropRoofInCellPhaseTwo(cell3, map);
                    cell = cell3;
                }
            }
            if (cell.IsValid)
            {
                SoundDefOf.RoofCollapse.PlayOneShot(new TargetInfo(cell, map, false));
            }
        }
Exemplo n.º 11
0
        private void ImpactSomething()
        {
            if (this.def.projectile.flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                if (roofDef != null)
                {
                    if (roofDef.isThickRoof)
                    {
                        this.ThrowDebugText("hit-thick-roof", base.Position);
                        this.def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(DestroyMode.Vanish);
                        return;
                    }
                    if (base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            if (!this.usedTarget.HasThing || !this.CanHit(this.usedTarget.Thing))
            {
                Projectile.cellThingsFiltered.Clear();
                List <Thing> thingList = base.Position.GetThingList(base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && this.CanHit(thing))
                    {
                        Projectile.cellThingsFiltered.Add(thing);
                    }
                }
                Projectile.cellThingsFiltered.Shuffle <Thing>();
                for (int j = 0; j < Projectile.cellThingsFiltered.Count; j++)
                {
                    Thing thing2 = Projectile.cellThingsFiltered[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (pawn.GetPosture() != PawnPosture.Standing && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25f)
                        {
                            num *= 0.2f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    if (Rand.Chance(num))
                    {
                        this.ThrowDebugText("hit-" + num.ToStringPercent(), base.Position);
                        this.Impact(Projectile.cellThingsFiltered.RandomElement <Thing>());
                        return;
                    }
                    this.ThrowDebugText("miss-" + num.ToStringPercent(), base.Position);
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && pawn2.GetPosture() != PawnPosture.Standing && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25f && !Rand.Chance(0.2f))
            {
                this.ThrowDebugText("miss-laying", base.Position);
                this.Impact(null);
                return;
            }
            this.Impact(this.usedTarget.Thing);
        }
        private static void DropRoofInCellPhaseOne(IntVec3 c, Map map, List <Thing> outCrushedThings)
        {
            RoofDef roofDef = map.roofGrid.RoofAt(c);

            if (roofDef == null)
            {
                return;
            }
            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.Kill(new DamageInfo?(new DamageInfo(DamageDefOf.Crush, 99999f, 999f, -1f, null, null, null, DamageInfo.SourceCategory.Collapse, null)), null);
                        }
                    }
                }
            }
            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);
            }
        }