Beispiel #1
0
        public void CompleteConstruction(Pawn worker)
        {
            resourceContainer.ClearAndDestroyContents();
            Map map = base.Map;

            Destroy();
            if (this.GetStatValue(StatDefOf.WorkToBuild) > 150f && def.entityDefToBuild is ThingDef && ((ThingDef)def.entityDefToBuild).category == ThingCategory.Building)
            {
                SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(base.Position, map));
            }
            ThingDef thingDef = def.entityDefToBuild as ThingDef;
            Thing    thing    = null;

            if (thingDef != null)
            {
                thing = ThingMaker.MakeThing(thingDef, base.Stuff);
                thing.SetFactionDirect(base.Faction);
                CompQuality compQuality = thing.TryGetComp <CompQuality>();
                if (compQuality != null)
                {
                    QualityCategory q = QualityUtility.GenerateQualityCreatedByPawn(worker, SkillDefOf.Construction);
                    compQuality.SetQuality(q, ArtGenerationContext.Colony);
                    QualityUtility.SendCraftNotification(thing, worker);
                }
                CompArt compArt = thing.TryGetComp <CompArt>();
                if (compArt != null)
                {
                    if (compQuality == null)
                    {
                        compArt.InitializeArt(ArtGenerationContext.Colony);
                    }
                    compArt.JustCreatedBy(worker);
                }
                thing.HitPoints = Mathf.CeilToInt((float)HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints);
                GenSpawn.Spawn(thing, base.Position, map, base.Rotation, WipeMode.FullRefund);
                Building b;
                if ((b = thing as Building) != null)
                {
                    worker.GetLord()?.AddBuilding(b);
                }
            }
            else
            {
                map.terrainGrid.SetTerrain(base.Position, (TerrainDef)def.entityDefToBuild);
                FilthMaker.RemoveAllFilth(base.Position, map);
            }
            worker.records.Increment(RecordDefOf.ThingsConstructed);
            if (thing != null && thing.GetStatValue(StatDefOf.WorkToBuild) >= 9500f)
            {
                TaleRecorder.RecordTale(TaleDefOf.CompletedLongConstructionProject, worker, thing.def);
            }
        }
        // Token: 0x060000D7 RID: 215 RVA: 0x000066F8 File Offset: 0x000048F8
        public void CompleteConstruction(Pawn worker)
        {
            Map  map  = base.Map;
            bool flag = this.GetStatValue(StatDefOf.WorkToBuild, true) > 150f && this.def.entityDefToBuild is ThingDef && ((ThingDef)this.def.entityDefToBuild).category == ThingCategory.Building;

            if (flag)
            {
                SoundDefOf.Building_Complete.PlayOneShot(new TargetInfo(base.Position, map, false));
            }
            ThingDef thingDef = this.def.entityDefToBuild as ThingDef;
            Thing    thing    = null;
            bool     flag2    = thingDef != null;

            if (flag2)
            {
                thing = ThingMaker.MakeThing(thingDef, base.Stuff);
                thing.SetFactionDirect(base.Faction);
                CompQuality compQuality = thing.TryGetComp <CompQuality>();
                bool        flag3       = compQuality != null;
                if (flag3)
                {
                    int relevantSkillLevel = 1;
                    compQuality.SetQuality(QualityUtility.GenerateQualityCreatedByPawn(relevantSkillLevel, false), ArtGenerationContext.Colony);
                }
                CompArt compArt = thing.TryGetComp <CompArt>();
                bool    flag4   = compArt != null;
                if (flag4)
                {
                    bool flag5 = compQuality == null;
                    if (flag5)
                    {
                        compArt.InitializeArt(ArtGenerationContext.Colony);
                    }
                    compArt.JustCreatedBy(worker);
                }
                thing.HitPoints = Mathf.CeilToInt((float)this.HitPoints / (float)base.MaxHitPoints * (float)thing.MaxHitPoints);
                GenSpawn.Spawn(thing, base.Position, map, base.Rotation, WipeMode.FullRefund, false);
            }
            else
            {
                map.terrainGrid.SetTerrain(base.Position, (TerrainDef)this.def.entityDefToBuild);
                FilthMaker.RemoveAllFilth(base.Position, map);
            }
            bool flag6 = thingDef != null && (thingDef.passability == Traversability.Impassable || thingDef.Fillage == FillCategory.Full) && (thing == null || !(thing is Building_Door));

            if (flag6)
            {
                foreach (IntVec3 c in GenAdj.CellsOccupiedBy(base.Position, base.Rotation, this.def.Size))
                {
                    foreach (Thing thing2 in map.thingGrid.ThingsAt(c).ToList <Thing>())
                    {
                        bool flag7 = thing2 is Plant;
                        if (flag7)
                        {
                            thing2.Destroy(DestroyMode.KillFinalize);
                        }
                        else
                        {
                            bool flag8 = thing2.def.category == ThingCategory.Item || thing2 is Pawn;
                            if (flag8)
                            {
                                GenPlace.TryPlaceThing(thing2, thing2.Position, thing2.Map, ThingPlaceMode.Near, null, null, default(Rot4));
                            }
                        }
                    }
                }
            }
            worker.records.Increment(RecordDefOf.ThingsConstructed);
        }