public override void Tick()
        {
            if (!base.Spawned)
            {
                return;
            }
            sustainer.Maintain();
            Vector3 vector = base.Position.ToVector3Shifted();

            if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out var result))
            {
                FilthMaker.TryMakeFilth(result, base.Map, filthTypes.RandomElement());
            }
            if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
            {
                Vector3 loc = new Vector3(vector.x, 0f, vector.z);
                loc.y = AltitudeLayer.MoteOverhead.AltitudeFor();
                MoteMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
            }
            if (secondarySpawnTick > Find.TickManager.TicksGame)
            {
                return;
            }
            sustainer.End();
            Map     map      = base.Map;
            IntVec3 position = base.Position;

            Destroy();
            if (spawnHive)
            {
                Hive obj = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), position, map);
                obj.SetFaction(Faction.OfInsects);
                obj.questTags = questTags;
                foreach (CompSpawner comp in obj.GetComps <CompSpawner>())
                {
                    if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                    {
                        comp.TryDoSpawn();
                        break;
                    }
                }
            }
            if (!(insectsPoints > 0f))
            {
                return;
            }
            insectsPoints = Mathf.Max(insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
            float       pointsLeft = insectsPoints;
            List <Pawn> list       = new List <Pawn>();
            int         num        = 0;
            PawnKindDef result2;

            for (; pointsLeft > 0f; pointsLeft -= result2.combatPower)
            {
                num++;
                if (num > 1000)
                {
                    Log.Error("Too many iterations.");
                    break;
                }
                if (!Hive.spawnablePawnKinds.Where((PawnKindDef x) => x.combatPower <= pointsLeft).TryRandomElement(out result2))
                {
                    break;
                }
                Pawn pawn = PawnGenerator.GeneratePawn(result2, Faction.OfInsects);
                GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                list.Add(pawn);
            }
            if (list.Any())
            {
                LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, canKidnap: true, canTimeoutOrFlee: false), map, list);
            }
        }
Пример #2
0
 public static void MakeStaticMote(IntVec3 cell, Map map, ThingDef moteDef, float scale = 1f)
 {
     MoteMaker.MakeStaticMote(cell.ToVector3Shifted(), map, moteDef, scale);
 }
Пример #3
0
        public static void DoRecruit(Pawn recruiter, Pawn recruitee, float recruitChance, out string letterLabel, out string letter, bool useAudiovisualEffects = true, bool sendLetter = true)
        {
            letterLabel   = null;
            letter        = null;
            recruitChance = Mathf.Clamp01(recruitChance);
            string value = recruitee.LabelIndefinite();

            if (recruitee.guest != null)
            {
                recruitee.guest.SetGuestStatus(null);
            }
            bool flag = recruitee.Name != null;

            if (recruitee.Faction != recruiter.Faction)
            {
                recruitee.SetFaction(recruiter.Faction, recruiter);
            }
            if (recruitee.RaceProps.Humanlike)
            {
                if (useAudiovisualEffects)
                {
                    letterLabel = "LetterLabelMessageRecruitSuccess".Translate();
                    if (sendLetter)
                    {
                        Find.LetterStack.ReceiveLetter(letterLabel, "MessageRecruitSuccess".Translate(recruiter, recruitee, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")), LetterDefOf.PositiveEvent, recruitee);
                    }
                }
                TaleRecorder.RecordTale(TaleDefOf.Recruited, recruiter, recruitee);
                recruiter.records.Increment(RecordDefOf.PrisonersRecruited);
                recruitee.needs.mood.thoughts.memories.TryGainMemory(ThoughtDefOf.RecruitedMe, recruiter);
            }
            else
            {
                if (useAudiovisualEffects)
                {
                    if (!flag)
                    {
                        Messages.Message("MessageTameAndNameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruitee.Name.ToStringFull, recruiter.Named("RECRUITER"), recruitee.Named("RECRUITEE")).AdjustedFor(recruitee), recruitee, MessageTypeDefOf.PositiveEvent);
                    }
                    else
                    {
                        Messages.Message("MessageTameSuccess".Translate(recruiter.LabelShort, value, recruitChance.ToStringPercent(), recruiter.Named("RECRUITER")), recruitee, MessageTypeDefOf.PositiveEvent);
                    }
                    if (recruiter.Spawned && recruitee.Spawned)
                    {
                        MoteMaker.ThrowText((recruiter.DrawPos + recruitee.DrawPos) / 2f, recruiter.Map, "TextMote_TameSuccess".Translate(recruitChance.ToStringPercent()), 8f);
                    }
                }
                recruiter.records.Increment(RecordDefOf.AnimalsTamed);
                RelationsUtility.TryDevelopBondRelation(recruiter, recruitee, 0.01f);
                float chance = Mathf.Lerp(0.02f, 1f, recruitee.RaceProps.wildness);
                if (Rand.Chance(chance) || recruitee.IsWildMan())
                {
                    TaleRecorder.RecordTale(TaleDefOf.TamedAnimal, recruiter, recruitee);
                }
                if (PawnsFinder.AllMapsWorldAndTemporary_Alive.Count((Pawn p) => p.playerSettings != null && p.playerSettings.Master == recruiter) >= 5)
                {
                    TaleRecorder.RecordTale(TaleDefOf.IncreasedMenagerie, recruiter, recruitee);
                }
            }
            if (recruitee.caller != null)
            {
                recruitee.caller.DoCall();
            }
        }
Пример #4
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedOrNull(this.BedInd);
                    this.FailOnDespawnedOrNull(this.PartnerInd);
                    this.FailOn(() => !base.Partner.health.capacities.CanBeAwake);
                    this.KeepLyingDown(this.BedInd);
                    this.$current = Toils_Bed.ClaimBedIfNonMedical(this.BedInd, TargetIndex.None);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$current = Toils_Bed.GotoBed(this.BedInd);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                {
                    Toil preparePartner = new Toil();
                    preparePartner.initAction = delegate()
                    {
                        if (base.Partner.CurJob == null || base.Partner.CurJob.def != JobDefOf.Lovin)
                        {
                            Job newJob = new Job(JobDefOf.Lovin, this.pawn, base.Bed);
                            base.Partner.jobs.StartJob(newJob, JobCondition.InterruptForced, null, false, true, null, null, false);
                            this.ticksLeft = (int)(2500f * Mathf.Clamp(Rand.Range(0.1f, 1.1f), 0.1f, 2f));
                        }
                        else
                        {
                            this.ticksLeft = 9999999;
                        }
                    };
                    preparePartner.defaultCompleteMode = ToilCompleteMode.Instant;
                    this.$current = preparePartner;
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);
                }

                case 3u:
                    doLovin = Toils_LayDown.LayDown(this.BedInd, true, false, false, false);
                    doLovin.FailOn(() => base.Partner.CurJob == null || base.Partner.CurJob.def != JobDefOf.Lovin);
                    doLovin.AddPreTickAction(delegate
                    {
                        this.ticksLeft--;
                        if (this.ticksLeft <= 0)
                        {
                            base.ReadyForNextToil();
                        }
                        else if (this.pawn.IsHashIntervalTick(100))
                        {
                            MoteMaker.ThrowMetaIcon(this.pawn.Position, this.pawn.Map, ThingDefOf.Mote_Heart);
                        }
                    });
                    doLovin.AddFinishAction(delegate
                    {
                        Thought_Memory newThought = (Thought_Memory)ThoughtMaker.MakeThought(ThoughtDefOf.GotSomeLovin);
                        this.pawn.needs.mood.thoughts.memories.TryGainMemory(newThought, base.Partner);
                        this.pawn.mindState.canLovinTick = Find.TickManager.TicksGame + base.GenerateRandomMinTicksToNextLovin(this.pawn);
                    });
                    doLovin.socialMode = RandomSocialMode.Off;
                    this.$current      = doLovin;
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }
Пример #5
0
        public static void ThrowDustPuff(IntVec3 cell, Map map, float scale)
        {
            Vector3 loc = cell.ToVector3() + new Vector3(Rand.Value, 0f, Rand.Value);

            MoteMaker.ThrowDustPuff(loc, map, scale);
        }
Пример #6
0
 public override void StartStrike()
 {
     base.StartStrike();
     MoteMaker.MakePowerBeamMote(base.Position, base.Map);
 }
Пример #7
0
        protected override void DoAction(object[] args)
        {
            if (this.points <= 0f)
            {
                return;
            }
            List <Pawn> list = new List <Pawn>();

            foreach (Pawn current in this.GenerateAmbushPawns())
            {
                IntVec3 loc;
                if (this.spawnPawnsOnEdge)
                {
                    if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(base.Map) && !x.Fogged(base.Map) && base.Map.reachability.CanReachColony(x), base.Map, CellFinder.EdgeRoadChance_Ignore, out loc))
                    {
                        Find.WorldPawns.PassToWorld(current, PawnDiscardDecideMode.Discard);
                        break;
                    }
                }
                else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(this.spawnAround, this.spawnNear, base.Map, out loc))
                {
                    Find.WorldPawns.PassToWorld(current, PawnDiscardDecideMode.Discard);
                    break;
                }
                GenSpawn.Spawn(current, loc, base.Map);
                if (!this.spawnPawnsOnEdge)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        MoteMaker.ThrowAirPuffUp(current.DrawPos, base.Map);
                    }
                }
                list.Add(current);
            }
            if (!list.Any <Pawn>())
            {
                return;
            }
            if (this.manhunters)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    list[j].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent, null, false, false, null);
                }
            }
            else
            {
                Faction faction = list[0].Faction;
                LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction, true, true, false, false, true), base.Map, list);
            }
            if (!this.spawnPawnsOnEdge)
            {
                for (int k = 0; k < list.Count; k++)
                {
                    list[k].jobs.StartJob(new Job(JobDefOf.Wait, 120, false), JobCondition.None, null, false, true, null, null, false);
                    list[k].Rotation = Rot4.Random;
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelAmbushInExistingMap".Translate(), "LetterAmbushInExistingMap".Translate(new object[]
            {
                Faction.OfPlayer.def.pawnsPlural
            }).CapitalizeFirst(), LetterDefOf.ThreatBig, list[0], null);
        }
Пример #8
0
        protected override void DoAction(SignalArgs args)
        {
            if (points <= 0f)
            {
                return;
            }
            List <Pawn> list = new List <Pawn>();

            foreach (Pawn item in GenerateAmbushPawns())
            {
                IntVec3 result;
                if (spawnPawnsOnEdge)
                {
                    if (!CellFinder.TryFindRandomEdgeCellWith((IntVec3 x) => x.Standable(base.Map) && !x.Fogged(base.Map) && base.Map.reachability.CanReachColony(x), base.Map, CellFinder.EdgeRoadChance_Ignore, out result))
                    {
                        Find.WorldPawns.PassToWorld(item);
                        break;
                    }
                }
                else if (!SiteGenStepUtility.TryFindSpawnCellAroundOrNear(spawnAround, spawnNear, base.Map, out result))
                {
                    Find.WorldPawns.PassToWorld(item);
                    break;
                }
                GenSpawn.Spawn(item, result, base.Map);
                if (!spawnPawnsOnEdge)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        MoteMaker.ThrowAirPuffUp(item.DrawPos, base.Map);
                    }
                }
                list.Add(item);
            }
            if (!list.Any())
            {
                return;
            }
            if (ambushType == SignalActionAmbushType.Manhunters)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    list[j].health.AddHediff(HediffDefOf.Scaria);
                    list[j].mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.ManhunterPermanent);
                }
            }
            else
            {
                Faction faction = list[0].Faction;
                LordMaker.MakeNewLord(faction, new LordJob_AssaultColony(faction), base.Map, list);
            }
            if (!spawnPawnsOnEdge)
            {
                for (int k = 0; k < list.Count; k++)
                {
                    list[k].jobs.StartJob(JobMaker.MakeJob(JobDefOf.Wait, 120));
                    list[k].Rotation = Rot4.Random;
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelAmbushInExistingMap".Translate(), "LetterAmbushInExistingMap".Translate(Faction.OfPlayer.def.pawnsPlural).CapitalizeFirst(), LetterDefOf.ThreatBig, list[0]);
        }
Пример #9
0
        public override void TickLong()
        {
            CheckTemperatureMakeLeafless();

            if (Destroyed)
            {
                return;
            }

            if (PlantUtility.GrowthSeasonNow(Position, Map))
            {
                //Grow
                float prevGrowth = growthInt;
                bool  wasMature  = LifeStage == PlantLifeStage.Mature;
                growthInt += GrowthPerTick * GenTicks.TickLongInterval;

                if (growthInt > 1f)
                {
                    growthInt = 1f;
                }

                //Regenerate layers
                if ((!wasMature && LifeStage == PlantLifeStage.Mature) ||
                    (int)(prevGrowth * 10f) != (int)(growthInt * 10f))
                {
                    if (CurrentlyCultivated())
                    {
                        Map.mapDrawer.MapMeshDirty(Position, MapMeshFlag.Things);
                    }
                }
            }

            bool hasLight = HasEnoughLightToGrow;

            //Record light starvation
            if (!hasLight)
            {
                unlitTicks += GenTicks.TickLongInterval;
            }
            else
            {
                unlitTicks = 0;
            }

            //Age
            ageInt += GenTicks.TickLongInterval;

            //Dying
            if (Dying)
            {
                var  map                        = Map;
                bool isCrop                     = IsCrop; // before applying damage!
                bool harvestableNow             = HarvestableNow;
                bool dyingBecauseExposedToLight = DyingBecauseExposedToLight;

                int dyingDamAmount = Mathf.CeilToInt(CurrentDyingDamagePerTick * GenTicks.TickLongInterval);
                TakeDamage(new DamageInfo(DamageDefOf.Rotting, dyingDamAmount));

                if (Destroyed)
                {
                    if (isCrop && def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + def.defName, 240f))
                    {
                        string messageKey;
                        if (harvestableNow)
                        {
                            messageKey = "MessagePlantDiedOfRot_LeftUnharvested";
                        }
                        else if (dyingBecauseExposedToLight)
                        {
                            messageKey = "MessagePlantDiedOfRot_ExposedToLight";
                        }
                        else
                        {
                            messageKey = "MessagePlantDiedOfRot";
                        }

                        Messages.Message(messageKey.Translate(GetCustomLabelNoCount(includeHp: false)).CapitalizeFirst(),
                                         new TargetInfo(Position, map),
                                         MessageTypeDefOf.NegativeEvent);
                    }

                    return;
                }
            }

            //State has changed, label may have to as well
            //Also, we want to keep this null so we don't have useless data sitting there a long time in plants that never get looked at
            cachedLabelMouseover = null;

            // Drop a leaf
            if (def.plant.dropLeaves)
            {
                var mote = MoteMaker.MakeStaticMote(Vector3.zero, Map, ThingDefOf.Mote_Leaf) as MoteLeaf;
                if (mote != null)
                {
                    float size        = def.plant.visualSizeRange.LerpThroughRange(growthInt);
                    float graphicSize = def.graphicData.drawSize.x * size;                   //Plants don't support non-square drawSizes

                    var disc = Rand.InsideUnitCircleVec3 * LeafSpawnRadius;                  // Horizontal alignment
                    mote.Initialize(Position.ToVector3Shifted()                              // Center of the tile
                                    + Vector3.up * Rand.Range(LeafSpawnYMin, LeafSpawnYMax)  // Vertical alignment
                                    + disc                                                   // Horizontal alignment
                                    + Vector3.forward * def.graphicData.shadowData.offset.z, // Move to the approximate base of the tree
                                    Rand.Value * GenTicks.TickLongInterval.TicksToSeconds(),
                                    disc.z > 0,
                                    graphicSize
                                    );
                }
            }
        }
        private void DoCellSteadyEffects(IntVec3 c)
        {
            Room room  = c.GetRoom(this.map, RegionType.Set_All);
            bool flag  = this.map.roofGrid.Roofed(c);
            bool flag2 = room != null && room.UsesOutdoorTemperature;

            if (room == null || flag2)
            {
                if (this.outdoorMeltAmount > 0f)
                {
                    this.map.snowGrid.AddDepth(c, -this.outdoorMeltAmount);
                }
                if (!flag && this.snowRate > 0.001f)
                {
                    this.AddFallenSnowAt(c, 0.046f * this.map.weatherManager.SnowRate);
                }
            }
            if (room != null)
            {
                bool         protectedByEdifice = SteadyEnvironmentEffects.ProtectedByEdifice(c, this.map);
                TerrainDef   terrain            = c.GetTerrain(this.map);
                List <Thing> thingList          = c.GetThingList(this.map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    Filth filth = thing as Filth;
                    if (filth != null)
                    {
                        if (!flag && thing.def.filth.rainWashes && Rand.Chance(this.rainRate))
                        {
                            filth.ThinFilth();
                        }
                    }
                    else
                    {
                        this.TryDoDeteriorate(thing, flag, flag2, protectedByEdifice, terrain);
                    }
                }
                if (!flag2)
                {
                    float temperature = room.Temperature;
                    if (temperature > 0f)
                    {
                        float num = this.MeltAmountAt(temperature);
                        if (num > 0f)
                        {
                            this.map.snowGrid.AddDepth(c, -num);
                        }
                        if (room.RegionType.Passable() && temperature > SteadyEnvironmentEffects.AutoIgnitionTemperatureRange.min)
                        {
                            float value = Rand.Value;
                            if (value < SteadyEnvironmentEffects.AutoIgnitionTemperatureRange.InverseLerpThroughRange(temperature) * 0.7f && Rand.Chance(FireUtility.ChanceToStartFireIn(c, this.map)))
                            {
                                FireUtility.TryStartFireIn(c, this.map, 0.1f);
                            }
                            if (value < 0.33f)
                            {
                                MoteMaker.ThrowHeatGlow(c, this.map, 2.3f);
                            }
                        }
                    }
                }
            }
            this.map.gameConditionManager.DoSteadyEffects(c, this.map);
        }
        public bool TryInteractWith(Pawn recipient, InteractionDef intDef)
        {
            if (DebugSettings.alwaysSocialFight)
            {
                intDef = InteractionDefOf.Insult;
            }
            if (this.pawn == recipient)
            {
                Log.Warning(this.pawn + " tried to interact with self, interaction=" + intDef.defName);
                return(false);
            }
            if (!this.CanInteractNowWith(recipient))
            {
                return(false);
            }
            if (this.InteractedTooRecentlyToInteract())
            {
                Log.Error(string.Concat(new object[]
                {
                    this.pawn,
                    " tried to do interaction ",
                    intDef,
                    " to ",
                    recipient,
                    " only ",
                    Find.TickManager.TicksGame - this.lastInteractionTime,
                    " ticks since last interaction (min is ",
                    120,
                    ")."
                }));
                return(false);
            }
            List <RulePackDef> list = new List <RulePackDef>();

            if (intDef.initiatorThought != null)
            {
                Pawn_InteractionsTracker.AddInteractionThought(this.pawn, recipient, intDef.initiatorThought);
            }
            if (intDef.recipientThought != null && recipient.needs.mood != null)
            {
                Pawn_InteractionsTracker.AddInteractionThought(recipient, this.pawn, intDef.recipientThought);
            }
            if (intDef.initiatorXpGainSkill != null)
            {
                this.pawn.skills.Learn(intDef.initiatorXpGainSkill, (float)intDef.initiatorXpGainAmount, false);
            }
            if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike)
            {
                recipient.skills.Learn(intDef.recipientXpGainSkill, (float)intDef.recipientXpGainAmount, false);
            }
            bool flag = false;

            if (recipient.RaceProps.Humanlike)
            {
                flag = recipient.interactions.CheckSocialFightStart(intDef, this.pawn);
            }
            if (!flag)
            {
                intDef.Worker.Interacted(this.pawn, recipient, list);
            }
            MoteMaker.MakeInteractionBubble(this.pawn, recipient, intDef.interactionMote, intDef.Symbol);
            this.lastInteractionTime = Find.TickManager.TicksGame;
            if (flag)
            {
                list.Add(RulePackDefOf.Sentence_SocialFightStarted);
            }
            Find.PlayLog.Add(new PlayLogEntry_Interaction(intDef, this.pawn, recipient, list));
            return(true);
        }
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
                    this.$current = Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                    this.$current = Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                    this.$current = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedOrNull(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 3;
                    }
                    return(true);

                case 3u:
                    repair = Toils_General.Wait(1000, TargetIndex.None);
                    repair.FailOnDespawnedOrNull(TargetIndex.A);
                    repair.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
                    repair.WithEffect(base.Building.def.repairEffect, TargetIndex.A);
                    repair.WithProgressBarToilDelay(TargetIndex.A, false, -0.5f);
                    this.$current = repair;
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                {
                    Toil finish = new Toil();
                    finish.initAction = delegate()
                    {
                        base.Components.Destroy(DestroyMode.Vanish);
                        if (Rand.Value > this.pawn.GetStatValue(StatDefOf.FixBrokenDownBuildingSuccessChance, true))
                        {
                            Vector3 loc = (this.pawn.DrawPos + base.Building.DrawPos) / 2f;
                            MoteMaker.ThrowText(loc, base.Map, "TextMote_FixBrokenDownBuildingFail".Translate(), 3.65f);
                        }
                        else
                        {
                            base.Building.GetComp <CompBreakdownable>().Notify_Repaired();
                        }
                    };
                    this.$current = finish;
                    if (!this.$disposing)
                    {
                        this.$PC = 5;
                    }
                    return(true);
                }

                case 5u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }
Пример #13
0
 public override void StartStrike()
 {
     base.StartStrike();
     MoteMaker.MakeBombardmentMote(base.Position, base.Map);
 }
Пример #14
0
 protected void Emit()
 {
     mote = MoteMaker.MakeStaticMote(parent.DrawPos + Props.offset, parent.Map, Props.mote);
 }
Пример #15
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.Init();
            yield return(Toils_JobTransforms.MoveCurrentTargetIntoQueue(TargetIndex.A));

            Toil initExtractTargetFromQueue = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, (this.RequiredDesignation == null) ? null : new Func <Thing, bool>((Thing t) => this.Map.designationManager.DesignationOn(t, this.RequiredDesignation) != null));

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(TargetIndex.A));

            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true));

            Toil gotoThing = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, initExtractTargetFromQueue);

            if (this.RequiredDesignation != null)
            {
                gotoThing.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation);
            }
            yield return(gotoThing);

            Toil cut = new Toil();

            cut.tickAction = delegate()
            {
                Pawn actor = cut.actor;
                if (actor.skills != null)
                {
                    actor.skills.Learn(SkillDefOf.Plants, this.xpPerTick, false);
                }
                float statValue = actor.GetStatValue(StatDefOf.PlantWorkSpeed, true);
                float num       = statValue;
                Plant plant     = this.Plant;
                num           *= Mathf.Lerp(3.3f, 1f, plant.Growth);
                this.workDone += num;
                if (this.workDone >= plant.def.plant.harvestWork)
                {
                    if (plant.def.plant.harvestedThingDef != null)
                    {
                        if (actor.RaceProps.Humanlike && plant.def.plant.harvestFailable && Rand.Value > actor.GetStatValue(StatDefOf.PlantHarvestYield, true))
                        {
                            Vector3 loc = (this.pawn.DrawPos + plant.DrawPos) / 2f;
                            MoteMaker.ThrowText(loc, this.Map, "TextMote_HarvestFailed".Translate(), 3.65f);
                        }
                        else
                        {
                            int num2 = plant.YieldNow();
                            if (num2 > 0)
                            {
                                Thing thing = ThingMaker.MakeThing(plant.def.plant.harvestedThingDef, null);
                                thing.stackCount = num2;
                                if (actor.Faction != Faction.OfPlayer)
                                {
                                    thing.SetForbidden(true, true);
                                }
                                GenPlace.TryPlaceThing(thing, actor.Position, this.Map, ThingPlaceMode.Near, null, null);
                                actor.records.Increment(RecordDefOf.PlantsHarvested);
                            }
                        }
                    }
                    plant.def.plant.soundHarvestFinish.PlayOneShot(actor);
                    plant.PlantCollected();
                    this.workDone = 0f;
                    this.ReadyForNextToil();
                    return;
                }
            };
            cut.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            if (this.RequiredDesignation != null)
            {
                cut.FailOnThingMissingDesignation(TargetIndex.A, this.RequiredDesignation);
            }
            cut.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
            cut.defaultCompleteMode = ToilCompleteMode.Never;
            cut.WithEffect(EffecterDefOf.Harvest, TargetIndex.A);
            cut.WithProgressBar(TargetIndex.A, () => this.workDone / this.Plant.def.plant.harvestWork, true, -0.5f);
            cut.PlaySustainerOrSound(() => this.Plant.def.plant.soundHarvesting);
            cut.activeSkill = (() => SkillDefOf.Plants);
            yield return(cut);

            Toil plantWorkDoneToil = this.PlantWorkDoneToil();

            if (plantWorkDoneToil != null)
            {
                yield return(plantWorkDoneToil);
            }
            yield return(Toils_Jump.Jump(initExtractTargetFromQueue));

            yield break;
        }
Пример #16
0
        public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true)
        {
            Toil layDown = new Toil();

            layDown.initAction = delegate
            {
                Pawn actor3 = layDown.actor;
                actor3.pather.StopDead();
                JobDriver curDriver3 = actor3.jobs.curDriver;
                if (hasBed)
                {
                    if (!((Building_Bed)actor3.CurJob.GetTarget(bedOrRestSpotIndex).Thing).OccupiedRect().Contains(actor3.Position))
                    {
                        Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor3);
                        actor3.jobs.EndCurrentJob(JobCondition.Errored);
                        return;
                    }
                    actor3.jobs.posture = PawnPosture.LayingInBed;
                }
                else
                {
                    actor3.jobs.posture = PawnPosture.LayingOnGroundNormal;
                }
                curDriver3.asleep = false;
                if (actor3.mindState.applyBedThoughtsTick == 0)
                {
                    actor3.mindState.applyBedThoughtsTick    = Find.TickManager.TicksGame + Rand.Range(2500, 10000);
                    actor3.mindState.applyBedThoughtsOnLeave = false;
                }
                if (actor3.ownership != null && actor3.CurrentBed() != actor3.ownership.OwnedBed)
                {
                    ThoughtUtility.RemovePositiveBedroomThoughts(actor3);
                }
                actor3.GetComp <CompCanBeDormant>()?.ToSleep();
            };
            layDown.tickAction = delegate
            {
                Pawn         actor2       = layDown.actor;
                Job          curJob       = actor2.CurJob;
                JobDriver    curDriver2   = actor2.jobs.curDriver;
                Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing;
                actor2.GainComfortFromCellIfPossible();
                if (!curDriver2.asleep)
                {
                    if (canSleep && ((actor2.needs.rest != null && actor2.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor2)) || curJob.forceSleep))
                    {
                        curDriver2.asleep = true;
                    }
                }
                else if (!canSleep)
                {
                    curDriver2.asleep = false;
                }
                else if ((actor2.needs.rest == null || actor2.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor2)) && !curJob.forceSleep)
                {
                    curDriver2.asleep = false;
                }
                if (curDriver2.asleep && gainRestAndHealth && actor2.needs.rest != null)
                {
                    float restEffectiveness = (building_Bed == null || !building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness)) ? StatDefOf.BedRestEffectiveness.valueIfMissing : building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness);
                    actor2.needs.rest.TickResting(restEffectiveness);
                }
                if (actor2.mindState.applyBedThoughtsTick != 0 && actor2.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame)
                {
                    ApplyBedThoughts(actor2);
                    actor2.mindState.applyBedThoughtsTick   += 60000;
                    actor2.mindState.applyBedThoughtsOnLeave = true;
                }
                if (actor2.IsHashIntervalTick(100) && !actor2.Position.Fogged(actor2.Map))
                {
                    if (curDriver2.asleep)
                    {
                        MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_SleepZ);
                    }
                    if (gainRestAndHealth && actor2.health.hediffSet.GetNaturallyHealingInjuredParts().Any())
                    {
                        MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_HealingCross);
                    }
                }
                if (actor2.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.OwnersForReading.Contains(actor2))
                {
                    if (actor2.Downed)
                    {
                        actor2.Position = CellFinder.RandomClosewalkCellNear(actor2.Position, actor2.Map, 1);
                    }
                    actor2.jobs.EndCurrentJob(JobCondition.Incompletable);
                }
                else if (lookForOtherJobs && actor2.IsHashIntervalTick(211))
                {
                    actor2.jobs.CheckForJobOverride();
                }
            };
            layDown.defaultCompleteMode = ToilCompleteMode.Never;
            if (hasBed)
            {
                layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex);
            }
            layDown.AddFinishAction(delegate
            {
                Pawn actor          = layDown.actor;
                JobDriver curDriver = actor.jobs.curDriver;
                if (actor.mindState.applyBedThoughtsOnLeave)
                {
                    ApplyBedThoughts(actor);
                }
                curDriver.asleep = false;
            });
            return(layDown);
        }
Пример #17
0
        public override void Tick()
        {
            if (!base.Spawned)
            {
                return;
            }
            if (sustainer == null)
            {
                Log.Error("Tornado sustainer is null.");
                CreateSustainer();
            }
            sustainer.Maintain();
            UpdateSustainerVolume();
            GetComp <CompWindSource>().wind = 5f * FadeInOutFactor;
            if (leftFadeOutTicks > 0)
            {
                leftFadeOutTicks--;
                if (leftFadeOutTicks == 0)
                {
                    Destroy();
                }
                return;
            }
            if (directionNoise == null)
            {
                directionNoise = new Perlin(0.0020000000949949026, 2.0, 0.5, 4, 1948573612, QualityMode.Medium);
            }
            direction   += (float)directionNoise.GetValue(Find.TickManager.TicksAbs, (float)(thingIDNumber % 500) * 1000f, 0.0) * 0.78f;
            realPosition = realPosition.Moved(direction, 17f / 600f);
            IntVec3 intVec = new Vector3(realPosition.x, 0f, realPosition.y).ToIntVec3();

            if (intVec.InBounds(base.Map))
            {
                base.Position = intVec;
                if (this.IsHashIntervalTick(15))
                {
                    DamageCloseThings();
                }
                if (Rand.MTBEventOccurs(15f, 1f, 1f))
                {
                    DamageFarThings();
                }
                if (this.IsHashIntervalTick(20))
                {
                    DestroyRoofs();
                }
                if (ticksLeftToDisappear > 0)
                {
                    ticksLeftToDisappear--;
                    if (ticksLeftToDisappear == 0)
                    {
                        leftFadeOutTicks = 120;
                        Messages.Message("MessageTornadoDissipated".Translate(), new TargetInfo(base.Position, base.Map), MessageTypeDefOf.PositiveEvent);
                    }
                }
                if (this.IsHashIntervalTick(4) && !CellImmuneToDamage(base.Position))
                {
                    float   num = Rand.Range(0.6f, 1f);
                    Vector3 a   = new Vector3(realPosition.x, 0f, realPosition.y);
                    a.y = AltitudeLayer.MoteOverhead.AltitudeFor();
                    MoteMaker.ThrowTornadoDustPuff(a + Vector3Utility.RandomHorizontalOffset(1.5f), base.Map, Rand.Range(1.5f, 3f), new Color(num, num, num));
                }
            }
            else
            {
                leftFadeOutTicks = 120;
                Messages.Message("MessageTornadoLeftMap".Translate(), new TargetInfo(base.Position, base.Map), MessageTypeDefOf.PositiveEvent);
            }
        }
Пример #18
0
        public bool TryInteractWith(Pawn recipient, InteractionDef intDef)
        {
            if (DebugSettings.alwaysSocialFight)
            {
                intDef = InteractionDefOf.Insult;
            }
            if (pawn == recipient)
            {
                Log.Warning(pawn + " tried to interact with self, interaction=" + intDef.defName);
                return(false);
            }
            if (!CanInteractNowWith(recipient, intDef))
            {
                return(false);
            }
            if (InteractedTooRecentlyToInteract())
            {
                Log.Error(pawn + " tried to do interaction " + intDef + " to " + recipient + " only " + (Find.TickManager.TicksGame - lastInteractionTime) + " ticks since last interaction (min is " + 120 + ").");
                return(false);
            }
            List <RulePackDef> list = new List <RulePackDef>();

            if (intDef.initiatorThought != null)
            {
                AddInteractionThought(pawn, recipient, intDef.initiatorThought);
            }
            if (intDef.recipientThought != null && recipient.needs.mood != null)
            {
                AddInteractionThought(recipient, pawn, intDef.recipientThought);
            }
            if (intDef.initiatorXpGainSkill != null)
            {
                pawn.skills.Learn(intDef.initiatorXpGainSkill, intDef.initiatorXpGainAmount);
            }
            if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike)
            {
                recipient.skills.Learn(intDef.recipientXpGainSkill, intDef.recipientXpGainAmount);
            }
            bool flag = false;

            if (recipient.RaceProps.Humanlike)
            {
                flag = recipient.interactions.CheckSocialFightStart(intDef, pawn);
            }
            string      letterText;
            string      letterLabel;
            LetterDef   letterDef;
            LookTargets lookTargets;

            if (!flag)
            {
                intDef.Worker.Interacted(pawn, recipient, list, out letterText, out letterLabel, out letterDef, out lookTargets);
            }
            else
            {
                letterText  = null;
                letterLabel = null;
                letterDef   = null;
                lookTargets = null;
            }
            MoteMaker.MakeInteractionBubble(pawn, recipient, intDef.interactionMote, intDef.Symbol);
            lastInteractionTime = Find.TickManager.TicksGame;
            if (flag)
            {
                list.Add(RulePackDefOf.Sentence_SocialFightStarted);
            }
            PlayLogEntry_Interaction playLogEntry_Interaction = new PlayLogEntry_Interaction(intDef, pawn, recipient, list);

            Find.PlayLog.Add(playLogEntry_Interaction);
            if (letterDef != null)
            {
                string text = playLogEntry_Interaction.ToGameStringFromPOV(pawn);
                if (!letterText.NullOrEmpty())
                {
                    text = text + "\n\n" + letterText;
                }
                Find.LetterStack.ReceiveLetter(letterLabel, text, letterDef, lookTargets ?? ((LookTargets)pawn));
            }
            return(true);
        }
Пример #19
0
        protected override bool TryCastShot()
        {
            Pawn casterPawn = base.CasterPawn;

            if (!casterPawn.Spawned)
            {
                return(false);
            }
            if (casterPawn.stances.FullBodyBusy)
            {
                return(false);
            }
            Thing thing = currentTarget.Thing;

            if (!CanHitTarget(thing))
            {
                Log.Warning(casterPawn + " meleed " + thing + " from out of melee position.");
            }
            casterPawn.rotationTracker.Face(thing.DrawPos);
            if (!IsTargetImmobile(currentTarget) && casterPawn.skills != null)
            {
                casterPawn.skills.Learn(SkillDefOf.Melee, 200f * verbProps.AdjustedFullCycleTime(this, casterPawn));
            }
            Pawn pawn = thing as Pawn;

            if (pawn != null && !pawn.Dead && (casterPawn.MentalStateDef != MentalStateDefOf.SocialFighting || pawn.MentalStateDef != MentalStateDefOf.SocialFighting))
            {
                pawn.mindState.meleeThreat             = casterPawn;
                pawn.mindState.lastMeleeThreatHarmTick = Find.TickManager.TicksGame;
            }
            Map      map     = thing.Map;
            Vector3  drawPos = thing.DrawPos;
            SoundDef soundDef;
            bool     result;

            if (Rand.Chance(GetNonMissChance(thing)))
            {
                if (!Rand.Chance(GetDodgeChance(thing)))
                {
                    soundDef = ((thing.def.category != ThingCategory.Building) ? SoundHitPawn() : SoundHitBuilding());
                    if (verbProps.impactMote != null)
                    {
                        MoteMaker.MakeStaticMote(drawPos, map, verbProps.impactMote);
                    }
                    BattleLogEntry_MeleeCombat battleLogEntry_MeleeCombat = CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesHit, alwaysShow: true);
                    result = true;
                    DamageWorker.DamageResult damageResult = ApplyMeleeDamageToTarget(currentTarget);
                    damageResult.AssociateWithLog(battleLogEntry_MeleeCombat);
                    if (damageResult.deflected)
                    {
                        battleLogEntry_MeleeCombat.RuleDef             = maneuver.combatLogRulesDeflect;
                        battleLogEntry_MeleeCombat.alwaysShowInCompact = false;
                    }
                }
                else
                {
                    result   = false;
                    soundDef = SoundMiss();
                    MoteMaker.ThrowText(drawPos, map, "TextMote_Dodge".Translate(), 1.9f);
                    CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesDodge, alwaysShow: false);
                }
            }
            else
            {
                result   = false;
                soundDef = SoundMiss();
                CreateCombatLog((ManeuverDef maneuver) => maneuver.combatLogRulesMiss, alwaysShow: false);
            }
            soundDef.PlayOneShot(new TargetInfo(thing.Position, map));
            if (casterPawn.Spawned)
            {
                casterPawn.Drawer.Notify_MeleeAttackOn(thing);
            }
            if (pawn != null && !pawn.Dead && pawn.Spawned)
            {
                pawn.stances.StaggerFor(95);
            }
            if (casterPawn.Spawned)
            {
                casterPawn.rotationTracker.FaceCell(thing.Position);
            }
            if (casterPawn.caller != null)
            {
                casterPawn.caller.Notify_DidMeleeAttack();
            }
            return(result);
        }
Пример #20
0
        public bool TryInteractWith(Pawn recipient, InteractionDef intDef)
        {
            if (DebugSettings.alwaysSocialFight)
            {
                intDef = InteractionDefOf.Insult;
            }
            bool result;

            if (this.pawn == recipient)
            {
                Log.Warning(this.pawn + " tried to interact with self, interaction=" + intDef.defName, false);
                result = false;
            }
            else if (!this.CanInteractNowWith(recipient))
            {
                result = false;
            }
            else if (this.InteractedTooRecentlyToInteract())
            {
                Log.Error(string.Concat(new object[]
                {
                    this.pawn,
                    " tried to do interaction ",
                    intDef,
                    " to ",
                    recipient,
                    " only ",
                    Find.TickManager.TicksGame - this.lastInteractionTime,
                    " ticks since last interaction (min is ",
                    120,
                    ")."
                }), false);
                result = false;
            }
            else
            {
                List <RulePackDef> list = new List <RulePackDef>();
                if (intDef.initiatorThought != null)
                {
                    Pawn_InteractionsTracker.AddInteractionThought(this.pawn, recipient, intDef.initiatorThought);
                }
                if (intDef.recipientThought != null && recipient.needs.mood != null)
                {
                    Pawn_InteractionsTracker.AddInteractionThought(recipient, this.pawn, intDef.recipientThought);
                }
                if (intDef.initiatorXpGainSkill != null)
                {
                    this.pawn.skills.Learn(intDef.initiatorXpGainSkill, (float)intDef.initiatorXpGainAmount, false);
                }
                if (intDef.recipientXpGainSkill != null && recipient.RaceProps.Humanlike)
                {
                    recipient.skills.Learn(intDef.recipientXpGainSkill, (float)intDef.recipientXpGainAmount, false);
                }
                bool flag = false;
                if (recipient.RaceProps.Humanlike)
                {
                    flag = recipient.interactions.CheckSocialFightStart(intDef, this.pawn);
                }
                string    text;
                string    label;
                LetterDef letterDef;
                if (!flag)
                {
                    intDef.Worker.Interacted(this.pawn, recipient, list, out text, out label, out letterDef);
                }
                else
                {
                    text      = null;
                    label     = null;
                    letterDef = null;
                }
                MoteMaker.MakeInteractionBubble(this.pawn, recipient, intDef.interactionMote, intDef.Symbol);
                this.lastInteractionTime = Find.TickManager.TicksGame;
                if (flag)
                {
                    list.Add(RulePackDefOf.Sentence_SocialFightStarted);
                }
                PlayLogEntry_Interaction playLogEntry_Interaction = new PlayLogEntry_Interaction(intDef, this.pawn, recipient, list);
                Find.PlayLog.Add(playLogEntry_Interaction);
                if (letterDef != null)
                {
                    string text2 = playLogEntry_Interaction.ToGameStringFromPOV(this.pawn, false);
                    if (!text.NullOrEmpty())
                    {
                        text2 = text2 + "\n\n" + text;
                    }
                    Find.LetterStack.ReceiveLetter(label, text2, letterDef, this.pawn, null, null);
                }
                result = true;
            }
            return(result);
        }
Пример #21
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         IntVec3 c;
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out c, 999999))
         {
             FilthMaker.MakeFilth(c, base.Map, TunnelHiveSpawner.filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(Faction.OfInsects, null);
                 foreach (CompSpawner compSpawner in hive.GetComps <CompSpawner>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.insectsPoints > 0f)
             {
                 this.insectsPoints = Mathf.Max(this.insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     PawnKindDef pawnKindDef;
                     if (!source.TryRandomElement(out pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }
 private static void SpawnEffect(Thing projector)
 {
     MoteMaker.MakeStaticMote(projector.TrueCenter(), projector.Map, ThingDefOf.Mote_BroadshieldActivation);
     SoundDefOf.Broadshield_Startup.PlayOneShot(new TargetInfo(projector.Position, projector.Map));
 }
Пример #23
0
 public override void TickLong()
 {
     this.CheckTemperatureMakeLeafless();
     if (base.Destroyed)
     {
         return;
     }
     if (PlantUtility.GrowthSeasonNow(base.Position, base.Map, false))
     {
         float num  = this.growthInt;
         bool  flag = this.LifeStage == PlantLifeStage.Mature;
         this.growthInt += this.GrowthPerTick * 2000f;
         if (this.growthInt > 1f)
         {
             this.growthInt = 1f;
         }
         if (((!flag && this.LifeStage == PlantLifeStage.Mature) || (int)(num * 10f) != (int)(this.growthInt * 10f)) && this.CurrentlyCultivated())
         {
             base.Map.mapDrawer.MapMeshDirty(base.Position, MapMeshFlag.Things);
         }
     }
     if (!this.HasEnoughLightToGrow)
     {
         this.unlitTicks += 2000;
     }
     else
     {
         this.unlitTicks = 0;
     }
     this.ageInt += 2000;
     if (this.Dying)
     {
         Map  map                        = base.Map;
         bool isCrop                     = this.IsCrop;
         bool harvestableNow             = this.HarvestableNow;
         bool dyingBecauseExposedToLight = this.DyingBecauseExposedToLight;
         int  num2                       = Mathf.CeilToInt(this.CurrentDyingDamagePerTick * 2000f);
         base.TakeDamage(new DamageInfo(DamageDefOf.Rotting, (float)num2, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null));
         if (base.Destroyed)
         {
             if (isCrop && this.def.plant.Harvestable && MessagesRepeatAvoider.MessageShowAllowed("MessagePlantDiedOfRot-" + this.def.defName, 240f))
             {
                 string key;
                 if (harvestableNow)
                 {
                     key = "MessagePlantDiedOfRot_LeftUnharvested";
                 }
                 else if (dyingBecauseExposedToLight)
                 {
                     key = "MessagePlantDiedOfRot_ExposedToLight";
                 }
                 else
                 {
                     key = "MessagePlantDiedOfRot";
                 }
                 Messages.Message(key.Translate(new object[]
                 {
                     this.GetCustomLabelNoCount(false)
                 }).CapitalizeFirst(), new TargetInfo(base.Position, map, false), MessageTypeDefOf.NegativeEvent, true);
             }
             return;
         }
     }
     this.cachedLabelMouseover = null;
     if (this.def.plant.dropLeaves)
     {
         MoteLeaf moteLeaf = MoteMaker.MakeStaticMote(Vector3.zero, base.Map, ThingDefOf.Mote_Leaf, 1f) as MoteLeaf;
         if (moteLeaf != null)
         {
             float   num3       = this.def.plant.visualSizeRange.LerpThroughRange(this.growthInt);
             float   treeHeight = this.def.graphicData.drawSize.x * num3;
             Vector3 b          = Rand.InsideUnitCircleVec3 * Plant.LeafSpawnRadius;
             moteLeaf.Initialize(base.Position.ToVector3Shifted() + Vector3.up * Rand.Range(Plant.LeafSpawnYMin, Plant.LeafSpawnYMax) + b + Vector3.forward * this.def.graphicData.shadowData.offset.z, Rand.Value * 2000.TicksToSeconds(), b.z > 0f, treeHeight);
         }
     }
 }
Пример #24
0
 public static void Resurrect(Pawn pawn)
 {
     if (!pawn.Dead)
     {
         Log.Error("Tried to resurrect a pawn who is not dead: " + pawn.ToStringSafe());
     }
     else if (pawn.Discarded)
     {
         Log.Error("Tried to resurrect a discarded pawn: " + pawn.ToStringSafe());
     }
     else
     {
         Corpse  corpse = pawn.Corpse;
         bool    flag   = false;
         IntVec3 loc    = IntVec3.Invalid;
         Map     map    = null;
         if (corpse != null)
         {
             flag             = corpse.Spawned;
             loc              = corpse.Position;
             map              = corpse.Map;
             corpse.InnerPawn = null;
             corpse.Destroy();
         }
         if (flag && pawn.IsWorldPawn())
         {
             Find.WorldPawns.RemovePawn(pawn);
         }
         pawn.ForceSetStateToUnspawned();
         PawnComponentsUtility.CreateInitialComponents(pawn);
         pawn.health.Notify_Resurrected();
         if (pawn.Faction != null && pawn.Faction.IsPlayer)
         {
             if (pawn.workSettings != null)
             {
                 pawn.workSettings.EnableAndInitialize();
             }
             Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(pawn, PopAdaptationEvent.GainedColonist);
         }
         if (flag)
         {
             GenSpawn.Spawn(pawn, loc, map);
             for (int i = 0; i < 10; i++)
             {
                 MoteMaker.ThrowAirPuffUp(pawn.DrawPos, map);
             }
             if (pawn.Faction != null && pawn.Faction != Faction.OfPlayer && pawn.HostileTo(Faction.OfPlayer))
             {
                 LordMaker.MakeNewLord(pawn.Faction, new LordJob_AssaultColony(pawn.Faction), pawn.Map, Gen.YieldSingle(pawn));
             }
             if (pawn.apparel != null)
             {
                 List <Apparel> wornApparel = pawn.apparel.WornApparel;
                 for (int j = 0; j < wornApparel.Count; j++)
                 {
                     wornApparel[j].Notify_PawnResurrected();
                 }
             }
         }
         PawnDiedOrDownedThoughtsUtility.RemoveDiedThoughts(pawn);
     }
 }
Пример #25
0
 public static void ThrowStone(Pawn thrower, IntVec3 targetCell)
 {
     MoteMaker.ThrowObjectAt(thrower, targetCell, ThingDefOf.Mote_Stone);
 }
 private void ThrowCurrentTemperatureText()
 {
     MoteMaker.ThrowText(parent.TrueCenter() + new Vector3(0.5f, 0f, 0.5f), parent.Map, targetTemperature.ToStringTemperature("F0"), Color.white);
 }
Пример #27
0
 public static void ThrowText(Vector3 loc, Map map, string text, float timeBeforeStartFadeout = -1f)
 {
     MoteMaker.ThrowText(loc, map, text, Color.white, timeBeforeStartFadeout);
 }
Пример #28
0
 private void TryMakeBreathMote()
 {
     MoteMaker.ThrowBreathPuff(pawn.Drawer.DrawPos + pawn.Drawer.renderer.BaseHeadOffsetAt(pawn.Rotation) + pawn.Rotation.FacingCell.ToVector3() * 0.21f + BreathOffset, inheritVelocity: pawn.Drawer.tweener.LastTickTweenedVelocity, map: pawn.Map, throwAngle: pawn.Rotation.AsAngle);
 }
Пример #29
0
 public override void Interacted(Pawn initiator, Pawn recipient, List <RulePackDef> extraSentencePacks, out string letterText, out string letterLabel, out LetterDef letterDef)
 {
     letterText  = null;
     letterLabel = null;
     letterDef   = null;
     if (!recipient.mindState.CheckStartMentalStateBecauseRecruitAttempted(initiator))
     {
         bool  flag  = recipient.AnimalOrWildMan() && !recipient.IsPrisoner;
         float x     = (float)((recipient.relations != null) ? recipient.relations.OpinionOf(initiator) : 0);
         bool  flag2 = initiator.InspirationDef == InspirationDefOf.Inspired_Recruitment && !flag && recipient.guest.interactionMode != PrisonerInteractionModeDefOf.ReduceResistance;
         if (DebugSettings.instantRecruit)
         {
             recipient.guest.resistance = 0f;
         }
         if (!flag && recipient.guest.resistance > 0f && !flag2)
         {
             float num = 1f;
             num *= initiator.GetStatValue(StatDefOf.NegotiationAbility);
             num *= ResistanceImpactFactorCurve_Mood.Evaluate(recipient.needs.mood.CurLevelPercentage);
             num *= ResistanceImpactFactorCurve_Opinion.Evaluate(x);
             num  = Mathf.Min(num, recipient.guest.resistance);
             float resistance = recipient.guest.resistance;
             recipient.guest.resistance = Mathf.Max(0f, recipient.guest.resistance - num);
             string text = "TextMote_ResistanceReduced".Translate(resistance.ToString("F1"), recipient.guest.resistance.ToString("F1"));
             if (recipient.needs.mood != null && recipient.needs.mood.CurLevelPercentage < 0.4f)
             {
                 text = text + "\n(" + "lowMood".Translate() + ")";
             }
             if (recipient.relations != null && (float)recipient.relations.OpinionOf(initiator) < -0.01f)
             {
                 text = text + "\n(" + "lowOpinion".Translate() + ")";
             }
             MoteMaker.ThrowText((initiator.DrawPos + recipient.DrawPos) / 2f, initiator.Map, text, 8f);
             if (recipient.guest.resistance == 0f)
             {
                 string text2 = "MessagePrisonerResistanceBroken".Translate(recipient.LabelShort, initiator.LabelShort, initiator.Named("WARDEN"), recipient.Named("PRISONER"));
                 if (recipient.guest.interactionMode == PrisonerInteractionModeDefOf.AttemptRecruit)
                 {
                     text2 = text2 + " " + "MessagePrisonerResistanceBroken_RecruitAttempsWillBegin".Translate();
                 }
                 Messages.Message(text2, recipient, MessageTypeDefOf.PositiveEvent);
             }
         }
         else
         {
             float statValue;
             if (flag)
             {
                 statValue = initiator.GetStatValue(StatDefOf.TameAnimalChance);
                 float x2 = (!recipient.IsWildMan()) ? recipient.RaceProps.wildness : 0.2f;
                 statValue *= TameChanceFactorCurve_Wildness.Evaluate(x2);
                 if (initiator.relations.DirectRelationExists(PawnRelationDefOf.Bond, recipient))
                 {
                     statValue *= 4f;
                 }
             }
             else if (flag2 || DebugSettings.instantRecruit)
             {
                 statValue = 1f;
             }
             else
             {
                 statValue = initiator.GetStatValue(StatDefOf.NegotiationAbility) * 0.5f;
                 float x3 = recipient.RecruitDifficulty(initiator.Faction);
                 statValue *= RecruitChanceFactorCurve_RecruitDifficulty.Evaluate(x3);
                 statValue *= RecruitChanceFactorCurve_Opinion.Evaluate(x);
                 if (recipient.needs.mood != null)
                 {
                     float curLevel = recipient.needs.mood.CurLevel;
                     statValue *= RecruitChanceFactorCurve_Mood.Evaluate(curLevel);
                 }
             }
             if (Rand.Chance(statValue))
             {
                 DoRecruit(initiator, recipient, statValue, out letterLabel, out letterText, useAudiovisualEffects: true, sendLetter: false);
                 if (!letterLabel.NullOrEmpty())
                 {
                     letterDef = LetterDefOf.PositiveEvent;
                 }
                 if (flag2)
                 {
                     initiator.mindState.inspirationHandler.EndInspiration(InspirationDefOf.Inspired_Recruitment);
                 }
                 extraSentencePacks.Add(RulePackDefOf.Sentence_RecruitAttemptAccepted);
             }
             else
             {
                 string text3 = (!flag) ? "TextMote_RecruitFail".Translate(statValue.ToStringPercent()) : "TextMote_TameFail".Translate(statValue.ToStringPercent());
                 if (!flag)
                 {
                     if (recipient.needs.mood != null && recipient.needs.mood.CurLevelPercentage < 0.4f)
                     {
                         text3 = text3 + "\n(" + "lowMood".Translate() + ")";
                     }
                     if (recipient.relations != null && (float)recipient.relations.OpinionOf(initiator) < -0.01f)
                     {
                         text3 = text3 + "\n(" + "lowOpinion".Translate() + ")";
                     }
                 }
                 MoteMaker.ThrowText((initiator.DrawPos + recipient.DrawPos) / 2f, initiator.Map, text3, 8f);
                 extraSentencePacks.Add(RulePackDefOf.Sentence_RecruitAttemptRejected);
             }
         }
     }
 }
Пример #30
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOn(delegate
            {
                if (!WorkGiver_Tend.GoodLayingStatusForTend(Deliveree, pawn))
                {
                    return(true);
                }
                if (MedicineUsed != null && pawn.Faction == Faction.OfPlayer)
                {
                    if (Deliveree.playerSettings == null)
                    {
                        return(true);
                    }
                    if (!Deliveree.playerSettings.medCare.AllowsMedicine(MedicineUsed.def))
                    {
                        return(true);
                    }
                }
                return((pawn == Deliveree && pawn.Faction == Faction.OfPlayer && !pawn.playerSettings.selfTend) ? true : false);
            });
            AddEndCondition(delegate
            {
                if (pawn.Faction == Faction.OfPlayer && HealthAIUtility.ShouldBeTendedNowByPlayer(Deliveree))
                {
                    return(JobCondition.Ongoing);
                }
                return((pawn.Faction != Faction.OfPlayer && Deliveree.health.HasHediffsNeedingTend()) ? JobCondition.Ongoing : JobCondition.Succeeded);
            });
            this.FailOnAggroMentalState(TargetIndex.A);
            Toil reserveMedicine = null;

            if (usesMedicine)
            {
                reserveMedicine = Toils_Tend.ReserveMedicine(TargetIndex.B, Deliveree).FailOnDespawnedNullOrForbidden(TargetIndex.B);
                yield return(reserveMedicine);

                yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B));

                yield return(Toils_Tend.PickupMedicine(TargetIndex.B, Deliveree).FailOnDestroyedOrNull(TargetIndex.B));

                yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveMedicine, TargetIndex.B, TargetIndex.None, takeFromValidStorage: true));
            }
            PathEndMode interactionCell = ((Deliveree == pawn) ? PathEndMode.OnCell : PathEndMode.InteractionCell);
            Toil        gotoToil        = Toils_Goto.GotoThing(TargetIndex.A, interactionCell);

            yield return(gotoToil);

            Toil toil = Toils_General.Wait((int)(1f / pawn.GetStatValue(StatDefOf.MedicalTendSpeed) * 600f)).FailOnCannotTouch(TargetIndex.A, interactionCell).WithProgressBarToilDelay(TargetIndex.A)
                        .PlaySustainerOrSound(SoundDefOf.Interact_Tend);

            toil.activeSkill = () => SkillDefOf.Medicine;
            if (pawn == Deliveree && pawn.Faction != Faction.OfPlayer)
            {
                toil.tickAction = delegate
                {
                    if (pawn.IsHashIntervalTick(100) && !pawn.Position.Fogged(pawn.Map))
                    {
                        MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_HealingCross);
                    }
                };
            }
            yield return(toil);

            yield return(Toils_Tend.FinalizeTend(Deliveree));

            if (usesMedicine)
            {
                Toil toil2 = new Toil();
                toil2.initAction = delegate
                {
                    if (MedicineUsed.DestroyedOrNull())
                    {
                        Thing thing = HealthAIUtility.FindBestMedicine(pawn, Deliveree);
                        if (thing != null)
                        {
                            job.targetB = thing;
                            JumpToToil(reserveMedicine);
                        }
                    }
                };
                yield return(toil2);
            }
            yield return(Toils_Jump.Jump(gotoToil));
        }