Beispiel #1
0
        public void ThrowSparks(Vector3 loc, Map map)
        {
            if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
            {
                return;
            }

            for (int i = 0; i < 3; i++)
            {
                MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_MicroSparks, null);
                moteThrown.Scale          = Rand.Range(2.5f, 3f);
                moteThrown.rotationRate   = Rand.Range(-12f, 12f);
                moteThrown.exactPosition  = loc;
                moteThrown.exactPosition -= new Vector3(0.5f, 0f, 0.5f);
                moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value);
                moteThrown.SetVelocity((float)Rand.Range(7 * (i + 1), 10 * (i + 1)), 2f);
                GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish);
            }
            MoteMaker.ThrowLightningGlow(this.parent.Position.ToVector3(), this.parent.Map, 6f);
        }
 public override void Tick()
 {
     if (ticksToImpact <= 60 && !once)
     {
         foreach (var item in this.OccupiedRect())
         {
             if (this.Map == Find.CurrentMap && item.InBounds(this.Map))
             {
                 MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(KThingDefOf.KCSG_LongMote_DustPuff, null);
                 moteThrown.Scale         = Rand.Range(3f, 6f);
                 moteThrown.rotationRate  = (float)Rand.Range(-60, 60);
                 moteThrown.exactPosition = item.ToVector3();
                 moteThrown.SetVelocity((float)Rand.Range(0, 360), Rand.Range(0.6f, 0.75f));
                 GenSpawn.Spawn(moteThrown, item, this.Map, WipeMode.Vanish);
             }
         }
         once = true;
     }
     base.Tick();
 }
        // ===================== Main Work Function =====================
        /// <summary>
        /// Main function:
        /// - update the scan progress,
        /// - throw a flash to help locate the MMS in the wild every few seconds.
        /// </summary>
        public override void Tick()
        {
            base.Tick();
            PerformScanUpdate();

            if (Find.TickManager.TicksGame >= this.nextFlashTick)
            {
                if (!this.Position.ShouldSpawnMotesAt(this.Map) || this.Map.moteCounter.SaturatedLowPriority)
                {
                    return;
                }
                MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_LightningGlow, null);
                moteThrown.Scale         = 5f;
                moteThrown.rotationRate  = Rand.Range(-3f, 3f);
                moteThrown.exactPosition = this.Position.ToVector3Shifted();
                moteThrown.SetVelocity((float)Rand.Range(0, 360), 1.2f);
                GenSpawn.Spawn(moteThrown, this.Position, this.Map);
                this.nextFlashTick = Find.TickManager.TicksGame + flashPeriodInSeconds * GenTicks.TicksPerRealSecond * (int)Find.TickManager.CurTimeSpeed;
            }
        }
        public static void ThrowDustPuff(Vector3 loc, Map map, float scale, ThingDef def = null, Color?color = null)
        {
            if (!loc.ShouldSpawnMotesAt(map))
            {
                return;
            }
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(def ?? ThingDefOf.Mote_DustPuff, null);

            moteThrown.Scale         = 1.9f * scale;
            moteThrown.rotationRate  = (float)Rand.Range(-60, 60);
            moteThrown.exactPosition = loc;
            moteThrown.SetVelocity((float)Rand.Range(0, 360), Rand.Range(0.6f, 0.75f));
            if (color.HasValue)
            {
                moteThrown.instanceColor = color.Value;
                //    moteThrown.instanceColor = new Color(0.368f, 0f, 1f);
            }

            GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish);
        }
Beispiel #5
0
        public static void ThrowHeatGlow(IntVec3 c, Map map, float size)
        {
            Vector3 vector = c.ToVector3Shifted();

            if (!vector.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
            {
                return;
            }
            vector += size * new Vector3(Rand.Value - 0.5f, 0f, Rand.Value - 0.5f);
            if (!vector.InBounds(map))
            {
                return;
            }
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_HeatGlow, null);

            moteThrown.Scale         = Rand.Range(4f, 6f) * size;
            moteThrown.rotationRate  = Rand.Range(-3f, 3f);
            moteThrown.exactPosition = vector;
            moteThrown.SetVelocity((float)Rand.Range(0, 360), 0.12f);
            GenSpawn.Spawn(moteThrown, vector.ToIntVec3(), map, WipeMode.Vanish);
        }
Beispiel #6
0
        public static void ThrowPawnEffectMote(Vector3 loc, Map map, ThingDef moteDef, bool rotation = true)
        {
            if (!loc.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
            {
                return;
            }
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef, null);

            moteThrown.Scale = Rand.Range(0.5f, 1.2f);
            if (rotation)
            {
                moteThrown.rotationRate = Rand.Range(-12f, 36f);
            }

            moteThrown.exactPosition  = loc;
            moteThrown.exactPosition -= new Vector3(0.5f, 0f, 0.5f);
            moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value);
            moteThrown.SetVelocity(Rand.Range(35, 45), 1.2f);

            GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map);
        }
Beispiel #7
0
        public static void MakeEffect(ThingDef mote, Vector3 loc, Map map, float scale, float directionAngle, float velocity, float rotationRate, float lookAngle, float solidTime, float fadeIn, float fadeOut, bool colorShift)
        {
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(mote, null);

            moteThrown.Scale         = 1.9f * scale;
            moteThrown.rotationRate  = rotationRate;
            moteThrown.exactPosition = loc;
            moteThrown.exactRotation = lookAngle;
            moteThrown.SetVelocity(directionAngle, velocity);
            moteThrown.def.mote.solidTime   = solidTime;
            moteThrown.def.mote.fadeInTime  = fadeIn;
            moteThrown.def.mote.fadeOutTime = fadeOut;

            if (colorShift)
            {
                Color color = moteThrown.instanceColor;
                color = new Color(color.r, color.g, color.b, color.a * Rand.Range(0, 1f));
                moteThrown.instanceColor = color;
            }
            GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map);
        }
Beispiel #8
0
        public static void ThrowAirPuffUp(Vector3 loc, Map map)
        {
            if (map == null)
            {
                return;
            }
            if (!loc.InBounds(map))
            {
                return;
            }
            if (!GenView.ShouldSpawnMotesAt(loc, map))
            {
                return;
            }
            MoteThrown moteThrown = TrailThrower.NewBaseAirPuff();

            moteThrown.exactPosition  = loc;
            moteThrown.exactPosition += new Vector3(Rand.Range(-0.02f, 0.02f), 0f, Rand.Range(-0.02f, 0.02f));
            moteThrown.SetVelocity((float)Rand.Range(-45, 45), Rand.Range(1.2f, 1.5f));
            GenSpawn.Spawn(moteThrown, loc.ToIntVec3(), map, WipeMode.Vanish);
        }
Beispiel #9
0
        public void DrawMotes()
        {
            foreach (OffsetMote offset in Props.motesGenerated)
            {
                for (int i = 0; i < offset.NumTimesSpawned; i++)
                {
                    try
                    {
                        Pair <float, float> moteOffset = HelperMethods.ShipDrawOffset(CompShip, offset.xOffset, offset.zOffset);
                        offsetX = moteOffset.First;
                        offsetZ = moteOffset.Second;

                        motePosition = new Vector3(parent.Position.x + offsetX + cellOffsetIntVec3ToVector3, parent.Position.y, parent.Position.z + offsetZ + cellOffsetIntVec3ToVector3);

                        MoteThrown mote = (MoteThrown)ThingMaker.MakeThing(Props.MoteDisplayed, null);
                        mote.exactPosition = motePosition;
                        mote.Scale         = 1f;
                        mote.rotationRate  = 15f;
                        float moteAngle = offset.predeterminedAngleVector is null ? (Pawn.Map.components.First(x => x is WindDirectional) as WindDirectional).WindDirection : (float)offset.predeterminedAngleVector;
                        float moteSpeed = offset.windAffected ? Rand.Range(0.5f, 3.5f) * Pawn.Map.windManager.WindSpeed : offset.moteThrownSpeed;
                        mote.SetVelocity(moteAngle, moteSpeed);
                        HelperMethods.ThrowMoteEnhanced(motePosition, parent.Map, mote);
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Concat(new object[]
                        {
                            "Exception thrown while trying to display ",
                            Props.MoteDisplayed.defName,
                            " Terminating MoteDraw Method from ",
                            parent.LabelShort,
                            " Exception: ",
                            ex.Message
                        }));
                        terminateMotes = true;
                        return;
                    }
                }
            }
        }
        public static Mote ThrowMetaIcon(IntVec3 cell, Map map, ThingDef moteDef)
        {
            Mote result;

            if (!cell.ShouldSpawnMotesAt(map) || map.moteCounter.Saturated)
            {
                result = null;
            }
            else
            {
                MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef, null);
                moteThrown.Scale          = 0.7f;
                moteThrown.rotationRate   = Rand.Range(-3f, 3f);
                moteThrown.exactPosition  = cell.ToVector3Shifted();
                moteThrown.exactPosition += new Vector3(0.35f, 0f, 0.35f);
                moteThrown.exactPosition += new Vector3(Rand.Value, 0f, Rand.Value) * 0.1f;
                moteThrown.SetVelocity((float)Rand.Range(30, 60), 0.42f);
                GenSpawn.Spawn(moteThrown, cell, map, WipeMode.Vanish);
                result = moteThrown;
            }
            return(result);
        }
Beispiel #11
0
        public static Mote ThrowBatteryXYZ(ThingDef moteDef, Vector3 loc, Map map, float scale)
        {
            Mote result;

            if (!GenView.ShouldSpawnMotesAt(loc, map) ||
                map.moteCounter.Saturated)
            {
                result = null;
            }
            else
            {
                MoteThrown batteryMote = (MoteThrown)ThingMaker.MakeThing(moteDef, null);
                batteryMote.Scale          = scale;
                batteryMote.rotationRate   = (float)Rand.Range(-1, 1);
                batteryMote.exactPosition  = loc;
                batteryMote.exactPosition += new Vector3(THIRTY_FIVE, 0, THIRTY_FIVE);
                batteryMote.exactPosition += new Vector3(Rand.Value, 0, Rand.Value) * POINT_TEN;
                batteryMote.SetVelocity(Rand.Range(30, 60), Rand.Range(THIRTY_FIVE, FIFTY_FIVE));
                GenSpawn.Spawn(batteryMote, IntVec3Utility.ToIntVec3(loc), map);
                result = batteryMote;
            }
            return(result);
        }
        public static void ThrowToxicSmoke(Vector3 loc, Map map, Color?color = null)
        {
            if (!loc.ShouldSpawnMotesAt(map))
            {
                return;
            }
            //moteThrown.instanceColor = new ColorInt(43, 56, 54).ToColor; // to investigate
            //moteThrown.Scale = Rand.Range(2.5f, 3.9f); to investigate
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_Smoke, null);

            moteThrown.Scale         = Rand.Range(0.5f, 0.9f);
            moteThrown.rotationRate  = Rand.Range(-30f, 30f);
            moteThrown.exactPosition = loc;
            moteThrown.airTimeLeft   = Rand.Range(0.1f, 0.4f);
            moteThrown.Speed         = 0.3f;
            moteThrown.SetVelocity((float)Rand.Range(-20, 20), Rand.Range(0.5f, 0.7f));
            if (color.HasValue)
            {
                moteThrown.instanceColor = color.Value;
                //    moteThrown.instanceColor = new Color(0f, 0.0862f, 0.094117f);
            }
            GenSpawn.Spawn(moteThrown, IntVec3Utility.ToIntVec3(loc), map, WipeMode.Vanish);
        }
        public void SaveImpact()
        {
            if (this.def.skyfaller.CausesExplosion)
            {
                GenExplosion.DoExplosion(base.Position, base.Map, this.def.skyfaller.explosionRadius, this.def.skyfaller.explosionDamage, null, GenMath.RoundRandom((float)this.def.skyfaller.explosionDamage.defaultDamage * this.def.skyfaller.explosionDamageFactor), -1f, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false, null, (!this.def.skyfaller.damageSpawnedThings) ? this.innerContainer.ToList <Thing>() : null);
            }
            this.SpawnThings();
            this.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish);

            foreach (var item in this.OccupiedRect())
            {
                if (this.Map == Find.CurrentMap && item.InBounds(this.Map))
                {
                    MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(KThingDefOf.KCSG_LongMote_DustPuff, null);
                    moteThrown.Scale         = Rand.Range(3f, 6f);
                    moteThrown.rotationRate  = (float)Rand.Range(-60, 60);
                    moteThrown.exactPosition = item.ToVector3();
                    moteThrown.SetVelocity((float)Rand.Range(0, 360), Rand.Range(0.6f, 0.75f));
                    GenSpawn.Spawn(moteThrown, item, this.Map, WipeMode.Vanish);
                }
            }

            this.Destroy(DestroyMode.Vanish);
        }
Beispiel #14
0
        public void FireTurretCannon(CannonHandler cannon, ref SPTuple2 <int, int> data)
        {
            if (cannon is null)
            {
                return;
            }
            bool flag = TryFindShootLineFromTo(cannon.TurretLocation.ToIntVec3(), cannon.cannonTarget, out ShootLine shootLine);

            //FIX FOR MULTIPLAYER
            IntVec3 c = cannon.cannonTarget.Cell + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(cannon.cannonDef.spreadRadius * (Range / cannon.cannonDef.maxRange)))];

            if (data.Second >= cannon.cannonDef.projectileShifting.Count)
            {
                data.Second = 0;
            }
            float   horizontalOffset = cannon.cannonDef.projectileShifting.Any() ? cannon.cannonDef.projectileShifting[data.Second] : 0;
            Vector3 launchCell       = cannon.TurretLocation + new Vector3(horizontalOffset, 1f, cannon.cannonDef.projectileOffset).RotatedBy(cannon.TurretRotation);

            ThingDef projectile;

            if (cannon.cannonDef.ammoAllowed?.Any() ?? false)
            {
                projectile = cannon.loadedAmmo;
            }
            else
            {
                projectile = cannon.cannonDef.projectile;
            }
            try
            {
                Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, Pawn.Position, Pawn.Map, WipeMode.Vanish);
                if (cannon.cannonDef.ammoAllowed?.Any() ?? false)
                {
                    cannon.ConsumeShellChambered();
                }
                if (cannon.cannonDef.cannonSound is null)
                {
                    SoundDefOf_Ships.Explosion_PirateCannon.PlayOneShot(new TargetInfo(Pawn.Position, Pawn.Map, false));
                }
                else
                {
                    cannon.cannonDef.cannonSound.PlayOneShot(new TargetInfo(Pawn.Position, Pawn.Map, false));
                }

                if (cannon.cannonDef.moteFlash != null)
                {
                    MoteMaker.MakeStaticMote(launchCell, Pawn.Map, cannon.cannonDef.moteFlash, 2);
                }
                if (cannon.cannonDef.moteCannon != null)
                {
                    MoteThrown mote = (MoteThrown)ThingMaker.MakeThing(cannon.cannonDef.moteCannon, null);
                    mote.exactPosition = launchCell;
                    mote.Scale         = 1f;
                    mote.rotationRate  = 15f;
                    mote.SetVelocity(cannon.TurretRotation, cannon.cannonDef.moteSpeedThrown);
                    HelperMethods.ThrowMoteEnhanced(launchCell, Pawn.Map, mote);
                }
                projectile2.Launch(Pawn, launchCell, c, cannon.cannonTarget, cannon.cannonDef.hitFlags);
            }
            catch (Exception ex)
            {
                Log.Error($"Exception when firing Cannon: {cannon.cannonDef.LabelCap} on Pawn: {Pawn.LabelCap}. Exception: {ex.Message}");
            }
        }
        private void checkPawns()
        {
            List <Pawn> pawns = this.map.mapPawns.AllPawnsSpawned;

            for (int i = 0; i < pawns.Count; i++)
            {
                Pawn pawn = pawns[i];
                if (pawn == null || !pawn.Spawned)
                {
                    continue;
                }

                #region paths
                if (pawn.Position.InBounds(map))
                {
                    //damage plants and remove snow/frost where they are. This will hopefully generate paths as pawns walk :)
                    if (this.checkIfCold(pawn.Position))
                    {
                        map.GetComponent <FrostGrid>().AddDepth(pawn.Position, (float)-.05);
                        map.snowGrid.AddDepth(pawn.Position, (float)-.05);
                    }

                    if (pawn.RaceProps.Humanlike)
                    {
                        List <Thing> things = pawn.Position.GetThingList(map);
                        foreach (Thing thing in things.ToList())
                        {
                            if (thing.def.category == ThingCategory.Plant && thing.def.altitudeLayer == AltitudeLayer.LowPlant && thing.def.plant.harvestTag != "Standard")
                            {
                                thing.TakeDamage(new DamageInfo(DamageDefOf.Rotting, 99999, -.05f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown));
                            }
                        }
                    }
                }
                #endregion

                TerrainDef terrain = pawn.Position.GetTerrain(map);
                if ((terrain.defName == "TKKN_SaltField" || terrain.defName == "TKKN_Salted_Earth") && pawn.def.defName == "TKKN_giantsnail")
                {
                    this.burnSnails(pawn);
                    continue;
                }
                if (this.ticks % 250 == 0 && (terrain.defName == "TKKN_HotSpringsWater" || terrain.defName == "TKKN_ColdSpringsWater"))
                {
                    if (pawn.RaceProps.Humanlike && pawn.needs == null)
                    {
                        continue;
                    }
                    HediffDef hediffDef = new HediffDef();
                    if (terrain.defName == "TKKN_HotSpringsWater")
                    {
                        if (pawn.needs.comfort != null)
                        {
                            pawn.needs.comfort.lastComfortUseTick--;
                        }
                        hediffDef = HediffDefOf.TKKN_hotspring_chill_out;
                        if (pawn.health.hediffSet.GetFirstHediffOfDef(hediffDef) == null)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
                            pawn.health.AddHediff(hediff, null, null);
                        }
                    }
                    if (terrain.defName == "TKKN_ColdSpringsWater")
                    {
                        pawn.needs.rest.CurLevel++;
                        hediffDef = HediffDefOf.TKKN_coldspring_chill_out;
                        if (pawn.health.hediffSet.GetFirstHediffOfDef(hediffDef, false) == null)
                        {
                            Hediff hediff = HediffMaker.MakeHediff(hediffDef, pawn, null);
                            pawn.health.AddHediff(hediff, null, null);
                        }
                    }
                }

                if (this.ticks % 150 != 0)
                {
                    return;
                }

                bool isCold = this.checkIfCold(pawn.Position);
                if (isCold)
                {
                    IntVec3 head = pawn.Position;
                    head.z += 1;
                    if (!head.ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
                    {
                        return;
                    }
                    MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDef.Named("TKKN_Mote_ColdBreath"), null);
                    moteThrown.airTimeLeft   = 99999f;
                    moteThrown.Scale         = Rand.Range(.5f, 1.5f);
                    moteThrown.rotationRate  = Rand.Range(-30f, 30f);
                    moteThrown.exactPosition = head.ToVector3();
                    moteThrown.SetVelocity((float)Rand.Range(20, 30), Rand.Range(0.5f, 0.7f));
                    GenSpawn.Spawn(moteThrown, head, map);
                }
            }
        }
        protected override bool TryCastShot()
        {
            bool flag = false;

            this.TargetsAoE.Clear();
            this.UpdateTargets();
            int  shotsPerBurst = this.ShotsPerBurst;
            bool flag2         = this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1;

            if (flag2)
            {
                this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1);
            }
            bool flag3 = this.UseAbilityProps.mustHaveTarget && this.TargetsAoE.Count == 0;
            bool result;

            if (flag3)
            {
                Messages.Message("AU_NoTargets".Translate(), MessageTypeDefOf.RejectInput, true);
                this.Ability.Notify_AbilityFailed(true);
                result = false;
            }
            else
            {
                for (int i = 0; i < this.TargetsAoE.Count; i++)
                {
                    bool abilitySucceeded = true;
                    foreach (Pawn targetPawn in CasterPawn.Map.mapPawns.AllPawnsSpawned)
                    {
                        if (targetPawn is Pawn_Grimm && CasterPawn.Position.DistanceTo(targetPawn.Position) <= this.verbProps.range)
                        {
                            if (TryFindShootLineFromTo(CasterPawn.Position, targetPawn, out ShootLine shootLine))
                            {
                                Projectile projectile = (Projectile)GenSpawn.Spawn(RWBYDefOf.RWBY_SilverEyes_Projectile, CasterPawn.Position, CasterPawn.Map);
                                projectile.Launch(CasterPawn, targetPawn, targetPawn, ProjectileHitFlags.IntendedTarget);
                            }
                        }
                    }

                    if (CasterPawn.story.traits.HasTrait(RWBYDefOf.RWBY_Aura))
                    {
                        Hediff silverEyesExhaustion = new Hediff();
                        silverEyesExhaustion = HediffMaker.MakeHediff(RWBYDefOf.RWBY_SilverEye_Exhaustion, CasterPawn);
                        if (burstShotsLeft == 1)
                        {
                            silverEyesExhaustion.Severity = 1.2f;
                        }
                        CasterPawn.health.AddHediff(silverEyesExhaustion);
                    }

                    if (!CasterPawn.Downed)
                    {
                        MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(RWBYDefOf.RWBY_SilverEye_Mote, null);
                        moteThrown.Scale         = 3f;
                        moteThrown.rotationRate  = 0f;
                        moteThrown.exactPosition = CasterPawn.Drawer.DrawPos + CasterPawn.Drawer.renderer.BaseHeadOffsetAt(CasterPawn.Rotation);
                        moteThrown.SetVelocity(0f, 0f);
                        Log.Warning(moteThrown.exactPosition.ToString());
                        GenSpawn.Spawn(moteThrown, CasterPawn.Position, CasterPawn.Map, WipeMode.Vanish);
                    }

                    if (abilitySucceeded)
                    {
                        flag = true;
                    }
                }
                this.PostCastShot(flag, out flag);
                bool postSucceed = !flag;
                if (postSucceed)
                {
                    this.Ability.Notify_AbilityFailed(this.UseAbilityProps.refundsPointsAfterFailing);
                }
                result = flag;
            }
            return(result);
        }
Beispiel #17
0
        // Token: 0x06002080 RID: 8320 RVA: 0x000C6E58 File Offset: 0x000C5058
        protected void MakeMote(CompTurretGun A, TargetInfo B)
        {
            Vector3 vector = Vector3.zero;

            switch (this.def.spawnLocType)
            {
            case MoteSpawnLocType.OnSource:
                vector = A.TurretPos;
                break;

            case MoteSpawnLocType.BetweenPositions:
            {
                Vector3 vector2 = A.IsOperated ? A.TurretPos : A.parent.DrawPos;
                Vector3 vector3 = B.HasThing ? B.Thing.DrawPos : B.Cell.ToVector3Shifted();
                if (A.IsOperated && !A.Operator.Spawned)
                {
                    vector = vector3;
                }
                else if (B.HasThing && !B.Thing.Spawned)
                {
                    vector = vector2;
                }
                else
                {
                    vector = vector2 * this.def.positionLerpFactor + vector3 * (1f - this.def.positionLerpFactor);
                }
                break;
            }

            case MoteSpawnLocType.BetweenTouchingCells:
                vector = A.Operator.Position.ToVector3Shifted() + (B.Cell - A.Operator.Position).ToVector3().normalized * 0.5f;
                break;

            case MoteSpawnLocType.RandomCellOnTarget:
            {
                CellRect cellRect;
                if (B.HasThing)
                {
                    cellRect = B.Thing.OccupiedRect();
                }
                else
                {
                    cellRect = CellRect.CenteredOn(B.Cell, 0);
                }
                vector = cellRect.RandomCell.ToVector3Shifted();
                break;
            }
            }
            if (this.parent != null)
            {
                Rand.PushState(this.parent.GetHashCode());
                if (A.TurretPos != B.CenterVector3)
                {
                    vector += (B.CenterVector3 - A.TurretPos).normalized * this.parent.def.offsetTowardsTarget.RandomInRange;
                }
                vector += Gen.RandomHorizontalVector(this.parent.def.positionRadius) + this.parent.offset;
                Rand.PopState();
            }
            Map   map  = A.Operator.Map ?? B.Map;
            float num  = this.def.absoluteAngle ? 0f : (B.Cell - A.Operator.Position).AngleFlat;
            float num2 = (this.parent != null) ? this.parent.scale : 1f;

            if (map != null && vector.ShouldSpawnMotesAt(map))
            {
                int randomInRange = this.def.burstCount.RandomInRange;
                for (int i = 0; i < randomInRange; i++)
                {
                    Mote mote = (Mote)ThingMaker.MakeThing(this.def.moteDef, null);
                    GenSpawn.Spawn(mote, vector.ToIntVec3(), map, WipeMode.Vanish);
                    mote.Scale         = this.def.scale.RandomInRange * num2;
                    mote.exactPosition = vector + this.def.positionOffset * num2 + Gen.RandomHorizontalVector(this.def.positionRadius) * num2;
                    mote.rotationRate  = this.def.rotationRate.RandomInRange;
                    mote.exactRotation = this.def.rotation.RandomInRange + num;
                    mote.instanceColor = this.def.color;
                    MoteThrown moteThrown = mote as MoteThrown;
                    if (moteThrown != null)
                    {
                        moteThrown.airTimeLeft = this.def.airTime.RandomInRange;
                        moteThrown.SetVelocity(this.def.angle.RandomInRange + num, this.def.speed.RandomInRange);
                    }
                }
            }
        }
Beispiel #18
0
 public static void TryStartCastOn_RapidFire_Prefix(ref Verb __instance, LocalTargetInfo castTarg, float __state, ref bool __result)
 {
     if (__instance.GetType() == typeof(Verb_Shoot))
     {
         if (__instance.EquipmentSource != null && __instance.CasterPawn != null)
         {
             Pawn pawn = __instance.CasterPawn;
             if (castTarg != null /*&& castTarg.HasThing*/ && __instance.CanHitTarget(castTarg))
             {
                 if (__instance.EquipmentSource.TryGetComp <CompLaserCapacitor>() != null)
                 {
                     if (__instance.EquipmentSource.GetComp <CompLaserCapacitor>() is CompLaserCapacitor GunExt)
                     {
                         if (GunExt.initalized == false)
                         {
                             GunExt.originalwarmupTime = __instance.verbProps.warmupTime;
                             GunExt.initalized         = true;
                         }
                         if (GunExt.hotshot)
                         {
                             CompEquippable eq      = __instance.EquipmentSource.TryGetComp <CompEquippable>();
                             IntVec3        lastpos = (IntVec3)GunExt.lastFiringLocation;
                             if (lastpos == pawn.Position)
                             {
                                 GunExt.shotstack++;
                                 __instance.verbProps.warmupTime = Math.Max(GunExt.originalwarmupTime - (GunExt.Props.WarmUpReductionPerShot * GunExt.shotstack), 0);
                             }
                             else
                             {
                                 GunExt.shotstack = 0;
                                 __instance.verbProps.warmupTime = GunExt.originalwarmupTime;
                             }
                             GunExt.lastFiringLocation = pawn.Position;
                             if (GunExt.Props.Overheats && __instance.verbProps.warmupTime == 0f)
                             {
                                 if (Rand.Chance(GunExt.Props.OverheatChance))
                                 {
                                     GunExt.CriticalOverheatExplosion((Verb_Shoot)__instance);
                                     if (GunExt.Props.OverheatDestroys)
                                     {
                                         eq.parent.Destroy();
                                     }
                                 }
                                 else
                                 {
                                     if (GunExt.Props.OverheatMoteThrown != null)
                                     {
                                         MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(GunExt.Props.OverheatMoteThrown, null);
                                         moteThrown.Scale         = Rand.Range(2f, 3f) * GunExt.Props.OverheatMoteSize;
                                         moteThrown.exactPosition = GunExt.lastFiringLocation.CenterVector3;
                                         moteThrown.rotationRate  = Rand.Range(-0.5f, 0.5f);
                                         moteThrown.SetVelocity((float)Rand.Range(30, 40), Rand.Range(0.008f, 0.012f));
                                         GenSpawn.Spawn(moteThrown, GunExt.lastFiringLocation.Cell, pawn.Map, WipeMode.Vanish);
                                     }
                                 }
                             }
                         }
                         else
                         {
                             if (GunExt.originalwarmupTime != 0)
                             {
                                 __instance.verbProps.warmupTime = GunExt.originalwarmupTime;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #19
0
        public void NotifyLevelDown()
        {
            // Do text message on screen on level down.
            if (Settings.allowLevelDownTextMessage)
            {
                Color  color     = Color.red;
                string pawn      = CurrentPawn.LabelShortCap.Bold();
                string skill     = SkillRecord.def.skillLabel.Italic();
                string level     = SkillRecord.levelInt.ToString().Bold().Colored(color);
                string levelDesc = SkillRecord.LevelDescriptor;
                string label;
                if (Settings.levelDescLevelDownLabel)
                {
                    label = "LevelDownLabelLong".Translate(pawn, level, skill, levelDesc);
                }
                else
                {
                    label = "LevelDownLabel".Translate(pawn, level, skill);
                }

                LookTargets lookTargets = new LookTargets(CurrentPawn);
                Messages.Message(label, lookTargets, MessageTypeDefOf.SilentInput);
            }

            if (Settings.allowLevelDownLetter)
            {
                string      pawn        = CurrentPawn.LabelShortCap;
                string      skill       = SkillRecord.def.skillLabel;
                string      level       = SkillRecord.levelInt.ToString();
                string      labelShort  = "LevelDownLabelShort".Translate(pawn);
                string      label       = "LevelDownLabel".Translate(pawn, level, skill);
                LookTargets lookTargets = new LookTargets(CurrentPawn);

                Find.LetterStack.ReceiveLetter(labelShort, label, LetterDefOf.NegativeEvent, lookTargets);
            }

            // Do sound effect on level down.
            if (Settings.allowLevelDownSoundEffect)
            {
                DefHandler.LevelDown.PlayOneShot(SoundInfo.InMap(new TargetInfo(CurrentPawn)));
            }

            // Do animation on pawn levelling down.
            if (!Settings.allowLevelDownAnimation)
            {
                return;
            }

            // Animation motes.
            Vector3 pawnPosition = CurrentPawn.Drawer.DrawPos;
            Map     map          = CurrentPawn.Map;

            if (!pawnPosition.ToIntVec3().ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
            {
                return;
            }

            MoteThrown topMote = (MoteThrown)ThingMaker.MakeThing(DefHandler.Mote_LevelDownBeamTop);

            topMote.Attach(new TargetInfo(CurrentPawn));
            topMote.Scale         = 1.5f;
            topMote.exactPosition = CurrentPawn.Drawer.DrawPos;
            topMote.SetVelocity(180, 0.1f);
            GenSpawn.Spawn(topMote, pawnPosition.ToIntVec3(), map);

            MoteThrown bottomMote = (MoteThrown)ThingMaker.MakeThing(DefHandler.Mote_LevelDownBeamBottom);

            bottomMote.Attach(new TargetInfo(CurrentPawn));
            bottomMote.Scale         = 1.5f;
            bottomMote.exactPosition = CurrentPawn.Drawer.DrawPos;
            bottomMote.SetVelocity(180, 0.1f);
            GenSpawn.Spawn(bottomMote, pawnPosition.ToIntVec3(), map);
        }
        /// <summary>
        /// Throw a fish mote. So cute! :-)
        /// </summary>
        public Mote ThrowFishMote()
        {
            if (!this.Position.ShouldSpawnMotesAt(this.Map) || this.Map.moteCounter.Saturated)
            {
                return(null);
            }

            bool     startFromLeft = Rand.Chance(0.5f);
            ThingDef moteDef       = null;

            if (this.speciesDef == Util_FishIndustry.MashgonPawnKindDef)
            {
                if (startFromLeft)
                {
                    moteDef = Util_FishIndustry.MoteFishMashgonEastDef;
                }
                else
                {
                    moteDef = Util_FishIndustry.MoteFishMashgonWestDef;
                }
            }
            else if (this.speciesDef == Util_FishIndustry.BluebladePawnKindDef)
            {
                if (startFromLeft)
                {
                    moteDef = Util_FishIndustry.MoteFishBluebladeEastDef;
                }
                else
                {
                    moteDef = Util_FishIndustry.MoteFishBluebladeWestDef;
                }
            }
            else if (this.speciesDef == Util_FishIndustry.TailteethPawnKindDef)
            {
                if (startFromLeft)
                {
                    moteDef = Util_FishIndustry.MoteFishTailteethEastDef;
                }
                else
                {
                    moteDef = Util_FishIndustry.MoteFishTailteethWestDef;
                }
            }
            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(moteDef, null);

            moteThrown.Scale = Mathf.Lerp(0.2f, 0.6f, (float)this.breedingProgressInTicks / (float)this.breedingDurationInTicks);
            Vector3 moteStartPosition = this.Position.ToVector3Shifted();

            moteThrown.exactRotation = Rand.Range(0f, 45f); // Texture rotation.
            if (startFromLeft)
            {
                // From left to right.
                moteStartPosition += 0.8f * Vector3Utility.HorizontalVectorFromAngle(270f + moteThrown.exactRotation);
                moteThrown.SetVelocity(90f + moteThrown.exactRotation, 0.25f);
            }
            else
            {
                // From east to west.
                moteStartPosition += 0.8f * Vector3Utility.HorizontalVectorFromAngle(90f + moteThrown.exactRotation);
                moteThrown.SetVelocity(270f + moteThrown.exactRotation, 0.25f);
            }
            moteThrown.exactPosition = moteStartPosition;
            GenSpawn.Spawn(moteThrown, this.Position, this.Map);
            return(moteThrown);
        }
        private static void Postfix(IntVec3 c, SteadyEnvironmentEffects __instance, Map ___map)
        {
            if (___map == null)
            {
                return;
            }
            Room room = c.GetRoom(___map, RegionType.Set_Passable);

            if (ReGrowthSettings.ColdFog || ReGrowthSettings.IceLayer)
            {
                Thing thing = (from t in c.GetThingList(___map)
                               where t.def == RGDefOf.RG_IceOverlay
                               select t).FirstOrDefault <Thing>();
                if (room == null && thing != null && ReGrowthSettings.IceLayer)
                {
                    thing.Destroy(DestroyMode.Vanish);
                    if (Rand.Range(1, 100) <= 20)
                    {
                        FilthMaker.TryMakeFilth(c, ___map, RGDefOf.RG_Filth_Water, 1);
                    }
                }
                if (room != null && !room.UsesOutdoorTemperature && !room.Fogged && !room.IsDoorway)
                {
                    float num = 0.8f;
                    if (room.Temperature < (float)ReGrowthSettings.FogTemp)
                    {
                        if (thing == null && ReGrowthSettings.IceLayer)
                        {
                            GenSpawn.Spawn(ThingMaker.MakeThing(RGDefOf.RG_IceOverlay), c, ___map);
                        }
                        if (ReGrowthSettings.ColdFog)
                        {
                            Vector3 vector = c.ToVector3Shifted();
                            bool    flag   = true;
                            if (!GenView.ShouldSpawnMotesAt(vector, ___map) || ___map.moteCounter.SaturatedLowPriority)
                            {
                                flag = false;
                            }
                            vector += num * new Vector3(Rand.Value - 0.5f, 0f, Rand.Value - 0.5f);
                            if (!GenGrid.InBounds(vector, ___map))
                            {
                                flag = false;
                            }
                            if (flag)
                            {
                                MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(RGDefOf.RG_Mote_FrostGlow, null);
                                moteThrown.Scale         = Rand.Range(4f, 6f) * num;
                                moteThrown.rotationRate  = Rand.Range(-3f, 3f);
                                moteThrown.exactPosition = vector;
                                moteThrown.SetVelocity((float)(Rand.Bool ? -90 : 90), (float)((double)ReGrowthSettings.FogVelocity * 0.01));
                                GenSpawn.Spawn(moteThrown, IntVec3Utility.ToIntVec3(vector), ___map);
                            }
                        }
                    }
                    else if (thing != null)
                    {
                        thing.Destroy(DestroyMode.Vanish);
                        if (Rand.Range(1, 100) <= 20)
                        {
                            FilthMaker.TryMakeFilth(c, ___map, RGDefOf.RG_Filth_Water, 1);
                        }
                    }
                }
            }
            if (!ReGrowthSettings.IceLayer)
            {
                Thing thing2 = (from t in c.GetThingList(___map)
                                where t.def == RGDefOf.RG_IceOverlay
                                select t).FirstOrDefault <Thing>();
                if (thing2 != null)
                {
                    thing2.Destroy(DestroyMode.Vanish);
                }
            }
            if (___map.roofGrid != null && !___map.roofGrid.Roofed(c) && (float)___map.weatherManager.curWeatherAge >= 7500f && (___map.weatherManager.curWeather.rainRate <= 0f ||
                                                                                                                                 ___map.weatherManager.curWeather.snowRate > 0f))
            {
                Thing thing3 = (from t in c.GetThingList(___map)
                                where t.def == RGDefOf.RG_Filth_Water || t.def == RGDefOf.RG_Filth_WaterSpatter
                                select t).FirstOrDefault <Thing>();
                if (thing3 != null && Rand.Value <= 0.2f)
                {
                    ((Filth)thing3).ThinFilth();
                }
            }
        }
        public override void Tick()
        {
            base.Tick();

            timer++;
            if (timer % 60 == 0)
            {
                isBlocked = false;
                blockedBy = null;
                foreach (var cell in GetLaunchCells())
                {
                    if (IsCellBlocked(cell, out blockedBy))
                    {
                        isBlocked = true;
                        break;
                    }
                }
            }

            var comp = GetComp <CompRefuelable>();

            comp.Props.fuelLabel      = CurrentShellDef.LabelCap;
            comp.Props.fuelGizmoLabel = CurrentShellDef.LabelCap;

            if (isFlying)
            {
                bool spawnSmoke = false;
                bool spawnFire  = false;
                ticksFlying++;
                if (ticksFlying <= TicksToLeave)
                {
                    Vector3 start = GetDroneIdlePos();
                    Vector3 end   = GetDroneIdlePos() + GetDroneTravelDirection() * 350;
                    float   p     = Mathf.Clamp01((float)ticksFlying / TicksToLeave);
                    float   t     = launchCurve.Evaluate(p);
                    droneDrawPos = Vector3.Lerp(start, end, t);
                    spawnSmoke   = true;
                    spawnFire    = true;
                }
                else if (ticksFlying >= TicksToLeave + TicksInMiddle)
                {
                    if (ticksFlying > TicksToLeave + TicksInMiddle + TicksToReturn)
                    {
                        isFlying = false;
                    }
                    else
                    {
                        Vector3 start = GetDroneIdlePos() + GetDroneReturnDirection() * 350;
                        Vector3 end   = GetDroneIdlePos();
                        float   p     = Mathf.Clamp01((float)(ticksFlying - TicksToLeave - TicksInMiddle) / TicksToReturn);
                        float   t     = launchCurve.Evaluate(p);
                        droneDrawPos = Vector3.Lerp(start, end, t);
                        spawnSmoke   = true;
                    }
                }

                Map map = Map;
                if (spawnFire)
                {
                    Vector3 pos2 = droneDrawPos + Rand.InsideUnitCircleVec3 * 0.5f;
                    if (pos2.ToIntVec3().InBounds(map))
                    {
#if V13
                        FleckMaker.ThrowFireGlow(pos2, map, 1f);
#else
                        MoteThrown moteThrown2 = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_FireGlow);
                        moteThrown2.Scale         = Rand.Range(4f, 6f) * 1f;
                        moteThrown2.rotationRate  = Rand.Range(-3f, 3f);
                        moteThrown2.exactPosition = pos2;
                        moteThrown2.SetVelocity(Rand.Range(0, 360), 0.12f);
                        GenSpawn.Spawn(moteThrown2, pos2.ToIntVec3(), map);
#endif
                    }
                }
                if (spawnSmoke)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        Vector3 pos = droneDrawPos + Rand.InsideUnitCircleVec3 * 2f;
                        if (pos.ToIntVec3().InBounds(map))
                        {
#if V13
                            FleckCreationData dataStatic = FleckMaker.GetDataStatic(pos, map, FleckDefOf.Smoke, Rand.Range(1.5f, 2.5f) * 1f);
                            dataStatic.spawnPosition = pos;
                            dataStatic.rotationRate  = Rand.Range(-30f, 30f);
                            dataStatic.velocityAngle = (float)Rand.Range(30, 40);
                            dataStatic.velocitySpeed = Rand.Range(0.5f, 0.7f);
                            map.flecks.CreateFleck(dataStatic);
#else
                            MoteThrown moteThrown = (MoteThrown)ThingMaker.MakeThing(ThingDefOf.Mote_Smoke);
                            moteThrown.Scale         = Rand.Range(1.5f, 2.5f) * 1f;
                            moteThrown.rotationRate  = Rand.Range(-30f, 30f);
                            moteThrown.exactPosition = pos;
                            moteThrown.SetVelocity(Rand.Range(30, 40), Rand.Range(0.5f, 0.7f));
                            GenSpawn.Spawn(moteThrown, pos.ToIntVec3(), map);
#endif
                        }
                    }
                }
            }
            else
            {
                droneDrawPos = GetDroneIdlePos();
            }
        }
Beispiel #23
0
        public void NotifyLevelUp()
        {
            // Do text message on screen on level up.
            if (Settings.allowLevelUpTextMessage)
            {
                Color  color     = Color.yellow;
                string pawn      = CurrentPawn.LabelShortCap.Bold();
                string skill     = SkillRecord.def.skillLabel.Italic();
                string level     = SkillRecord.levelInt.ToString().Bold().Colored(color);
                string levelDesc = SkillRecord.LevelDescriptor;
                string label;
                if (Settings.levelDescLevelUpLabel)
                {
                    label = "LevelUpLabelLong".Translate(pawn, level, skill, levelDesc);
                }
                else
                {
                    label = "LevelUpLabel".Translate(pawn, level, skill);
                }

                LookTargets lookTargets = new LookTargets(CurrentPawn);
                Messages.Message(label, lookTargets, MessageTypeDefOf.SilentInput);
            }

            if (Settings.allowLevelUpLetter)
            {
                string      pawn        = CurrentPawn.LabelShortCap;
                string      skill       = SkillRecord.def.skillLabel;
                string      level       = SkillRecord.levelInt.ToString();
                string      labelShort  = "LevelUpLabelShort".Translate(pawn);
                string      label       = "LevelUpLabel".Translate(pawn, level, skill);
                LookTargets lookTargets = new LookTargets(CurrentPawn);

                Find.LetterStack.ReceiveLetter(labelShort, label, LetterDefOf.PositiveEvent, lookTargets);
            }

            // Do sound effect on level up.
            if (Settings.allowLevelUpSoundEffect)
            {
                DefHandler.GetSound(Settings.LvlUpSound).PlayOneShot(SoundInfo.InMap(new TargetInfo(CurrentPawn)));
            }

            // Do animation on pawn levelling up.
            if (!Settings.allowLevelUpAnimation)
            {
                return;
            }

            // Animation motes. Using three similar ones on top of each other to achieve stretch effect.
            Vector3 pawnPosition = CurrentPawn.Drawer.DrawPos;
            Map     map          = CurrentPawn.Map;

            if (!pawnPosition.ToIntVec3().ShouldSpawnMotesAt(map) || map.moteCounter.SaturatedLowPriority)
            {
                return;
            }

            MoteThrown innerMote = MakeMote(DefHandler.Mote_LevelUpBeamInner, CurrentPawn);

            innerMote.SetVelocity(0, 0.6f);
            GenSpawn.Spawn(innerMote, pawnPosition.ToIntVec3(), map);

            MoteThrown middleMote1 = MakeMote(DefHandler.Mote_LevelUpBeamMiddle, CurrentPawn);

            middleMote1.SetVelocity(0, 0.3f);
            GenSpawn.Spawn(middleMote1, pawnPosition.ToIntVec3(), map);

            MoteThrown middleMote2 = MakeMote(DefHandler.Mote_LevelUpBeamMiddle, CurrentPawn);

            middleMote2.SetVelocity(0, 0.5f);
            GenSpawn.Spawn(middleMote2, pawnPosition.ToIntVec3(), map);

            MoteThrown outerMote1 = MakeMote(DefHandler.Mote_LevelUpBeamOuter, CurrentPawn);

            outerMote1.SetVelocity(0, 0.15f);
            GenSpawn.Spawn(outerMote1, pawnPosition.ToIntVec3(), map);

            MoteThrown outerMote2 = MakeMote(DefHandler.Mote_LevelUpBeamOuter, CurrentPawn);

            outerMote2.SetVelocity(0, 0.25f);
            GenSpawn.Spawn(outerMote2, pawnPosition.ToIntVec3(), map);
        }
        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));
        }