예제 #1
0
        public static Thing ShadowMoteSpawner_ThrowObjectAt(this JobDriver_PlayGenericTargetingGame PGTG)
        {
            Pawn     thrower    = PGTG.pawn;
            IntVec3  targetCell = PGTG.PetanqueSpotCell;
            SkillDef skillDef   = PGTG.SkillDefScaling;

            ThingDef moteDef = PGTG.MoteDef;

            if (!thrower.AllowedMoteSpawn())
            {
                return(null);
            }

            float   randomSpeed     = PGTG.Speed.RandomInRange;
            Vector3 destinationCell =
                targetCell.ToVector3Shifted() +
                Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(skillDef).Level / 20f) * 1.8f);

            destinationCell.y = thrower.DrawPos.y;
            ShadowMote moteThrown = (ShadowMote)ThingMaker.MakeThing(moteDef);

            //moteThrown.Initialization(thrower.DrawPos, destinationCell, PGTG.PetanqueSpotCell.ToVector3Shifted(), thrower);
            moteThrown.Initialization(PGTG, destinationCell);

            moteThrown.Scale         = 1f;
            moteThrown.rotationRate  = PGTG.Rotation.RandomInRange;
            moteThrown.exactPosition = thrower.DrawPos;
            moteThrown.SetVelocity((destinationCell - moteThrown.exactPosition).AngleFlat(), randomSpeed);

            moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - destinationCell).MagnitudeHorizontal() / randomSpeed);

            return(GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map));
        }
예제 #2
0
        public static Thing MoteSpawner_ThrowObjectAt(this JobDriver_PlayGenericTargetingGame PGTG)
        {
            IntVec3  targetCell = PGTG.PetanqueSpotCell;
            Pawn     thrower    = PGTG.pawn;
            ThingDef moteDef    = PGTG.MoteDef;
            SkillDef skillDef   = PGTG.SkillDefScaling;

            if (thrower.Position.ShouldSpawnMotesAt(thrower.Map) && !thrower.Map.moteCounter.Saturated)
            {
                float   randomSpeed     = PGTG.Speed.RandomInRange;
                Vector3 destinationCell =
                    targetCell.ToVector3Shifted() +
                    Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(skillDef).Level / 20f) * 1.8f);

                destinationCell.y = thrower.DrawPos.y;
                MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef);

                moteThrown.Scale         = 1f;
                moteThrown.rotationRate  = PGTG.Rotation.RandomInRange;
                moteThrown.exactPosition = thrower.DrawPos;
                moteThrown.SetVelocity((destinationCell - moteThrown.exactPosition).AngleFlat(), randomSpeed);

                moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - destinationCell).MagnitudeHorizontal() / randomSpeed);

                return(GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map));
            }
            return(null);
        }
        /// <summary>
        /// The for arrows ballanced mote thrower
        /// Original: MoteThrower.ThrowHorseshoe
        /// </summary>
        public static void ShootArrow(Pawn thrower, IntVec3 targetCell)
        {
            if (!thrower.Position.ShouldSpawnMotesAt(thrower.Map) || thrower.Map.moteCounter.Saturated)
            {
                return;
            }

            float   speed  = Rand.Range(4.0f, 6.5f) * 1.8f;
            Vector3 vector = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(SkillDefOf.Shooting).Level / 20f) * 1.8f);

            vector.y = thrower.DrawPos.y;
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(DefDatabase <ThingDef> .GetNamed("Mote_ArcheryArrow"), null);

            moteThrown.Scale         = 1f;
            moteThrown.rotationRate  = 0f;
            moteThrown.exactPosition = thrower.DrawPos;
            moteThrown.exactRotation = (vector - moteThrown.exactPosition).AngleFlat(); // this corrects the angle of the arrow
            moteThrown.SetVelocity((vector - moteThrown.exactPosition).AngleFlat(), speed);
            moteThrown.airTimeLeft = ((moteThrown.exactPosition - vector).MagnitudeHorizontal() / speed);
            if (moteThrown.airTimeLeft > 1f) // reduce the airtime randomly to let the arrows be too short from time to time
            {
                moteThrown.airTimeLeft -= Rand.Value;
            }
            GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map);
        }
예제 #4
0
        public void CryptoStasis()
        {
            Hediff_CryptoStasis revertMentalState = null;

            if (!Wearer.health.hediffSet.HasHediff(SS_HediffDefOf.Crypto_Stasis))
            {
                Wearer.health.AddHediff(SS_HediffDefOf.Crypto_Stasis);
                revertMentalState = Wearer.health.hediffSet.GetFirstHediffOfDef(SS_HediffDefOf.Crypto_Stasis) as Hediff_CryptoStasis;
                revertMentalState.SaveMemory();
            }
            if (!Wearer.Spawned || Wearer.Downed)
            {
                armed = false;
                RevertMentalState();
                return;
            }
            if (Wearer.mindState.mentalStateHandler.CurStateDef != SS_MentalStateDefOf.CryptoStasis)
            {
                Wearer.mindState.mentalStateHandler.TryStartMentalState(SS_MentalStateDefOf.CryptoStasis, null, true, false, null, true);
            }
            if (Rand.Value < 0.33f)
            {
                MoteMaker.ThrowTornadoDustPuff(Wearer.TrueCenter() + Vector3Utility.RandomHorizontalOffset(0.5f), Wearer.Map, Rand.Range(0.25f, 1f), new Color(0.65f, 0.9f, 0.93f));
            }
        }
예제 #5
0
        private void SpawnRequestedReinforcements()
        {
            Building_OrbitalRelay orbitalRelay = OG_Util.FindOrbitalRelay(this.Faction);

            if (orbitalRelay != null)
            {
                for (int pawnIndex = 0; pawnIndex < orbitalRelay.requestedOfficersNumber; pawnIndex++)
                {
                    Pawn pawn = OG_Inhabitants.GeneratePawn(OG_Util.OutpostOfficerDef);
                    GenSpawn.Spawn(pawn, this.Position);
                }
                for (int pawnIndex = 0; pawnIndex < orbitalRelay.requestedHeavyGuardsNumber; pawnIndex++)
                {
                    Pawn pawn = OG_Inhabitants.GeneratePawn(OG_Util.OutpostHeavyGuardDef);
                    GenSpawn.Spawn(pawn, this.Position);
                }
                for (int pawnIndex = 0; pawnIndex < orbitalRelay.requestedGuardsNumber; pawnIndex++)
                {
                    Pawn pawn = OG_Inhabitants.GeneratePawn(OG_Util.OutpostGuardDef);
                    GenSpawn.Spawn(pawn, this.Position);
                }
                for (int pawnIndex = 0; pawnIndex < orbitalRelay.requestedScoutsNumber; pawnIndex++)
                {
                    Pawn pawn = OG_Inhabitants.GeneratePawn(OG_Util.OutpostScoutDef);
                    GenSpawn.Spawn(pawn, this.Position);
                }
                for (int pawnIndex = 0; pawnIndex < orbitalRelay.requestedTechniciansNumber; pawnIndex++)
                {
                    Pawn pawn = OG_Inhabitants.GeneratePawn(OG_Util.OutpostTechnicianDef);
                    GenSpawn.Spawn(pawn, this.Position + Vector3Utility.RandomHorizontalOffset(4f).ToIntVec3());
                }
            }
        }
예제 #6
0
        private static void SpawnChipChunksAt(IntVec3 position)
        {
            int partsNumber = Rand.Range(2, 5);

            for (int partIndex = 0; partIndex < partsNumber; partIndex++)
            {
                IntVec3 spawnCell = position + Vector3Utility.RandomHorizontalOffset(5f).ToIntVec3();
                GenSpawn.Spawn(ThingDefOf.ShipChunk, spawnCell);
            }
        }
예제 #7
0
        public void UpdateDrawingParameters()
        {
            const float fadingOffset   = 0.3f;
            const float fadingVariable = 0.7f;

            if ((this.forceFieldState == ForceFieldState.Charging) ||
                (this.forceFieldState == ForceFieldState.Sustaining) ||
                (this.forceFieldState == ForceFieldState.Discharging))
            {
                // Standard matrix cyan effect.
                for (int matrixIndex = 0; matrixIndex < 5; matrixIndex++)
                {
                    this.matrixFadingCoefficient[matrixIndex] = fadingOffset + fadingVariable * (this.forceFieldCharge / this.properties.forceFieldMaxCharge);
                }

                // Additional lightning effect.
                if (Find.TickManager.TicksGame > this.nextSparkTick)
                {
                    this.nextSparkTick = Find.TickManager.TicksGame + Rand.RangeInclusive(150, 300);
                    int        effectCellIndex = Rand.RangeInclusive(0, 4);
                    MoteThrown moteThrown      = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("Mote_ElectricalSpark"), null);
                    moteThrown.Scale         = 0.8f;
                    moteThrown.exactRotation = Rand.Range(0f, 360f);
                    moteThrown.exactPosition = this.effectCells[effectCellIndex] + Vector3Utility.RandomHorizontalOffset(0.15f);
                    GenSpawn.Spawn(moteThrown, moteThrown.exactPosition.ToIntVec3(), this.Map);
                }
            }

            for (int matrixIndex = 0; matrixIndex < 5; matrixIndex++)
            {
                // Absorbing matrix red effect.
                if (this.matrixIsStartingAbsorbion[matrixIndex])
                {
                    this.matrixAbsorbtionCounterInTicks[matrixIndex] = matrixAbsorbtionDurationInTicks;
                    this.matrixIsStartingAbsorbion[matrixIndex]      = false;
                    MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_LightningGlow, null);
                    moteThrown.Scale         = 4f;
                    moteThrown.exactRotation = Rand.Range(0f, 360f);
                    moteThrown.exactPosition = this.effectCells[matrixIndex] + Vector3Utility.RandomHorizontalOffset(0.3f);
                    GenSpawn.Spawn(moteThrown, moteThrown.exactPosition.ToIntVec3(), this.Map);
                }
                if (this.matrixAbsorbtionCounterInTicks[matrixIndex] > 0)
                {
                    this.matrixAbsorbtionCounterInTicks[matrixIndex]--;
                    this.matrixAbsorbtionFadingCoefficient[matrixIndex] = 0.5f * ((float)this.matrixAbsorbtionCounterInTicks[matrixIndex] / (float)matrixAbsorbtionDurationInTicks);
                }
            }
        }
예제 #8
0
 private static void ThrowObjectAt(Pawn thrower, IntVec3 targetCell, ThingDef mote)
 {
     if (thrower.Position.ShouldSpawnMotesAt(thrower.Map) && !thrower.Map.moteCounter.Saturated)
     {
         float   num    = Rand.Range(3.8f, 5.6f);
         Vector3 vector = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(SkillDefOf.Shooting).Level / 20f) * 1.8f);
         vector.y = thrower.DrawPos.y;
         MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(mote);
         moteThrown.Scale         = 1f;
         moteThrown.rotationRate  = Rand.Range(-300, 300);
         moteThrown.exactPosition = thrower.DrawPos;
         moteThrown.SetVelocity((vector - moteThrown.exactPosition).AngleFlat(), num);
         moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - vector).MagnitudeHorizontal() / num);
         GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map);
     }
 }
예제 #9
0
        public void ThrowPoisonSmoke()
        {
            Vector3 spawnPosition = this.Position.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset(3f);

            if (!spawnPosition.ShouldSpawnMotesAt(this.Map) || this.Map.moteCounter.SaturatedLowPriority)
            {
                return;
            }
            MoteThrown moteThrown = ThingMaker.MakeThing(Util_CaveworldFlora.MotePoisonSmokeDef, null) as MoteThrown;

            moteThrown.Scale         = 3f * this.Growth;
            moteThrown.rotationRate  = (float)Rand.Range(-5, 5);
            moteThrown.exactPosition = spawnPosition;
            moteThrown.SetVelocity((float)Rand.Range(-20, 20), 0);
            GenSpawn.Spawn(moteThrown, spawnPosition.ToIntVec3(), this.Map);
        }
 private static void ThrowObjectAt(Pawn thrower, IntVec3 targetCell, FleckDef fleck)
 {
     if (thrower.Position.ShouldSpawnMotesAt(thrower.Map))
     {
         float   num    = Rand.Range(9.8f, 15.6f);
         Vector3 vector = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(SkillDefOf.Shooting).Level / 20f) * 1.8f);
         vector.y = thrower.DrawPos.y;
         FleckCreationData dataStatic = FleckMaker.GetDataStatic(thrower.DrawPos, thrower.Map, fleck);
         dataStatic.rotationRate  = 0;
         dataStatic.rotation      = thrower.Rotation.AsAngle;
         dataStatic.velocityAngle = (vector - dataStatic.spawnPosition).AngleFlat();
         dataStatic.velocitySpeed = num;
         dataStatic.airTimeLeft   = Mathf.RoundToInt((dataStatic.spawnPosition - vector).MagnitudeHorizontal() / num);
         thrower.Map.flecks.CreateFleck(dataStatic);
     }
 }
예제 #11
0
        private static void ThrowObjectAt(Pawn thrower, IntVec3 targetCell, FleckDef fleck)
        {
            bool flag = !thrower.Position.ShouldSpawnMotesAt(thrower.Map);

            if (!flag)
            {
                float   speed       = Rand.Range(3.8f, 5.6f);
                Vector3 exactTarget = targetCell.ToVector3Shifted() + Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(SkillDefOf.Shooting).Level / 20f) * 1.8f);
                exactTarget.y = thrower.DrawPos.y;
                FleckCreationData data = AdeptusFleckMaker.GetDataStatic(thrower.DrawPos, thrower.Map, fleck, 1f);
                data.rotationRate  = (float)Rand.Range(-300, 300);
                data.velocityAngle = (exactTarget - data.spawnPosition).AngleFlat();
                data.velocitySpeed = speed;
                data.airTimeLeft   = new float?((float)Mathf.RoundToInt((data.spawnPosition - exactTarget).MagnitudeHorizontal() / speed));
                thrower.Map.flecks.CreateFleck(data);
            }
        }
예제 #12
0
        public static Thing ShadowMoteSpawner_ThrowObjectAt(this JobDriver_ThrowRocks JDTR)
        {
            bool   MyDebug  = JDTR.gameSettings.debug;
            string debugStr = MyDebug ? JDTR.PawnLabel + "ShadowMoteSpawner_ThrowObjectAt - " : "";

            Pawn     thrower    = JDTR.pawn;
            IntVec3  targetCell = JDTR.TargetCell;
            SkillDef skillDef   = JDTR.SkillDefScaling;

            ThingDef moteDef = JDTR.MoteDef;

            if (!thrower.AllowedMoteSpawn())
            {
                return(null);
            }

            float   randomSpeed     = JDTR.Speed.RandomInRange;
            Vector3 destinationCell =
                targetCell.ToVector3Shifted() +
                Vector3Utility.RandomHorizontalOffset((1f - (float)thrower.skills.GetSkill(skillDef).Level / 20f) * 1.8f);

            destinationCell.y = thrower.DrawPos.y;
            if (moteDef == null)
            {
                Tools.Warn(debugStr + "found no moteDef", MyDebug);
                return(null);
            }

            ShadowMote moteThrown = (ShadowMote)ThingMaker.MakeThing(moteDef);

            //moteThrown.Initialization(thrower.DrawPos, destinationCell, PGTG.PetanqueSpotCell.ToVector3Shifted(), thrower);
            moteThrown.Initialization(JDTR, destinationCell);

            moteThrown.Scale         = 1f;
            moteThrown.rotationRate  = JDTR.Rotation.RandomInRange;
            moteThrown.exactPosition = thrower.DrawPos;
            moteThrown.SetVelocity((destinationCell - moteThrown.exactPosition).AngleFlat(), randomSpeed);

            moteThrown.airTimeLeft = Mathf.RoundToInt((moteThrown.exactPosition - destinationCell).MagnitudeHorizontal() / randomSpeed);

            return(GenSpawn.Spawn(moteThrown, thrower.Position, thrower.Map));
        }
예제 #13
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         if (this.sustainer == null)
         {
             Log.Error("DustDevil sustainer is null.");
             this.CreateSustainer();
         }
         this.sustainer.Maintain();
         this.UpdateSustainerVolume();
         base.GetComp <CompWindSource>().wind = 5f * this.FadeInOutFactor;
         if (this.leftFadeOutTicks > 0)
         {
             this.leftFadeOutTicks--;
             if (this.leftFadeOutTicks == 0)
             {
                 this.Destroy(DestroyMode.Vanish);
             }
         }
         else
         {
             if (DustDevil.directionNoise == null)
             {
                 DustDevil.directionNoise = new Perlin(0.0020000000949949026, 2.0, 0.5, 4, 1948573612, QualityMode.Medium);
             }
             this.direction   += (float)DustDevil.directionNoise.GetValue((double)Find.TickManager.TicksAbs, (double)((float)(this.thingIDNumber % 500) * 1000f), 0.0) * 0.78f;
             this.realPosition = this.realPosition.Moved(this.direction, 0.0283333343f);
             IntVec3 intVec = new Vector3(this.realPosition.x, 0f, this.realPosition.y).ToIntVec3();
             if (intVec.InBounds(base.Map))
             {
                 base.Position = intVec;
                 if (this.IsHashIntervalTick(15))
                 {
                     this.DamageCloseThings();
                 }
                 if (Rand.MTBEventOccurs(15f, 1f, 1f))
                 {
                     this.DamageFarThings();
                 }
                 if (this.ticksLeftToDisappear > 0)
                 {
                     this.ticksLeftToDisappear--;
                     if (this.ticksLeftToDisappear == 0)
                     {
                         this.leftFadeOutTicks = 120;
                         Messages.Message("MessageDustDevilDissipated".Translate(), new TargetInfo(base.Position, base.Map, false), MessageTypeDefOf.PositiveEvent);
                     }
                 }
                 if (this.IsHashIntervalTick(4) && !this.CellImmuneToDamage(base.Position))
                 {
                     float num = Rand.Range(0.6f, 1f);
                     MoteMaker.ThrowTornadoDustPuff(new Vector3(this.realPosition.x, 0f, this.realPosition.y)
                     {
                         y = Altitudes.AltitudeFor(AltitudeLayer.MoteOverhead)
                     } +Vector3Utility.RandomHorizontalOffset(1.5f), base.Map, Rand.Range(1.5f, 3f), new Color(num, num, num));
                 }
             }
             else
             {
                 this.leftFadeOutTicks = 120;
                 Messages.Message("MessageDustDevilLeftMap".Translate(), new TargetInfo(base.Position, base.Map, false), MessageTypeDefOf.PositiveEvent);
             }
         }
     }
 }
예제 #14
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);
            }
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            const float baseFishingDuration    = 1600f;
            const float catchSuccessRateOnPier = 0.90f;
            const float skillGainPerTick       = 0.15f;

            int fishingDuration = (int)baseFishingDuration;
            Building_FishingPier fishingPier = this.TargetThingA as Building_FishingPier;
            int thrownCornCount   = 0;
            int nextCornThrowTick = 0;

            this.FailOnBurningImmobile(fishingPierIndex);

            // Drawing.
            this.rotateToFace = TargetIndex.B;
            this.pawn.CurJob.SetTarget(TargetIndex.C, fishingPier.riverCell);
            TargetIndex riverCellIndex = TargetIndex.C;

            // Compute fishing duration.
            float fishingSkillLevel = 0f;

            fishingSkillLevel = this.pawn.skills.AverageOfRelevantSkillsFor(WorkTypeDefOf.Hunting);
            float fishingSkillDurationFactor = fishingSkillLevel / 20f;

            fishingDuration = (int)(baseFishingDuration * (1.5f - fishingSkillDurationFactor));

            yield return(Toils_Goto.GotoThing(fishingPierIndex, fishingPier.riverCell).FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil attractfishesToil = new Toil()
            {
                tickAction = () =>
                {
                    if (fishingPier.allowUsingGrain == false)
                    {
                        this.ReadyForNextToil();
                        return;
                    }
                    if (Find.TickManager.TicksGame >= nextCornThrowTick)
                    {
                        nextCornThrowTick = Find.TickManager.TicksGame + 3 * GenTicks.TicksPerRealSecond;
                        // Look for corn in inventory.
                        Thing corn = null;
                        foreach (Thing thing in this.pawn.inventory.innerContainer)
                        {
                            if (thing.def == Util_FishIndustry.RawCornDef)
                            {
                                corn = thing;
                                break;
                            }
                        }
                        if ((corn == null) ||
                            (thrownCornCount >= grainCountToAttractFishes))
                        {
                            fishingDuration -= Mathf.CeilToInt((float)fishingDuration * 0.75f * ((float)thrownCornCount / (float)grainCountToAttractFishes));
                            this.ReadyForNextToil();
                            return;
                        }
                        // Throw corn grains.
                        thrownCornCount++;
                        this.pawn.inventory.innerContainer.Take(corn, 1);
                        for (int cornGrainIndex = 0; cornGrainIndex < 5; cornGrainIndex++)
                        {
                            if (!this.pawn.Position.ShouldSpawnMotesAt(this.pawn.Map) || this.pawn.Map.moteCounter.Saturated)
                            {
                                break;
                            }
                            float   speed          = Rand.Range(1.5f, 3f);
                            Vector3 targetPosition = this.pawn.Position.ToVector3Shifted() + new Vector3(0f, 0f, 2f).RotatedBy(fishingPier.Rotation.AsAngle) + Vector3Utility.RandomHorizontalOffset(1.5f);
                            targetPosition.y = this.pawn.DrawPos.y;
                            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_Stone, null);
                            moteThrown.Scale         = 0.2f;
                            moteThrown.rotationRate  = (float)Rand.Range(-300, 300);
                            moteThrown.exactPosition = this.pawn.DrawPos;
                            moteThrown.SetVelocity((targetPosition - moteThrown.exactPosition).AngleFlat(), speed);
                            moteThrown.airTimeLeft = (float)Mathf.RoundToInt((moteThrown.exactPosition - targetPosition).MagnitudeHorizontal() / speed);
                            GenSpawn.Spawn(moteThrown, this.pawn.Position, this.pawn.Map);
                            MoteMaker.MakeWaterSplash(targetPosition, this.pawn.Map, 1.8f, 0.5f);
                        }
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(attractfishesToil.FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil fishToil = new Toil()
            {
                initAction = () =>
                {
                    ThingDef moteDef = null;
                    if (fishingPier.Rotation == Rot4.North)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodNorthDef;
                    }
                    else if (fishingPier.Rotation == Rot4.East)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodEastDef;
                    }
                    else if (fishingPier.Rotation == Rot4.South)
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodSouthDef;
                    }
                    else
                    {
                        moteDef = Util_FishIndustry.MoteFishingRodWestDef;
                    }
                    this.fishingRodMote = (Mote)ThingMaker.MakeThing(moteDef, null);
                    this.fishingRodMote.exactPosition = fishingPier.fishingSpotCell.ToVector3Shifted();
                    this.fishingRodMote.Scale         = 1f;
                    GenSpawn.Spawn(this.fishingRodMote, fishingPier.fishingSpotCell, this.Map);
                },
                tickAction = () =>
                {
                    this.pawn.skills.Learn(SkillDefOf.Shooting, skillGainPerTick);

                    if (this.fishingRodMote != null)
                    {
                        this.fishingRodMote.Maintain();
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(fishToil.WithProgressBarToilDelay(riverCellIndex).FailOn(FishingForbiddenOrPierDestroyedOrNoFish));

            Toil catchFishToil = new Toil()
            {
                initAction = () =>
                {
                    Thing fishingCatch = null;

                    bool catchIsSuccessful = (Rand.Value <= catchSuccessRateOnPier);
                    if (catchIsSuccessful == false)
                    {
                        MoteMaker.ThrowMetaIcon(this.pawn.Position, this.Map, ThingDefOf.Mote_IncapIcon);
                        this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        return;
                    }

                    float catchSelectorValue = Rand.Value;

                    if (catchSelectorValue < 0.02)
                    {
                        float bonusCatchValue = Rand.Value;
                        if (bonusCatchValue < 0.01f)
                        {
                            // Really small chance to find a sunken treasure!!!
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(58, 289);
                            Thing treasureSilver = GenSpawn.Spawn(ThingDefOf.Silver, fishingPier.middleCell, this.Map);
                            treasureSilver.stackCount = Rand.RangeInclusive(237, 2154);
                            Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelSunkenTreasure".Translate(), "FishIndustry.SunkenTreasure".Translate(this.pawn.Name.ToStringShort.CapitalizeFirst()),
                                                           LetterDefOf.PositiveEvent, this.pawn);
                        }
                        else if (bonusCatchValue < 0.02f)
                        {
                            // Really small chance to find a complete power armor set + sniper or charge rifle.
                            Thing powerArmor = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmor"), this.pawn.Position, this.Map);
                            fishingCatch = powerArmor; // Used to carry the power armor.
                            Thing powerArmorHelmet = GenSpawn.Spawn(ThingDef.Named("Apparel_PowerArmorHelmet"), this.pawn.Position, this.Map);
                            Thing rifle            = null;
                            if (Rand.Value < 0.5f)
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_ChargeRifle"), this.pawn.Position, this.Map);
                            }
                            else
                            {
                                rifle = GenSpawn.Spawn(ThingDef.Named("Gun_SniperRifle"), this.pawn.Position, this.Map);
                            }
                            CompQuality qualityComp = powerArmor.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = powerArmorHelmet.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }
                            qualityComp = rifle.TryGetComp <CompQuality>();
                            if (qualityComp != null)
                            {
                                qualityComp.SetQuality(QualityCategory.Masterwork, ArtGenerationContext.Outsider);
                            }

                            Faction faction    = Find.FactionManager.FirstFactionOfDef(FactionDefOf.AncientsHostile);
                            Pawn    deadMarine = PawnGenerator.GeneratePawn(PawnKindDefOf.AncientSoldier, faction);
                            HealthUtility.DamageUntilDead(deadMarine);
                            Corpse       corpse  = deadMarine.ParentHolder as Corpse;
                            CompRottable rotComp = corpse.TryGetComp <CompRottable>();
                            if (rotComp != null)
                            {
                                rotComp.RotProgress = 20f * GenDate.TicksPerDay; // 20 days so the corpse is dessicated.
                            }
                            GenSpawn.Spawn(corpse, fishingPier.bankCell, this.Map);
                            string eventText = "FishIndustry.LetterDescDeadMarine".Translate(this.pawn.Name.ToStringShort.CapitalizeFirst());
                            Find.LetterStack.ReceiveLetter("FishIndustry.LetterLabelDeadMarine".Translate(), eventText, LetterDefOf.PositiveEvent, this.pawn);
                        }
                        else
                        {
                            // Find a small amount of gold.
                            fishingCatch            = GenSpawn.Spawn(ThingDefOf.Gold, this.pawn.Position, this.Map);
                            fishingCatch.stackCount = Rand.RangeInclusive(1, 7);
                        }
                    }
                    else if (catchSelectorValue < 0.04)
                    {
                        // Find oysters.
                        fishingCatch            = GenSpawn.Spawn(Util_FishIndustry.OysterDef, this.pawn.Position, this.Map);
                        fishingCatch.stackCount = Rand.RangeInclusive(2, 9);
                    }
                    else
                    {
                        // Catch a fish.
                        IntVec3 fishSpot        = fishingPier.aquaticCells.RandomElement();
                        bool    fishSpotIsOcean = (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDefOf.WaterOceanShallow) ||
                                                  (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDefOf.WaterOceanDeep);
                        bool fishSpotIsMarshy = (this.Map.terrainGrid.TerrainAt(fishSpot) == TerrainDef.Named("Marsh"));

                        PawnKindDef caugthFishDef = null;
                        if (fishSpotIsOcean)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInOcean
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else if (fishSpotIsMarshy)
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInMarsh
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        else
                        {
                            caugthFishDef = (from fishSpecies in Util_FishIndustry.GetFishSpeciesList(this.Map.Biome)
                                             where fishSpecies.livesInRiver
                                             select fishSpecies).RandomElementByWeight((PawnKindDef_FishSpecies def) => def.commonality);
                        }
                        Pawn caughtFish = PawnGenerator.GeneratePawn(caugthFishDef);
                        ExecutionUtility.DoExecutionByCut(this.pawn, caughtFish);
                        Corpse corpse = caughtFish.ParentHolder as Corpse;
                        GenSpawn.Spawn(corpse, this.pawn.Position, this.Map);
                        fishingCatch = corpse;
                        fishingCatch.SetForbidden(false);
                        if (caughtFish.BodySize >= 0.1f)
                        {
                            fishingPier.fishStock--;
                        }
                    }
                    IntVec3 storageCell;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(fishingCatch, this.pawn, this.Map, StoragePriority.Unstored, this.pawn.Faction, out storageCell, true))
                    {
                        this.pawn.Reserve(fishingCatch, this.job);
                        this.pawn.Reserve(storageCell, this.job);
                        this.pawn.CurJob.SetTarget(TargetIndex.B, storageCell);
                        this.pawn.CurJob.SetTarget(TargetIndex.A, fishingCatch);
                        this.pawn.CurJob.count    = 9999;
                        this.pawn.CurJob.haulMode = HaulMode.ToCellStorage;
                    }
                    else
                    {
                        this.pawn.jobs.EndCurrentJob(JobCondition.Succeeded);
                    }
                }
            };

            yield return(catchFishToil);

            yield return(Toils_Haul.StartCarryThing(TargetIndex.A));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.B);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.B, carryToCell, true));
        }
예제 #16
0
        public override void Tick()
        {
            if (base.Spawned)
            {
                if (this.sustainer == null)
                {
                    Log.Error("Tornado sustainer is null.", false);
                    this.CreateSustainer();
                }
                this.sustainer.Maintain();
                this.UpdateSustainerVolume();

                //	base.GetComp<CompWindSource>().wind = 5f * this.FadeInOutFactor;
                if (this.leftFadeOutTicks > 0)
                {
                    this.leftFadeOutTicks--;
                    if (this.leftFadeOutTicks == 0)
                    {
                        this.Destroy(DestroyMode.Vanish);
                        return;
                    }
                }
                else
                {
                    if (GlassingBeam.directionNoise == null)
                    {
                        GlassingBeam.directionNoise = new Perlin(0.0020000000949949026, 2.0, 0.5, 4, 1948573612, QualityMode.Medium);
                    }
                    this.direction   += (float)GlassingBeam.directionNoise.GetValue((double)Find.TickManager.TicksAbs, (double)((float)(this.thingIDNumber % 500) * 1000f), 0.0) * 0.78f;
                    this.realPosition = this.realPosition.Moved(this.direction, 0.0283333343f);
                    IntVec3 intVec = new Vector3(this.realPosition.x, 0f, this.realPosition.y).ToIntVec3();
                    if (intVec.InBounds(base.Map))
                    {
                        base.Position = intVec;
                        if (powerBeamMote == null)
                        {
                            powerBeamMote = MakePowerBeamMote(base.Position, base.Map, beamWidth * 3f, this.ticksLeftToDisappear.TicksToSeconds());
                        }
                        powerBeamMote.exactPosition = DrawPos;
                        powerBeamMote.spawnTick     = Find.TickManager.TicksGame - 60;
                        for (int i = 0; i < 4; i++)
                        {
                            this.StartRandomFireAndDoFlameDamage();
                        }
                        if (this.IsHashIntervalTick(15))
                        {
                            this.DamageCloseThings();
                        }
                        if (Rand.MTBEventOccurs(15f, 1f, 1f))
                        {
                            this.DamageFarThings();
                        }
                        if (this.IsHashIntervalTick(20))
                        {
                            this.DestroyRoofs();
                        }
                        if (this.ticksLeftToDisappear > 0)
                        {
                            this.ticksLeftToDisappear--;
                            if (this.ticksLeftToDisappear == 0)
                            {
                                this.leftFadeOutTicks = 120;
                                Messages.Message("MessageTornadoDissipated".Translate(), new TargetInfo(base.Position, base.Map, false), MessageTypeDefOf.PositiveEvent, true);
                            }
                        }
                        if (this.IsHashIntervalTick(4) && !this.CellImmuneToDamage(base.Position))
                        {
                            float num = Rand.Range(0.6f, 1f);
                            MoteMaker.ThrowTornadoDustPuff(new Vector3(this.realPosition.x, 0f, this.realPosition.y)
                            {
                                y = AltitudeLayer.MoteOverhead.AltitudeFor()
                            } +Vector3Utility.RandomHorizontalOffset(1.5f), base.Map, Rand.Range(1.5f, 3f), new Color(num, num, num));
                            return;
                        }
                    }
                    else
                    {
                        this.leftFadeOutTicks = 120;
                        Messages.Message("MessageTornadoLeftMap".Translate(), new TargetInfo(base.Position, base.Map, false), MessageTypeDefOf.PositiveEvent, true);
                    }
                }
            }
        }