예제 #1
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);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// This is a customized copy of the vanilla version
        /// </summary>
        /// <param name="map"></param>
        /// <param name="parms"></param>
        public override void Generate(Map map, GenStepParams parms)
        {
            if (map.Biome.defName != "RockMoonBiome")
            {
                return;
            }

            mapRadiusSize = map.Size.x / 2;

            map.regionAndRoomUpdater.Enabled = false;
            float num = 0.7f;
            List <GenStep_MoonRocks.RoofThreshold> list = new List <GenStep_MoonRocks.RoofThreshold>();

            list.Add(new GenStep_MoonRocks.RoofThreshold
            {
                roofDef    = RoofDefOf.RoofRockThick,
                minGridVal = num * 1.14f
            });
            list.Add(new GenStep_MoonRocks.RoofThreshold
            {
                roofDef    = RoofDefOf.RoofRockThin,
                minGridVal = num * 1.04f
            });
            MapGenFloatGrid elevation = MapGenerator.Elevation;
            MapGenFloatGrid caves     = MapGenerator.Caves;
            MapGenFloatGrid fertility = MapGenerator.Fertility;

            foreach (IntVec3 current in map.AllCells)
            {
                if (IsInRadius(current))
                {
                    float num2 = elevation[current];
                    if (num2 > num)
                    {
                        if (caves[current] <= 0f)
                        {
                            ThingDef def = GenStep_MoonRocks.RockDefAt(fertility[current]);


                            GenSpawn.Spawn(def, current, map, WipeMode.Vanish);
                        }
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (num2 > list[i].minGridVal)
                            {
                                map.roofGrid.SetRoof(current, list[i].roofDef);
                                break;
                            }
                        }
                    }
                }
            }

            BoolGrid       visited  = new BoolGrid(map);
            List <IntVec3> toRemove = new List <IntVec3>();

            foreach (IntVec3 current2 in map.AllCells)
            {
                if (!visited[current2])
                {
                    if (this.IsNaturalRoofAt(current2, map))
                    {
                        toRemove.Clear();
                        map.floodFiller.FloodFill(current2, (IntVec3 x) => this.IsNaturalRoofAt(x, map), delegate(IntVec3 x)
                        {
                            visited[x] = true;
                            toRemove.Add(x);
                        }, 2147483647, false, null);
                        if (toRemove.Count < 20)
                        {
                            for (int j = 0; j < toRemove.Count; j++)
                            {
                                map.roofGrid.SetRoof(toRemove[j], null);
                            }
                        }
                    }
                }
            }
            GenStep_ScatterLumpsMineable genStep_ScatterLumpsMineable = new GenStep_ScatterLumpsMineable();

            genStep_ScatterLumpsMineable.maxValue = this.maxMineableValue;
            float num3 = 10f;

            genStep_ScatterLumpsMineable.countPer10kCellsRange = new FloatRange(num3, num3);
            genStep_ScatterLumpsMineable.Generate(map, parms);
            map.regionAndRoomUpdater.Enabled = true;
        }
        public override void CompPostTick(ref float severityAdjustment)
        {
            if (this.Pawn.Spawned && !this.Pawn.Dead && !this.Pawn.Downed)
            {
                base.CompPostTick(ref severityAdjustment);
                if (base.Pawn != null & base.parent != null)
                {
                    if (!initialized)
                    {
                        initialized = true;
                        this.Initialize();
                    }
                }

                CompAbilityUserMagic comp = this.Pawn.GetComp <CompAbilityUserMagic>();

                if (this.ticksBitWorking > 0 && this.nextBitEffect < Find.TickManager.TicksGame && this.moteLoc != Vector3.zero)
                {
                    Vector3 rndVec = this.moteLoc;
                    rndVec.x += Rand.Range(-.15f, .15f);
                    rndVec.z += Rand.Range(-.15f, .15f);
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SparkFlash"), rndVec, this.Pawn.Map, Rand.Range(.9f, 1.5f), .05f, 0f, .1f, 0, 0f, 0f, 0f);
                    rndVec    = this.moteLoc;
                    rndVec.x += Rand.Range(-.15f, .15f);
                    rndVec.z += Rand.Range(-.15f, .15f);
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SparkFlash"), rndVec, this.Pawn.Map, Rand.Range(.6f, 1.1f), .05f, 0f, .1f, 0, 0f, 0f, 0f);
                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Enchanting, comp.bitPosition, this.Pawn.Map, Rand.Range(0.35f, 0.43f), .2f, .05f, Rand.Range(.4f, .6f), Rand.Range(-200, 200), 0, 0, 0);
                    this.ticksBitWorking--;
                    this.nextBitEffect = Find.TickManager.TicksGame + Rand.Range(6, 10);
                    if (this.ticksBitWorking == 0)
                    {
                        this.moteLoc = Vector3.zero;
                    }
                }

                if (comp.useTechnoBitToggle)
                {
                    if (Find.TickManager.TicksGame % 60 == 0)
                    {
                        DetermineHDRank();
                    }
                    if (Find.TickManager.TicksGame % 600 == 0 && !this.Pawn.Drafted)
                    {
                        if (comp.Mana.CurLevelPercentage >= .9f && comp.Mana.CurLevel >= (.06f - (.001f * this.VerVal)) && this.Pawn.CurJob.targetA.Thing != null)
                        {
                            if (this.Pawn.CurJob.targetA.Thing != null)
                            {
                                if ((this.Pawn.Position - this.Pawn.CurJob.targetA.Thing.Position).LengthHorizontal < 2 && (this.Pawn.CurJob.bill != null || this.Pawn.CurJob.def.defName == "FinishFrame" || this.Pawn.CurJob.def.defName == "Deconstruct" || this.Pawn.CurJob.def.defName == "Repair" || this.Pawn.CurJob.def.defName == "Mine" || this.Pawn.CurJob.def.defName == "SmoothFloor" || this.Pawn.CurJob.def.defName == "SmoothWall"))
                                {
                                    comp.Mana.CurLevel -= (.05f - (.001f * this.VerVal));
                                    HealthUtility.AdjustSeverity(this.Pawn, HediffDef.Named("TM_BitAssistHD"), .5f + 1f * this.VerVal);
                                    comp.MagicUserXP    += Rand.Range(6, 8);
                                    this.ticksBitWorking = 8;
                                    this.moteLoc         = this.Pawn.CurJob.targetA.Thing.DrawPos;
                                }
                            }
                        }
                    }

                    if (comp.useTechnoBitRepairToggle && Find.TickManager.TicksGame % (160 - 3 * EffVal) == 0 && this.Pawn.Drafted && comp.Mana.CurLevel >= (.03f - .0006f * EffVal))
                    {
                        Thing    damagedThing   = TM_Calc.FindNearbyDamagedThing(this.Pawn, Mathf.RoundToInt(5 + .33f * EffVal));
                        Building repairBuilding = damagedThing as Building;
                        if (repairBuilding != null)
                        {
                            repairBuilding.HitPoints = Mathf.Min(Mathf.RoundToInt(repairBuilding.HitPoints + (Rand.Range(8, 12) + (.5f * EffVal))), repairBuilding.MaxHitPoints);
                            comp.Mana.CurLevel      -= (.03f - .0006f * EffVal);
                            comp.MagicUserXP        += Rand.Range(4, 5);
                            this.ticksBitWorking     = 8;
                            this.moteLoc             = repairBuilding.DrawPos;
                        }
                        Pawn damagedRobot = damagedThing as Pawn;
                        if (damagedRobot != null)
                        {
                            TM_Action.DoAction_HealPawn(this.Pawn, damagedRobot, 1, (4 + .4f * EffVal));
                            comp.Mana.CurLevel  -= (.03f - .0006f * EffVal);
                            comp.MagicUserXP    += Rand.Range(4, 6);
                            this.ticksBitWorking = 5;
                            this.moteLoc         = damagedRobot.DrawPos;
                        }
                    }

                    if (comp.useTechnoBitRepairToggle && Find.TickManager.TicksGame % (600 - 6 * EffVal) == 0 && !this.Pawn.Drafted && comp.Mana.CurLevel >= .05f)
                    {
                        Thing    damagedThing   = TM_Calc.FindNearbyDamagedThing(this.Pawn, Mathf.RoundToInt(10 + .5f * EffVal));
                        Building repairBuilding = damagedThing as Building;
                        if (repairBuilding != null)
                        {
                            repairBuilding.HitPoints = Mathf.Min(repairBuilding.HitPoints + (25 + (2 * EffVal)), repairBuilding.MaxHitPoints);
                            comp.Mana.CurLevel      -= (.05f - .0008f * EffVal);
                            comp.MagicUserXP        += Rand.Range(9, 11);
                            this.ticksBitWorking     = 8;
                            this.moteLoc             = repairBuilding.DrawPos;
                        }
                        Pawn damagedRobot = damagedThing as Pawn;
                        if (damagedRobot != null)
                        {
                            TM_Action.DoAction_HealPawn(this.Pawn, damagedRobot, 2, (8 + .4f * EffVal));
                            comp.Mana.CurLevel  -= (.05f - .0008f * EffVal);
                            comp.MagicUserXP    += Rand.Range(9, 11);
                            this.ticksBitWorking = 5;
                            this.moteLoc         = damagedRobot.DrawPos;
                        }
                    }

                    if (comp.Mana.CurLevel >= .1f && (this.Pawn.Drafted || !this.Pawn.IsColonist))
                    {
                        if (this.Pawn.TargetCurrentlyAimingAt != null && (this.Pawn.CurJob.def.defName == "AttackStatic" || this.Pawn.CurJob.def.defName == "Wait_Combat") && this.nextBitGrenade < Find.TickManager.TicksGame)
                        {
                            float maxRange       = 25 + this.PwrVal;
                            Thing targetThing    = this.Pawn.TargetCurrentlyAimingAt.Thing;
                            float targetDistance = (this.Pawn.Position - targetThing.Position).LengthHorizontal;
                            if (TM_Calc.HasLoSFromTo(this.Pawn.Position, this.Pawn.TargetCurrentlyAimingAt.Thing, this.Pawn as Thing, 2f, maxRange) && targetThing.Map != null && this.bitGrenadeCount > 0)
                            {
                                IntVec3 rndTargetCell = targetThing.Position;
                                rndTargetCell.x += (int)Rand.Range(-targetDistance / 8f, targetDistance / 8f);
                                rndTargetCell.z += (int)Rand.Range(-targetDistance / 8f, targetDistance / 8f);
                                LocalTargetInfo ltiTarget = rndTargetCell;
                                if (this.bitGrenadeCount == 2)
                                {
                                    //launch emp grenade
                                    Projectile projectile  = (Projectile)GenSpawn.Spawn(ThingDef.Named("Projectile_TMEMPGrenade"), this.Pawn.Position, this.Pawn.Map, WipeMode.Vanish);
                                    float      launchAngle = (Quaternion.AngleAxis(90, Vector3.up) * TM_Calc.GetVector(this.Pawn.Position, ltiTarget.Cell)).ToAngleFlat();
                                    for (int m = 0; m < 4; m++)
                                    {
                                        TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, comp.bitPosition, this.Pawn.Map, Rand.Range(.4f, .7f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(3f, 5f), launchAngle += Rand.Range(-25, 25), Rand.Range(0, 360));
                                    }
                                    SoundInfo info = SoundInfo.InMap(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false), MaintenanceType.None);
                                    info.pitchFactor  = 2f;
                                    info.volumeFactor = .6f;
                                    SoundDef.Named("Mortar_LaunchA").PlayOneShot(info);
                                    projectile.def.projectile.speed          = 20 + PwrVal;
                                    projectile.def.projectile.explosionDelay = Rand.Range(80, 120) - (4 * PwrVal);
                                    projectile.Launch(this.Pawn, comp.bitPosition, ltiTarget, targetThing, ProjectileHitFlags.All, null, null);
                                }
                                else
                                {
                                    //fire he grenade
                                    Projectile projectile  = (Projectile)GenSpawn.Spawn(ThingDef.Named("Projectile_TMFragGrenade"), this.Pawn.Position, this.Pawn.Map, WipeMode.Vanish);
                                    float      launchAngle = (Quaternion.AngleAxis(90, Vector3.up) * TM_Calc.GetVector(this.Pawn.Position, ltiTarget.Cell)).ToAngleFlat();
                                    for (int m = 0; m < 4; m++)
                                    {
                                        TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, comp.bitPosition, this.Pawn.Map, Rand.Range(.4f, .7f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(3f, 5f), launchAngle += Rand.Range(-25, 25), Rand.Range(0, 360));
                                    }
                                    SoundInfo info = SoundInfo.InMap(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false), MaintenanceType.None);
                                    info.pitchFactor  = 1.4f;
                                    info.volumeFactor = .5f;
                                    SoundDef.Named("Mortar_LaunchA").PlayOneShot(info);
                                    projectile.def.projectile.speed          = 20 + PwrVal;
                                    projectile.def.projectile.explosionDelay = Rand.Range(80, 120) - (4 * PwrVal);
                                    projectile.Launch(this.Pawn, comp.bitPosition, ltiTarget, targetThing, ProjectileHitFlags.All, null, null);
                                }
                                this.nextBitGrenade = 18 + Find.TickManager.TicksGame;
                                this.bitGrenadeCount--;
                                if (this.bitGrenadeCount == 0)
                                {
                                    this.bitGrenadeCount = 1 + (int)((this.PwrVal) / 5);
                                    this.nextBitGrenade  = Find.TickManager.TicksGame + (600 - 6 * PwrVal);
                                    comp.Mana.CurLevel  -= (.08f - (.001f * this.PwrVal));
                                    comp.MagicUserXP    += Rand.Range(12, 18);
                                }
                            }
                            else if (this.nextBitGrenade < Find.TickManager.TicksGame && this.bitGrenadeCount <= 0)
                            {
                                this.bitGrenadeCount = 1 + (int)((this.PwrVal) / 5);
                                this.nextBitGrenade  = Find.TickManager.TicksGame + (600 - 6 * PwrVal);
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
 private void PortalPawn(Pawn pawn)
 {
     pawn.DeSpawn();
     GenSpawn.Spawn(pawn, this.PortalDestinationPosition, this.PortalDestinationMap);
 }
예제 #5
0
        public static BomberSkyfaller SpawnSkyfaller(ThingDef skyfaller, ThingDef innerThing, IntVec3 pos, Map map)
        {
            BomberSkyfaller thing = BomberSkyfallerMaker.MakeSkyfaller(skyfaller, innerThing);

            return((BomberSkyfaller)GenSpawn.Spawn(thing, pos, map, WipeMode.Vanish));
        }
예제 #6
0
        public static int SpawnSinglePawn(this CorpseProduct CP, Pawn ParentPawn, IntVec3 SpawnPos, Map map, bool MyDebug = false)
        {
            string DebugStr = MyDebug ? "SpawnSinglePawn " : null;

            PawnGenOption PGO = CP.pawnKind.RandomElementByWeight(p => p.selectionWeight);

            if (PGO == null)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + " No PawnGenOption found");
                }
                return(0);
            }

            PawnKindDef PKD           = PGO.kind;
            Faction     RandomFaction = CP.HasWeightedFaction ? CP.forcedFaction?.GetFaction(ParentPawn) : null;

            if (PKD == null)
            {
                if (MyDebug)
                {
                    Log.Warning(DebugStr + " No PKD found");
                }
                return(0);
            }
            if (MyDebug)
            {
                Log.Warning(DebugStr + "PKD:" + PKD.label + " faction:" + RandomFaction);
            }

            bool wantNewBorn = Rand.Chance(CP.newBornChance);

            float combatPowerMultiplier = wantNewBorn ? CP.newBornCombatPowerRatio : 1;

            PawnGenerationRequest request =
                new PawnGenerationRequest(
                    kind: PKD, faction: RandomFaction, context: PawnGenerationContext.NonPlayer, tile: -1, forceGenerateNewPawn: false,
                    newborn: wantNewBorn, colonistRelationChanceFactor: 0, allowAddictions: false, allowFood: false, relationWithExtraPawnChanceFactor: 0
                    );
            Pawn NewPawn = PawnGenerator.GeneratePawn(request);

            GenSpawn.Spawn(NewPawn, SpawnPos, map, WipeMode.Vanish);

            if (CP.HasRelevantManhunterChance && Rand.Chance(CP.manhunterChance))
            {
                NewPawn.MakeManhunter(MyDebug);
            }

            if (CP.inheritSettingsFromParent && NewPawn.InheritParentSettings(ParentPawn, RandomFaction) && MyDebug)
            {
                Log.Warning(DebugStr + "applied parent settings");
            }

            if (CP.setRelationsWithParent && NewPawn.AddParentRelations(ParentPawn) && MyDebug)
            {
                Log.Warning(DebugStr + "added relations");
            }

            return((int)(combatPowerMultiplier * NewPawn.kindDef.combatPower));
        }
예제 #7
0
        // Verse.Dialog_DebugActionsMenu
        public static void DoListingItems_MapTools_Vamp(Dialog_DebugActionsMenu __instance)
        {
            AccessTools.Method(typeof(Dialog_DebugActionsMenu), "DoLabel").Invoke(__instance, new object[] { "Tools - Vampirism" });
            AccessTools.Method(typeof(Dialog_DebugActionsMenu), "DebugToolMap").Invoke(__instance, new object[] {
                "Spawn Vampire (Random)", new Action(() =>
                {
                    Pawn randomVampire =
                        VampireGen.GenerateVampire(VampireUtility.RandHigherGeneration, VampireUtility.RandBloodline, null);
                    GenSpawn.Spawn(randomVampire, UI.MouseCell(), Find.CurrentMap);
                })
            });


            AccessTools.Method(typeof(Dialog_DebugActionsMenu), "DebugToolMap").Invoke(__instance, new object[] {
                "Give Vampirism (Default)", new Action(() =>
                {
                    Pawn pawn = Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).Where((Thing t) => t is Pawn).Cast <Pawn>().FirstOrDefault();
                    if (pawn != null)
                    {
                        if (!pawn.IsVampire())
                        {
                            pawn.health.AddHediff(VampDefOf.ROM_Vampirism, null, null);
                            pawn.Drawer.Notify_DebugAffected();
                            MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, pawn.LabelShort + " is now a vampire");
                        }
                        else
                        {
                            Messages.Message(pawn.LabelCap + " is already a vampire.", MessageTypeDefOf.RejectInput);
                        }
                    }
                })
            });

            AccessTools.Method(typeof(Dialog_DebugActionsMenu), "DebugToolMap").Invoke(__instance, new object[] {
                "Give Vampirism (w/Settings)", new Action(() =>
                {
                    Pawn pawn = Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).Where((Thing t) => t is Pawn).Cast <Pawn>().FirstOrDefault();
                    if (pawn != null)
                    {
                        //pawn.health.AddHediff(VampDefOf.ROM_Vampirism, null, null);
                        Find.WindowStack.Add(new Dialog_DebugOptionListLister(Options_Bloodlines(pawn)));
                        //DebugTools.curTool = null;
                    }
                })
            });



            AccessTools.Method(typeof(Dialog_DebugActionsMenu), "DebugToolMap").Invoke(__instance, new object[] {
                "Remove Vampirism", new Action(() =>
                {
                    Pawn pawn = Find.CurrentMap.thingGrid.ThingsAt(UI.MouseCell()).Where((Thing t) => t is Pawn).Cast <Pawn>().FirstOrDefault();
                    if (pawn != null)
                    {
                        if (pawn.IsVampire())
                        {
                            if (pawn.health.hediffSet.GetFirstHediffOfDef(VampDefOf.ROM_Vampirism) is HediffVampirism vampirism)
                            {
                                pawn.health.RemoveHediff(vampirism);
                            }
                            if (pawn?.health?.hediffSet?.GetHediffs <Hediff_AddedPart>()?.First() is Hediff_AddedPart_Fangs fangs)
                            {
                                BodyPartRecord rec = fangs.Part;
                                pawn.health.RemoveHediff(fangs);
                                pawn.health.RestorePart(rec);
                            }
                            pawn.Drawer.Notify_DebugAffected();
                            MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, pawn.LabelShort + " is no longer a vampire");
                        }
                        else
                        {
                            Messages.Message(pawn.LabelCap + " is already a vampire.", MessageTypeDefOf.RejectInput);
                        }
                    }
                })
            });
예제 #8
0
        // Token: 0x0600219B RID: 8603 RVA: 0x000CBD34 File Offset: 0x000C9F34
        protected override bool TryCastShot()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            ThingDef projectile = this.Projectile;

            if (projectile == null)
            {
                return(false);
            }
            ShootLine shootLine;
            bool      flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            if (this.EquipmentSource != null)
            {
                CompChangeableProjectile comp = this.EquipmentSource.GetComp <CompChangeableProjectile>();
                if (comp != null)
                {
                    comp.Notify_ProjectileLaunched();
                }
            }
            Thing        launcher     = this.caster;
            Thing        equipment    = this.EquipmentSource;
            CompMannable compMannable = this.caster.TryGetComp <CompMannable>();

            if (compMannable != null && compMannable.ManningPawn != null)
            {
                launcher  = compMannable.ManningPawn;
                equipment = this.caster;
            }
            Vector3    drawPos     = this.caster.DrawPos;
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, shootLine.Source, this.caster.Map, WipeMode.Vanish);

            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float num = VerbUtility.CalculateAdjustedForcedMiss(this.verbProps.forcedMissRadius, this.currentTarget.Cell - this.caster.Position);
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(num);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2];
                        this.ThrowDebugText("ToRadius");
                        this.ThrowDebugText("Rad\nDest", c);
                        ProjectileHitFlags projectileHitFlags = ProjectileHitFlags.NonTargetWorld;
                        if (Rand.Chance(0.5f))
                        {
                            projectileHitFlags = ProjectileHitFlags.All;
                        }
                        if (!this.canHitNonTargetPawnsNow)
                        {
                            projectileHitFlags &= ~ProjectileHitFlags.NonTargetPawns;
                        }
                        projectile2.Launch(launcher, drawPos, c, this.currentTarget, projectileHitFlags, equipment, null);
                        return(true);
                    }
                }
            }
            ShotReport shotReport            = ShotReport.HitReportFor(this.caster, this, this.currentTarget);
            Thing      randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
            ThingDef   targetCoverDef        = (randomCoverToMissInto != null) ? randomCoverToMissInto.def : null;

            if (!Rand.Chance(shotReport.AimOnTargetChance_IgnoringPosture))
            {
                shootLine.ChangeDestToMissWild(shotReport.AimOnTargetChance_StandardTarget);
                this.ThrowDebugText("ToWild" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Wild\nDest", shootLine.Dest);
                ProjectileHitFlags projectileHitFlags2 = ProjectileHitFlags.NonTargetWorld;
                if (Rand.Chance(0.5f) && this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags2 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags2, equipment, targetCoverDef);
                return(true);
            }
            if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn && !Rand.Chance(shotReport.PassCoverChance))
            {
                this.ThrowDebugText("ToCover" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
                this.ThrowDebugText("Cover\nDest", randomCoverToMissInto.Position);
                ProjectileHitFlags projectileHitFlags3 = ProjectileHitFlags.NonTargetWorld;
                if (this.canHitNonTargetPawnsNow)
                {
                    projectileHitFlags3 |= ProjectileHitFlags.NonTargetPawns;
                }
                projectile2.Launch(launcher, drawPos, randomCoverToMissInto, this.currentTarget, projectileHitFlags3, equipment, targetCoverDef);
                return(true);
            }
            ProjectileHitFlags projectileHitFlags4 = ProjectileHitFlags.IntendedTarget;

            if (this.canHitNonTargetPawnsNow)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetPawns;
            }
            if (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full)
            {
                projectileHitFlags4 |= ProjectileHitFlags.NonTargetWorld;
            }
            this.ThrowDebugText("ToHit" + (this.canHitNonTargetPawnsNow ? "\nchntp" : ""));
            if (this.currentTarget.Thing != null)
            {
                projectile2.Launch(launcher, drawPos, this.currentTarget, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", this.currentTarget.Cell);
            }
            else
            {
                projectile2.Launch(launcher, drawPos, shootLine.Dest, this.currentTarget, projectileHitFlags4, equipment, targetCoverDef);
                this.ThrowDebugText("Hit\nDest", shootLine.Dest);
            }
            return(true);
        }
        public void UsedBy(Pawn p)
        {
            if (this.parent.Stuff == null)
            {
                this.parent.SetStuffDirect(ThingDefOf.Cloth);
            }
            IntVec3  pos      = this.parent.Position;
            CellRect cellRect = new CellRect(pos.x - 2, pos.z - 2, 5, 4);
            int      damage   = 0;

            this.parent.Destroy(DestroyMode.Vanish);
            Thing tent = ThingMaker.MakeThing(ThingDef.Named(tentName), this.parent.Stuff);
            CompTargetable_Tent tentComp;

            tentComp            = tent.TryGetComp <CompTargetable_Tent>();
            tentComp.placingRot = this.placingRot;
            tentComp.GetPlacements(pos);


            foreach (IntVec3 current in tentComp.wallCells)
            {
                if (p.Map.roofGrid.RoofAt(current) == RoofDefOf.RoofConstructed)
                {
                    p.Map.roofGrid.SetRoof(current, null);
                }
            }
            foreach (IntVec3 current in tentComp.doorCells)
            {
                if (p.Map.roofGrid.RoofAt(current) == RoofDefOf.RoofConstructed)
                {
                    p.Map.roofGrid.SetRoof(current, null);
                }
            }
            foreach (IntVec3 current in tentComp.roofCells)
            {
                if (p.Map.roofGrid.RoofAt(current) == RoofDefOf.RoofConstructed)
                {
                    p.Map.roofGrid.SetRoof(current, null);
                }
            }
            if (p.Map.roofGrid.RoofAt(tentComp.supportCell) == RoofDefOf.RoofConstructed)
            {
                p.Map.roofGrid.SetRoof(tentComp.supportCell, null);
            }

            foreach (IntVec3 current in tentComp.wallCells)
            {
                List <Thing> thingList = current.GetThingList(p.Map);
                bool         nowall    = true;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i].def == ThingDef.Named("TentWall"))
                    {
                        thingList[i].Destroy(DestroyMode.Vanish);
                        nowall = false;
                    }
                }
                if (nowall)
                {
                    damage = damage + 10;
                }
            }



            foreach (IntVec3 current in tentComp.doorCells)
            {
                IntVec3      DoorPos    = current;
                List <Thing> thingList2 = DoorPos.GetThingList(p.Map);
                bool         nodoor     = true;
                for (int i = 0; i < thingList2.Count; i++)
                {
                    if (thingList2[i].def == ThingDef.Named("TentDoor"))
                    {
                        nodoor = false;
                        thingList2[i].Destroy(DestroyMode.Vanish);
                    }
                }
                if (nodoor)
                {
                    damage = damage + 10;
                }
            }

            tent.HitPoints = tent.HitPoints - damage;
            GenSpawn.Spawn(tent, pos, p.Map);

            return;
        }
예제 #10
0
        public void ApplyRoomDefToRoom(DungeonNode node, RoomGenDef rgd)
        {
            Log.Message($"{rgd.defName} for {node.room.CenterCell.ToString()}");

            bool hasCenterpiece = false;


            var minWallSize = Mathf.Min(node.room.Width, node.room.Height);

            if (minWallSize <= 5)
            {
                SpawnBuildings(rgd.furnishingsDef.tinyRoomBuildingsToSpawn, node, ref hasCenterpiece);
            }
            else if (minWallSize <= 8)
            {
                SpawnBuildings(rgd.furnishingsDef.tinyRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.smallRoomBuildingsToSpawn, node, ref hasCenterpiece);
            }
            else if (minWallSize <= 12)
            {
                SpawnBuildings(rgd.furnishingsDef.tinyRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.smallRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.mediumRoomBuildingsToSpawn, node, ref hasCenterpiece);
            }
            else if (minWallSize <= 24)
            {
                SpawnBuildings(rgd.furnishingsDef.tinyRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.smallRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.mediumRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.largeRoomBuildingsToSpawn, node, ref hasCenterpiece);
            }
            else
            {
                SpawnBuildings(rgd.furnishingsDef.tinyRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.smallRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.mediumRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.largeRoomBuildingsToSpawn, node, ref hasCenterpiece);
                SpawnBuildings(rgd.furnishingsDef.colossalRoomBuildingsToSpawn, node, ref hasCenterpiece);
            }

            if (rgd.pawnsToSpawn?.Count > 0)
            {
                foreach (var pawnKind in rgd.pawnsToSpawn)
                {
                    for (int i = 0; i < pawnKind.numToSpawn.RandomInRange; i++)
                    {
                        IntVec3 spawnPoint;
                        CellFinder.TryFindRandomCellInsideWith(node.room, ((IntVec3 x) => { return(x.Standable(map)); }), out spawnPoint);
                        var pawn = PawnGenerator.GeneratePawn(pawnKind.pawnKindDef, null);
                        GenSpawn.Spawn(pawn, spawnPoint, map);
                        if (pawnKind.spawnDead)
                        {
                            pawn.Kill(null);
                        }
                        if (pawnKind.factionDef != null)
                        {
                            pawn.SetFactionDirect(Find.FactionManager.FirstFactionOfDef(pawnKind.factionDef));
                        }
                    }
                }
            }
        }
        // Token: 0x060028DA RID: 10458 RVA: 0x001352F0 File Offset: 0x001336F0
        public void TryLaunch(int destinationTile, TransportPodsArrivalAction arrivalAction, Caravan cafr = null)
        {
            //Log.Warning("CARR:" + this.carr+"/"+cafr);
            if (cafr == null)
            {
                if (!this.parent.Spawned)
                {
                    Log.Error("Tried to launch " + this.parent + ", but it's unspawned.", false);
                    return;
                }
            }

            /*
             * List<CompTransporter> transportersInGroup = this.TransportersInGroup;
             * if (transportersInGroup == null)
             * {
             *  Log.Error("Tried to launch " + this.parent + ", but it's not in any group.", false);
             *  return;
             * }
             */
            if (this.parent.Spawned)
            {
                if (!this.LoadingInProgressOrReadyToLaunch)
                {
                    return;
                }
            }
            if (!this.AllInGroupConnectedToFuelingPort || !this.AllFuelingPortSourcesInGroupHaveAnyFuel)
            {
                return;
            }
            if (cafr == null)
            {
                Map map = this.parent.Map;
                int num = Find.WorldGrid.TraversalDistanceBetween(map.Tile, destinationTile, true, int.MaxValue);
                if (num > this.MaxLaunchDistance)
                {
                    return;
                }
                this.Transporter.TryRemoveLord(map);
                int   groupID = this.Transporter.groupID;
                float amount  = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
                //for (int i = 0; i < transportersInGroup.Count; i++)

                CompTransporter compTransporter   = this.FuelingPortSource.TryGetComp <CompTransporter>(); //transportersInGroup[i];
                Building        fuelingPortSource = this.FuelingPortSource;                                //compTransporter.Launchable.FuelingPortSource;
                if (fuelingPortSource != null)
                {
                    fuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                }
                ThingOwner directlyHeldThings = compTransporter.GetDirectlyHeldThings();

                Thing helicopter = ThingMaker.MakeThing(ThingDef.Named("Building_Helicopter"));
                helicopter.SetFactionDirect(Faction.OfPlayer);

                CompRefuelable compr  = helicopter.TryGetComp <CompRefuelable>();
                Type           tcr    = compr.GetType();
                FieldInfo      finfos = tcr.GetField("fuel", BindingFlags.NonPublic | BindingFlags.Instance);
                finfos.SetValue(compr, fuelingPortSource.TryGetComp <CompRefuelable>().Fuel);

                compr.TargetFuelLevel = fuelingPortSource.TryGetComp <CompRefuelable>().TargetFuelLevel;

                helicopter.stackCount = 1;
                directlyHeldThings.TryAddOrTransfer(helicopter);

                ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(directlyHeldThings, true, true);
                HelicopterLeaving dropPodLeaving = (HelicopterLeaving)SkyfallerMaker.MakeSkyfaller(ThingDef.Named("HelicopterLeaving"), activeDropPod);
                dropPodLeaving.groupID         = groupID;
                dropPodLeaving.destinationTile = destinationTile;
                dropPodLeaving.arrivalAction   = arrivalAction;
                compTransporter.CleanUpLoadingVars(map);
                //compTransporter.parent
                IntVec3 poc = fuelingPortSource.Position;
                // fuelingPortSource.Destroy(DestroyMode.Vanish);
                HelicopterStatic.HelicopterDestroy(fuelingPortSource, DestroyMode.Vanish);
                GenSpawn.Spawn(dropPodLeaving, poc, map, WipeMode.Vanish);

                CameraJumper.TryHideWorld();
            }
            else
            {
                int num = Find.WorldGrid.TraversalDistanceBetween(carr.Tile, destinationTile, true, int.MaxValue);
                if (num > this.MaxLaunchDistance)
                {
                    return;
                }
                float amount = Mathf.Max(CompLaunchableHelicopter.FuelNeededToLaunchAtDist((float)num), 1f);
                if (FuelingPortSource != null)
                {
                    FuelingPortSource.TryGetComp <CompRefuelable>().ConsumeFuel(amount);
                }


                ThingOwner <Pawn> directlyHeldThings = (ThingOwner <Pawn>)cafr.GetDirectlyHeldThings();
                Thing             helicopter         = null;
                foreach (Pawn pawn in directlyHeldThings.InnerListForReading)
                {
                    Pawn_InventoryTracker pinv = pawn.inventory;
                    for (int i = 0; i < pinv.innerContainer.Count; i++)
                    {
                        if (pinv.innerContainer[i].def.defName == ("Building_Helicopter"))
                        {
                            helicopter = pinv.innerContainer[i];
                            pinv.innerContainer[i].holdingOwner.Remove(pinv.innerContainer[i]);

                            break;
                        }
                    }
                }

                ThingOwner <Thing> finalto = new ThingOwner <Thing>();
                List <Pawn>        lpto    = directlyHeldThings.AsEnumerable <Pawn>().ToList();
                foreach (Pawn p in lpto)
                {
                    finalto.TryAddOrTransfer(p);
                }


                if (helicopter != null)
                {
                    // Log.Warning("TRY ADD"+helicopter);
                    if (helicopter.holdingOwner == null)
                    {
                        //Log.Warning("NULL");
                        //directlyHeldThings.
                        finalto.TryAddOrTransfer(helicopter, false);
                    }
                }


                ActiveDropPod activeDropPod = (ActiveDropPod)ThingMaker.MakeThing(ThingDef.Named("ActiveHelicopter"), null);
                activeDropPod.Contents = new ActiveDropPodInfo();
                activeDropPod.Contents.innerContainer.TryAddRangeOrTransfer(
                    //directlyHeldThings
                    finalto, true, true);

                cafr.RemoveAllPawns();
                if (cafr.Spawned)
                {
                    Find.WorldObjects.Remove(cafr);
                }

                TravelingTransportPods travelingTransportPods = (TravelingTransportPods)WorldObjectMaker.MakeWorldObject(DefDatabase <WorldObjectDef> .GetNamed("TravelingHelicopters", true));
                travelingTransportPods.Tile = cafr.Tile;
                travelingTransportPods.SetFaction(Faction.OfPlayer);
                travelingTransportPods.destinationTile = destinationTile;
                travelingTransportPods.arrivalAction   = arrivalAction;
                Find.WorldObjects.Add(travelingTransportPods);
                travelingTransportPods.AddPod(activeDropPod.Contents, true);
                activeDropPod.Contents = null;
                activeDropPod.Destroy(DestroyMode.Vanish);
                // CameraJumper.TryHideWorld();
                Find.WorldTargeter.StopTargeting();
            }
        }
예제 #12
0
파일: Verb_Summon.cs 프로젝트: asl97/TMagic
        protected override bool TryCastShot()
        {
            CellRect cellRect = CellRect.CenteredOn(this.currentTarget.Cell, 1);
            Map      map      = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell      = cellRect.CenterCell;
            Thing   summonableThing = new Thing();
            //FlyingObject flyingPawn = new FlyingObject();
            Pawn summonablePawn = new Pawn();

            bool pflag = true;

            summonableThing = centerCell.GetFirstPawn(map);
            if (summonableThing == null)
            {
                pflag           = false;
                summonableThing = centerCell.GetFirstItem(map);
            }
            else
            {
                pVect          = summonableThing.TrueCenter();
                pVect.x        = base.caster.TrueCenter().x;
                pVect.z        = base.caster.TrueCenter().z;
                pVect.y        = 0f;
                summonablePawn = summonableThing as Pawn;
                if (summonablePawn != base.CasterPawn)
                {
                    //flyingPawn = (FlyingObject)GenSpawn.Spawn(ThingDef.Named("TM_SummonedPawn"), summonableThing.Position, summonableThing.Map);
                }
                else
                {
                    //flyingPawn = null;
                    summonableThing = null;
                    Messages.Message("TM_CantSummonSelf".Translate(), MessageTypeDefOf.NegativeEvent);
                }
            }

            bool result = false;
            bool arg_40_0;

            if (this.currentTarget != null && base.CasterPawn != null)
            {
                IntVec3 arg_29_0 = this.currentTarget.Cell;
                arg_40_0 = this.currentTarget.Cell.IsValid;
            }
            else
            {
                arg_40_0 = false;
            }
            bool flag = arg_40_0;

            if (flag)
            {
                if (summonableThing != null)
                {
                    if (pflag)// && flyingPawn != null)
                    {
                        //Thing p = summonablePawn;

                        //summonablePawn.DeSpawn();
                        //GenSpawn.Spawn(p, base.caster.Position, base.CasterPawn.Map, Rot4.North, false);

                        //Pawn p = summonablePawn;
                        summonablePawn.DeSpawn();
                        //p.SetPositionDirect(this.currentTarget.Cell);
                        GenSpawn.Spawn(summonablePawn, base.CasterPawn.Position, map);
                        //flyingPawn = null;



                        //summonablePawn.Position = base.CasterPawn.Position;
                        //p.jobs.StopAll(false);
                    }
                    else
                    {
                        summonableThing.Position = base.CasterPawn.Position;
                        summonableThing.Rotation = Rot4.North;
                        //summonableThing.SetPositionDirect(base.CasterPawn.InteractionCell);
                    }
                    result = true;
                }
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            return(result);
        }
예제 #13
0
        protected void TrySpread()
        {
            IntVec3 intVec = base.Position;
            bool    flag;

            Rand.PushState();
            if (Rand.Chance(0.8f))
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(1, 8)];
                flag   = true;
            }
            else
            {
                intVec = base.Position + GenRadial.ManualRadialPattern[Rand.RangeInclusive(10, 20)];
                flag   = false;
            }
            Rand.PopState();
            if (!intVec.InBounds(base.Map))
            {
                return;
            }

            float chance;

            if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
            {
                chance = WarpfireUtility.ChanceToStartWarpfireIn(intVec, base.Map);
            }
            else
            {
                chance = FireUtility.ChanceToStartFireIn(intVec, base.Map);
            }

            Rand.PushState();
            bool f = Rand.Chance(chance);

            Rand.PopState();
            if (f)
            {
                if (!flag)
                {
                    CellRect startRect = CellRect.SingleCell(base.Position);
                    CellRect endRect   = CellRect.SingleCell(intVec);
                    if (!GenSight.LineOfSight(base.Position, intVec, base.Map, startRect, endRect, null))
                    {
                        return;
                    }
                    Spark spark;
                    if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
                    {
                        spark = (Spark)GenSpawn.Spawn(AdeptusThingDefOf.OG_WarpSpark, base.Position, base.Map, WipeMode.Vanish);
                    }
                    else
                    {
                        spark = (Spark)GenSpawn.Spawn(ThingDefOf.Spark, base.Position, base.Map, WipeMode.Vanish);
                    }
                    spark.Launch(this, intVec, intVec, ProjectileHitFlags.All, null);
                }
                else
                {
                    if (this.def.projectile.damageDef == AdeptusDamageDefOf.OG_Chaos_Deamon_Warpfire)
                    {
                        WarpfireUtility.TryStartWarpfireIn(intVec, base.Map, 0.1f);
                    }
                    else
                    {
                        FireUtility.TryStartFireIn(intVec, base.Map, 0.1f);
                    }
                }
            }
        }
예제 #14
0
        public bool TryCastShot_A16Vanilla_Modified()
        {
            if (this.currentTarget.HasThing && this.currentTarget.Thing.Map != this.caster.Map)
            {
                return(false);
            }
            bool flag = base.TryFindShootLineFromTo(this.caster.Position, this.currentTarget, out ShootLine shootLine);

            if (this.verbProps.stopBurstWithoutLos && !flag)
            {
                return(false);
            }
            Vector3    drawPos    = this.caster.DrawPos;
            Projectile projectile = (Projectile)GenSpawn.Spawn(this.verbProps.projectileDef, shootLine.Source, this.caster.Map);

            ///MODIFIED SECTION
            ////////////////////////////////////////////

            if (this.lastShotReflected)
            {
                ////Log.Message("lastShotReflected Called");
                projectile.Launch(this.caster, drawPos, this.currentTarget, this.ownerEquipment);
                return(true);
            }

            ////////////////////////////////////////////
            //

            projectile.FreeIntercept = (this.canFreeInterceptNow && !projectile.def.projectile.flyOverhead);
            if (this.verbProps.forcedMissRadius > 0.5f)
            {
                float lengthHorizontalSquared = (this.currentTarget.Cell - this.caster.Position).LengthHorizontalSquared;
                float num;
                if (lengthHorizontalSquared < 9f)
                {
                    num = 0f;
                }
                else if (lengthHorizontalSquared < 25f)
                {
                    num = this.verbProps.forcedMissRadius * 0.5f;
                }
                else if (lengthHorizontalSquared < 49f)
                {
                    num = this.verbProps.forcedMissRadius * 0.8f;
                }
                else
                {
                    num = this.verbProps.forcedMissRadius * 1f;
                }
                if (num > 0.5f)
                {
                    int max  = GenRadial.NumCellsInRadius(this.verbProps.forcedMissRadius);
                    int num2 = Rand.Range(0, max);
                    if (num2 > 0)
                    {
                        if (DebugViewSettings.drawShooting)
                        {
                            MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToForRad", -1f);
                        }
                        IntVec3 c = this.currentTarget.Cell + GenRadial.RadialPattern[num2];
                        if (this.currentTarget.HasThing)
                        {
                            projectile.ThingToNeverIntercept = this.currentTarget.Thing;
                        }
                        if (!projectile.def.projectile.flyOverhead)
                        {
                            projectile.InterceptWalls = true;
                        }
                        projectile.Launch(this.caster, drawPos, c, this.ownerEquipment);
                        return(true);
                    }
                }
            }
            ShotReport shotReport = ShotReport.HitReportFor(this.caster, this, this.currentTarget);

            if (Rand.Value > shotReport.ChanceToNotGoWild_IgnoringPosture)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToWild", -1f);
                }
                shootLine.ChangeDestToMissWild();
                if (this.currentTarget.HasThing)
                {
                    projectile.ThingToNeverIntercept = this.currentTarget.Thing;
                }
                if (!projectile.def.projectile.flyOverhead)
                {
                    projectile.InterceptWalls = true;
                }
                projectile.Launch(this.caster, drawPos, shootLine.Dest, this.ownerEquipment);
                return(true);
            }
            if (Rand.Value > shotReport.ChanceToNotHitCover)
            {
                if (DebugViewSettings.drawShooting)
                {
                    MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToCover", -1f);
                }
                if (this.currentTarget.Thing != null && this.currentTarget.Thing.def.category == ThingCategory.Pawn)
                {
                    Thing randomCoverToMissInto = shotReport.GetRandomCoverToMissInto();
                    if (!projectile.def.projectile.flyOverhead)
                    {
                        projectile.InterceptWalls = true;
                    }
                    projectile.Launch(this.caster, drawPos, randomCoverToMissInto, this.ownerEquipment);
                    return(true);
                }
            }
            if (DebugViewSettings.drawShooting)
            {
                MoteMaker.ThrowText(this.caster.DrawPos, this.caster.Map, "ToHit", -1f);
            }
            if (!projectile.def.projectile.flyOverhead)
            {
                projectile.InterceptWalls = (!this.currentTarget.HasThing || this.currentTarget.Thing.def.Fillage == FillCategory.Full);
            }
            if (this.currentTarget.Thing != null)
            {
                projectile.Launch(this.caster, drawPos, this.currentTarget, this.ownerEquipment);
            }
            else
            {
                projectile.Launch(this.caster, drawPos, shootLine.Dest, this.ownerEquipment);
            }
            return(true);
        }
        //returns pawns for compatibility reasons.
        public static void SpawnHackedMechanoids(List <Pawn> pawns, IncidentParms parms)
        {
            if (pawns.Count == 0)
            {
                return;
            }
            if (parms.faction == Faction.OfMechanoids)
            {
                return;
            }
            Random rand = new Random(DateTime.Now.Millisecond);

            if (rand.Next(0, 100) > Base.hackedMechChance)
            {
                return;
            }

            int         minHackedMechPoints = Math.Min(Base.minHackedMechPoints, Base.maxHackedMechPoints);
            float       maxMechPoints       = parms.points * ((float)rand.Next(minHackedMechPoints, Base.maxHackedMechPoints)) / 100f; //TODO: no magic numbers
            float       cumulativePoints    = 0;
            Map         map        = parms.target as Map;
            List <Pawn> addedPawns = new List <Pawn>();

            while (cumulativePoints < maxMechPoints)
            {
                PawnKindDef pawnKindDef = null;
                IEnumerable <PawnKindDef> selectedPawns = (from a in DefDatabase <PawnKindDef> .AllDefs
                                                           where a.RaceProps.IsMechanoid &&
                                                           cumulativePoints + a.combatPower < maxMechPoints &&
                                                           Utilities.IsAllowedInModOptions(a.race.defName, parms.faction) &&
                                                           (parms.raidArrivalMode == PawnsArrivalModeDefOf.EdgeWalkIn || a.RaceProps.baseBodySize <= 1) //Only allow small mechs to use drop pods
                                                           select a);

                if (selectedPawns != null)
                {
                    selectedPawns.TryRandomElement(out pawnKindDef);
                }
                if (pawnKindDef != null)
                {
                    Pawn mechanoid = PawnGenerator.GeneratePawn(pawnKindDef, parms.faction);
                    if (parms.raidArrivalMode == PawnsArrivalModeDefOf.EdgeWalkIn)
                    {
                        IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 8, null);
                        GenSpawn.Spawn(mechanoid, loc, map, parms.spawnRotation);
                    }
                    mechanoid.health.AddHediff(WTH_DefOf.WTH_TargetingHacked);
                    mechanoid.health.AddHediff(WTH_DefOf.WTH_BackupBattery);
                    Need_Power powerNeed = (Need_Power)mechanoid.needs.TryGetNeed(WTH_DefOf.WTH_Mechanoid_Power);
                    powerNeed.CurLevel = powerNeed.MaxLevel;
                    addedPawns.Add(mechanoid);
                    cumulativePoints += pawnKindDef.combatPower;
                    AddModules(mechanoid);
                }
                else
                {
                    break;
                }
            }
            if (addedPawns.Count > 0 && !addedPawns[0].Spawned)
            {
                parms.raidArrivalMode.Worker.Arrive(addedPawns, parms);
            }
            pawns.AddRange(addedPawns);

            foreach (Pawn pawn in pawns)
            {
                if (pawn.equipment == null)
                {
                    pawn.equipment = new Pawn_EquipmentTracker(pawn);
                }
            }
        }
        protected virtual void Impact(Thing hitThing)
        {
            bool flag = hitThing == null;

            if (flag)
            {
                Pawn pawn;
                bool flag2 = (pawn = (base.Position.GetThingList(base.Map).FirstOrDefault((Thing x) => x == this.assignedTarget) as Pawn)) != null;
                if (flag2)
                {
                    hitThing = pawn;
                }
            }
            bool hasValue = this.impactDamage.HasValue;

            if (hasValue)
            {
                hitThing.TakeDamage(this.impactDamage.Value);
            }
            try
            {
                SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);

                if (this.flyingThing != null)
                {
                    GenSpawn.Spawn(this.flyingThing, base.Position, base.Map);
                    if (this.flyingThing is Pawn)
                    {
                        Pawn p = this.flyingThing as Pawn;
                        if (p.IsColonist && this.drafted)
                        {
                            p.drafter.Drafted = true;
                        }
                        if (this.earlyImpact)
                        {
                            damageEntities(p, this.impactForce, DamageDefOf.Blunt);
                            damageEntities(p, this.impactForce, DamageDefOf.Stun);
                        }
                    }
                    else if (flyingThing.def.thingCategories != null && (flyingThing.def.thingCategories.Contains(ThingCategoryDefOf.Chunks) || flyingThing.def.thingCategories.Contains(ThingCategoryDef.Named("StoneChunks"))))
                    {
                        float   radius = 4f;
                        Vector3 center = this.ExactPosition;
                        if (this.earlyImpact)
                        {
                            bool    wallFlag90neg = false;
                            IntVec3 wallCheck     = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3();
                            MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                            wallFlag90neg = wallCheck.Walkable(base.Map);

                            wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3();
                            MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                            bool wallFlag90 = wallCheck.Walkable(base.Map);

                            if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg))
                            {
                                //fragment energy bounces in reverse direction of travel
                                center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3);
                            }
                            else if (wallFlag90)
                            {
                                center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3);
                            }
                            else if (wallFlag90neg)
                            {
                                center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3);
                            }
                        }

                        List <IntVec3> damageRing  = GenRadial.RadialCellsAround(base.Position, radius, true).ToList();
                        List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList();
                        for (int i = 0; i < damageRing.Count; i++)
                        {
                            List <Thing> allThings = damageRing[i].GetThingList(base.Map);
                            for (int j = 0; j < allThings.Count; j++)
                            {
                                if (allThings[j] is Pawn)
                                {
                                    damageEntities(allThings[j], Rand.Range(14, 22), DamageDefOf.Blunt);
                                }
                                else if (allThings[j] is Building)
                                {
                                    damageEntities(allThings[j], Rand.Range(56, 88), DamageDefOf.Blunt);
                                }
                                else
                                {
                                    if (Rand.Chance(.1f))
                                    {
                                        GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], base.Map, ThingPlaceMode.Near);
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < outsideRing.Count; i++)
                        {
                            IntVec3 intVec = outsideRing[i];
                            if (intVec.IsValid && intVec.InBounds(base.Map))
                            {
                                Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec);
                                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0);
                                TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0);
                                GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, ThingDefOf.Filth_RubbleRock, .4f, 1, false, null, 0f, 1, 0, false);
                                //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f));
                            }
                        }
                        //damageEntities(this.flyingThing, 305, DamageDefOf.Blunt);
                        this.flyingThing.Destroy(DestroyMode.Vanish);
                    }
                    else if ((flyingThing.def.thingCategories != null && (flyingThing.def.thingCategories.Contains(ThingCategoryDefOf.Corpses))) || this.flyingThing is Corpse)
                    {
                        Corpse  flyingCorpse = this.flyingThing as Corpse;
                        float   radius       = 3f;
                        Vector3 center       = this.ExactPosition;
                        if (this.earlyImpact)
                        {
                            bool    wallFlag90neg = false;
                            IntVec3 wallCheck     = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3();
                            MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                            wallFlag90neg = wallCheck.Walkable(base.Map);

                            wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3();
                            MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                            bool wallFlag90 = wallCheck.Walkable(base.Map);

                            if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg))
                            {
                                //fragment energy bounces in reverse direction of travel
                                center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3);
                            }
                            else if (wallFlag90)
                            {
                                center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3);
                            }
                            else if (wallFlag90neg)
                            {
                                center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3);
                            }
                        }

                        List <IntVec3> damageRing  = GenRadial.RadialCellsAround(base.Position, radius, true).ToList();
                        List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList();
                        Filth          filth       = (Filth)ThingMaker.MakeThing(flyingCorpse.InnerPawn.def.race.BloodDef);
                        for (int i = 0; i < damageRing.Count; i++)
                        {
                            List <Thing> allThings = damageRing[i].GetThingList(base.Map);
                            for (int j = 0; j < allThings.Count; j++)
                            {
                                if (allThings[j] is Pawn)
                                {
                                    damageEntities(allThings[j], Rand.Range(18, 28), DamageDefOf.Blunt);
                                }
                                else if (allThings[j] is Building)
                                {
                                    damageEntities(allThings[j], Rand.Range(56, 88), DamageDefOf.Blunt);
                                }
                                else
                                {
                                    if (Rand.Chance(.25f))
                                    {
                                        if (filth != null)
                                        {
                                            filth = (Filth)ThingMaker.MakeThing(flyingCorpse.InnerPawn.def.race.BloodDef);
                                            GenPlace.TryPlaceThing(filth, damageRing[i], base.Map, ThingPlaceMode.Near);
                                        }
                                        else
                                        {
                                            GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_Blood), damageRing[i], base.Map, ThingPlaceMode.Near);
                                        }
                                    }
                                    if (Rand.Chance(.25f))
                                    {
                                        GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_CorpseBile), damageRing[i], base.Map, ThingPlaceMode.Near);
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < outsideRing.Count; i++)
                        {
                            IntVec3 intVec = outsideRing[i];
                            if (intVec.IsValid && intVec.InBounds(base.Map))
                            {
                                Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec);
                                TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_BloodSquirt, this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(4f, 13f), (Quaternion.AngleAxis(Rand.Range(60, 120), Vector3.up) * moteDirection).ToAngleFlat(), 0);
                                TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_BloodMist, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0);
                                GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, filth.def, .4f, 1, false, null, 0f, 1, 0, false);
                                //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f));
                            }
                        }
                        //damageEntities(this.flyingThing, 305, DamageDefOf.Blunt);
                        //this.flyingThing.Destroy(DestroyMode.Vanish);
                    }
                }
                else
                {
                    float   radius = 2f;
                    Vector3 center = this.ExactPosition;
                    if (this.earlyImpact)
                    {
                        bool    wallFlag90neg = false;
                        IntVec3 wallCheck     = (center + (Quaternion.AngleAxis(-90, Vector3.up) * this.direction)).ToIntVec3();
                        MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                        wallFlag90neg = wallCheck.Walkable(base.Map);

                        wallCheck = (center + (Quaternion.AngleAxis(90, Vector3.up) * this.direction)).ToIntVec3();
                        MoteMaker.ThrowMicroSparks(wallCheck.ToVector3Shifted(), base.Map);
                        bool wallFlag90 = wallCheck.Walkable(base.Map);

                        if ((!wallFlag90 && !wallFlag90neg) || (wallFlag90 && wallFlag90neg))
                        {
                            //fragment energy bounces in reverse direction of travel
                            center = center + ((Quaternion.AngleAxis(180, Vector3.up) * this.direction) * 3);
                        }
                        else if (wallFlag90)
                        {
                            center = center + ((Quaternion.AngleAxis(90, Vector3.up) * this.direction) * 3);
                        }
                        else if (wallFlag90neg)
                        {
                            center = center + ((Quaternion.AngleAxis(-90, Vector3.up) * this.direction) * 3);
                        }
                    }

                    List <IntVec3> damageRing  = GenRadial.RadialCellsAround(base.Position, radius, true).ToList();
                    List <IntVec3> outsideRing = GenRadial.RadialCellsAround(base.Position, radius, false).Except(GenRadial.RadialCellsAround(base.Position, radius - 1, true)).ToList();
                    for (int i = 0; i < damageRing.Count; i++)
                    {
                        List <Thing> allThings = damageRing[i].GetThingList(base.Map);
                        for (int j = 0; j < allThings.Count; j++)
                        {
                            if (allThings[j] is Pawn)
                            {
                                damageEntities(allThings[j], Rand.Range(10, 16), DamageDefOf.Blunt);
                            }
                            else if (allThings[j] is Building)
                            {
                                damageEntities(allThings[j], Rand.Range(32, 88), DamageDefOf.Blunt);
                            }
                            else
                            {
                                if (Rand.Chance(.1f))
                                {
                                    GenPlace.TryPlaceThing(ThingMaker.MakeThing(ThingDefOf.Filth_RubbleRock), damageRing[i], base.Map, ThingPlaceMode.Near);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < outsideRing.Count; i++)
                    {
                        IntVec3 intVec = outsideRing[i];
                        if (intVec.IsValid && intVec.InBounds(base.Map))
                        {
                            Vector3 moteDirection = TM_Calc.GetVector(this.ExactPosition.ToIntVec3(), intVec);
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Rubble"), this.ExactPosition, base.Map, Rand.Range(.3f, .6f), .2f, .02f, .05f, Rand.Range(-100, 100), Rand.Range(8f, 13f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0);
                            TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_Smoke, this.ExactPosition, base.Map, Rand.Range(.9f, 1.2f), .3f, .02f, Rand.Range(.25f, .4f), Rand.Range(-100, 100), Rand.Range(5f, 8f), (Quaternion.AngleAxis(90, Vector3.up) * moteDirection).ToAngleFlat(), 0);
                            GenExplosion.DoExplosion(intVec, base.Map, .4f, DamageDefOf.Blunt, pawn, 0, 0, SoundDefOf.Pawn_Melee_Punch_HitBuilding, null, null, null, null, .4f, 1, false, null, 0f, 1, 0, false);
                            //MoteMaker.ThrowSmoke(intVec.ToVector3Shifted(), base.Map, Rand.Range(.6f, 1f));
                        }
                    }
                }
                this.Destroy(DestroyMode.Vanish);
            }
            catch
            {
                if (this.flyingThing != null)
                {
                    if (!this.flyingThing.Spawned)
                    {
                        GenSpawn.Spawn(this.flyingThing, base.Position, base.Map);
                        Log.Message("catch");
                    }
                }
                this.Destroy(DestroyMode.Vanish);
            }
        }
        // duplicated to make changes (added container support)
        public bool TryPlaceDirect(Thing thing, IntVec3 loc, out Thing resultingThing)
        {
            // boolean success indicator
            bool flag = false;

            // container code part
            List <Thing> list = Find.ThingGrid.ThingsListAt(loc);

            if (list.Exists(storage => storage.TryGetComp <CompContainer>() != null))
            {
                resultingThing = null;

                // stackables (like resources)
                if (thing.def.stackLimit > 1)
                {
                    foreach (Thing item in list)

                    {
                        if (!item.CanStackWith(thing))
                        {
                            continue;
                        }
                        // if item can stack with another
                        else
                        {
                            // Required, because thing reference is changed to the absorber, if absorbed
                            Thing t = thing;
                            if (item.TryAbsorbStack(thing, true))
                            {
                                // Clean up to prevent haulables lists overflow
                                RemoveHaulableFromLists(t);
                                // it gets absorbed and destroyed
                                resultingThing = item;
                                return(!flag);
                            }
                        }
                    }
                }

                resultingThing = GenSpawn.Spawn(thing, loc);

                // Clean up to prevent haulables lists overflow
                RemoveHaulableFromLists(thing);

                return(!flag);
            }

            // vanilla code part
            if (thing.stackCount > thing.def.stackLimit)
            {
                thing = thing.SplitOff(thing.def.stackLimit);
                flag  = true;
            }
            if (thing.def.stackLimit > 1)
            {
                List <Thing> thingList = loc.GetThingList();
                int          i         = 0;
                while (i < thingList.Count)
                {
                    Thing thing2 = thingList[i];
                    if (!thing2.CanStackWith(thing))
                    {
                        i++;
                    }
                    else
                    {
                        // Required, because thing reference is changed to the absorber, if absorbed
                        Thing t = thing;
                        if (thing2.TryAbsorbStack(thing, true))
                        {
                            // Clean up to prevent haulables lists overflow
                            RemoveHaulableFromLists(t);
                            resultingThing = thing2;
                            return(!flag);
                        }
                        resultingThing = null;
                        return(false);
                    }
                }
            }

            resultingThing = GenSpawn.Spawn(thing, loc);
            // Clean up to prevent haulables lists overflow
            RemoveHaulableFromLists(thing);

            SlotGroup slotGroup1 = loc.GetSlotGroup();

            if (slotGroup1 != null && slotGroup1.parent != null)
            {
                slotGroup1.parent.Notify_ReceivedThing(resultingThing);
            }
            return(!flag);
        }
예제 #18
0
        // ===================== Main function =====================
        public override void Tick()
        {
            base.Tick();

            if (this.ticksToLanding == horizontalTrajectoryDurationInTicks + verticalTrajectoryDurationInTicks)
            {
                // Atmosphere entry sound.
                FlyingSpaceshipLanding.preLandingSound.PlayOneShot(new TargetInfo(this.Position, this.Map));
            }
            this.ticksToLanding--;
            if (this.ticksToLanding == verticalTrajectoryDurationInTicks)
            {
                // Landing on sound.
                FlyingSpaceshipLanding.landingSound.PlayOneShot(new TargetInfo(this.Position, this.Map));
            }
            if (this.ticksToLanding <= verticalTrajectoryDurationInTicks)
            {
                // Throw dust during descent.
                MoteMaker.ThrowDustPuff(GenAdj.CellsAdjacentCardinal(this.landingPadPosition, this.landingPadRotation, Util_ThingDefOf.LandingPad.Size).RandomElement(), this.Map, 3f * (1f - (float)this.ticksToLanding / (float)verticalTrajectoryDurationInTicks));
            }
            if (this.ticksToLanding == 0)
            {
                Building_Spaceship spaceship = null;
                switch (this.spaceshipKind)
                {
                case SpaceshipKind.CargoPeriodic:
                case SpaceshipKind.CargoRequested:
                    // Spawn cargo spaceship.
                    Building_SpaceshipCargo cargoSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipCargo) as Building_SpaceshipCargo;
                    cargoSpaceship.InitializeData_Cargo(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(cargoSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.Damaged:
                    // Spawn damaged spaceship.
                    Building_SpaceshipDamaged damagedSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDamaged) as Building_SpaceshipDamaged;
                    damagedSpaceship.InitializeData_Damaged(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind, this.HitPoints);
                    // Faction will be set to player when repair materials are delivered.
                    spaceship = GenSpawn.Spawn(damagedSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.DispatcherDrop:
                    // Spawn dispatcher spaceship.
                    Building_SpaceshipDispatcherDrop dispatcherSpaceshipDrop = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDispatcherDrop) as Building_SpaceshipDispatcherDrop;
                    dispatcherSpaceshipDrop.InitializeData_DispatcherDrop(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(dispatcherSpaceshipDrop, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.DispatcherPick:
                    // Spawn dispatcher spaceship.
                    Building_SpaceshipDispatcherPick dispatcherSpaceshipPick = ThingMaker.MakeThing(Util_Spaceship.SpaceshipDispatcherPick) as Building_SpaceshipDispatcherPick;
                    dispatcherSpaceshipPick.InitializeData_DispatcherPick(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(dispatcherSpaceshipPick, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                case SpaceshipKind.Medical:
                    // Spawn medical spaceship.
                    Building_SpaceshipMedical medicalSpaceship = ThingMaker.MakeThing(Util_Spaceship.SpaceshipMedical) as Building_SpaceshipMedical;
                    medicalSpaceship.InitializeData_Medical(Util_Faction.MiningCoFaction, this.HitPoints, this.landingDuration, this.spaceshipKind);
                    spaceship = GenSpawn.Spawn(medicalSpaceship, this.landingPadPosition, this.Map, this.landingPadRotation) as Building_Spaceship;
                    break;

                default:
                    Log.ErrorOnce("MiningCo. Spaceship: unhandled SpaceshipKind (" + this.spaceshipKind.ToString() + ").", 123456783);
                    break;
                }
                this.Destroy();
            }
        }
예제 #19
0
 protected override TornadoCopy Spawn(IntVec3 loc, Map map)
 {
     return((TornadoCopy)GenSpawn.Spawn(ThingDef.Named("Sharknado"), loc, map));
 }
예제 #20
0
        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;
                    if (TargetsAoE[i].Thing != null && TargetsAoE[i].Thing is Pawn targetPawn)
                    {
                        float damageToDeal = ((Aura_Adam)CasterPawn.TryGetComp <CompAbilityUserAura>().aura).absorbedDamage;
                        if (targetPawn.TryGetComp <CompAbilityUserAura>() is CompAbilityUserAura compAbilityUserAura && targetPawn.TryGetComp <CompAbilityUserAura>().IsInitialized&& compAbilityUserAura.aura.currentEnergy > 0f)
                        {
                            float damageToDealToAura = 0f;
                            if (compAbilityUserAura.aura.currentEnergy > damageToDeal)
                            {
                                damageToDealToAura = damageToDeal;
                                damageToDeal       = 0;
                            }
                            else
                            {
                                damageToDealToAura = compAbilityUserAura.aura.currentEnergy * 100f + 1f;
                                damageToDeal       = damageToDeal - compAbilityUserAura.aura.currentEnergy;
                            }
                            DamageInfo extraDinfoToAura = new DamageInfo(DamageDefOf.Cut, damageToDealToAura, 0f, -1f, CasterPawn, null, CasterPawn.def, DamageInfo.SourceCategory.ThingOrUnknown, targetPawn);
                            extraDinfoToAura.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                            Vector3 direction = (targetPawn.Position - CasterPawn.Position).ToVector3();
                            extraDinfoToAura.SetAngle(direction);
                            targetPawn.TakeDamage(extraDinfoToAura);
                        }
                        if (damageToDeal > 0)
                        {
                            DamageInfo extraDinfo = new DamageInfo(DamageDefOf.Cut, damageToDeal, 0f, -1f, CasterPawn, null, CasterPawn.def, DamageInfo.SourceCategory.ThingOrUnknown, targetPawn);
                            extraDinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside);
                            Vector3 direction = (targetPawn.Position - CasterPawn.Position).ToVector3();
                            extraDinfo.SetAngle(direction);
                            targetPawn.TakeDamage(extraDinfo);
                        }
                        Projectile projectile = (Projectile)GenSpawn.Spawn(RWBYDefOf.RWBY_Ability_Adam_Projectile, CasterPawn.Position, CasterPawn.Map, WipeMode.Vanish);
                        projectile.Launch(CasterPawn, targetPawn, targetPawn, ProjectileHitFlags.IntendedTarget);
                        ((Aura_Adam)CasterPawn.TryGetComp <CompAbilityUserAura>().aura).absorbedDamage = 1f;
                    }
                    else
                    {
                        abilitySucceeded = false;
                    }
                    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);
        }
예제 #21
0
        public override void Tick()
        {
            base.Tick();

            if (Manned)
            {
                if (!initialized)
                {
                    comp        = mannableComp.ManningPawn.GetComp <CompAbilityUserMagic>();
                    this.verVal = mannableComp.ManningPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_ver").level;
                    this.pwrVal = mannableComp.ManningPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_pwr").level;
                    this.effVal = mannableComp.ManningPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_eff").level;

                    if (this.verVal >= 5)
                    {
                        this.rocketTicksToFire = 600 - ((verVal - 5) * 20);
                        this.rocketCount       = verVal / 5;
                        this.rocketManaCost    = .055f - (.001f * this.effVal);
                    }
                    if (this.verVal >= 10)
                    {
                        this.mortarTicksToFire = 900 - ((verVal - 10) * 40);
                        this.mortarMaxRange   += ((verVal - 10) * 5);
                        this.mortarManaCost    = .1f - (.002f * effVal);
                    }

                    this.initialized = true;
                }

                if (!mannableComp.ManningPawn.DestroyedOrNull() && !mannableComp.ManningPawn.Dead && !mannableComp.ManningPawn.Downed)
                {
                    if (this.verVal >= 5 && this.nextRocketFireTick < Find.TickManager.TicksGame && this.TargetCurrentlyAimingAt != null && comp.Mana.CurLevel >= this.rocketManaCost)
                    {
                        if (this.TargetCurrentlyAimingAt.Cell.IsValid && this.TargetCurrentlyAimingAt.Cell.DistanceToEdge(this.Map) > 5 && (this.TargetCurrentlyAimingAt.Cell - this.Position).LengthHorizontal >= this.rocketMinRange)
                        {
                            bool flag = this.TargetCurrentlyAimingAt.Cell != default(IntVec3);
                            if (flag)
                            {
                                Thing launchedThing = new Thing()
                                {
                                    def = ThingDef.Named("FlyingObject_RocketSmall")
                                };
                                FlyingObject_Advanced flyingObject = (FlyingObject_Advanced)GenSpawn.Spawn(ThingDef.Named("FlyingObject_RocketSmall"), this.Position, this.Map);
                                flyingObject.AdvancedLaunch(this, ThingDef.Named("Mote_Smoke"), 1, Rand.Range(5, 25), false, this.DrawPos, this.TargetCurrentlyAimingAt.Cell, launchedThing, Rand.Range(32, 38), true, Rand.Range(16, 22), 2, DamageDefOf.Bomb, null);
                                this.rocketCount--;
                                SoundInfo info = SoundInfo.InMap(new TargetInfo(this.Position, this.Map, false), MaintenanceType.None);
                                info.pitchFactor  = 1.3f;
                                info.volumeFactor = 1.5f;
                                TorannMagicDefOf.TM_AirWoosh.PlayOneShot(info);
                            }
                            if (rocketCount <= 0)
                            {
                                this.rocketCount        = verVal / 5;
                                this.nextRocketFireTick = Find.TickManager.TicksGame + (600 - ((verVal - 5) * 20));
                                comp.Mana.CurLevel     -= this.rocketManaCost;
                                comp.MagicUserXP       += Rand.Range(9, 12);
                            }
                            else
                            {
                                this.nextRocketFireTick = Find.TickManager.TicksGame + 20;
                            }
                        }
                    }

                    if (this.verVal >= 10 && this.mortarTicksToFire < Find.TickManager.TicksGame && comp.Mana.CurLevel >= this.mortarManaCost)
                    {
                        this.mortarTicksToFire = Find.TickManager.TicksGame + (900 - ((verVal - 10) * 40));
                        Pawn target = TM_Calc.FindNearbyEnemy(this.Position, this.Map, this.Faction, this.mortarMaxRange, this.mortarMinRange);
                        if (target != null && target.Position.IsValid && target.Position.DistanceToEdge(this.Map) > 5)
                        {
                            bool flag = target.Position != default(IntVec3);
                            if (flag)
                            {
                                IntVec3 rndTarget = target.Position;
                                rndTarget.x += Rand.RangeInclusive(-4, 4);
                                rndTarget.z += Rand.RangeInclusive(-4, 4);
                                Projectile newProjectile = (Projectile)GenSpawn.Spawn(ThingDef.Named("Bullet_Shell_TechnoTurretExplosive"), this.Position, this.Map, WipeMode.Vanish);
                                newProjectile.Launch(this, rndTarget, target, ProjectileHitFlags.All, null);
                            }
                            SoundInfo info = SoundInfo.InMap(new TargetInfo(this.Position, this.Map, false), MaintenanceType.None);
                            info.pitchFactor  = 1.3f;
                            info.volumeFactor = .8f;
                            SoundDef.Named("Mortar_LaunchA").PlayOneShot(info);
                            comp.Mana.CurLevel -= this.mortarManaCost;
                            comp.MagicUserXP   += Rand.Range(12, 15);
                        }
                    }

                    if (CanExtractShell && MannedByColonist)
                    {
                        CompChangeableProjectile compChangeableProjectile = gun.TryGetComp <CompChangeableProjectile>();
                        if (!compChangeableProjectile.allowedShellsSettings.AllowedToAccept(compChangeableProjectile.LoadedShell))
                        {
                            ExtractShell();
                        }
                    }
                    if (forcedTarget.IsValid && !CanSetForcedTarget)
                    {
                        ResetForcedTarget();
                    }
                    if (!CanToggleHoldFire)
                    {
                        holdFire = false;
                    }
                    if (forcedTarget.ThingDestroyed)
                    {
                        ResetForcedTarget();
                    }
                    if ((powerComp == null || powerComp.PowerOn) && (mannableComp == null || mannableComp.MannedNow) && base.Spawned)
                    {
                        GunCompEq.verbTracker.VerbsTick();
                        if (!stunner.Stunned && AttackVerb.state != VerbState.Bursting)
                        {
                            if (WarmingUp)
                            {
                                burstWarmupTicksLeft--;
                                if (burstWarmupTicksLeft == 0)
                                {
                                    BeginBurst();
                                }
                            }
                            else
                            {
                                if (burstCooldownTicksLeft > 0)
                                {
                                    burstCooldownTicksLeft--;
                                }
                                if (burstCooldownTicksLeft <= 0 && this.IsHashIntervalTick(10))
                                {
                                    TryStartShootSomething(canBeginBurstImmediately: true);
                                }
                            }
                            top.TurretTopTick();
                        }
                    }
                    else
                    {
                        ResetCurrentTarget();
                    }
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    Vector3 rndPos = this.DrawPos;
                    rndPos.x += Rand.Range(-.5f, .5f);
                    rndPos.z += Rand.Range(-.5f, .5f);
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SparkFlash"), rndPos, this.Map, Rand.Range(.6f, .8f), .1f, .05f, .05f, 0, 0, 0, Rand.Range(0, 360));
                    MoteMaker.ThrowSmoke(rndPos, this.Map, Rand.Range(.8f, 1.2f));
                    rndPos    = this.DrawPos;
                    rndPos.x += Rand.Range(-.5f, .5f);
                    rndPos.z += Rand.Range(-.5f, .5f);
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ElectricalSpark"), rndPos, this.Map, Rand.Range(.4f, .7f), .2f, .05f, .1f, 0, 0, 0, Rand.Range(0, 360));
                }
                GenExplosion.DoExplosion(this.Position, this.Map, 1f, DamageDefOf.EMP, this, 0, 0, SoundDefOf.Crunch, null, null, this, null, 0, 0, false, null, 0, 0, 0, false);
                this.Destroy(DestroyMode.Vanish);
            }
        }
예제 #22
0
        private void burrowTurret()
        {
            SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(parent.Position, parent.Map, false));
            Map     map  = parent.Map;
            String  name = parent.def.defName;
            IntVec3 loc  = parent.Position;
            float   HPp  = (float)parent.HitPoints / (float)parent.MaxHitPoints;
            float   FUEL = 0;

            if (refuelableComp != null)
            {
                FUEL = refuelableComp.Fuel;
            }
            bool     needStuff = true;
            ThingDef thatstuff = parent.Stuff;

            if (thatstuff == null)
            {
                thatstuff = ThingDefOf.Steel;
                needStuff = false;
            }

            if (parent.def.size.x > 3)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_XXBig"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
            }
            else if (parent.def.size.x > 2)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_XBig"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
            }
            else if (parent.def.Size.x > 1)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_Big"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
            }
            else
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);
                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
            }
        }
        public override void Resolve(ResolveParams rp)
        {
            Map     map  = BaseGen.globalSettings.map;
            IntVec3 root = IntVec3Utility.ToIntVec3(rp.rect.CenterVector3);
            IntVec3 motherVec;

            CellFinder.TryFindRandomCellNear(root, map, 3, (IntVec3 x) => x.Standable(map) && map.fertilityGrid.FertilityAt(x) > ThingDefOf.Plant_Ambrosia.plant.fertilityMin, out motherVec);
            float eventPoints = StorytellerUtility.DefaultThreatPointsNow(Find.World) * 0.6f;

            if (eventPoints > 4000f)
            {
                eventPoints *= 0.9f;
                if (eventPoints > 7000f)
                {
                    eventPoints = 7000f;
                }
            }
            if (eventPoints < 400f)
            {
                eventPoints = 400f;
            }

            foreach (IntVec3 vec in rp.rect)
            {
                if (map.terrainGrid.TerrainAt(vec).fertility < 0.7f)
                {
                    if (Rand.Chance(0.5f))
                    {
                        map.terrainGrid.SetTerrain(vec, TerrainDefOf.Gravel);
                    }
                }
            }

            //spawn mother plant
            MotherAmbrosiaLGE motherAmbrosia = (MotherAmbrosiaLGE)GenSpawn.Spawn(DefsOfLGE.Plant_MotherAmbrosiaLGE, motherVec, map, WipeMode.Vanish);

            motherAmbrosia.Growth = Rand.Range(0.9f, 0.98f);

            PawnKindDef animalKind;

            (from k in map.Biome.AllWildAnimals
             where Find.World.tileTemperatures.SeasonAndOutdoorTemperatureAcceptableFor(map.Tile, k.race)
             select k).TryRandomElement(out animalKind);
            if (animalKind == null)
            {
                animalKind = ThingDefOfVanilla.Warg;
            }
            motherAmbrosia.SpawnAnimals(animalKind, eventPoints);


            int randomInRange = (int)(eventPoints / 80);//SymbolResolver_AmbrosiaAnimalsLGE.CountRange.RandomInRange;

            for (int i = 0; i < randomInRange; i++)
            {
                IntVec3 intVec;
                if (!CellFinder.TryRandomClosewalkCellNear(motherVec, map, SpawnRadius, out intVec, (IntVec3 x) => this.CanSpawnAt(x, map)))
                {
                    break;
                }
                Plant plant = intVec.GetPlant(map);
                if (plant != null)
                {
                    plant.Destroy(DestroyMode.Vanish);
                }
                Plant ambrosia = (Plant)GenSpawn.Spawn(ThingDefOf.Plant_Ambrosia, intVec, map, WipeMode.Vanish);
                ambrosia.Growth = Rand.Range(0.6f, 0.95f);
            }

            //Spawn ambrosia reward
            ResolveParams resolveParamsReward = rp;

            resolveParamsReward.rect = CellRect.CenteredOn(motherVec, SpawnRadius - 2);
            resolveParamsReward.stockpileConcreteContents = RewardGeneratorUtilityLGE.GenerateAmbrosia((int)(eventPoints / 150f));
            BaseGen.symbolStack.Push("spawnStockpileLGE", resolveParamsReward);
        }
예제 #24
0
        public void FireCannonBroadside(CannonHandler cannon, int i)
        {
            if (cannon is null)
            {
                return;
            }
            float initialOffset;
            float offset;
            bool  mirrored = false;

            if (this.Pawn.Rotation == Rot4.South || this.Pawn.Rotation == Rot4.West)
            {
                mirrored = true;
            }
            if (cannon.splitCannonGroups)
            {
                int   group       = cannon.CannonGroup(i);
                float groupOffset = cannon.centerPoints[group];
                initialOffset = ((cannon.spacing * (cannon.cannonsPerPoint[group] - 1)) / 2f) + groupOffset; // s(n-1) / 2
                offset        = (cannon.spacing * i - initialOffset) * (mirrored ? -1 : 1);                  //s*i - x
            }
            else
            {
                initialOffset = ((cannon.spacing * (cannon.numberCannons - 1)) / 2f) + cannon.offset; // s(n-1) / 2
                offset        = (cannon.spacing * i - initialOffset) * (mirrored ? -1 : 1);           //s*i - x
            }

            float projectileOffset = (this.Pawn.def.size.x / 2f) + cannon.projectileOffset; // (s/2)

            SPTuples.SPTuple2 <float, float> angleOffset = this.AngleRotationProjectileOffset(offset, projectileOffset);
            ThingDef projectile = cannon.projectile;
            IntVec3  targetCell = IntVec3.Invalid;
            Vector3  launchCell = this.Pawn.DrawPos;

            switch (cannon.weaponLocation)
            {
            case WeaponLocation.Port:
                if (this.CompShip.Angle == 0)
                {
                    if (this.Pawn.Rotation == Rot4.North)
                    {
                        launchCell.x -= projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.East)
                    {
                        launchCell.x += offset;
                        launchCell.z += projectileOffset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.South)
                    {
                        launchCell.x += projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.West)
                    {
                        launchCell.x += offset;
                        launchCell.z -= projectileOffset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z -= (int)this.Range;
                    }
                }
                else
                {
                    if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == 45)
                    {
                        launchCell.x += angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == -45)
                    {
                        launchCell.x -= angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                }
                break;

            case WeaponLocation.Starboard:
                if (this.CompShip.Angle == 0)
                {
                    if (this.Pawn.Rotation == Rot4.North)
                    {
                        launchCell.x += projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.East)
                    {
                        launchCell.z -= projectileOffset;
                        launchCell.x += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.South)
                    {
                        launchCell.x -= projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.West)
                    {
                        launchCell.z += projectileOffset;
                        launchCell.x += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z += (int)this.Range;
                    }
                }
                else
                {
                    if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.Second;
                        launchCell.z += angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.Second;
                        launchCell.z -= angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.Second;
                        launchCell.z -= angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.Second;
                        launchCell.z += angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                }
                break;

            case WeaponLocation.Turret:
                throw new NotImplementedException();
            }
            LocalTargetInfo target = new LocalTargetInfo(targetCell);
            ShootLine       shootLine;
            bool            flag = TryFindShootLineFromTo(this.Pawn.Position, target, out shootLine);

            //FIX FOR MULTIPLAYER
            IntVec3    c           = target.Cell + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(cannon.spreadRadius * (this.Range / cannon.maxRange)))];
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, this.Pawn.Position, this.Pawn.Map, WipeMode.Vanish);

            if (cannon.cannonSound is null)
            {
                SoundDefOf_Ships.Explosion_PirateCannon.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            else
            {
                cannon.cannonSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            if (cannon.moteCannon != null)
            {
                MoteMaker.MakeStaticMote(launchCell, this.Pawn.Map, cannon.moteCannon, 1f);
            }
            projectile2.Launch(this.Pawn, launchCell, c, target, cannon.hitFlags);
        }
예제 #25
0
        public static BomberSkyfaller SpawnSkyfaller(ThingDef skyfaller, IEnumerable <Thing> things, IntVec3 pos, Map map)
        {
            BomberSkyfaller thing = BomberSkyfallerMaker.MakeSkyfaller(skyfaller, things);

            return((BomberSkyfaller)GenSpawn.Spawn(thing, pos, map, WipeMode.Vanish));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            const float baseFishingDuration    = 2400f;
            const float skillGainPerTick       = 0.15f;
            const float catchSuccessRateInZone = 0.70f;

            int fishingDuration = (int)baseFishingDuration;

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

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

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

            Toil faceWaterToil = new Toil()
            {
                initAction = () =>
                {
                    // Compute pawn rotation during fishing.
                    foreach (IntVec3 offset in GenAdj.CardinalDirections.InRandomOrder())
                    {
                        IntVec3      adjacentCell = this.TargetLocA + offset;
                        Zone_Fishing fishingZone  = adjacentCell.GetZone(this.Map) as Zone_Fishing;
                        if ((fishingZone != null) &&
                            fishingZone.fishingSpots.Contains(this.TargetLocA))
                        {
                            this.cardinalDir = offset;
                            this.pawn.CurJob.SetTarget(TargetIndex.B, adjacentCell);
                            this.rotateToFace = TargetIndex.B;
                            break;
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            };

            yield return(faceWaterToil);

            yield return(Toils_Goto.GotoCell(this.TargetLocA, this.pathEndMode).FailOn(FishingForbiddenOrInvalidSpot));

            Toil fishToil = new Toil()
            {
                tickAction = () =>
                {
                    this.pawn.skills.Learn(SkillDefOf.Shooting, skillGainPerTick);

                    // Spawn mote or maintain it.
                    if (this.fishingRodMote.DestroyedOrNull())
                    {
                        IntVec3  motePosition = this.TargetB.Cell;
                        ThingDef moteDef      = null;
                        if (cardinalDir == IntVec3.North)
                        {
                            moteDef = Util_FishIndustry.MoteFishingRodNorthDef;
                        }
                        else if (cardinalDir == IntVec3.East)
                        {
                            moteDef = Util_FishIndustry.MoteFishingRodEastDef;
                        }
                        else if (cardinalDir == IntVec3.South)
                        {
                            moteDef = Util_FishIndustry.MoteFishingRodSouthDef;
                        }
                        else
                        {
                            moteDef = Util_FishIndustry.MoteFishingRodWestDef;
                        }
                        this.fishingRodMote = (Mote)ThingMaker.MakeThing(moteDef, null);
                        this.fishingRodMote.exactPosition = motePosition.ToVector3Shifted();
                        this.fishingRodMote.Scale         = 1f;
                        GenSpawn.Spawn(this.fishingRodMote, motePosition, this.Map);
                    }
                    else
                    {
                        this.fishingRodMote.Maintain();
                    }
                },
                defaultDuration     = fishingDuration,
                defaultCompleteMode = ToilCompleteMode.Delay
            };

            yield return(fishToil.WithProgressBarToilDelay(this.fishPositionIndex, true).FailOn(FishingForbiddenOrInvalidSpot));

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

                    bool catchIsSuccessful = (Rand.Value <= catchSuccessRateInZone);
                    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) &&
                        Util_FishIndustry.GetFishSpeciesList(this.Map.Biome).Contains(Util_FishIndustry.TailteethPawnKindDef as PawnKindDef_FishSpecies))
                    {
                        // Get hurt by a tailteeth.
                        this.pawn.TakeDamage(new DamageInfo(DamageDefOf.Bite, Rand.Range(5, 12)));
                        Messages.Message(this.pawn.Name.ToStringShort + "FishIndustry.FisherBitten".Translate(), this.pawn, MessageTypeDefOf.NegativeHealthEvent);
                        this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                        return;
                    }
                    else if (catchSelectorValue < 0.04)
                    {
                        // Find oysters.
                        fishingCatch            = GenSpawn.Spawn(Util_FishIndustry.OysterDef, this.pawn.Position, this.Map);
                        fishingCatch.stackCount = Rand.RangeInclusive(5, 27);
                    }
                    else
                    {
                        // Catch a fish.
                        bool fishSpotIsOcean = (this.Map.terrainGrid.TerrainAt(this.TargetLocA) == TerrainDefOf.WaterOceanShallow) ||
                                               (this.Map.terrainGrid.TerrainAt(this.TargetLocA) == TerrainDefOf.WaterOceanDeep);
                        bool fishSpotIsMarshy = (this.Map.terrainGrid.TerrainAt(this.TargetLocA) == 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)
                        {
                            Zone_Fishing fishingZone = this.TargetB.Cell.GetZone(this.Map) as Zone_Fishing;
                            if ((fishingZone != null) &&
                                fishingZone.fishingSpots.Contains(this.TargetLocA))
                            {
                                fishingZone.fishingSpots.Remove(this.TargetLocA);
                            }
                        }
                    }

                    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));
        }
예제 #27
0
        public override void PassingParameters(ResolveParams rp)
        {
            string defChair = "DiningChair";
            string defLamp  = "Jecrell_GasLamp";

            ThingDef lampDef      = Cthulhu.Utility.IsIndustrialAgeLoaded() ? ThingDef.Named(defLamp) : ThingDefOf.TorchLamp;
            ThingDef lampStuffDef = Cthulhu.Utility.IsIndustrialAgeLoaded() ? ThingDefOf.Steel : null;

            Map      map      = BaseGen.globalSettings.map;
            bool     @bool    = Rand.Bool;
            bool     hasLamp  = false;
            ThingDef thingDef = ThingDefOf.SleepingSpot;
            ThingDef chairDef = ThingDef.Named(defChair);

            foreach (IntVec3 current in rp.rect)
            {
                if (@bool)
                {
                    if (current.x % 3 != 0 || current.z % 3 != 0)
                    {
                        continue;
                    }
                }
                else if (current.x % 3 != 0 || current.z % 3 != 0)
                {
                    continue;
                }
                Rot4 rot = (!@bool) ? Rot4.South : Rot4.West;
                if (!GenSpawn.WouldWipeAnythingWith(current, rot, thingDef, map, (Thing x) => x.def.category == ThingCategory.Building))
                {
                    bool flag = false;
                    foreach (IntVec3 current2 in GenAdj.CellsOccupiedBy(current, rot, thingDef.Size))
                    {
                        if (BaseGenUtility.AnyDoorAdjacentCardinalTo(current2, map))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        ///Bed
                        ThingDef stuff = null;
                        if (thingDef.MadeFromStuff)
                        {
                            stuff = ThingDefOf.WoodLog;
                        }
                        Thing thing = ThingMaker.MakeThing(thingDef, stuff);
                        thing.SetFaction(rp.faction, null);

                        GenSpawn.Spawn(thing, current, map, rot);

                        if (thing != null)
                        {
                            if (thing.Spawned && thing.Position.InBounds(map))
                            {
                                CellRect thingRect = thing.OccupiedRect();
                                if (thingRect != null)
                                {
                                    thingRect = thingRect.ExpandedBy(1);
                                    List <IntVec3> possibleCells = new List <IntVec3>();
                                    possibleCells.AddRange(thingRect.GetEdgeCells(Rot4.North));
                                    possibleCells.AddRange(thingRect.GetEdgeCells(Rot4.South));
                                    possibleCells.AddRange(thingRect.GetEdgeCells(Rot4.East));
                                    possibleCells.AddRange(thingRect.GetEdgeCells(Rot4.West));
                                    possibleCells.Remove(Cthulhu.Utility.GetCornerPos(thingRect, 0));
                                    possibleCells.Remove(Cthulhu.Utility.GetCornerPos(thingRect, 1));
                                    possibleCells.Remove(Cthulhu.Utility.GetCornerPos(thingRect, 2));
                                    possibleCells.Remove(Cthulhu.Utility.GetCornerPos(thingRect, 3));

                                    IntVec3 spawnPos = IntVec3.Invalid;
                                    spawnPos = possibleCells.InRandomOrder <IntVec3>().FirstOrDefault((IntVec3 x) => x.InBounds(map) && x.Walkable(map));
                                    if (spawnPos != null)
                                    {
                                        possibleCells.Remove(spawnPos);
                                        Thing thing2 = ThingMaker.MakeThing(chairDef, ThingDefOf.WoodLog);
                                        thing2.SetFaction(rp.faction, null);
                                        GenSpawn.Spawn(thing2, spawnPos, map, rot.Opposite);
                                    }
                                    if (!hasLamp)
                                    {
                                        hasLamp  = true;
                                        spawnPos = possibleCells.FirstOrDefault((IntVec3 x) => x.InBounds(map) && x.Walkable(map));
                                        if (spawnPos != null)
                                        {
                                            possibleCells.Remove(spawnPos);
                                            Thing thing3 = ThingMaker.MakeThing(lampDef, lampStuffDef);
                                            thing3.SetFaction(rp.faction, null);
                                            GenSpawn.Spawn(thing3, spawnPos, map, rot.Opposite);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //if (!Cthulhu.Utility.IsCosmicHorrorsLoaded())
            //{
            PawnGroupKindDef    groupKind           = rp.pawnGroupKindDef ?? PawnGroupKindDefOf.Normal;
            PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms()
            {
                faction = (from x in Find.FactionManager.AllFactions
                           where x.HostileTo(rp.faction) && x.def.pawnGroupMakers != null &&
                           x.def.pawnGroupMakers.Count > 0 &&
                           x.def.humanlikeFaction &&
                           IsCosmicHorrorFaction(x) == false &&
                           (x.def.pawnGroupMakers.FirstOrDefault((PawnGroupMaker y) => y.kindDef == PawnGroupKindDefOf.Normal) != null)
                           select x).RandomElement <Faction>(),
                tile   = map.Tile,
                points = 5000,
                generateFightersOnly = false,
            };
            int num = 0;

            foreach (Pawn current in PawnGroupMakerUtility.GeneratePawns(groupKind, pawnGroupMakerParms, true))
            {
                num++;
                ResolveParams resolveParams = rp;
                resolveParams.singlePawnToSpawn = current;
                BaseGen.symbolStack.Push("pawn", resolveParams);
                if (num == 3)
                {
                    break;
                }
            }
            //}
            //else
            //{
            //    Faction tempFaction = Find.FactionManager.AllFactions.InRandomOrder<Faction>().FirstOrDefault((Faction z) => IsCosmicHorrorFaction(z));
            //    PawnGroupKindDef groupKind = rp.pawnGroupKindDef ?? PawnGroupKindDefOf.Normal;
            //    PawnGroupMakerParms pawnGroupMakerParms = new PawnGroupMakerParms()
            //    {
            //        faction = tempFaction,
            //        map = map,
            //        points = 5000,
            //        generateFightersOnly = false,
            //        generateMeleeOnly = false
            //    };
            //    int num = 0;
            //    foreach (Pawn current in PawnGroupMakerUtility.GeneratePawns(groupKind, pawnGroupMakerParms, true))
            //    {
            //        num++;
            //        ResolveParams resolveParams = rp;
            //        resolveParams.singlePawnToSpawn = current;
            //        resolveParams.singlePawnLord = null;
            //        BaseGen.symbolStack.Push("pawn", resolveParams);
            //        if (num == 3) break;
            //    }
            //}

            //List<int> corners = new List<int>() { 0, 1, 2, 3 };
            //foreach (int corner in corners.InRandomOrder<int>())
            //{
            //    IntVec3 loc = Cthulhu.Utility.GetCornerPos(rp.rect.ContractedBy(1), corner);
            //    if (!GenSpawn.WouldWipeAnythingWith(loc, Rot4.South, lampDef, map, (Thing x) => x.def.category == ThingCategory.Building))
            //    {
            //        ThingDef singleThingDef3 = (Cthulhu.Utility.IsIndustrialAgeLoaded()) ? lampDef : ThingDefOf.TorchLamp;
            //        Thing thing3 = ThingMaker.MakeThing(singleThingDef3, ThingDefOf.Steel);
            //        GenSpawn.Spawn(thing3, loc, map);
            //        break;
            //    }
            //}
        }
예제 #28
0
        private void burrowTurret()
        {
            SoundDefOf.DropPod_Open.PlayOneShot(new TargetInfo(parent.Position, parent.Map, false));
            Map     map  = parent.Map;
            String  name = parent.def.defName;
            IntVec3 loc  = parent.Position;
            float   HPp  = (float)parent.HitPoints / (float)parent.MaxHitPoints;
            float   FUEL = 0;

            if (refuelableComp != null)
            {
                FUEL = refuelableComp.Fuel;
            }
            bool     needStuff = true;
            ThingDef thatstuff = parent.Stuff;

            if (thatstuff == null)
            {
                thatstuff = ThingDefOf.Steel;
                needStuff = false;
            }



            if (this.Props.Customhatch != "")
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named(this.Props.Customhatch), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
                try
                {
                    ((Action)(() =>
                    {
                        if (ModCompatibilityCheck.TurretExtensionsIsActive)
                        {
                            TurretExtensions.CompUpgradable comp = this.parent.GetComp <TurretExtensions.CompUpgradable>();
                            if (comp != null)
                            {
                                if (comp.upgraded)
                                {
                                    ((GTM_Hatch)thing).upgradedbyturretextensions = true;

                                    if (comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints) != 1f)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Factor = comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints);
                                    }
                                    if (comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints) > 0)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Offset = (int)(comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                    }
                                }
                            }
                        }
                    }))();
                }
                catch (TypeLoadException ex)
                {
                    Log.Message("error in burrowTurret XP");
                }
            }
            else if (parent.def.size.x > 3)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_XXBig"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                if (this.Props.CustomxPath != "")
                {
                    ((GTM_Hatch)thing).customxpath = this.Props.CustomxPath;
                }
                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
                try
                {
                    ((Action)(() =>
                    {
                        if (ModCompatibilityCheck.TurretExtensionsIsActive)
                        {
                            TurretExtensions.CompUpgradable comp = this.parent.GetComp <TurretExtensions.CompUpgradable>();
                            if (comp != null)
                            {
                                if (comp.upgraded)
                                {
                                    ((GTM_Hatch)thing).upgradedbyturretextensions = true;

                                    if (comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints) != 1f)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Factor = comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints);
                                    }
                                    if (comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints) > 0)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Offset = (int)(comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                    }
                                }
                            }
                        }
                    }))();
                }
                catch (TypeLoadException ex)
                {
                    Log.Message("error in burrowTurret XP");
                }
            }
            else if (parent.def.size.x > 2)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_XBig"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                if (this.Props.CustomxPath != "")
                {
                    ((GTM_Hatch)thing).customxpath = this.Props.CustomxPath;
                }
                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
                try
                {
                    ((Action)(() =>
                    {
                        if (ModCompatibilityCheck.TurretExtensionsIsActive)
                        {
                            TurretExtensions.CompUpgradable comp = this.parent.GetComp <TurretExtensions.CompUpgradable>();
                            if (comp != null)
                            {
                                if (comp.upgraded)
                                {
                                    ((GTM_Hatch)thing).upgradedbyturretextensions = true;

                                    if (comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints) != 1f)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Factor = comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints);
                                    }
                                    if (comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints) > 0)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Offset = (int)(comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                    }
                                }
                            }
                        }
                    }))();
                }
                catch (TypeLoadException ex)
                {
                    Log.Message("error in burrowTurret XP");
                }
            }
            else if (parent.def.Size.x > 1)
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch_Big"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                if (this.Props.CustomxPath != "")
                {
                    ((GTM_Hatch)thing).customxpath = this.Props.CustomxPath;
                }
                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
                try
                {
                    ((Action)(() =>
                    {
                        if (ModCompatibilityCheck.TurretExtensionsIsActive)
                        {
                            TurretExtensions.CompUpgradable comp = this.parent.GetComp <TurretExtensions.CompUpgradable>();
                            if (comp != null)
                            {
                                if (comp.upgraded)
                                {
                                    ((GTM_Hatch)thing).upgradedbyturretextensions = true;

                                    if (comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints) != 1f)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Factor = comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints);
                                    }
                                    if (comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints) > 0)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Offset = (int)(comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                    }
                                }
                            }
                        }
                    }))();
                }
                catch (TypeLoadException ex)
                {
                    Log.Message("error in burrowTurret XP");
                }
            }
            else
            {
                Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(ThingDef.Named("GTM_Hatch"), thatstuff), loc, map, WipeMode.Vanish);
                thing.SetFaction(Faction.OfPlayer, null);
                thing.HitPoints = (int)Math.Ceiling(thing.MaxHitPoints * HPp);

                if (this.Props.CustomxPath != "")
                {
                    ((GTM_Hatch)thing).customxpath = this.Props.CustomxPath;
                }
                ((GTM_Hatch)thing).insideman = name;
                if (refuelableComp != null)
                {
                    ((GTM_Hatch)thing).insidefuel = FUEL;
                }
                ((GTM_Hatch)thing).insideStuff = needStuff;
                try
                {
                    ((Action)(() =>
                    {
                        if (ModCompatibilityCheck.TurretExtensionsIsActive)
                        {
                            TurretExtensions.CompUpgradable comp = this.parent.GetComp <TurretExtensions.CompUpgradable>();
                            if (comp != null)
                            {
                                if (comp.upgraded)
                                {
                                    ((GTM_Hatch)thing).upgradedbyturretextensions = true;

                                    if (comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints) != 1f)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Factor = comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints);
                                    }
                                    if (comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints) > 0)
                                    {
                                        //Log.Message("GetStatFactorFromList : " + comp.Props.statFactors.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                        ((GTM_Hatch)thing).TE_HP_Offset = (int)(comp.Props.statOffsets.GetStatFactorFromList(StatDefOf.MaxHitPoints));
                                    }
                                }
                            }
                        }
                    }))();
                }
                catch (TypeLoadException ex)
                {
                    Log.Message("error in burrowTurret XP");
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def = this.def;

            if (!this.initialized)
            {
                caster = this.launcher as Pawn;
                CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();
                pwrVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Encase.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Encase_pwr").level;
                verVal = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Encase.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Encase_ver").level;
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless))
                {
                    pwrVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr").level;
                    verVal = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver").level;
                }
                if (settingsRef.AIHardMode && !caster.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }

                if (pwrVal == 3)
                {
                    spawnDef = ThingDef.Named("Granite"); //900
                }
                else if (pwrVal == 2)
                {
                    spawnDef = ThingDef.Named("Limestone"); //700
                }
                else if (pwrVal == 1)
                {
                    spawnDef = ThingDef.Named("Slate"); //500
                }
                else
                {
                    spawnDef = ThingDef.Named("Sandstone"); //400
                }
                IEnumerable <IntVec3> outerCells = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius + 1f, true);
                IEnumerable <IntVec3> innerCells = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius - 1f, true);
                this.wallPositions = new List <IntVec3>();
                this.wallPositions.Clear();
                this.terrainList = new List <TerrainDef>();
                this.terrainList.Clear();
                this.wallPositions = outerCells.Except(innerCells).ToList();
                for (int t = 0; t < wallPositions.Count(); t++)
                {
                    var    wallPosition = wallPositions[t];
                    Encase temp         = new Encase(wallPosition, wallPosition.GetTerrain(caster.Map));
                    wall.Add(temp);
                    this.terrainList.Add(wallPosition.GetTerrain(caster.Map));
                }
                float magnitude = (base.Position.ToVector3Shifted() - Find.Camera.transform.position).magnitude;
                Find.CameraDriver.shaker.DoShake(10 / magnitude);
                //for (int k = 0; k < wallPositions.Count(); k++)
                //{
                for (int k = 0; k < wall.Count; k++)
                {
                    var wallElement = wall[k];
                    if (wallElement.position.IsValid && wallElement.position.InBounds(caster.Map) && !wallElement.position.Fogged(caster.Map) && !wallElement.position.InNoZoneEdgeArea(caster.Map))
                    //if (wallPositions[k].IsValid && wallPositions[k].InBounds(caster.Map) && !wallPositions[k].Fogged(caster.Map) && !wallPositions[k].InNoZoneEdgeArea(caster.Map))
                    {
                        if (wallElement.terrain.defName == "Marsh" || wallElement.terrain.defName == "WaterShallow" || wallElement.terrain.defName == "WaterMovingShallow" || wallElement.terrain.defName == "WaterOceanShallow" || wallElement.terrain.defName == "WaterMovingChestDeep")
                        {
                            MoteSplash moteSplash = (MoteSplash)ThingMaker.MakeThing(ThingDefOf.Mote_WaterSplash, null);
                            moteSplash.Initialize(wallPositions[k].ToVector3Shifted(), 8f, 1f);
                            GenSpawn.Spawn(moteSplash, wallPositions[k], map, WipeMode.Vanish);
                        }
                        List <Thing> cellList = new List <Thing>();
                        bool         hasWall  = false;
                        try
                        {
                            cellList = wallElement.position.GetThingList(caster.Map);
                            for (int i = 0; i < cellList.Count; i++)
                            {
                                var cell = cellList[i];
                                if (cell.def.designationCategory == DesignationCategoryDefOf.Structure || cell.def.altitudeLayer == AltitudeLayer.Building || cell.def.altitudeLayer == AltitudeLayer.Item || cell.def.altitudeLayer == AltitudeLayer.ItemImportant)
                                {
                                    if (!cell.def.EverHaulable)
                                    {
                                        hasWall = true;
                                        //this.terrainList.Remove(this.terrainList[k]);
                                        //this.wallPositions.Remove(this.wallPositions[k]); //don't do anything if a building/wall already exists
                                        wall.Remove(wallElement);
                                        break;
                                    }
                                }
                            }
                        }
                        catch //remove square if it threw an error trying to get item list at this location
                        {
                            hasWall = true;
                            //this.terrainList.Remove(this.terrainList[k]);
                            //this.wallPositions.Remove(this.wallPositions[k]);
                            wall.Remove(wallElement);
                            continue;
                        }

                        if (!hasWall)
                        {
                            bool spawnWall = true;
                            for (int i = 0; i < cellList.Count; i++)
                            {
                                var cell = cellList[i];
                                if (!(cell is Pawn)) //
                                {
                                    if (cell.def.defName.Contains("Mote"))
                                    {
                                        //Log.Message("avoided storing " + cell.def.defName);
                                    }
                                    else if (cell.def.defName == "Fire" || cell.def.defName == "Spark")
                                    {
                                        cell.Destroy(DestroyMode.Vanish);
                                    }
                                    else
                                    {
                                        this.despawnedThingList.Add(cell);
                                        cell.DeSpawn();
                                    }
                                }
                            }
                            if (spawnWall)
                            {
                                AbilityUser.SpawnThings tempSpawn = new SpawnThings()
                                {
                                    def        = spawnDef,
                                    spawnCount = 1
                                };
                                try
                                {
                                    SingleSpawnLoop(tempSpawn, wallElement.position, caster.Map);
                                    for (int m = 0; m < 4; m++)
                                    {
                                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ThickDust"), wallElement.position.ToVector3Shifted(), caster.Map, Rand.Range(.6f, .8f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(1f, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
                                    }
                                }
                                catch
                                {
                                    //dont spawn wall
                                    continue;
                                }
                            }
                        }
                    }
                }
                this.duration    = Mathf.RoundToInt(1800 + (240 * verVal * comp.arcaneDmg));
                this.initialized = true;
                this.wallActive  = true;
            }
            else if (this.initialized && this.wallActive && !(this.age < this.duration))
            {
                for (int j = 0; j < wall.Count(); j++)
                {
                    Building structure = null;
                    structure = this.wall[j].position.GetFirstBuilding(this.Map);
                    if (structure != null)
                    {
                        structure.Destroy();
                        for (int m = 0; m < 4; m++)
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ThickDust"), wall[j].position.ToVector3Shifted(), this.Map, Rand.Range(.4f, .8f), Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), Rand.Range(-20, 20), Rand.Range(1f, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
                        }
                    }
                    structure = null;
                    this.Map.terrainGrid.SetTerrain(wall[j].position, wall[j].terrain);
                }

                for (int i = 0; i < this.despawnedThingList.Count(); i++)
                {
                    GenSpawn.Spawn(this.despawnedThingList[i], this.despawnedThingList[i].Position, this.Map);
                }
                this.wallActive = false;
            }
        }
예제 #30
0
        protected override bool TryCastShot()
        {
            bool result = false;
            bool arg_40_0;

            if (this.currentTarget != null && base.CasterPawn != null)
            {
                IntVec3 arg_29_0 = this.currentTarget.Cell;
                Vector3 vector   = this.currentTarget.CenterVector3;
                arg_40_0 = this.currentTarget.Cell.IsValid;
                arg_41_0 = vector.InBounds(base.CasterPawn.Map);
                arg_42_0 = true; // vector.ToIntVec3().Standable(base.CasterPawn.Map);
            }
            else
            {
                arg_40_0 = false;
            }
            bool flag  = arg_40_0;
            bool flag2 = arg_41_0;
            bool flag3 = arg_42_0;

            if (flag)
            {
                if (flag2 & flag3)
                {
                    Pawn    p    = this.CasterPawn;
                    Map     map  = this.CasterPawn.Map;
                    IntVec3 cell = this.CasterPawn.Position;
                    try
                    {
                        if (this.CasterPawn.IsColonist)
                        {
                            ThingSelectionUtility.SelectNextColonist();
                            this.CasterPawn.DeSpawn();
                            //p.SetPositionDirect(this.currentTarget.Cell);
                            GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                            p.drafter.Drafted = true;
                            ThingSelectionUtility.SelectPreviousColonist();
                        }
                        else
                        {
                            this.CasterPawn.DeSpawn();
                            GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                        }
                    }
                    catch
                    {
                        if (!this.CasterPawn.Spawned)
                        {
                            GenSpawn.Spawn(p, cell, map);
                            Log.Message("Exception occured when trying to blink - recovered pawn at position ability was used from.");
                        }
                    }
                    this.Ability.PostAbilityAttempt();

                    //this.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                    //base.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                    //this.CasterPawn.pather.ResetToCurrentPosition();
                    result = true;
                }
                else
                {
                    Messages.Message("InvalidTargetLocation".Translate(), MessageTypeDefOf.RejectInput);
                }
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            return(result);
        }