示例#1
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            if (innerContainer.Count > 0 && (mode == DestroyMode.Deconstruct || mode == DestroyMode.KillFinalize))
            {
                if (mode != DestroyMode.Deconstruct)
                {
                    var list = new List <Pawn>();
                    foreach (var current in innerContainer)
                    {
                        if (current is Pawn pawn)
                        {
                            list.Add(pawn);
                        }
                    }

                    foreach (var current2 in list)
                    {
                        HealthUtility.DamageUntilDowned(current2);
                    }
                }

                EjectContents();
            }

            innerContainer.ClearAndDestroyContents();
            base.Destroy(mode);
        }
 public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     if (innerContainer.Count > 0 && (mode == DestroyMode.Deconstruct || mode == DestroyMode.KillFinalize) && !this.active && this.curTicksToGrow == this.totalTicksToGrow)
     {
         if (mode != DestroyMode.Deconstruct)
         {
             List <Pawn> list = new List <Pawn>();
             foreach (Thing item in (IEnumerable <Thing>)innerContainer)
             {
                 Pawn pawn = item as Pawn;
                 if (pawn != null)
                 {
                     list.Add(pawn);
                 }
             }
             foreach (Pawn item2 in list)
             {
                 HealthUtility.DamageUntilDowned(item2);
             }
         }
         EjectContents();
     }
     innerContainer.ClearAndDestroyContents();
     base.Destroy(mode);
 }
示例#3
0
        public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
        {
            if (innerContainer.Count > 0 && (mode == DestroyMode.Deconstruct || mode == DestroyMode.KillFinalize))
            {
                EjectAllContents();
            }

            innerContainer.ClearAndDestroyContents();
            base.Destroy(mode);
        }
 private void CompleteUpgrade()
 {
     beginUpgrade = false;
     if (!complete)
     {
         complete = true;
         ingredients.ClearAndDestroyContents(DestroyMode.Vanish);
         UpdateDesignation();
         PostUpgrade(false);
     }
 }
示例#5
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);
            }
        }
 private void CompleteUpgrade()
 {
     if (complete)
     {
         return;
     }
     complete = true;
     ingredients.ClearAndDestroyContents();
     UpdateDesignation();
     if (Props.statModifiers.Any(m => m.stat == StatDefOf.MaxHitPoints))
     {
         parent.HitPoints = parent.MaxHitPoints;
     }
     parent.BroadcastCompSignal(UpgradeCompleteSignal);
 }
 private void Arrived()
 {
     if (arrivalAction != null)
     {
         try
         {
             arrivalAction.Arrived(ArtilleryStrikes.ToList(), destinationTile);
         }
         catch (Exception ex)
         {
             Log.Error($"Exception in artillery strike arrival action: {ex}");
         }
     }
     else
     {
         innerContainer.ClearAndDestroyContents();
     }
     Find.WorldObjects.Remove(this);
 }
示例#8
0
 private void CompleteUpgrade()
 {
     //Log.Message("完成升级" + UpgradeCompleteSignal);
     if (curComplete)
     {
         return;
     }
     curComplete = true;
     upgradeCount++;
     workDone  = 0;
     wantsWork = false;
     ingredients.ClearAndDestroyContents();
     UpdateDesignation();
     if (Props.statModifiers.Any(m => m.stat == StatDefOf.MaxHitPoints))
     {
         parent.HitPoints = parent.MaxHitPoints;
     }
     //Log.Message("广播信号" + UpgradeCompleteSignal);
     parent.BroadcastCompSignal(UpgradeCompleteSignal);
 }
        // Token: 0x06000027 RID: 39 RVA: 0x00002C28 File Offset: 0x00000E28
        public override void Tick()
        {
            base.Tick();
            AdjustPowerNeed();
            if (flickableComp != null && (flickableComp == null || !flickableComp.SwitchIsOn))
            {
                return;
            }

            switch (crafterStatus)
            {
            case CrafterStatus.Filling:
            {
                ExtraCrafterTickAction();
                var enumerable   = orderProcessor.PendingRequests();
                var isEnumerable = enumerable == null || !enumerable.Any();

                if (isEnumerable)
                {
                    StartPrinting();
                }

                break;
            }

            case CrafterStatus.Crafting:
                ExtraCrafterTickAction();
                if (powerComp.PowerOn)
                {
                    nextResourceTick--;
                    if (nextResourceTick <= 0)
                    {
                        nextResourceTick     = crafterProperties.resourceTick;
                        using var enumerator = orderProcessor.requestedItems.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            var thingOrderRequest = enumerator.Current;
                            if (ingredients.All(thing => thing.def != thingOrderRequest?.thingDef))
                            {
                                continue;
                            }

                            var thing2 = ingredients.First(thing =>
                                                           thing.def == thingOrderRequest?.thingDef);

                            if (thingOrderRequest == null)
                            {
                                continue;
                            }

                            var count = Math.Min(
                                (int)Math.Ceiling(thingOrderRequest.amount /
                                                  (crafterProperties.ticksToCraft /
                                                   (float)crafterProperties.resourceTick)),
                                thing2.stackCount);
                            ingredients.Take(thing2, count).Destroy();
                        }
                    }

                    if (craftingTicksLeft > 0)
                    {
                        craftingTicksLeft--;
                        return;
                    }

                    crafterStatus = CrafterStatus.Finished;
                }

                break;

            case CrafterStatus.Finished:
                if (pawnBeingCrafted != null)
                {
                    ExtraCrafterTickAction();
                    ingredients.ClearAndDestroyContents();
                    FinishAction();
                    pawnBeingCrafted = null;
                    crafterStatus    = CrafterStatus.Idle;
                }

                break;

            default:
                return;
            }
        }
示例#10
0
 public void DestroyAll(DestroyMode mode = DestroyMode.Vanish)
 {
     wornApparel.ClearAndDestroyContents(mode);
 }
示例#11
0
 public void StopQuest()
 {
     active            = false;
     requestingFaction = null;
     rewards.ClearAndDestroyContents();
 }
 public override void PostDestroy()
 {
     base.PostDestroy();
     contents.ClearAndDestroyContents();
 }
示例#13
0
 public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     innerContainer.TryDropAll(InteractionCell, Map, ThingPlaceMode.Near);
     innerContainer.ClearAndDestroyContents();
     base.Destroy(mode);
 }
        public override void Tick()
        {
            base.Tick();

            AdjustPowerNeed();

            if (!powerComp.PowerOn && soundSustainer != null && !soundSustainer.Ended)
            {
                soundSustainer.End();
            }

            if (flickableComp == null || (flickableComp != null && flickableComp.SwitchIsOn))
            {
                //State machine
                switch (printerStatus)
                {
                case CrafterStatus.Filling:
                {
                    //Emit smoke
                    if (powerComp.PowerOn && Current.Game.tickManager.TicksGame % 300 == 0)
                    {
                        MoteMaker.ThrowSmoke(Position.ToVector3(), Map, 1f);
                    }

                    //If we aren't being filled, then start.
                    var  pendingRequests = orderProcessor.PendingRequests();
                    bool startPrinting   = pendingRequests == null;
                    if (pendingRequests != null && pendingRequests.Count() == 0)
                    {
                        startPrinting = true;
                    }

                    if (startPrinting)
                    {
                        //Initiate printing phase.
                        StartPrinting();
                    }
                }
                break;

                case CrafterStatus.Crafting:
                {
                    if (powerComp.PowerOn)
                    {
                        //Emit smoke
                        if (Current.Game.tickManager.TicksGame % 100 == 0)
                        {
                            MoteMaker.ThrowSmoke(Position.ToVector3(), Map, 1.33f);
                        }

                        //Visual effects
                        if (Current.Game.tickManager.TicksGame % 250 == 0)
                        {
                            for (int i = 0; i < 3; i++)
                            {
                                MoteMaker.ThrowMicroSparks(Position.ToVector3() + new Vector3(Rand.Range(-1, 1), 0f, Rand.Range(-1, 1)), Map);
                            }
                        }

                        //Sound effect
                        if (soundSustainer == null || soundSustainer.Ended)
                        {
                            SoundDef soundDef = printerProperties.craftingSound;
                            if (soundDef != null && soundDef.sustain)
                            {
                                SoundInfo info = SoundInfo.InMap(this, MaintenanceType.PerTick);
                                soundSustainer = soundDef.TrySpawnSustainer(info);
                            }
                        }

                        if (soundSustainer != null && !soundSustainer.Ended)
                        {
                            soundSustainer.Maintain();
                        }

                        //Periodically use resources.
                        nextResourceTick--;

                        if (nextResourceTick <= 0)
                        {
                            nextResourceTick = printerProperties.resourceTick;

                            //Deduct resources from each category.
                            foreach (ThingOrderRequest thingOrderRequest in orderProcessor.requestedItems)
                            {
                                if (thingOrderRequest.nutrition)
                                {
                                    //Food
                                    if (CountNutrition() > 0f)
                                    {
                                        //Grab first stack of Nutrition.
                                        Thing item = ingredients.First(thing => thing.def.IsIngestible);

                                        if (item != null)
                                        {
                                            int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((double)(printerProperties.ticksToCraft + extraTimeCost) / printerProperties.resourceTick)));

                                            int   amount   = Math.Min(resourceTickAmount, item.stackCount);
                                            Thing outThing = null;

                                            Corpse outCorpse = item as Corpse;
                                            if (outCorpse != null)
                                            {
                                                if (outCorpse.IsDessicated())
                                                {
                                                    //If rotten, just drop it.
                                                    ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing);
                                                }
                                                else
                                                {
                                                    //Not rotten, dump all equipment.
                                                    ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing);
                                                    outCorpse.InnerPawn?.equipment?.DropAllEquipment(InteractionCell, false);
                                                    outCorpse.InnerPawn?.apparel?.DropAll(InteractionCell, false);

                                                    item.Destroy();
                                                }
                                            }
                                            else
                                            {
                                                Thing takenItem = ingredients.Take(item, amount);
                                                takenItem.Destroy();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //Item
                                    if (ingredients.Any(thing => thing.def == thingOrderRequest.thingDef))
                                    {
                                        //Grab first stack of Plasteel.
                                        Thing item = ingredients.First(thing => thing.def == thingOrderRequest.thingDef);

                                        if (item != null)
                                        {
                                            int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((float)(printerProperties.ticksToCraft + extraTimeCost) / printerProperties.resourceTick)));

                                            int   amount    = Math.Min(resourceTickAmount, item.stackCount);
                                            Thing takenItem = ingredients.Take(item, amount);

                                            takenItem.Destroy();
                                        }
                                    }
                                }
                            }
                        }

                        //Are we done yet?
                        if (printingTicksLeft > 0)
                        {
                            printingTicksLeft--;
                        }
                        else
                        {
                            printerStatus = CrafterStatus.Finished;
                        }
                    }
                }
                break;

                case CrafterStatus.Finished:
                {
                    if (pawnToPrint != null)
                    {
                        //Clear remaining materials.
                        ingredients.ClearAndDestroyContents();

                        //Add effects
                        FilthMaker.TryMakeFilth(InteractionCell, Map, RimWorld.ThingDefOf.Filth_Slime, 5);

                        //Spawn
                        GenSpawn.Spawn(pawnToPrint, InteractionCell, Map);
                        pawnToPrint.health.AddHediff(RimWorld.HediffDefOf.CryptosleepSickness);
                        pawnToPrint.needs.mood.thoughts.memories.TryGainMemory(NeedsDefOf.ChJAndroidSpawned);

                        //Make and send letter.
                        ChoiceLetter letter = LetterMaker.MakeLetter("AndroidPrintedLetterLabel".Translate(pawnToPrint.Name.ToStringShort), "AndroidPrintedLetterDescription".Translate(pawnToPrint.Name.ToStringFull), LetterDefOf.PositiveEvent, pawnToPrint);
                        Find.LetterStack.ReceiveLetter(letter);

                        //Reset
                        pawnToPrint   = null;
                        printerStatus = CrafterStatus.Idle;
                        extraTimeCost = 0;
                        orderProcessor.requestedItems.Clear();
                    }
                }
                break;

                default:
                {
                    if (soundSustainer != null && !soundSustainer.Ended)
                    {
                        soundSustainer.End();
                    }
                }
                break;
                }
            }
        }
示例#15
0
        public override void Tick()
        {
            base.Tick();

            AdjustPowerNeed();

            if (flickableComp == null || (flickableComp != null && flickableComp.SwitchIsOn))
            {
                //State machine
                switch (crafterStatus)
                {
                case CrafterStatus.Filling:
                {
                    ExtraCrafterTickAction();

                    //If we aren't being filled, then start.
                    var  pendingRequests = orderProcessor.PendingRequests();
                    bool startPrinting   = pendingRequests == null;
                    if (pendingRequests != null && pendingRequests.Count() == 0)
                    {
                        startPrinting = true;
                    }

                    if (startPrinting)
                    {
                        //Initiate printing phase.
                        StartPrinting();
                    }
                }
                break;

                case CrafterStatus.Crafting:
                {
                    ExtraCrafterTickAction();

                    if (powerComp.PowerOn)
                    {
                        //Periodically use resources.
                        nextResourceTick--;

                        if (nextResourceTick <= 0)
                        {
                            nextResourceTick = printerProperties.resourceTick;

                            //Deduct resources from each category.
                            foreach (ThingOrderRequest thingOrderRequest in orderProcessor.requestedItems)
                            {
                                if (thingOrderRequest.nutrition)
                                {
                                    //Food
                                    if (CountNutrition() > 0f)
                                    {
                                        //Grab first stack of Nutrition.
                                        Thing item = ingredients.First(thing => thing.def.IsIngestible);

                                        if (item != null)
                                        {
                                            int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((double)CraftingTicks / printerProperties.resourceTick)));

                                            int   amount   = Math.Min(resourceTickAmount, item.stackCount);
                                            Thing outThing = null;

                                            Corpse outCorpse = item as Corpse;
                                            if (outCorpse != null)
                                            {
                                                if (outCorpse.IsDessicated())
                                                {
                                                    //If rotten, just drop it.
                                                    ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing);
                                                }
                                                else
                                                {
                                                    //Not rotten, dump all equipment.
                                                    ingredients.TryDrop(outCorpse, InteractionCell, Map, ThingPlaceMode.Near, 1, out outThing);
                                                    outCorpse.InnerPawn?.equipment?.DropAllEquipment(InteractionCell, false);
                                                    outCorpse.InnerPawn?.apparel?.DropAll(InteractionCell, false);

                                                    item.Destroy();
                                                }
                                            }
                                            else
                                            {
                                                Thing takenItem = ingredients.Take(item, amount);
                                                takenItem.Destroy();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    //Item
                                    if (ingredients.Any(thing => thing.def == thingOrderRequest.thingDef))
                                    {
                                        //Grab first stack of Plasteel.
                                        Thing item = ingredients.First(thing => thing.def == thingOrderRequest.thingDef);

                                        if (item != null)
                                        {
                                            int resourceTickAmount = (int)Math.Ceiling((thingOrderRequest.amount / ((float)CraftingTicks / printerProperties.resourceTick)));

                                            int   amount    = Math.Min(resourceTickAmount, item.stackCount);
                                            Thing takenItem = ingredients.Take(item, amount);

                                            takenItem.Destroy();
                                        }
                                    }
                                }
                            }
                        }

                        //Are we done yet?
                        if (craftingTicksLeft > 0)
                        {
                            craftingTicksLeft--;
                        }
                        else
                        {
                            crafterStatus = CrafterStatus.Finished;
                        }
                    }
                }
                break;

                case CrafterStatus.Finished:
                {
                    if (pawnBeingCrafted != null)
                    {
                        ExtraCrafterTickAction();

                        //Clear remaining materials.
                        ingredients.ClearAndDestroyContents();

                        //Spawn
                        GenSpawn.Spawn(pawnBeingCrafted, InteractionCell, Map);
                        if (printerProperties.hediffOnPawnCrafted != null)
                        {
                            pawnBeingCrafted.health.AddHediff(printerProperties.hediffOnPawnCrafted);
                        }

                        if (printerProperties.thoughtOnPawnCrafted != null)
                        {
                            pawnBeingCrafted.needs.mood.thoughts.memories.TryGainMemory(printerProperties.thoughtOnPawnCrafted);
                        }

                        //Make and send letter.
                        ChoiceLetter letter = LetterMaker.MakeLetter(printerProperties.pawnCraftedLetterLabel.Translate(pawnBeingCrafted.Name.ToStringShort), printerProperties.pawnCraftedLetterText.Translate(pawnBeingCrafted.Name.ToStringFull), LetterDefOf.PositiveEvent, pawnBeingCrafted);
                        Find.LetterStack.ReceiveLetter(letter);

                        //Reset
                        pawnBeingCrafted = null;
                        crafterStatus    = CrafterStatus.Idle;

                        FinishAction();
                    }
                }
                break;

                default:
                    break;
                }
            }
        }
示例#16
0
 public override void Destroy(DestroyMode mode = DestroyMode.Vanish)
 {
     base.Destroy(mode);
     innerContainer.ClearAndDestroyContents();
 }
示例#17
0
 public void Disable()
 {
     expiration = -1;
     rewards.ClearAndDestroyContents();
 }