예제 #1
0
        protected override void Impact(Thing hitThing)
        {
            Pawn caster = this.launcher as Pawn;
            CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();
            Map map = base.Map;

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

            GenExplosion.DoExplosion(base.Position, map, this.def.projectile.explosionRadius, this.def.projectile.damageDef, this.launcher, (int)(this.def.projectile.GetDamageAmount(1, null) * comp.arcaneDmg), 0, SoundDefOf.Artillery_ShellLoaded, def, this.equipmentDef, null, null, 0f, 1, false, null, 0f, 1, 0f, true);
            if (caster != null && comp != null)
            {
                if (comp.MagicData?.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_ver").level >= 14)
                {
                    List <Pawn> allPawns = TM_Calc.FindAllPawnsAround(map, base.Position, this.def.projectile.explosionRadius);
                    if (allPawns != null && allPawns.Count > 0)
                    {
                        for (int i = 0; i < allPawns.Count; i++)
                        {
                            Pawn e = allPawns[i];
                            if (TM_Calc.IsRobotPawn(e) && Rand.Chance(.4f))
                            {
                                float rnd = Rand.Range(0f, 1f);
                                TM_Action.DoAction_SabotagePawn(e, caster, rnd, 0, 1f, this.launcher);
                            }
                        }
                    }
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            Pawn caster = this.launcher as Pawn;

            if (!this.initialized)
            {
                ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                CompAbilityUserMagic   comp        = caster.GetComp <CompAbilityUserMagic>();

                pwrVal = comp.MagicData.MagicPowerSkill_Sabotage.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Sabotage_pwr").level;
                verVal = comp.MagicData.MagicPowerSkill_Sabotage.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Sabotage_ver").level;
                if (caster.story.traits.HasTrait(TorannMagicDefOf.Faceless))
                {
                    MightPowerSkill mpwr = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_pwr");
                    MightPowerSkill mver = caster.GetComp <CompAbilityUserMight>().MightData.MightPowerSkill_Mimic.FirstOrDefault((MightPowerSkill x) => x.label == "TM_Mimic_ver");
                    pwrVal = mpwr.level;
                    verVal = mver.level;
                }
                this.arcaneDmg = comp.arcaneDmg;
                if (settingsRef.AIHardMode && !caster.IsColonist)
                {
                    pwrVal = 3;
                    verVal = 3;
                }
                SoundInfo info = SoundInfo.InMap(new TargetInfo(base.Position, this.Map, false), MaintenanceType.None);
                info.pitchFactor  = .5f;
                info.volumeFactor = .8f;
                SoundDefOf.PsychicPulseGlobal.PlayOneShot(info);
                Effecter SabotageEffect = TorannMagicDefOf.TM_SabotageExplosion.Spawn();
                SabotageEffect.Trigger(new TargetInfo(base.Position, this.Map, false), new TargetInfo(base.Position, this.Map, false));
                SabotageEffect.Cleanup();
                targetCells       = GenRadial.RadialCellsAround(base.Position, this.def.projectile.explosionRadius, true).ToList();
                this.targetThings = new List <SabotageThing>();
                this.targetThings.Clear();
                this.initialized = true;

                Pawn     targetPawn     = null;
                Building targetBuilding = null;

                for (int i = 0; i < this.targetCells.Count; i++)
                {
                    var targetCell = this.targetCells[i];
                    if (Rand.Chance((.5f + (.1f * verVal)) * this.arcaneDmg))
                    {
                        float rnd = Rand.Range(0, 1f);
                        targetPawn = targetCell.GetFirstPawn(this.Map);
                        if (targetPawn != null)
                        {
                            if (TM_Calc.IsRobotPawn(targetPawn))
                            {
                                TM_Action.DoAction_SabotagePawn(targetPawn, caster, rnd, pwrVal, this.arcaneDmg, this.launcher);
                                this.age = this.duration;
                            }
                            else
                            {
                                targetPawn = null;
                                //Log.Message("pawn not a robot, mechanoid, or android");
                            }
                        }

                        targetBuilding = targetCell.GetFirstBuilding(this.Map);
                        if (targetPawn == null && targetBuilding != null)
                        {
                            CompPower       compP = targetBuilding.GetComp <CompPower>();
                            CompPowerTrader cpt   = targetBuilding.GetComp <CompPowerTrader>();
                            if (compP != null && compP.Props.basePowerConsumption != 0 && cpt != null && cpt.powerOutputInt != 0)
                            {
                                if (true)
                                {
                                    //stun/electrical explosion
                                    GenExplosion.DoExplosion(targetBuilding.Position, base.Map, 2 + pwrVal + Mathf.RoundToInt(cpt.powerOutputInt / 400), DamageDefOf.Stun, null);
                                    GenExplosion.DoExplosion(targetBuilding.Position, base.Map, 1 + pwrVal + Mathf.RoundToInt(cpt.powerOutputInt / 600), TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, null);
                                }
                                else
                                {
                                }
                            }

                            Building_Battery targetBattery = targetBuilding as Building_Battery;
                            if (targetBattery != null && targetBattery.def.thingClass.ToString() == "RimWorld.Building_Battery")
                            {
                                CompPowerBattery compB = targetBattery.GetComp <CompPowerBattery>();
                                if (rnd <= .5f)
                                {
                                    Traverse.Create(root: targetBattery).Field(name: "ticksToExplode").SetValue(Rand.Range(40, 130) - (5 * pwrVal));
                                    compB.SetStoredEnergyPct(.81f);
                                }
                                else
                                {
                                    GenExplosion.DoExplosion(targetBattery.Position, base.Map, 2 + pwrVal + Mathf.RoundToInt(compB.StoredEnergy / 200), DamageDefOf.EMP, null);
                                    compB.DrawPower(compB.StoredEnergy);
                                }
                            }

                            Building_TurretGun targetTurret = targetBuilding as Building_TurretGun;
                            if (targetTurret != null && targetTurret.gun != null)
                            {
                                if (rnd <= .5f)
                                {
                                    targetTurret.SetFaction(Faction.OfAncientsHostile, null);
                                }
                                else
                                {
                                    GenExplosion.DoExplosion(targetTurret.Position, base.Map, 2 + pwrVal, TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, null); //20 default damage
                                }
                            }
                        }
                        else
                        {
                            //Log.Message("no thing to sabotage");
                        }
                        targetPawn     = null;
                        targetBuilding = null;
                    }
                }
            }
            else if (this.targetThings.Count > 0)
            {
                this.age = this.duration;
            }
            else
            {
                this.age = this.duration;
            }
        }