Esempio n. 1
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            try
            {
                GenExplosion.DoExplosion(base.Position, map, this.def.projectile.explosionRadius, DamageDefOf.Bomb, this.launcher, this.def.projectile.GetDamageAmount(1, null), 2, SoundDefOf.Crunch, def, this.equipmentDef, null, null, 0f, 1, false, null, 0f, 1, 0.1f, false);
            }
            catch
            {
                //don't care
            }
            CellRect cellRect = CellRect.CenteredOn(base.Position, 2);

            cellRect.ClipInsideMap(map);
            Pawn pawn = this.launcher as Pawn;

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    IntVec3 randomCell = cellRect.RandomCell;
                    if (randomCell.IsValid && randomCell.InBounds(map))
                    {
                        this.FireExplosion(randomCell, map, 1f);
                    }
                }
                catch
                {
                    //don't care
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            IntVec3   position         = base.Position;
            Map       map2             = map;
            float     explosionRadius  = this.def.projectile.explosionRadius;
            DamageDef bomb             = DamageDefOf.Bomb;
            Thing     launcher         = this.launcher;
            int       damageAmount     = base.DamageAmount;
            float     armorPenetration = base.ArmorPenetration;
            ThingDef  equipmentDef     = this.equipmentDef;

            GenExplosion.DoExplosion(position, map2, explosionRadius, bomb, launcher, damageAmount, armorPenetration, null, equipmentDef, this.def, this.intendedTarget.Thing, null, 0f, 1, false, null, 0f, 1, 0f, false);
            CellRect cellRect = CellRect.CenteredOn(base.Position, 5);

            cellRect.ClipInsideMap(map);
            for (int i = 0; i < 3; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                this.DoFireExplosion(randomCell, map, 3.9f);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Ensures the cellrect inhabited by the vehicle contains no Things that will block pathing and movement.
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="c"></param>
        public static bool CellRectStandable(this VehiclePawn vehicle, Map map, IntVec3?c = null, Rot4?rot = null)
        {
            IntVec3 loc        = c ?? vehicle.Position;
            IntVec2 dimensions = vehicle.VehicleDef.Size;

            if (rot?.IsHorizontal ?? false)
            {
                int x = dimensions.x;
                dimensions.x = dimensions.z;
                dimensions.z = x;
            }
            foreach (IntVec3 cell in CellRect.CenteredOn(loc, dimensions.x, dimensions.z))
            {
                if (vehicle.IsBoat() && !GenGridVehicles.Standable(cell, map))
                {
                    return(false);
                }
                else if (!GenGrid.Standable(cell, map))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 4
0
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map, GenStepParams parms)
        {
            int      nextSignalTagID = Find.UniqueIDsManager.GetNextSignalTagID();
            string   signalTag       = "ambushActivated-" + nextSignalTagID;
            CellRect rect;

            if (root.IsValid)
            {
                rect = CellRect.CenteredOn(root, 17);
            }
            else
            {
                rect = rectToDefend.ExpandedBy(12);
            }
            SignalAction_Ambush signalAction_Ambush = this.MakeAmbushSignalAction(rectToDefend, root, parms);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map, WipeMode.Vanish);
            RectTrigger rectTrigger = this.MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map, WipeMode.Vanish);
        }
Esempio n. 5
0
        public static bool TryFindRandomCellNearWith(IntVec3 near, Predicate <IntVec3> validator, Map map, out IntVec3 result, int startingSearchRadius = 5, int maxSearchRadius = 2147483647)
        {
            int      num      = startingSearchRadius;
            CellRect cellRect = CellRect.CenteredOn(near, num);

            cellRect.ClipInsideMap(map);
            int     num2 = 0;
            IntVec3 randomCell;

            while (true)
            {
                num2++;
                if (num2 > 30)
                {
                    if (num >= maxSearchRadius || (num > map.Size.x * 2 && num > map.Size.z * 2))
                    {
                        break;
                    }
                    num      = Mathf.Min((int)((float)num * 1.5f), maxSearchRadius);
                    cellRect = CellRect.CenteredOn(near, num);
                    cellRect.ClipInsideMap(map);
                    num2 = 0;
                }
                randomCell = cellRect.RandomCell;
                if (validator(randomCell))
                {
                    goto IL_9B;
                }
            }
            result = near;
            return(false);

IL_9B:
            result = randomCell;
            return(true);
        }
        public void SearchForTargets(IntVec3 center, float radius)
        {
            Pawn target = null;

            if (faction == null)
            {
                faction = Faction.OfPlayer;
            }
            target = TM_Calc.FindNearbyEnemy(center, this.Map, this.faction, radius, 0f);
            if (target != null)
            {
                CellRect cellRect = CellRect.CenteredOn(target.Position, 2);
                cellRect.ClipInsideMap(base.Map);
                DrawStrike(center, target.Position.ToVector3());
                for (int k = 0; k < Rand.Range(1, 5); k++)
                {
                    IntVec3 randomCell = cellRect.RandomCell;
                    GenExplosion.DoExplosion(randomCell, base.Map, Rand.Range(.4f, .8f), TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(4, 6)), 0, SoundDefOf.Thunder_OnMap, null, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                }
                GenExplosion.DoExplosion(target.Position, base.Map, 1f, TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(5, 9) * this.arcaneDmg), 0, SoundDefOf.Thunder_OffMap, null, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                this.lastStrike = this.age;
            }
            DrawStrikeFading();
        }
Esempio n. 7
0
        protected override bool TryCastShot()
        {
            bool flag10 = 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);
            }
            for (int i = 0; i < this.TargetsAoE.Count; i++)
            {
                bool?flag3    = this.TryLaunchProjectile(this.verbProps.defaultProjectile, this.TargetsAoE[i]);
                bool hasValue = flag3.HasValue;
                if (hasValue)
                {
                    bool flag4 = flag3 == true;
                    if (flag4)
                    {
                        flag10 = true;
                    }
                    bool flag5 = flag3 == false;
                    if (flag5)
                    {
                        flag10 = false;
                    }
                }
            }

            CellRect cellRect = CellRect.CenteredOn(this.currentTarget.Cell, 1);
            Map      map      = caster.Map;

            cellRect.ClipInsideMap(map);

            IntVec3      centerCell      = cellRect.CenterCell;
            Thing        summonableThing = new Thing();
            FlyingObject summonablePawn  = new FlyingObject();
            Pawn         victim          = null;
            //dinfo.SetAmount(10);
            //dinfo.SetWeaponHediff(TorannMagicDefOf.TM_GrapplingHook);

            bool pflag = true;

            summonableThing = centerCell.GetFirstPawn(map);
            if (summonableThing == null)
            {
                pflag = false;
                //miss
            }
            else
            {
                pVect   = summonableThing.TrueCenter();
                pVect.x = base.caster.TrueCenter().x;
                pVect.z = base.caster.TrueCenter().z;
                pVect.y = 0f;
                victim  = summonableThing as Pawn;
                if (victim != null)
                {
                    if (!victim.IsColonist && !victim.IsPrisoner && !victim.Faction.HostileTo(this.CasterPawn.Faction) && victim.Faction != null && victim.RaceProps.Humanlike)
                    {
                        Faction faction = victim.Faction;
                        faction.TrySetRelationKind(this.CasterPawn.Faction, FactionRelationKind.Ally, false, null);
                    }
                }
            }
            bool result;
            bool arg_40_0;

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

            if (flag)
            {
                if (summonableThing != null)
                {
                    if (pflag)
                    {
                        DamageInfo dinfo2 = new DamageInfo(DamageDefOf.Stun, 10, 10, -1, this.CasterPawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown, victim);
                        if (!victim.RaceProps.Humanlike || victim.Faction == this.CasterPawn.Faction)
                        {
                            summonablePawn = (FlyingObject)GenSpawn.Spawn(ThingDef.Named("TM_SummonedPawn"), summonableThing.Position, summonableThing.Map);
                            summonablePawn.impactDamage = dinfo2;
                            summonablePawn.Launch(base.caster, new LocalTargetInfo(pVect.ToIntVec3()), summonableThing);
                        }
                        else if (victim.RaceProps.Humanlike && victim.Faction != this.CasterPawn.Faction && Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, victim, true)))
                        {
                            summonablePawn = (FlyingObject)GenSpawn.Spawn(ThingDef.Named("TM_SummonedPawn"), summonableThing.Position, summonableThing.Map);
                            summonablePawn.impactDamage = dinfo2;
                            summonablePawn.Launch(base.caster, new LocalTargetInfo(pVect.ToIntVec3()), summonableThing);
                        }
                        else
                        {
                            MoteMaker.ThrowText(victim.DrawPos, victim.Map, "TM_ResistedSpell".Translate(), -1);
                        }
                    }
                    else
                    {
                        //miss
                    }
                    result = true;
                }
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            //this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            this.PostCastShot(flag10, out flag10);
            return(flag);
        }
        public void SearchForTargets(IntVec3 center, float radius)
        {
            Pawn     curPawnTarg = null;
            Building curBldgTarg = null;
            IntVec3  curCell;
            IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(center, radius, true);

            for (int i = 0; i < targets.Count(); i++)
            {
                curCell = targets.ToArray <IntVec3>()[i];
                if (curCell.InBounds(base.Map) && curCell.IsValid)
                {
                    curPawnTarg = curCell.GetFirstPawn(base.Map);
                    curBldgTarg = curCell.GetFirstBuilding(base.Map);
                }

                if (curPawnTarg != null && curPawnTarg != launcher)
                {
                    bool newTarg = false;
                    if (this.age > this.lastStrike + (this.maxStrikeDelay - (int)Rand.Range(0 + (pwrVal * 20), 40 + (pwrVal * 15))))
                    {
                        if (Rand.Chance(.1f))
                        {
                            newTarg = true;
                        }
                        if (newTarg)
                        {
                            CellRect cellRect = CellRect.CenteredOn(curCell, 2);
                            cellRect.ClipInsideMap(base.Map);
                            DrawStrike(center, curPawnTarg.Position.ToVector3());
                            for (int k = 0; k < Rand.Range(1, 8); k++)
                            {
                                IntVec3 randomCell = cellRect.RandomCell;
                                GenExplosion.DoExplosion(randomCell, base.Map, Rand.Range(.4f, .8f), TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(3 + 3 * pwrVal, 7 + 5 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OnMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                            }
                            GenExplosion.DoExplosion(curPawnTarg.Position, base.Map, 1f, TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(3 + 3 * pwrVal, 7 + 5 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                            this.lastStrike = this.age;
                        }
                    }
                }
                if (curBldgTarg != null)
                {
                    bool newTarg = false;
                    if (this.age > this.lastStrikeBldg + (this.maxStrikeDelayBldg - (int)Rand.Range(0 + (pwrVal * 10), (pwrVal * 15))))
                    {
                        if (Rand.Chance(.1f))
                        {
                            newTarg = true;
                        }
                        if (newTarg)
                        {
                            CellRect cellRect = CellRect.CenteredOn(curCell, 1);
                            cellRect.ClipInsideMap(base.Map);
                            DrawStrike(center, curBldgTarg.Position.ToVector3());
                            for (int k = 0; k < Rand.Range(1, 8); k++)
                            {
                                IntVec3 randomCell = cellRect.RandomCell;
                                GenExplosion.DoExplosion(randomCell, base.Map, Rand.Range(.2f, .6f), TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(3 + 3 * pwrVal, 7 + 5 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                            }
                            GenExplosion.DoExplosion(curBldgTarg.Position, base.Map, 1f, TMDamageDefOf.DamageDefOf.TM_Lightning, this.launcher, Mathf.RoundToInt(Rand.Range(5 + 5 * pwrVal, 10 + 10 * pwrVal) * this.arcaneDmg), SoundDefOf.Thunder_OffMap, null, null, null, 0f, 1, false, null, 0f, 1, 0.1f, true);
                            this.lastStrikeBldg = this.age;
                        }
                    }
                }
                targets.GetEnumerator().MoveNext();
            }
            DrawStrikeFading();
            age++;
        }
Esempio n. 9
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);

            if (!initialized)
            {
                SpawnThings spawnThing = new SpawnThings();
                pawn = this.launcher as Pawn;
                comp = pawn.GetComp <CompAbilityUserMagic>();
                MagicPowerSkill        pwr         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonMinion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonMinion_pwr");
                MagicPowerSkill        ver         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonMinion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonMinion_ver");
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                pwrVal = pwr.level;
                verVal = ver.level;
                if (settingsRef.AIHardMode && !pawn.IsColonistPlayerControlled)
                {
                    pwrVal = 3;
                    verVal = 3;
                }
                CellRect cellRect = CellRect.CenteredOn(this.Position, 1);
                cellRect.ClipInsideMap(map);

                IntVec3       centerCell = cellRect.CenterCell;
                System.Random random     = new System.Random();
                random = new System.Random();

                duration += (verVal * durationMultiplier);

                spawnThing.factionDef = TorannMagicDefOf.TM_SummonedFaction;
                spawnThing.spawnCount = 1;
                spawnThing.temporary  = false;

                if (pwrVal >= 2)
                {
                    for (int i = 0; i < pwrVal - 1; i++)
                    {
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterMinionR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterMinion");
                        SingleSpawnLoop(spawnThing, centerCell, map);
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 2 + pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    MoteMaker.ThrowHeatGlow(centerCell, map, 2 + pwrVal);
                }
                else
                {
                    for (int i = 0; i < pwrVal + 1; i++)
                    {
                        spawnThing.def     = TorannMagicDefOf.TM_MinionR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Minion");

                        SingleSpawnLoop(spawnThing, centerCell, map);
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 1 + pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    MoteMaker.ThrowHeatGlow(centerCell, map, 1 + pwrVal);
                }

                SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f);
                this.initialized = true;
            }
            else
            {
                this.age = this.duration;
            }
        }
Esempio n. 10
0
        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)
            {
                for (int i = 0; i < this.timesToDamage; i++)
                {
                    bool flag3 = this.damageLaunched;
                    if (flag3)
                    {
                        this.flyingThing.TakeDamage(this.impactDamage.Value);
                    }
                    else
                    {
                        hitThing.TakeDamage(this.impactDamage.Value);
                    }
                }
                bool flag4 = this.explosion;
                if (flag4)
                {
                    GenExplosion.DoExplosion(base.Position, base.Map, 0.9f, DamageDefOf.Stun, this, -1, 0, null, null, null, null, null, 0f, 1, false, null, 0f, 1, 0f, false);
                }
            }
            try
            {
                SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                this.FireExplosion(pwrVal, verVal, base.Position, base.Map, (1.2f + (float)(verVal * .8f)));
                MoteMaker.ThrowSmoke(pawn.Position.ToVector3(), base.Map, (0.8f + (float)(verVal * .8f)));

                for (int i = 0; i < (2 + verVal); i++)
                {
                    expCell1 = GetNewPos(expCell1, this.origin.x <= this.DestinationCell.x, this.origin.z <= this.DestinationCell.z, false, 0, 0, xProb, 1 - xProb);
                    MoteMaker.ThrowSmoke(expCell1.ToVector3(), base.Map, 1.6f);
                    expCell2 = GetNewPos(expCell2, this.origin.x <= this.DestinationCell.x, this.origin.z <= this.DestinationCell.z, false, 0, 0, 1 - xProb, xProb);
                    MoteMaker.ThrowSmoke(expCell2.ToVector3(), base.Map, 1.6f);
                }
                for (int i = 0; i < (4 + (3 * verVal)); i++)
                {
                    CellRect cellRect = CellRect.CenteredOn(expCell1, (1 + verVal));
                    cellRect.ClipInsideMap(base.Map);
                    IntVec3 randomCell = cellRect.RandomCell;
                    this.FireExplosion(pwrVal, verVal, randomCell, base.Map, .4f);
                    cellRect   = CellRect.CenteredOn(expCell2, (1 + verVal));
                    randomCell = cellRect.RandomCell;
                    this.FireExplosion(pwrVal, verVal, randomCell, base.Map, .4f);
                }

                GenSpawn.Spawn(this.flyingThing, base.Position, base.Map);
                ModOptions.Constants.SetPawnInFlight(false);
                Pawn p = this.flyingThing as Pawn;
                RemoveInvul(p);
                this.Destroy(DestroyMode.Vanish);
            }
            catch
            {
                GenSpawn.Spawn(this.flyingThing, base.Position, base.Map);
                ModOptions.Constants.SetPawnInFlight(false);
                Pawn p = this.flyingThing as Pawn;
                RemoveInvul(p);
                this.Destroy(DestroyMode.Vanish);
            }
        }
Esempio n. 11
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            //Log.Message(pawn + " - " + pawn.mindState.duty);
            if (!pawn.HostileTo(Faction.OfPlayer))
            {
                //Log.Message("0 - " + pawn + " - null", true);
                return(null);
            }

            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
            {
                //Log.Message(pawn + " found spot: " + spot, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 50f, out Thing item, pawn))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("3 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            bool     flag     = pawn.natives.IgniteVerb != null && pawn.natives.IgniteVerb.IsStillUsableBy(pawn) && pawn.HostileTo(Faction.OfPlayer);
            CellRect cellRect = CellRect.CenteredOn(pawn.Position, 5);

            for (int i = 0; i < 35; i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                if (!randomCell.InBounds(pawn.Map))
                {
                    continue;
                }
                Building edifice = randomCell.GetEdifice(pawn.Map);
                if (edifice != null && TrashUtility.ShouldTrashBuilding(pawn, edifice) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                {
                    Job job = TrashJob(pawn, edifice);
                    if (job != null)
                    {
                        //Log.Message("1 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
                if (flag)
                {
                    Plant plant = randomCell.GetPlant(pawn.Map);
                    if (plant != null && TrashUtility.ShouldTrashPlant(pawn, plant) && GenSight.LineOfSight(pawn.Position, randomCell, pawn.Map))
                    {
                        Job job2 = TrashJob(pawn, plant);
                        if (job2 != null)
                        {
                            //Log.Message("2 - " + pawn + " - " + job2, true);

                            return(job2);
                        }
                    }
                }
            }

            List <Building> allBuildingsColonist = pawn.Map.listerBuildings.allBuildingsColonist;

            if (allBuildingsColonist.Count == 0)
            {
                //Log.Message("4 - " + pawn + " - null", true);
                return(null);
            }
            foreach (var building in allBuildingsColonist.OrderBy(x => IntVec3Utility.DistanceTo(x.Position, pawn.Position)).Take(10).InRandomOrder())
            {
                if (TrashUtility.ShouldTrashBuilding(pawn, building, true) && pawn.CanReach(building, PathEndMode.Touch, Danger.None))
                {
                    Job job = TrashJob(pawn, building, true);
                    if (job != null)
                    {
                        //Log.Message("5 - " + pawn + " - " + job, true);
                        return(job);
                    }
                }
            }
            if (RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot2))
            {
                //Log.Message(pawn + " found spot: " + spot2, true);
                if (TryFindBestItemToSteal(pawn.Position, pawn.Map, 100f, out Thing item, pawn, danger: Danger.None))                // && !GenAI.InDangerousCombat(pawn))
                {
                    Job job = JobMaker.MakeJob(JobDefOf.Steal);
                    job.targetA       = item;
                    job.targetB       = spot2;
                    job.canBashDoors  = true;
                    job.canBashFences = true;
                    job.count         = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
                    //Log.Message("6 - " + pawn + " - " + job, true);
                    return(job);
                }
                //Log.Message(pawn + " cant find item to steal", true);
            }
            //Log.Message("7 - " + pawn + " - null", true);
            return(null);
        }
Esempio n. 12
0
 // Token: 0x060000B2 RID: 178 RVA: 0x00004BC5 File Offset: 0x00002DC5
 private CellRect CalculateSpectateRect()
 {
     return(CellRect.CenteredOn(performThing.Position, 8));
 }
Esempio n. 13
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            //base.Impact(hitThing);
            ThingDef def    = this.def;
            Pawn     victim = hitThing as Pawn;
            Thing    item   = hitThing as Thing;
            IntVec3  arg_pos_1;

            Pawn pawn = this.launcher as Pawn;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonPylon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonPylon_pwr");
            MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonPylon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonPylon_ver");

            verVal = ver.level;
            pwrVal = pwr.level;
            if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                pwrVal = mpwr.level;
                verVal = mver.level;
            }
            CellRect cellRect = CellRect.CenteredOn(base.Position, 1);

            cellRect.ClipInsideMap(map);
            IntVec3 centerCell = cellRect.CenterCell;

            if (!this.primed)
            {
                duration += (verVal * 7200);
                duration  = (int)(duration * comp.arcaneDmg);
                arg_pos_1 = centerCell;

                if ((arg_pos_1.IsValid && arg_pos_1.Standable(map)))
                {
                    AbilityUser.SpawnThings tempPod = new SpawnThings();
                    IntVec3 shiftPos = centerCell;
                    centerCell.x++;

                    if (pwrVal == 1)
                    {
                        tempPod.def = ThingDef.Named("DefensePylon_I");
                    }
                    else if (pwrVal == 2)
                    {
                        tempPod.def = ThingDef.Named("DefensePylon_II");
                    }
                    else if (pwrVal == 3)
                    {
                        tempPod.def = ThingDef.Named("DefensePylon_III");
                    }
                    else
                    {
                        tempPod.def = ThingDef.Named("DefensePylon");
                    }
                    tempPod.spawnCount = 1;
                    try
                    {
                        this.SingleSpawnLoop(tempPod, shiftPos, map);
                    }
                    catch
                    {
                        comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonPylon);
                        this.age            = this.duration;
                        Log.Message("TM_Exception".Translate(
                                        pawn.LabelShort,
                                        this.def.defName
                                        ));
                    }

                    this.primed = true;
                }
                else
                {
                    Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                    comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_SummonExplosive));
                    this.duration = 0;
                }
            }
            this.age = this.duration;
            Destroy();
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def    = this.def;
            Pawn     victim = hitThing as Pawn;
            Thing    item   = hitThing as Thing;
            IntVec3  arg_pos_1;
            IntVec3  arg_pos_2;
            IntVec3  arg_pos_3;

            Pawn pawn = this.launcher as Pawn;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonExplosive.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonExplosive_pwr");
            MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonExplosive.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonExplosive_ver");

            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
            pwrVal = pwr.level;
            verVal = ver.level;
            if (settingsRef.AIHardMode && !pawn.IsColonistPlayerControlled)
            {
                pwrVal = 3;
                verVal = 3;
            }
            CellRect cellRect = CellRect.CenteredOn(base.Position, 1);

            cellRect.ClipInsideMap(map);
            IntVec3 centerCell = cellRect.CenterCell;

            if (!this.primed)
            {
                duration += (verVal * 3600);
                arg_pos_1 = centerCell;

                if ((arg_pos_1.IsValid && arg_pos_1.Standable(map)))
                {
                    AbilityUser.SpawnThings tempPod = new SpawnThings();
                    IntVec3 shiftPos = centerCell;
                    centerCell.x++;

                    if (pwrVal == 1)
                    {
                        tempPod.def = ThingDef.Named("TM_ManaMine_I");
                    }
                    else if (pwrVal == 2)
                    {
                        tempPod.def = ThingDef.Named("TM_ManaMine_II");
                    }
                    else if (pwrVal == 3)
                    {
                        tempPod.def = ThingDef.Named("TM_ManaMine_III");
                    }
                    else
                    {
                        tempPod.def = ThingDef.Named("TM_ManaMine");
                    }
                    tempPod.spawnCount = 1;
                    try
                    {
                        this.SingleSpawnLoop(tempPod, shiftPos, map);
                    }
                    catch
                    {
                        Log.Message("Attempted to create an explosive but threw an unknown exception - recovering and ending attempt");
                        if (pawn != null)
                        {
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonExplosive);
                        }
                        this.age = this.duration;
                        return;
                    }

                    this.primed = true;
                }
                else
                {
                    Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                    comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_SummonExplosive));
                    this.duration = 0;
                }
            }

            this.age = this.duration;
        }
Esempio n. 15
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            //base.Impact(hitThing);
            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            if (!initialized)
            {
                SpawnThings spawnThing = new SpawnThings();
                pawn = this.launcher as Pawn;
                MagicPowerSkill        pwr         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonElemental.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonElemental_pwr");
                MagicPowerSkill        ver         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonElemental.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonElemental_ver");
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                pwrVal = pwr.level;
                verVal = ver.level;
                if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
                {
                    MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                    MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                    pwrVal = mpwr.level;
                    verVal = mver.level;
                }
                if (settingsRef.AIHardMode && !pawn.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }
                CellRect cellRect = CellRect.CenteredOn(this.Position, 1);
                cellRect.ClipInsideMap(map);

                IntVec3       centerCell = cellRect.CenterCell;
                System.Random random     = new System.Random();
                random = new System.Random();

                duration += (verVal * 900);
                duration  = Mathf.RoundToInt(duration * pawn.GetComp <CompAbilityUserMagic>().arcaneDmg);

                int rnd = GenMath.RoundRandom(random.Next(0, 8));
                if (rnd < 2)
                {
                    spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction;
                    spawnThing.spawnCount = 1;
                    spawnThing.temporary  = false;

                    if (pwrVal == 3)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_Earth_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_Earth_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterEarth_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental");
                    }
                    else if (pwrVal == 2)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserEarth_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterEarth_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterEarth_Elemental");
                    }
                    else if (pwrVal == 1)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserEarth_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_Earth_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Earth_Elemental");
                    }
                    else
                    {
                        for (int i = 0; i < 1; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserEarth_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_LesserEarth_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_LesserEarth_Elemental");
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                }
                else if (rnd >= 2 && rnd < 4)
                {
                    spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction;
                    spawnThing.spawnCount = 1;
                    spawnThing.temporary  = false;

                    if (pwrVal == 3)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_Fire_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_Fire_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterFire_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterFire_Elemental");
                    }
                    else if (pwrVal == 2)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserFire_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterFire_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterFire_Elemental");
                    }
                    else if (pwrVal == 1)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserFire_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_Fire_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Fire_Elemental");
                    }
                    else
                    {
                        for (int i = 0; i < 1; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserFire_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_LesserFire_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_LesserFire_Elemental");
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    MoteMaker.ThrowFireGlow(centerCell, map, pwrVal);
                    MoteMaker.ThrowHeatGlow(centerCell, map, pwrVal);
                }
                else if (rnd >= 4 && rnd < 6)
                {
                    spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction;
                    spawnThing.spawnCount = 1;
                    spawnThing.temporary  = false;

                    if (pwrVal == 3)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_Water_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_Water_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterWater_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWater_Elemental");
                    }
                    else if (pwrVal == 2)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWater_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterWater_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWater_Elemental");
                    }
                    else if (pwrVal == 1)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWater_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_Water_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Water_Elemental");
                    }
                    else
                    {
                        for (int i = 0; i < 1; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWater_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_LesserWater_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_LesserWater_Elemental");
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, pwrVal);
                    SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                    MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue);
                    MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue);
                    MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.blue);
                }
                else
                {
                    spawnThing.factionDef = TorannMagicDefOf.TM_ElementalFaction;
                    spawnThing.spawnCount = 1;
                    spawnThing.temporary  = false;

                    if (pwrVal == 3)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWind_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_Wind_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterWind_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental");
                    }
                    else if (pwrVal == 2)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWind_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterWind_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterWind_Elemental");
                    }
                    else if (pwrVal == 1)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWind_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_Wind_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Wind_Elemental");
                    }
                    else
                    {
                        for (int i = 0; i < 1; i++)
                        {
                            spawnThing.def     = TorannMagicDefOf.TM_LesserWind_ElementalR;
                            spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental");
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        spawnThing.def     = TorannMagicDefOf.TM_LesserWind_ElementalR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_LesserWind_Elemental");
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 1 + pwrVal * 2);
                    SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                    MoteMaker.ThrowTornadoDustPuff(centerCell.ToVector3(), map, pwrVal, Color.white);
                }

                SingleSpawnLoop(spawnThing, centerCell, map);

                this.age         = this.duration;
                this.initialized = true;
            }
            Destroy();
        }
Esempio n. 16
0
        public (PawnPath path, bool found) FindVehiclePath(IntVec3 start, LocalTargetInfo dest, TraverseParms traverseParms, CancellationToken token, PathEndMode peMode = PathEndMode.OnCell, bool waterPathing = false)
        {
            if (report)
            {
                Debug.Message($"{VehicleHarmony.LogLabel} MainPath for {traverseParms.pawn.LabelShort} - ThreadId: [{Thread.CurrentThread.ManagedThreadId}] TaskId: [{Task.CurrentId}]");
            }

            postCalculatedCells.Clear();
            VehicleMapping VehicleMapping = map.GetCachedMapComponent <VehicleMapping>();

            if (DebugSettings.pathThroughWalls)
            {
                traverseParms.mode = TraverseMode.PassAllDestroyableThings;
            }
            VehiclePawn pawn = traverseParms.pawn as VehiclePawn;

            if (!pawn.IsBoat() && waterPathing)
            {
                Log.Error($"Set to waterPathing but {pawn.LabelShort} is not registered as a Boat. Self Correcting...");
                waterPathing = false;
            }
            if (!(pawn is null) && pawn.Map != map)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindVehiclePath for pawn which is spawned in another map. Their map PathFinder should  have been used, not this one. " +
                    "pawn=", pawn,
                    " pawn.Map=", pawn.Map,
                    " map=", map
                }));
                return(PawnPath.NotFound, false);
            }
            if (!start.IsValid)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindShipPath with invalid start ",
                    start,
                    ", pawn=", pawn
                }));
                return(PawnPath.NotFound, false);
            }
            if (!dest.IsValid)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Tried to FindPath with invalid dest ",
                    dest,
                    ", pawn= ",
                    pawn
                }));
                return(PawnPath.NotFound, false);
            }
            if (traverseParms.mode == TraverseMode.ByPawn)
            {
                if (waterPathing)
                {
                    if (!ShipReachabilityUtility.CanReachShip(pawn, dest, peMode, Danger.Deadly, false, traverseParms.mode))
                    {
                        return(PawnPath.NotFound, false);
                    }
                }
                else
                {
                    if (!ReachabilityUtility.CanReach(pawn, dest, peMode, Danger.Deadly, false, traverseParms.mode))
                    {
                        return(PawnPath.NotFound, false);
                    }
                }
            }
            else
            {
                if (waterPathing)
                {
                    if (!VehicleMapping.VehicleReachability.CanReachShip(start, dest, peMode, traverseParms))
                    {
                        return(PawnPath.NotFound, false);
                    }
                }
                else
                {
                    if (!map.reachability.CanReach(start, dest, peMode, traverseParms))
                    {
                        return(PawnPath.NotFound, false);
                    }
                }
            }
            cellIndices = map.cellIndices;

            VehiclePathGrid  = VehicleMapping.VehiclePathGrid;
            pathGrid         = map.pathGrid;
            this.edificeGrid = map.edificeGrid.InnerArray;
            blueprintGrid    = map.blueprintGrid.InnerArray;
            int      x        = dest.Cell.x;
            int      z        = dest.Cell.z;
            int      num      = cellIndices.CellToIndex(start);
            int      num2     = cellIndices.CellToIndex(dest.Cell);
            ByteGrid byteGrid = (pawn is null) ? null : pawn.GetAvoidGrid(true);
            bool     flag     = traverseParms.mode == TraverseMode.PassAllDestroyableThings || traverseParms.mode == TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag2    = traverseParms.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParms.mode != TraverseMode.PassAllDestroyableThingsNotWater;
            bool     flag3    = !flag;
            CellRect cellRect = CalculateDestinationRect(dest, peMode);
            bool     flag4    = cellRect.Width == 1 && cellRect.Height == 1;

            int[]        boatsArray   = VehiclePathGrid.pathGrid;
            int[]        vehicleArray = pathGrid.pathGrid;
            TerrainDef[] topGrid      = map.terrainGrid.topGrid;
            EdificeGrid  edificeGrid  = map.edificeGrid;
            int          num3         = 0;
            int          num4         = 0;
            Area         allowedArea  = GetAllowedArea(pawn);
            bool         flag5        = !(pawn is null) && PawnUtility.ShouldCollideWithPawns(pawn);
            bool         flag6        = true && DebugViewSettings.drawPaths;
            bool         flag7        = !flag && !(VehicleGridsUtility.GetRegion(start, map, RegionType.Set_Passable) is null) && flag2;
            bool         flag8        = !flag || !flag3;
            bool         flag9        = false;
            bool         flag10       = !(pawn is null) && pawn.Drafted;
            bool         flag11       = !(pawn is null) && !(pawn is null);

            int   num5  = (!flag11) ? NodesToOpenBeforeRegionbasedPathing_NonShip : NodesToOpenBeforeRegionBasedPathing_Ship;
            int   num6  = 0;
            int   num7  = 0;
            float num8  = DetermineHeuristicStrength(pawn, start, dest);
            int   num9  = !(pawn is null) ? pawn.TicksPerMoveCardinal : DefaultMoveTicksCardinal;
            int   num10 = !(pawn is null) ? pawn.TicksPerMoveDiagonal : DefaultMoveTicksDiagonal;

            CalculateAndAddDisallowedCorners(traverseParms, peMode, cellRect);
            InitStatusesAndPushStartNode(ref num, start);
            Rot8 rot        = pawn.FullRotation;
            int  iterations = 0;

            for (;;)
            {
                if (token.IsCancellationRequested)
                {
                    return(PawnPath.NotFound, false);
                }

                iterations++;
                if (openList.Count <= 0)
                {
                    break;
                }
                num6 += openList.Count;
                num7++;
                CostNode costNode = openList.Pop();
                num = costNode.index;
                if (costNode.cost == calcGrid[num].costNodeCost && calcGrid[num].status != statusClosedValue)
                {
                    IntVec3 c        = cellIndices.IndexToCell(num);
                    IntVec3 prevCell = c;
                    int     x2       = c.x;
                    int     z2       = c.z;
                    if (flag6)
                    {
                        DebugFlash(c, calcGrid[num].knownCost / 1500f, calcGrid[num].knownCost.ToString());
                    }
                    if (flag4)
                    {
                        if (num == num2)
                        {
                            goto Block_32;
                        }
                    }
                    else if (cellRect.Contains(c) && !disallowedCornerIndices.Contains(num))
                    {
                        goto Block_32;
                    }
                    if (num3 > SearchLimit)
                    {
                        goto Block_33;
                    }

                    List <IntVec3> fullRectCells = CellRect.CenteredOn(c, pawn.def.size.x, pawn.def.size.z).Where(cl2 => cl2 != c).ToList();

                    for (int i = 0; i < 8; i++)
                    {
                        uint num11 = (uint)(x2 + Directions[i]);                           //x
                        uint num12 = (uint)(z2 + Directions[i + 8]);                       //y

                        if (num11 < ((ulong)mapSizeX) && num12 < (ulong)(mapSizeZ))
                        {
                            int num13 = (int)num11;
                            int num14 = (int)num12;
                            int num15 = cellIndices.CellToIndex(num13, num14);

                            IntVec3 cellToCheck = cellIndices.IndexToCell(num15);
                            if (VehicleMod.settings.main.fullVehiclePathing && pawn.LocationRestrictedBySize(cellToCheck))
                            {
                                goto EndPathing;
                            }

                            if (calcGrid[num15].status != statusClosedValue || flag9)
                            {
                                int  num16  = 0;
                                bool flag12 = false;                                 //Extra cost for traversing water

                                if (flag2 || !new IntVec3(num13, 0, num14).GetTerrain(map).HasTag("Water"))
                                {
                                    if (waterPathing)
                                    {
                                        if (!pawn.DrivableFast(num15))
                                        {
                                            if (!flag)
                                            {
                                                if (flag6)
                                                {
                                                    DebugFlash(new IntVec3(num13, 0, num14), 0.22f, "walk");
                                                }
                                                goto EndPathing;
                                            }

                                            num16 += 70;
                                            Building building = edificeGrid[num15];
                                            if (building is null)
                                            {
                                                goto EndPathing;
                                            }
                                            if (!IsDestroyable(building))
                                            {
                                                goto EndPathing;
                                            }
                                            num16 += (int)(building.HitPoints * 0.2f);
                                        }
                                    }
                                    else
                                    {
                                        if (!pawn.DrivableFast(num15))
                                        {
                                            if (!flag)
                                            {
                                                if (flag6)
                                                {
                                                    DebugFlash(new IntVec3(num13, 0, num14), 0.22f, "walk");
                                                }
                                                goto EndPathing;
                                            }
                                            flag12 = true;
                                            num16 += 70;
                                            Building building = edificeGrid[num15];
                                            if (building is null)
                                            {
                                                goto EndPathing;
                                            }
                                            if (!IsDestroyable(building))
                                            {
                                                goto EndPathing;
                                            }
                                            num16 += (int)(building.HitPoints * 0.2f);
                                        }
                                    }

                                    if (i > 3)
                                    {
                                        switch (i)
                                        {
                                        case 4:
                                            if (BlocksDiagonalMovement(pawn, num - mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            if (BlocksDiagonalMovement(pawn, num + 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 5:
                                            if (BlocksDiagonalMovement(pawn, num + mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            if (BlocksDiagonalMovement(pawn, num + 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2 + 1, 0, z2), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 6:
                                            if (BlocksDiagonalMovement(pawn, num + mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2, 0, z2 + 1), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            if (BlocksDiagonalMovement(pawn, num - 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            break;

                                        case 7:
                                            if (BlocksDiagonalMovement(pawn, num - mapSizeX))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2, 0, z2 - 1), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            if (BlocksDiagonalMovement(pawn, num - 1))
                                            {
                                                if (flag8)
                                                {
                                                    if (flag6)
                                                    {
                                                        DebugFlash(new IntVec3(x2 - 1, 0, z2), 0.9f, "ships");
                                                    }
                                                    goto EndPathing;
                                                }
                                                num16 += 70;
                                            }
                                            break;
                                        }
                                    }
                                    int num17 = (i <= 3) ? num9 : num10;
                                    num17 += num16;
                                    //if (Rot8.DirectionFromCells(prevCell, cellToCheck) != rot)
                                    //{
                                    //    Log.Message("Additional Cost");
                                    //    num17 += ChangeDirectionAdditionalCost;
                                    //}
                                    if (!flag12 && !waterPathing)
                                    {
                                        //Extra Terrain costs
                                        if (pawn.VehicleDef.properties.customTerrainCosts?.NotNullAndAny() ?? false)
                                        {
                                            TerrainDef currentTerrain = map.terrainGrid.TerrainAt(num15);
                                            if (pawn.VehicleDef.properties.customTerrainCosts.ContainsKey(currentTerrain))
                                            {
                                                int customCost = pawn.VehicleDef.properties.customTerrainCosts[currentTerrain];
                                                if (customCost < 0)
                                                {
                                                    goto EndPathing;
                                                }
                                                num17 += customCost;
                                            }
                                            else
                                            {
                                                num17 += vehicleArray[num15];
                                            }
                                        }
                                        else
                                        {
                                            num17 += vehicleArray[num15];
                                        }
                                        num17 += flag10 ? topGrid[num15].extraDraftedPerceivedPathCost : topGrid[num15].extraNonDraftedPerceivedPathCost;
                                    }
                                    if (byteGrid != null)
                                    {
                                        num17 += (byteGrid[num15] * 8);
                                    }
                                    //Allowed area cost?
                                    if (flag5 && MultithreadHelper.AnyVehicleBlockingPathAt(new IntVec3(num13, 0, num14), pawn, false, false, true) != null)
                                    {
                                        num17 += Cost_PawnCollision;
                                    }
                                    Building building2 = edificeGrid[num15];
                                    if (!(building2 is null))
                                    {
                                        //Building Costs Here
                                    }
                                    if (blueprintGrid[num15] != null)
                                    {
                                        List <Blueprint> list = new List <Blueprint>(blueprintGrid[num15]);
                                        if (!list.NullOrEmpty())
                                        {
                                            int num18 = 0;
                                            foreach (Blueprint bp in list)
                                            {
                                                num18 = Mathf.Max(num18, GetBlueprintCost(bp, pawn));
                                            }
                                            if (num18 == int.MaxValue)
                                            {
                                                goto EndPathing;
                                            }
                                            num17 += num18;
                                        }
                                    }

                                    int    num19  = num17 + calcGrid[num].knownCost;
                                    ushort status = calcGrid[num15].status;

                                    //if(pawn.Props.useFullHitboxPathing)
                                    //{
                                    //    foreach(IntVec3 fullRect in fullRectCells)
                                    //    {
                                    //        if(fullRect != cellToCheck)
                                    //        {
                                    //            num19 += calcGrid[cellIndices.CellToIndex(fullRect)].knownCost;
                                    //            Log.Message($"Cell: {fullRect} Cost: {num19}");
                                    //            if(postCalculatedCells.ContainsKey(fullRect))
                                    //            {
                                    //                postCalculatedCells[fullRect] = num19;
                                    //            }
                                    //            else
                                    //            {
                                    //                postCalculatedCells.Add(fullRect, num19);
                                    //            }
                                    //        }
                                    //    }
                                    //}

                                    //Only generate path costs for linear non-reverse pathing check
                                    if (report)
                                    {
                                        if (postCalculatedCells.ContainsKey(cellToCheck))
                                        {
                                            postCalculatedCells[cellToCheck] = num19;
                                        }
                                        else
                                        {
                                            postCalculatedCells.Add(cellToCheck, num19);
                                        }
                                    }

                                    if (waterPathing && !map.terrainGrid.TerrainAt(num15).IsWater)
                                    {
                                        num19 += 10000;
                                    }
                                    if (status == statusClosedValue || status == statusOpenValue)
                                    {
                                        int num20 = 0;
                                        if (status == statusClosedValue)
                                        {
                                            num20 = num9;
                                        }
                                        if (calcGrid[num15].knownCost <= num19 + num20)
                                        {
                                            goto EndPathing;
                                        }
                                    }
                                    if (flag9)
                                    {
                                        calcGrid[num15].heuristicCost = waterPathing ? Mathf.RoundToInt(regionCostCalculatorSea.GetPathCostFromDestToRegion(num15) *
                                                                                                        RegionheuristicWeighByNodesOpened.Evaluate(num4)) : Mathf.RoundToInt(regionCostCalculatorLand.GetPathCostFromDestToRegion(num15) *
                                                                                                                                                                             RegionheuristicWeighByNodesOpened.Evaluate(num4));
                                        if (calcGrid[num15].heuristicCost < 0)
                                        {
                                            Log.ErrorOnce(string.Concat(new object[]
                                            {
                                                "Heuristic cost overflow for vehicle ", pawn.ToStringSafe <Pawn>(),
                                                " pathing from ", start,
                                                " to ", dest, "."
                                            }), pawn.GetHashCode() ^ 193840009);
                                            calcGrid[num15].heuristicCost = 0;
                                        }
                                    }
                                    else if (status != statusClosedValue && status != statusOpenValue)
                                    {
                                        int dx    = Math.Abs(num13 - x);
                                        int dz    = Math.Abs(num14 - z);
                                        int num21 = GenMath.OctileDistance(dx, dz, num9, num10);
                                        calcGrid[num15].heuristicCost = Mathf.RoundToInt((float)num21 * num8);
                                    }
                                    int num22 = num19 + calcGrid[num15].heuristicCost;
                                    if (num22 < 0)
                                    {
                                        Log.ErrorOnce(string.Concat(new object[]
                                        {
                                            "Node cost overflow for ship ", pawn.ToStringSafe <Pawn>(),
                                            " pathing from ", start,
                                            " to ", dest, "."
                                        }), pawn.GetHashCode() ^ 87865822);
                                        num22 = 0;
                                    }
                                    calcGrid[num15].parentIndex  = num;
                                    calcGrid[num15].knownCost    = num19;
                                    calcGrid[num15].status       = statusOpenValue;
                                    calcGrid[num15].costNodeCost = num22;
                                    num4++;
                                    rot = Rot8.DirectionFromCells(prevCell, cellToCheck);
                                    openList.Push(new CostNode(num15, num22));
                                }
                            }
                        }
                        EndPathing :;
                    }
                    num3++;
                    calcGrid[num].status = statusClosedValue;
                    if (num4 >= num5 && flag7 && !flag9)
                    {
                        flag9 = true;
                        if (waterPathing)
                        {
                            regionCostCalculatorSea.Init(cellRect, traverseParms, num9, num10, byteGrid, allowedArea, flag10, disallowedCornerIndices);
                        }
                        else
                        {
                            regionCostCalculatorLand.Init(cellRect, traverseParms, num9, num10, byteGrid, allowedArea, flag10, disallowedCornerIndices);
                        }

                        InitStatusesAndPushStartNode(ref num, start);
                        num4 = 0;
                        num3 = 0;
                    }
                }
            }
            string text  = ((pawn is null) || pawn.CurJob is null) ? "null" : pawn.CurJob.ToString();
            string text2 = ((pawn is null) || pawn.Faction is null) ? "null" : pawn.Faction.ToString();

            if (report)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "ship pawn: ", pawn, " pathing from ", start,
                    " to ", dest, " ran out of cells to process.\nJob:", text,
                    "\nFaction: ", text2,
                    "\niterations: ", iterations
                }));
            }
            DebugDrawRichData();
            return(PawnPath.NotFound, false);

Block_32:
            PawnPath result = PawnPath.NotFound;

            if (report)
            {
                result = FinalizedPath(num, flag9);
            }
            DebugDrawPathCost();
            return(result, true);

Block_33:
            Log.Warning(string.Concat(new object[]
            {
                "Ship ", pawn, " pathing from ", start,
                " to ", dest, " hit search limit of ", SearchLimit, " cells."
            }));
            DebugDrawRichData();
            return(PawnPath.NotFound, false);
        }
Esempio n. 17
0
        protected override bool TryCastShot()
        {
            bool flag10 = 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);
            }
            for (int i = 0; i < this.TargetsAoE.Count; i++)
            {
                bool?flag3    = this.TryLaunchProjectile(this.verbProps.defaultProjectile, this.TargetsAoE[i]);
                bool hasValue = flag3.HasValue;
                if (hasValue)
                {
                    bool flag4 = flag3 == true;
                    if (flag4)
                    {
                        flag10 = true;
                    }
                    bool flag5 = flag3 == false;
                    if (flag5)
                    {
                        flag10 = false;
                    }
                }
            }

            CellRect cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
            Map      map      = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell        = cellRect.CenterCell;
            CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();

            pwr = comp.MightData.MightPowerSkill_Cleave.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Cleave_pwr");
            str = comp.MightData.MightPowerSkill_global_strength.FirstOrDefault((MightPowerSkill x) => x.label == "TM_global_strength_pwr");
            ver = comp.MightData.MightPowerSkill_Cleave.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Cleave_ver");
            int dmgNum = 0;

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                weaponComp      = base.CasterPawn.equipment.Primary;
                weaponDPS       = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) * .7f;
                dmgMultiplier   = weaponComp.GetStatValue(StatDefOf.MeleeWeapon_DamageMultiplier, false);
                pawnDPS         = base.CasterPawn.GetStatValue(StatDefOf.MeleeDPS, false);
                skillMultiplier = (1.2f + (.025f * str.level));
                dmgNum          = Mathf.RoundToInt(skillMultiplier * dmgMultiplier * (pawnDPS + weaponDPS));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonist && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }
            }
            else
            {
                dmgNum = 4;
            }

            for (int i = 0; i < 8; i++)
            {
                IntVec3 searchCell = base.CasterPawn.Position + GenAdj.AdjacentCells8WayRandomized()[i];
                Pawn    victim     = searchCell.GetFirstPawn(map);
                if (victim != null && base.CasterPawn != null & dmgNum != 0 && victim.Faction != base.CasterPawn.Faction)
                {
                    dinfo = new DamageInfo(TMDamageDefOf.DamageDefOf.TM_Cleave, dmgNum, 0, (float)-1, this.CasterPawn, null, null, DamageInfo.SourceCategory.ThingOrUnknown);
                    ApplyCleaveDamage(dinfo, this.CasterPawn, victim, map, ver.level);
                    DrawCleaving(victim, base.CasterPawn, 10);
                    i = 8;
                }
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }
Esempio n. 18
0
        protected override bool TryCastShot()
        {
            CompAbilityUserMight comp = this.CasterPawn.GetComp <CompAbilityUserMight>();
            MightPowerSkill      ver  = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_ver");

            pwrVal = TM_Calc.GetMightSkillLevel(this.CasterPawn, comp.MightData.MightPowerSkill_SeismicSlash, "TM_SeismicSlash", "_pwr", true);
            CellRect cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
            Map      map      = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell = cellRect.CenterCell;

            this.origin        = base.CasterPawn.Position.ToVector3();
            this.destination   = this.currentTarget.Cell.ToVector3Shifted();
            this.ticksToImpact = Mathf.RoundToInt((this.origin - this.destination).magnitude);

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                TMAbilityDef           ad          = (TMAbilityDef)this.Ability.Def;
                int                    dmgNum      = Mathf.RoundToInt(comp.weaponDamage * ad.weaponDamageFactor * (1 + (.1f * pwrVal)));
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonist && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }

                Vector3 strikeVec = this.origin;
                DrawBlade(strikeVec, 0);
                for (int i = 0; i < this.StartingTicksToImpact; i++)
                {
                    strikeVec = this.ExactPosition;
                    Pawn victim = strikeVec.ToIntVec3().GetFirstPawn(map);
                    if (victim != null && victim.Faction != base.CasterPawn.Faction)
                    {
                        DrawStrike(strikeVec.ToIntVec3(), strikeVec, map);
                        damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                    }
                    float angle = (Quaternion.AngleAxis(90, Vector3.up) * TM_Calc.GetVector(this.CasterPawn.DrawPos, this.currentTarget.CenterVector3)).ToAngleFlat();
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_DirectionalDirt"), strikeVec, this.CasterPawn.Map, .3f + (.08f * i), .05f, .15f, .38f, 0, 5f - (.2f * i), angle, angle);
                    if (i == 2)
                    {
                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_Cleave"), strikeVec, this.CasterPawn.Map, .6f + (.05f * i), .05f, .04f + (.03f * i), .15f, -10000, 30, angle, angle);
                    }
                    //MoteMaker.ThrowTornadoDustPuff(strikeVec, map, .6f, Color.white);
                    for (int j = 0; j < 2 + (2 * verVal); j++)
                    {
                        IntVec3 searchCell = strikeVec.ToIntVec3() + GenAdj.AdjacentCells8WayRandomized()[j];
                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_DirectionalDirt"), searchCell.ToVector3Shifted(), this.CasterPawn.Map, .1f + (.04f * i), .05f, .04f, .28f, 0, 4f - (.2f * i), angle, angle);
                        //MoteMaker.ThrowTornadoDustPuff(searchCell.ToVector3(), map, .4f, Color.gray);
                        victim = searchCell.GetFirstPawn(map);
                        if (victim != null && victim.Faction != base.CasterPawn.Faction)
                        {
                            DrawStrike(searchCell, searchCell.ToVector3(), map);
                            damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                        }
                    }
                    this.ticksToImpact--;
                }
            }
            else
            {
                Messages.Message("MustHaveMeleeWeapon".Translate(
                                     this.CasterPawn.LabelCap
                                     ), MessageTypeDefOf.RejectInput);
                return(false);
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }
Esempio n. 19
0
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map, GenStepParams parms)
        {
            int                 nextSignalTagID     = Find.UniqueIDsManager.GetNextSignalTagID();
            string              signalTag           = "ambushActivated-" + nextSignalTagID;
            CellRect            rect                = (!root.IsValid) ? rectToDefend.ExpandedBy(12) : CellRect.CenteredOn(root, 17);
            SignalAction_Ambush signalAction_Ambush = MakeAmbushSignalAction(rectToDefend, root, parms);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map);
            RectTrigger rectTrigger = MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map);
            TriggerUnfogged obj = (TriggerUnfogged)ThingMaker.MakeThing(ThingDefOf.TriggerUnfogged);

            obj.signalTag = signalTag;
            GenSpawn.Spawn(obj, rect.CenterCell, map);
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def  = this.def;
            Pawn     pawn = this.launcher as Pawn;

            if (!this.initialized)
            {
                CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
                MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_CorpseExplosion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_CorpseExplosion_pwr");
                MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_CorpseExplosion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_CorpseExplosion_ver");
                pwrVal = pwr.level;
                verVal = ver.level;
                Initialize();

                CellRect cellRect = CellRect.CenteredOn(base.Position, 1);
                cellRect.ClipInsideMap(map);
                IntVec3 curCell = cellRect.CenterCell;
                if (curCell.InBounds(map) && curCell.IsValid)
                {
                    Pawn undead = curCell.GetFirstPawn(map);
                    bool flag   = undead != null && !undead.Dead;
                    if (flag)
                    {
                        if (undead.health.hediffSet.HasHediff(TorannMagicDefOf.TM_UndeadHD))
                        {
                            this.targetPawn = undead;
                        }
                        if (undead.health.hediffSet.HasHediff(TorannMagicDefOf.TM_UndeadAnimalHD))
                        {
                            this.targetPawn = undead;
                        }
                    }

                    Thing  corpseThing = curCell.GetFirstItem(map);
                    Corpse corpse      = null;
                    if (corpseThing != null)
                    {
                        bool validator = corpseThing is Corpse;
                        if (validator)
                        {
                            corpse = corpseThing as Corpse;
                            Pawn corpsePawn = corpse.InnerPawn;
                            if (corpsePawn.RaceProps.IsFlesh)
                            {
                                if (corpsePawn.RaceProps.Humanlike || corpsePawn.RaceProps.Animal)
                                {
                                    this.targetCorpse = corpse;
                                }
                            }
                        }
                    }
                }
            }

            if (this.targetPawn != null && !this.targetPawn.Destroyed)
            {
                if (this.age == 360)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "6", -.5f);
                }
                if (this.age == 300)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "5", -.5f);
                }
                if (this.age == 240)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "4", -.5f);
                }
                if (this.age == 180)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "3", -.5f);
                }
                if (this.age == 120)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "2", -.5f);
                }
                if (this.age == 60)
                {
                    MoteMaker.ThrowText(this.targetPawn.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "1", -.5f);
                }
                if (this.age == 1)
                {
                    //explode
                    TM_MoteMaker.ThrowBloodSquirt(this.targetPawn.Position.ToVector3Shifted(), map, 1.2f);
                    TM_MoteMaker.ThrowBloodSquirt(this.targetPawn.Position.ToVector3Shifted(), map, .6f);
                    TM_MoteMaker.ThrowBloodSquirt(this.targetPawn.Position.ToVector3Shifted(), map, .8f);
                    if (this.targetPawn.RaceProps.Humanlike)
                    {
                        this.targetPawn.inventory.DropAllNearPawn(this.targetPawn.Position, false, true);
                        this.targetPawn.equipment.DropAllEquipment(this.targetPawn.Position, false);
                        this.targetPawn.apparel.DropAll(this.targetPawn.Position, false);
                    }
                    GenExplosion.DoExplosion(this.targetPawn.Position, map, this.radius, TMDamageDefOf.DamageDefOf.TM_CorpseExplosion, this.launcher, Mathf.RoundToInt(Rand.Range(18f, 30f) + (5f * pwrVal)), this.def.projectile.soundExplode, def, this.equipmentDef, null, 0f, 01, false, null, 0f, 0, 0.0f, true);
                    if (!this.targetPawn.Destroyed)
                    {
                        this.targetPawn.Destroy();
                    }
                }
            }

            if (this.targetCorpse != null && !this.targetCorpse.Destroyed)
            {
                if (this.age == 360)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "6", -.5f);
                }
                if (this.age == 300)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "5", -.5f);
                }
                if (this.age == 240)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "4", -.5f);
                }
                if (this.age == 180)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "3", -.5f);
                }
                if (this.age == 120)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "2", -.5f);
                }
                if (this.age == 60)
                {
                    MoteMaker.ThrowText(this.targetCorpse.Position.ToVector3ShiftedWithAltitude(AltitudeLayer.MoteOverhead), map, "1", -.5f);
                }
                if (this.age == 1)
                {
                    //explode
                    TM_MoteMaker.ThrowBloodSquirt(this.targetCorpse.Position.ToVector3Shifted(), map, 1.2f);
                    TM_MoteMaker.ThrowBloodSquirt(this.targetCorpse.Position.ToVector3Shifted(), map, .6f);
                    TM_MoteMaker.ThrowBloodSquirt(this.targetCorpse.Position.ToVector3Shifted(), map, .8f);
                    Pawn corpsePawn = this.targetCorpse.InnerPawn;
                    if (corpsePawn.RaceProps.Humanlike)
                    {
                        corpsePawn.inventory.DropAllNearPawn(this.targetCorpse.Position, false, true);
                        corpsePawn.equipment.DropAllEquipment(this.targetCorpse.Position, false);
                        corpsePawn.apparel.DropAll(this.targetCorpse.Position, false);
                    }
                    GenExplosion.DoExplosion(this.targetCorpse.Position, map, this.radius, TMDamageDefOf.DamageDefOf.TM_CorpseExplosion, this.launcher, Mathf.RoundToInt(Rand.Range(18f, 30f) + (5f * pwrVal)), this.def.projectile.soundExplode, def, this.equipmentDef, null, 0f, 01, false, null, 0f, 0, 0.0f, true);
                    if (!this.targetCorpse.Destroyed)
                    {
                        this.targetCorpse.Destroy();
                    }
                }
            }
        }
Esempio n. 21
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            CellRect cellRect = CellRect.CenteredOn(base.Position, 1);

            cellRect.ClipInsideMap(map);
            IntVec3 centerCell = cellRect.CenterCell;
            IntVec3 expCell1   = centerCell;
            IntVec3 expCell2   = centerCell;
            IntVec3 target     = base.Position;

            Hediff invul = new Hediff();

            invul.def      = TorannMagicDefOf.TM_HediffInvulnerable;
            invul.Severity = 5;

            pawn = this.launcher as Pawn;
            pawn.health.AddHediff(invul, null, null);

            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_ValiantCharge.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_ValiantCharge_pwr");
            MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_ValiantCharge.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_ValiantCharge_ver");

            if (initialize)
            {
                Initialize(target, pawn);
                pawn.Rotation = pawn.Rotation.Opposite;
            }

            bool flag = arg_40_0 && arg_41_0 && arg_42_0;

            if (flag)
            {
                if (!destinationReached && this.age >= lastMove + moveRate)
                {
                    lastMove = this.age;
                    XProb(target, pawn);
                    if (target.x == pawn.Position.x)
                    {
                        xflag = true;
                    }
                    if (target.z == pawn.Position.z)
                    {
                        zflag = true;
                    }
                    MoteMaker.ThrowDustPuff(newPos, pawn.Map, Rand.Range(0.8f, 1.2f));
                    newPos = GetNewPos(pawn.Position, pawn.Position.x <= target.x, pawn.Position.z <= target.z, false, 0, 0, xProb, 1 - xProb);
                    pawn.SetPositionDirect(newPos);
                    pawn.Rotation = pawn.Rotation.Opposite;
                    pawn.mindState.priorityWork.ClearPrioritizedWorkAndJobQueue();

                    if (xflag && zflag)
                    {
                        destinationReached = true;
                    }
                }
                DrawWings(pawn, 10);
            }
            else
            {
                // Log.Message("arg_40_0:" + arg_40_0 + " arg_41_0:" + arg_41_0 + " arg_42_0:" + arg_42_0);
                Messages.Message("InvalidTargetLocation".Translate(), MessageTypeDefOf.RejectInput);
                destinationReached = true;
            }

            if (destinationReached)
            {
                zflag = false;
                xflag = false;
                SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                this.FireExplosion(pwr.level, ver.level, centerCell, map, 1.2f + (float)(ver.level * .8f));
                MoteMaker.ThrowSmoke(pawn.Position.ToVector3(), map, 0.8f + (float)(ver.level * .8f));

                pawn.mindState.priorityWork.ClearPrioritizedWorkAndJobQueue();
                pawn.Map.pawnDestinationReservationManager.ReleaseAllClaimedBy(pawn);
                pawn.Map.physicalInteractionReservationManager.ReleaseAllClaimedBy(pawn);
                //pawn.Map.pawnDestinationManager.UnreserveAllFor(pawn);
                pawn.jobs.StopAll();
                RemoveInvul(pawn);

                for (int i = 0; i < (2 + ver.level); i++)
                {
                    expCell1 = GetNewPos(expCell1, originPos.x <= target.x, originPos.z <= target.z, false, 0, 0, xProbOrigin, 1 - xProbOrigin);
                    MoteMaker.ThrowSmoke(expCell1.ToVector3(), map, 1.6f);
                    expCell2 = GetNewPos(expCell2, originPos.x <= target.x, originPos.z <= target.z, false, 0, 0, 1 - xProbOrigin, xProbOrigin);
                    MoteMaker.ThrowSmoke(expCell2.ToVector3(), map, 1.6f);
                }
                for (int i = 0; i < (4 + (3 * ver.level)); i++)
                {
                    cellRect = CellRect.CenteredOn(expCell1, 1 + ver.level);
                    IntVec3 randomCell = cellRect.RandomCell;
                    this.FireExplosion(pwr.level, ver.level, randomCell, map, .4f);
                    cellRect   = CellRect.CenteredOn(expCell2, 1 + ver.level);
                    randomCell = cellRect.RandomCell;
                    this.FireExplosion(pwr.level, ver.level, randomCell, map, .4f);
                }
            }
        }
Esempio n. 22
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            //GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            //base.Impact(hitThing);

            if (!initialized)
            {
                SpawnThings spawnThing = new SpawnThings();
                pawn = this.launcher as Pawn;
                comp = pawn.GetComp <CompAbilityUserMagic>();
                MagicPowerSkill        pwr         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonMinion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonMinion_pwr");
                MagicPowerSkill        ver         = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_SummonMinion.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_SummonMinion_ver");
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                pwrVal = pwr.level;
                verVal = ver.level;
                if (settingsRef.AIHardMode && !pawn.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }
                if (pawn.story.traits.HasTrait(TorannMagicDefOf.TM_Wanderer) || (comp.customClass != null && comp.customClass.classMageAbilities.Contains(TorannMagicDefOf.TM_Cantrips)))
                {
                    int tmpPwrVal = (int)((pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_pwr").level) / 5);
                    pwrVal = (tmpPwrVal > pwrVal) ? tmpPwrVal : pwrVal;
                    int tmpVerVal = (int)((pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_ver").level) / 5);
                    verVal = (tmpVerVal > verVal) ? tmpVerVal : verVal;
                }
                CellRect cellRect = CellRect.CenteredOn(this.Position, 1);
                cellRect.ClipInsideMap(map);

                IntVec3       centerCell = cellRect.CenterCell;
                System.Random random     = new System.Random();
                random = new System.Random();

                duration += (verVal * durationMultiplier);
                duration  = (int)(duration * comp.arcaneDmg);

                spawnThing.factionDef = TorannMagicDefOf.TM_SummonedFaction;
                spawnThing.spawnCount = 1;
                spawnThing.temporary  = false;

                if (pwrVal >= 2)
                {
                    for (int i = 0; i < pwrVal - 1; i++)
                    {
                        spawnThing.def     = TorannMagicDefOf.TM_GreaterMinionR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_GreaterMinion");
                        SingleSpawnLoop(spawnThing, centerCell, map);
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 2 + pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    MoteMaker.ThrowHeatGlow(centerCell, map, 2 + pwrVal);
                }
                else
                {
                    for (int i = 0; i < pwrVal + 1; i++)
                    {
                        spawnThing.def     = TorannMagicDefOf.TM_MinionR;
                        spawnThing.kindDef = PawnKindDef.Named("TM_Minion");

                        SingleSpawnLoop(spawnThing, centerCell, map);
                    }
                    MoteMaker.ThrowSmoke(centerCell.ToVector3(), map, 1 + pwrVal);
                    MoteMaker.ThrowMicroSparks(centerCell.ToVector3(), map);
                    MoteMaker.ThrowHeatGlow(centerCell, map, 1 + pwrVal);
                }

                SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                this.initialized = true;
            }
            else
            {
                this.age = this.duration;
            }
            Destroy();
        }
        private void SpawnTrigger(CellRect rectToDefend, IntVec3 root, Map map)
        {
            int                 nextSignalTagID     = Find.UniqueIDsManager.GetNextSignalTagID();
            string              signalTag           = "ambushActivated-" + nextSignalTagID;
            CellRect            rect                = (!root.IsValid) ? rectToDefend.ExpandedBy(12) : CellRect.CenteredOn(root, 17);
            SignalAction_Ambush signalAction_Ambush = this.MakeAmbushSignalAction(rectToDefend, root);

            signalAction_Ambush.signalTag = signalTag;
            GenSpawn.Spawn(signalAction_Ambush, rect.CenterCell, map);
            RectTrigger rectTrigger = this.MakeRectTrigger();

            rectTrigger.signalTag = signalTag;
            rectTrigger.Rect      = rect;
            GenSpawn.Spawn(rectTrigger, rect.CenterCell, map);
        }
Esempio n. 24
0
        public override void Impact_Override(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact_Override(hitThing);

            Pawn pawn = this.launcher as Pawn;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningBolt.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningBolt_pwr");
            MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningBolt.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningBolt_ver");

            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
            pwrVal         = pwr.level;
            verVal         = ver.level;
            this.arcaneDmg = comp.arcaneDmg;
            if (settingsRef.AIHardMode && !pawn.IsColonistPlayerControlled)
            {
                pwrVal = 3;
                verVal = 3;
            }
            bool flag = hitThing != null;

            if (flag)
            {
                int        damageAmountBase = Mathf.RoundToInt(this.def.projectile.damageAmountBase + (pwrVal * 9) * this.arcaneDmg);
                DamageInfo dinfo            = new DamageInfo(this.def.projectile.damageDef, damageAmountBase, this.ExactRotation.eulerAngles.y, this.launcher, null, this.equipmentDef, DamageInfo.SourceCategory.ThingOrUnknown);
                hitThing.TakeDamage(dinfo);

                bool flag2 = this.canStartFire && Rand.Range(0f, 1f) > this.startFireChance;
                if (flag2)
                {
                    hitThing.TryAttachFire(0.05f);
                }
                Pawn hitTarget;
                bool flag3 = (hitTarget = (hitThing as Pawn)) != null;
                if (flag3)
                {
                    this.PostImpactEffects(this.launcher as Pawn, hitTarget);
                    MoteMaker.ThrowMicroSparks(this.destination, base.Map);
                    MoteMaker.MakeStaticMote(this.destination, base.Map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                }
            }
            else
            {
                MoteMaker.MakeStaticMote(this.ExactPosition, base.Map, ThingDefOf.Mote_ShotHit_Dirt, 1f);
                MoteMaker.ThrowMicroSparks(this.ExactPosition, base.Map);
            }
            for (int i = 0; i <= verVal; i++)
            {
                SoundInfo info = SoundInfo.InMap(new TargetInfo(base.Position, base.Map, false), MaintenanceType.None);
                SoundDefOf.Thunder_OnMap.PlayOneShot(info);
            }
            CellRect cellRect = CellRect.CenteredOn(hitThing.Position, 2);

            cellRect.ClipInsideMap(map);
            for (int i = 0; i < Rand.Range(verVal, verVal * 4); i++)
            {
                IntVec3 randomCell = cellRect.RandomCell;
                this.StaticExplosion(randomCell, map, 0.4f);
            }
        }
Esempio n. 25
0
        private static bool IsSafeDropSpot(IntVec3 cell, Map map, Faction faction, IntVec2?size = null, int distToEdge = 25, int distToHostiles = 35, int distToFires = 15)
        {
            Faction factionBaseFaction = map.ParentFaction ?? Faction.OfPlayer;

            if (size.HasValue)
            {
                foreach (IntVec3 item in GenAdj.OccupiedRect(cell, Rot4.North, size.Value))
                {
                    if (!IsGoodDropSpot(item, map, allowFogged: false, canRoofPunch: false, allowIndoors: false))
                    {
                        return(false);
                    }
                }
            }
            else if (!IsGoodDropSpot(cell, map, allowFogged: false, canRoofPunch: false, allowIndoors: false))
            {
                return(false);
            }
            if (distToEdge > 0 && cell.CloseToEdge(map, distToEdge))
            {
                return(false);
            }
            if (faction != null)
            {
                foreach (IAttackTarget item2 in map.attackTargetsCache.TargetsHostileToFaction(faction))
                {
                    if (!item2.ThreatDisabled(null) && item2.Thing.Position.InHorDistOf(cell, distToHostiles))
                    {
                        return(false);
                    }
                }
            }
            if (!map.reachability.CanReachFactionBase(cell, factionBaseFaction))
            {
                return(false);
            }
            if (size.HasValue)
            {
                foreach (IntVec3 cell2 in CellRect.CenteredOn(cell, size.Value.x, size.Value.z).Cells)
                {
                    if (CellHasCrops(cell2))
                    {
                        return(false);
                    }
                }
            }
            else if (CellHasCrops(cell))
            {
                return(false);
            }
            float minDistToFiresSq = distToFires * distToFires;
            float closestDistSq    = float.MaxValue;
            int   firesCount       = 0;

            RegionTraverser.BreadthFirstTraverse(cell, map, (Region from, Region to) => true, delegate(Region x)
            {
                List <Thing> list = x.ListerThings.ThingsInGroup(ThingRequestGroup.Fire);
                for (int i = 0; i < list.Count; i++)
                {
                    float num = cell.DistanceToSquared(list[i].Position);
                    if (!(num > minDistToFiresSq))
                    {
                        if (num < closestDistSq)
                        {
                            closestDistSq = num;
                        }
                        firesCount++;
                    }
                }
                return(closestDistSq <= minDistToFiresSq && firesCount >= 5);
            }, 15);
            if (closestDistSq <= minDistToFiresSq && firesCount >= 5)
            {
                return(false);
            }
            return(true);

            bool CellHasCrops(IntVec3 c)
            {
                Plant plant = c.GetPlant(map);

                if (plant != null && plant.sown)
                {
                    return(map.zoneManager.ZoneAt(c) is Zone_Growing);
                }
                return(false);
            }
        }
Esempio n. 26
0
        public override void Tick()
        {
            base.Tick();
            age++;
            if (this.ticksToImpact >= 0)
            {
                DrawEffects(this.ExactPosition, base.Map);
            }
            this.ticksToImpact--;
            this.ticksFollowingImpact--;
            base.Position = this.ExactPosition.ToIntVec3();
            bool flag = !this.ExactPosition.InBounds(base.Map);

            if (flag)
            {
                this.ticksToImpact++;
                this.Destroy(DestroyMode.Vanish);
            }
            else
            {
                bool flag2 = this.ticksToImpact <= 0 && !impacted;
                if (flag2)
                {
                    bool flag3 = this.DestinationCell.InBounds(base.Map);
                    if (flag3)
                    {
                        base.Position = this.DestinationCell;
                    }
                    this.ImpactSomething();
                }
            }

            if (this.impacted)
            {
                if (this.ticksFollowingImpact > 0 && Find.TickManager.TicksGame % 5 == 0)
                {
                    CellRect cellRect = CellRect.CenteredOn(base.Position, 2);
                    cellRect.ClipInsideMap(base.Map);
                    IntVec3 spreadingDarknessCell;
                    if (!(cellRect.CenterCell.GetTerrain(base.Map).passability == Traversability.Impassable) && !cellRect.CenterCell.IsValid || !cellRect.CenterCell.InBounds(base.Map))
                    {
                        this.ticksFollowingImpact = -1;
                    }
                    for (int i = 0; i < 2; i++)
                    {
                        spreadingDarknessCell = cellRect.RandomCell;
                        if (spreadingDarknessCell.IsValid && spreadingDarknessCell.InBounds(base.Map))
                        {
                            GenExplosion.DoExplosion(spreadingDarknessCell, base.Map, .4f, TMDamageDefOf.DamageDefOf.TM_DeathBolt, this.pawn, Mathf.RoundToInt((Rand.Range(.4f * this.def.projectile.GetDamageAmount(1, null), .8f * this.def.projectile.GetDamageAmount(1, null)) + (3f * pwrVal)) * this.arcaneDmg), 2, this.def.projectile.soundExplode, def, null, null, null, 0f, 1, false, null, 0f, 0, 0.0f, true);
                            TM_MoteMaker.ThrowDiseaseMote(base.Position.ToVector3Shifted(), base.Map, .6f);
                            if (powered)
                            {
                                TM_MoteMaker.ThrowBoltMote(base.Position.ToVector3Shifted(), base.Map, 0.3f);
                            }
                        }
                    }
                }

                if (this.ticksFollowingImpact < 0)
                {
                    this.Destroy(DestroyMode.Vanish);
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def    = this.def;
            Pawn     victim = hitThing as Pawn;

            Pawn pawn = this.launcher as Pawn;

            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();

            if (pawn.story.traits.HasTrait(TorannMagicDefOf.Faceless))
            {
                MightPowerSkill mpwr = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                MightPowerSkill mver = pawn.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                pwrVal         = mpwr.level;
                verVal         = mver.level;
                this.arcaneDmg = pawn.GetComp <CompAbilityUserMight>().mightPwr;
            }
            else
            {
                CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
                pwr            = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningCloud.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningCloud_pwr");
                ver            = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningCloud.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningCloud_ver");
                pwrVal         = pwr.level;
                verVal         = ver.level;
                this.arcaneDmg = comp.arcaneDmg;
            }

            if (settingsRef.AIHardMode && !pawn.IsColonist)
            {
                pwrVal = 3;
                verVal = 3;
            }
            radius = (int)this.def.projectile.explosionRadius + (1 * verVal);

            CellRect cellRect = CellRect.CenteredOn(base.Position, radius - 3);

            cellRect.ClipInsideMap(map);
            IntVec3 randomCell = cellRect.RandomCell;

            duration = 900 + (verVal * 120);

            if (this.primed == true)
            {
                if ((this.shockDelay + this.lastStrike) < this.age)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        randomCell = cellRect.RandomCell;
                        if (randomCell.InBounds(map))
                        {
                            victim = randomCell.GetFirstPawn(map);
                            if (victim != null)
                            {
                                if (Rand.Chance(TM_Calc.GetSpellSuccessChance(pawn, victim) - .3f))
                                {
                                    damageEntities(victim, Mathf.RoundToInt((this.def.projectile.GetDamageAmount(1, null) + pwrVal) * this.arcaneDmg));
                                }
                            }
                        }
                    }

                    Vector3 loc2 = base.Position.ToVector3Shifted();
                    Vector3 loc  = randomCell.ToVector3Shifted();

                    bool rand1 = Rand.Range(0, 100) < 3;
                    bool rand2 = Rand.Range(0, 100) < 16;
                    if (rand1)
                    {
                        MoteMaker.ThrowSmoke(loc2, map, radius);
                        SoundDefOf.Ambient_AltitudeWind.sustainFadeoutTime.Equals(30.0f);
                    }
                    if (rand2)
                    {
                        MoteMaker.ThrowSmoke(loc, map, 4f);
                    }

                    MoteMaker.ThrowMicroSparks(loc, map);
                    MoteMaker.ThrowLightningGlow(loc, map, 2f);

                    strikeInt++;
                    this.lastStrike = this.age;
                    this.shockDelay = Rand.Range(1, 5);

                    bool flag1 = this.age <= duration;
                    if (!flag1)
                    {
                        this.primed = false;
                    }
                }
            }
        }
Esempio n. 28
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            base.Impact(hitThing);
            ThingDef def    = this.def;
            Pawn     victim = hitThing as Pawn;

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

            pwr = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningCloud.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningCloud_pwr");
            ver = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_LightningCloud.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_LightningCloud_ver");
            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
            pwrVal = pwr.level;
            verVal = ver.level;
            if (settingsRef.AIHardMode && !pawn.IsColonistPlayerControlled)
            {
                pwrVal = 3;
                verVal = 3;
            }
            radius = (int)this.def.projectile.explosionRadius + (2 * verVal);

            CellRect cellRect = CellRect.CenteredOn(base.Position, radius - 3);

            cellRect.ClipInsideMap(map);
            IntVec3 randomCell = cellRect.RandomCell;

            duration = 900 + (verVal * 360);

            if (this.primed == true)
            {
                if (((this.shockDelay + this.lastStrike) < this.age))
                {
                    for (int i = 0; i < 5; i++)
                    {
                        randomCell = cellRect.RandomCell;
                        if (randomCell.InBounds(map))
                        {
                            victim = randomCell.GetFirstPawn(map);
                            if (victim != null)
                            {
                                damageEntities(victim, this.def.projectile.damageAmountBase + pwrVal);
                            }
                        }
                    }

                    Vector3 loc2 = base.Position.ToVector3Shifted();
                    Vector3 loc  = randomCell.ToVector3Shifted();

                    bool rand1 = Rand.Range(0, 100) < 3;
                    bool rand2 = Rand.Range(0, 100) < 16;
                    if (rand1)
                    {
                        MoteMaker.ThrowSmoke(loc2, map, radius);
                        SoundDefOf.AmbientAltitudeWind.sustainFadeoutTime.Equals(30.0f);
                    }
                    if (rand2)
                    {
                        MoteMaker.ThrowSmoke(loc, map, 4f);
                    }

                    MoteMaker.ThrowMicroSparks(loc, map);
                    MoteMaker.ThrowLightningGlow(loc, map, 2f);

                    strikeInt++;
                    this.lastStrike = this.age;
                    this.shockDelay = Rand.Range(1, 3);

                    bool flag1 = this.age <= duration;
                    if (!flag1)
                    {
                        this.primed = false;
                    }
                }
            }
        }
Esempio n. 29
0
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            //base.Impact(hitThing);
            string   msg;
            ThingDef def    = this.def;
            Pawn     victim = hitThing as Pawn;
            Thing    item   = hitThing as Thing;
            IntVec3  arg_pos_1;
            IntVec3  arg_pos_2;
            IntVec3  arg_pos_3;

            Pawn pawn = this.launcher as Pawn;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = comp.MagicData.MagicPowerSkill_Teleport.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Teleport_pwr");
            MagicPowerSkill      ver  = comp.MagicData.MagicPowerSkill_Teleport.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Teleport_ver");

            pwrVal = pwr.level;
            verVal = ver.level;
            CellRect cellRect = CellRect.CenteredOn(base.Position, 1);

            cellRect.ClipInsideMap(map);
            IntVec3 centerCell = cellRect.CenterCell;

            if (pawn.story.traits.HasTrait(TorannMagicDefOf.TM_Wanderer) || (comp.customClass != null && comp.customClass.classMageAbilities.Contains(TorannMagicDefOf.TM_Cantrips)))
            {
                int tmpPwrVal = (int)((pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_pwr").level) / 5);
                int tmpVerVal = (int)((pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_ver").level) / 5);
                pwrVal = (tmpPwrVal > pwrVal) ? tmpPwrVal : pwrVal;
                verVal = (tmpVerVal > verVal) ? tmpVerVal : verVal;
            }
            if (this.primed != false)
            {
                destructTimer = Mathf.RoundToInt((4800 + (pwrVal * 1200) + (pwrVal * 1200)) * comp.arcaneDmg);
                arg_pos_1     = centerCell;
                centerCell.x++;
                arg_pos_2 = centerCell;
                centerCell.z++;
                arg_pos_3  = centerCell;
                centerCell = cellRect.CenterCell;

                if ((arg_pos_1.IsValid && arg_pos_1.Standable(map)) && (arg_pos_2.IsValid && arg_pos_2.Standable(map)) && (arg_pos_3.IsValid && arg_pos_3.Standable(map)))
                {
                    AbilityUser.SpawnThings tempPod = new SpawnThings();
                    IntVec3 shiftPos = centerCell;
                    centerCell.x++;

                    if (pwrVal == 1)
                    {
                        tempPod.def = ThingDef.Named("TM_Teleporter_I");
                    }
                    else if (pwrVal == 2)
                    {
                        tempPod.def = ThingDef.Named("TM_Teleporter_II");
                    }
                    else if (pwrVal == 3)
                    {
                        tempPod.def = ThingDef.Named("TM_Teleporter_III");
                    }
                    else
                    {
                        tempPod.def = ThingDef.Named("TM_Teleporter");
                    }
                    tempPod.spawnCount = 1;
                    try
                    {
                        this.SingleSpawnLoop(tempPod, shiftPos, map);
                        Building teleporter = shiftPos.GetFirstBuilding(map);
                        int      num        = teleporter.TryGetComp <CompRefuelable>().GetFuelCountToFullyRefuel();
                        teleporter.TryGetComp <CompRefuelable>().Refuel(num);
                    }
                    catch
                    {
                        Log.Message("Attempted to create a portal but threw an unknown exception - recovering and ending attempt");
                        PortalCollapse(shiftPos, map, 3);
                        if (pawn != null)
                        {
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_Teleport);
                        }
                        this.age = this.destructTimer;
                        return;
                    }


                    if (verVal == 1)
                    {
                        tempPod.def = ThingDef.Named("TM_TeleportPod_I");
                    }
                    else if (verVal == 2)
                    {
                        tempPod.def = ThingDef.Named("TM_TeleportPod_II");
                    }
                    else if (verVal == 3)
                    {
                        tempPod.def = ThingDef.Named("TM_TeleportPod_III");
                    }
                    else
                    {
                        tempPod.def = ThingDef.Named("TM_TeleportPod");
                    }
                    tempPod.spawnCount = 1;
                    shiftPos           = centerCell;
                    centerCell.z++;
                    try
                    {
                        this.SingleSpawnLoop(tempPod, shiftPos, map);
                    }
                    catch
                    {
                        Log.Message("Attempted to create a portal but threw an unknown exception - recovering and ending attempt");
                        PortalCollapse(shiftPos, map, 3);
                        if (pawn != null)
                        {
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_Teleport);
                        }
                        this.age = this.destructTimer;
                        return;
                    }

                    //tempPod.def = ThingDef.Named("Portfuel");
                    //tempPod.spawnCount = 45 + (pwr.level * 15);
                    //tempPod.factionDef = null;
                    //shiftPos = centerCell;

                    //for (int i = 0; i < tempPod.spawnCount; i++)
                    //{
                    //    try
                    //    {
                    //        this.SingleSpawnLoop(tempPod, shiftPos, map);
                    //    }
                    //    catch
                    //    {
                    //        Log.Message("Attempted to create a portal but threw an unknown exception - recovering and ending attempt");
                    //        PortalCollapse(shiftPos, map, 3);
                    //        if (pawn != null)
                    //        {
                    //            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_Teleport);
                    //        }
                    //        this.age = this.destructTimer;
                    //        i = tempPod.spawnCount;
                    //        return;
                    //    }
                    //}

                    msg = "PortalCollapseIn".Translate(((destructTimer - this.age) / 60).ToString()
                                                       );
                    Messages.Message(msg, MessageTypeDefOf.NeutralEvent);
                    this.primed = false;
                }
                else
                {
                    Messages.Message("InvalidPortal".Translate(), MessageTypeDefOf.RejectInput);
                    comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_Teleport));
                    this.destructTimer = 0;
                }
            }
            //foreach (SpawnThings current in this.localSpawnThings)
            //{

            //    string msg = "spawned thing is " + current.def;
            //    Messages.Message(msg, MessageSound.Standard);

            //}

            if (this.age < this.destructTimer)
            {
                if (this.age == (destructTimer * 0.5))
                {
                    msg = "PortalCollapseIn".Translate(
                        ((destructTimer - this.age) / 60).ToString()
                        );
                    Messages.Message(msg, MessageTypeDefOf.NeutralEvent);
                }
                if (this.age == (destructTimer * 0.75))
                {
                    msg = "PortalCollapseIn".Translate(
                        ((destructTimer - this.age) / 60).ToString()
                        );
                    Messages.Message(msg, MessageTypeDefOf.NeutralEvent);
                }
                if (this.age == (destructTimer * 0.95))
                {
                    //msg = "Portal collapses in " + ((destructTimer - this.age) / 60) + " seconds!!";
                    //Messages.Message(msg, MessageTypeDefOf.ThreatBig);
                    msg = "PortalCollapseIn".Translate(
                        ((destructTimer - this.age) / 60).ToString()
                        );
                    Messages.Message(msg, MessageTypeDefOf.NeutralEvent);
                }
            }
            else
            {
                //age expired, destroy teleport
                this.PortalCollapse(centerCell, map, 3);
            }
            Destroy();
        }
Esempio n. 30
0
        protected override bool TryCastShot()
        {
            CompAbilityUserMight comp     = this.CasterPawn.GetComp <CompAbilityUserMight>();
            MightPowerSkill      ver      = comp.MightData.MightPowerSkill_SeismicSlash.FirstOrDefault((MightPowerSkill x) => x.label == "TM_SeismicSlash_ver");
            CellRect             cellRect = CellRect.CenteredOn(base.CasterPawn.Position, 1);
            Map map = base.CasterPawn.Map;

            cellRect.ClipInsideMap(map);

            IntVec3 centerCell = cellRect.CenterCell;

            this.origin        = base.CasterPawn.Position.ToVector3();
            this.destination   = this.currentTarget.Cell.ToVector3Shifted();
            this.ticksToImpact = Mathf.RoundToInt((this.origin - this.destination).magnitude);

            if (this.CasterPawn.equipment.Primary != null && !this.CasterPawn.equipment.Primary.def.IsRangedWeapon)
            {
                int dmgNum = GetWeaponDmg(this.CasterPawn);
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                if (!this.CasterPawn.IsColonist && settingsRef.AIHardMode)
                {
                    dmgNum += 10;
                }

                Vector3 strikeVec = this.origin;
                DrawBlade(strikeVec, 0);
                for (int i = 0; i < this.StartingTicksToImpact; i++)
                {
                    strikeVec = this.ExactPosition;
                    Pawn victim = strikeVec.ToIntVec3().GetFirstPawn(map);
                    if (victim != null && victim.Faction != base.CasterPawn.Faction)
                    {
                        DrawStrike(strikeVec.ToIntVec3(), strikeVec, map);
                        damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                    }
                    MoteMaker.ThrowTornadoDustPuff(strikeVec, map, .6f, Color.white);
                    for (int j = 0; j < 2 + (2 * verVal); j++)
                    {
                        IntVec3 searchCell = strikeVec.ToIntVec3() + GenAdj.AdjacentCells8WayRandomized()[j];
                        MoteMaker.ThrowTornadoDustPuff(searchCell.ToVector3(), map, .1f, Color.gray);
                        victim = searchCell.GetFirstPawn(map);
                        if (victim != null && victim.Faction != base.CasterPawn.Faction)
                        {
                            DrawStrike(searchCell, searchCell.ToVector3(), map);
                            damageEntities(victim, null, dmgNum, DamageDefOf.Cut);
                        }
                    }
                    this.ticksToImpact--;
                }
            }
            else
            {
                Messages.Message("MustHaveMeleeWeapon".Translate(new object[]
                {
                    this.CasterPawn.LabelCap
                }), MessageTypeDefOf.RejectInput);
                return(false);
            }

            this.burstShotsLeft = 0;
            this.PostCastShot(flag10, out flag10);
            return(flag10);
        }