Exemple #1
0
        protected override void Impact(Thing hitThing)
        {
            Map  map  = this.launcher.Map;
            Pawn pawn = this.launcher as Pawn;

            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            MagicPowerSkill      pwr  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_pwr");
            MagicPowerSkill      ver  = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_ver");

            effVal = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_TechnoTurret.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_TechnoTurret_eff").level;
            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;
            }

            if ((pawn.Position.IsValid && pawn.Position.Standable(map)))
            {
                AbilityUser.SpawnThings tempPod = new SpawnThings();
                IntVec3 shiftPos = pawn.Position;

                tempPod.def = ThingDef.Named("TM_TechnoTurret_Base");
                Thing turretGun = new Thing();
                turretGun.def = ThingDef.Named("Gun_Mark-IV");
                if (this.verVal >= 5)
                {
                    tempPod.def   = ThingDef.Named("TM_TechnoTurret_Base_RL");
                    turretGun.def = ThingDef.Named("Gun_Mark-IV_RL");
                }
                if (this.verVal >= 10)
                {
                    tempPod.def   = ThingDef.Named("TM_TechnoTurret_Base_RL_MTR");
                    turretGun.def = ThingDef.Named("Gun_Mark-IV_RL_MTR");
                }

                turretGun.def.SetStatBaseValue(StatDefOf.AccuracyTouch, 0.8f + (.01f * pwrVal));
                turretGun.def.SetStatBaseValue(StatDefOf.AccuracyShort, 0.75f + (.01f * pwrVal));
                turretGun.def.SetStatBaseValue(StatDefOf.AccuracyMedium, 0.65f + (.01f * pwrVal));
                turretGun.def.SetStatBaseValue(StatDefOf.AccuracyLong, 0.35f + (.01f * pwrVal));
                turretGun.def.Verbs.FirstOrDefault().burstShotCount = Mathf.RoundToInt(6 + (.4f * pwrVal));
                turretGun.def.Verbs.FirstOrDefault().warmupTime     = 1.5f - (.03f * pwrVal);
                turretGun.def.Verbs.FirstOrDefault().range          = 35 + verVal;

                tempPod.def.building.turretGunDef = turretGun.def;

                tempPod.def.SetStatBaseValue(StatDefOf.MaxHitPoints, 200 + (10 * effVal));
                tempPod.spawnCount = 1;
                try
                {
                    this.turret = TM_Action.SingleSpawnLoop(pawn, tempPod, base.Position, map, 6000, true);
                    this.turret.def.building.turretBurstCooldownTime = 4.5f - (.1f * pwrVal);

                    for (int i = 0; i < 4; i++)
                    {
                        Vector3 rndPos = this.DrawPos;
                        rndPos.x += Rand.Range(-.5f, .5f);
                        rndPos.z += Rand.Range(-.5f, .5f);
                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SparkFlash"), rndPos, this.Map, Rand.Range(.6f, .8f), .1f, .05f, .05f, 0, 0, 0, Rand.Range(0, 360));
                        MoteMaker.ThrowSmoke(rndPos, this.Map, Rand.Range(.8f, 1.2f));
                        rndPos    = this.DrawPos;
                        rndPos.x += Rand.Range(-.5f, .5f);
                        rndPos.z += Rand.Range(-.5f, .5f);
                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_ElectricalSpark"), rndPos, this.Map, Rand.Range(.4f, .7f), .2f, .05f, .1f, 0, 0, 0, Rand.Range(0, 360));
                    }
                }
                catch
                {
                    comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonPylon);
                    Log.Message("TM_Exception".Translate(
                                    pawn.LabelShort,
                                    "techno turret"
                                    ));
                }
            }
            else
            {
                Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_TechnoTurret));
            }


            if ((turret != null && turret.Spawned && turret.Position.IsValid))
            {
                turret.def.interactionCellOffset = (this.launcher.Position - base.Position);
                Job job = new Job(JobDefOf.ManTurret, turret);
                pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                //this.Ability.PostAbilityAttempt();
            }
            else
            {
                Log.Message("turret was null");
            }
            base.Impact(hitThing);
        }
        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;

            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;
        }
Exemple #3
0
        public static void Evaluate(CompAbilityUserMagic casterComp, TMAbilityDef abilitydef, PawnAbility ability, MagicPower power, float minDistance, out bool success)
        {
            success = false;
            Pawn            caster       = casterComp.Pawn;
            LocalTargetInfo jobTarget    = caster.CurJob.targetA;
            Thing           carriedThing = null;

            if (caster.CurJob.targetA.Thing != null)               //&& caster.CurJob.def.defName != "Sow")
            {
                if (caster.CurJob.targetA.Thing.Map != caster.Map) //carrying thing
                {
                    jobTarget    = caster.CurJob.targetB;
                    carriedThing = caster.CurJob.targetA.Thing;
                }
                else if (caster.CurJob.targetB != null && caster.CurJob.targetB.Thing != null && caster.CurJob.def != JobDefOf.Rescue) //targetA using targetB for job
                {
                    if (caster.CurJob.targetB.Thing.Map != caster.Map)                                                                 //carrying targetB to targetA
                    {
                        jobTarget    = caster.CurJob.targetA;
                        carriedThing = caster.CurJob.targetB.Thing;
                    }
                    else if (caster.CurJob.def == JobDefOf.TendPatient)
                    {
                        jobTarget = caster.CurJob.targetB;
                    }
                    else //Getting targetA to carry to TargetB
                    {
                        jobTarget = caster.CurJob.targetA;
                    }
                }
                else
                {
                    jobTarget = caster.CurJob.targetA;
                }
            }
            float   distanceToTarget  = (jobTarget.Cell - caster.Position).LengthHorizontal;
            Vector3 directionToTarget = TM_Calc.GetVector(caster.Position, jobTarget.Cell);

            //Log.Message("" + caster.LabelShort + " job def is " + caster.CurJob.def.defName + " targetA " + caster.CurJob.targetA + " targetB " + caster.CurJob.targetB + " jobTarget " + jobTarget + " at distance " + distanceToTarget + " min distance " + minDistance + " at vector " + directionToTarget);
            if (casterComp.Mana.CurLevel >= casterComp.ActualManaCost(abilitydef) && ability.CooldownTicksLeft <= 0 && distanceToTarget < 200)
            {
                if (distanceToTarget > minDistance && caster.CurJob.locomotionUrgency >= LocomotionUrgency.Jog && caster.CurJob.bill == null)
                {
                    if (distanceToTarget <= abilitydef.MainVerb.range && jobTarget.Cell != default(IntVec3))
                    {
                        //Log.Message("doing blink to thing");
                        DoBlink(caster, jobTarget.Cell, ability, carriedThing);
                        success = true;
                    }
                    else
                    {
                        IntVec3 blinkToCell = caster.Position + (directionToTarget * abilitydef.MainVerb.range).ToIntVec3();
                        //Log.Message("doing partial blink to cell " + blinkToCell);
                        //MoteMaker.ThrowHeatGlow(blinkToCell, caster.Map, 1f);
                        if (blinkToCell.IsValid && blinkToCell.InBounds(caster.Map) && blinkToCell.Walkable(caster.Map) && !blinkToCell.Fogged(caster.Map) && ((blinkToCell - caster.Position).LengthHorizontal < distanceToTarget))
                        {
                            DoBlink(caster, blinkToCell, ability, carriedThing);
                            success = true;
                        }
                    }
                }
            }
        }
        protected override bool TryCastShot()
        {
            Pawn    caster            = base.CasterPawn;
            Map     map               = caster.Map;
            IntVec3 cell              = currentTarget.Cell;
            CompAbilityUserMagic comp = caster.TryGetComp <CompAbilityUserMagic>();

            pwrVal = TM_Calc.GetMagicSkillLevel(caster, comp.MagicData.MagicPowerSkill_GuardianSpirit, "TM_GuardianSpirit", "_pwr", true);
            verVal = TM_Calc.GetMagicSkillLevel(caster, comp.MagicData.MagicPowerSkill_GuardianSpirit, "TM_GuardianSpirit", "_ver", true);
            effVal = TM_Calc.GetMagicSkillLevel(caster, comp.MagicData.MagicPowerSkill_GuardianSpirit, "TM_GuardianSpirit", "_eff", true);

            if (cell != null && cell.IsValid && cell.Walkable(map))
            {
                AbilityUser.SpawnThings tempPod = new SpawnThings();
                IntVec3 shiftPos = cell;

                tempPod.def = comp.GuardianSpiritType;
                if (comp.GuardianSpiritType == TorannMagicDefOf.TM_SpiritBearR)
                {
                    tempPod.kindDef = PawnKindDef.Named("TM_SpiritBear");
                }
                else if (comp.GuardianSpiritType == TorannMagicDefOf.TM_SpiritMongooseR)
                {
                    tempPod.kindDef = PawnKindDef.Named("TM_SpiritMongoose");
                }
                else
                {
                    tempPod.kindDef = PawnKindDef.Named("TM_SpiritCrow");
                }
                tempPod.spawnCount = 1;

                if (shiftPos != default(IntVec3))
                {
                    try
                    {
                        if (comp.bondedSpirit != null)
                        {
                            if (comp.bondedSpirit.Map != null)
                            {
                                MoteMaker.ThrowSmoke(comp.bondedSpirit.DrawPos, comp.bondedSpirit.Map, 1f);
                                TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Ghost, comp.bondedSpirit.DrawPos, comp.bondedSpirit.Map, 1.3f, .25f, .1f, .45f, 0, Rand.Range(1f, 2f), 0, 0);
                            }
                            comp.bondedSpirit.Destroy(DestroyMode.Vanish);
                        }
                        this.spirit = TM_Action.SingleSpawnLoop(caster, tempPod, shiftPos, map, 5, false, false, caster.Faction, false);
                        Pawn animal = this.spirit as Pawn;
                        TM_Action.TrainAnimalFull(animal, caster);
                        HealthUtility.AdjustSeverity(animal, TorannMagicDefOf.TM_SpiritBondHD, -4f);
                        HealthUtility.AdjustSeverity(animal, TorannMagicDefOf.TM_SpiritBondHD, .5f + verVal);
                        if (animal.def == TorannMagicDefOf.TM_SpiritCrowR)
                        {
                            HealthUtility.AdjustSeverity(animal, TorannMagicDefOf.TM_BirdflightHD, .5f);
                        }
                        comp.bondedSpirit = animal;
                        CompAnimalController animalComp = animal.TryGetComp <CompAnimalController>();
                        if (animalComp != null)
                        {
                            animalComp.summonerPawn = caster;
                        }
                        for (int i = 0; i < 3; i++)
                        {
                            Vector3 rndPos = this.spirit.DrawPos;
                            rndPos.x += Rand.Range(-.5f, .5f);
                            rndPos.z += Rand.Range(-.5f, .5f);
                            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Healing_Small, rndPos, map, Rand.Range(.6f, .8f), .1f, .05f, .05f, 0, 0, 0, Rand.Range(0, 360));
                            MoteMaker.ThrowSmoke(rndPos, map, Rand.Range(.8f, 1.2f));
                        }
                    }
                    catch
                    {
                        comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_GuardianSpirit);
                        Log.Message("TM_Exception".Translate(
                                        caster.LabelShort,
                                        "Guardian Spirit"
                                        ));
                    }
                }
                else
                {
                    Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                    comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_GuardianSpirit));
                }
            }
            else
            {
                Messages.Message("InvalidSummon".Translate(), MessageTypeDefOf.RejectInput);
                comp.Mana.GainNeed(comp.ActualManaCost(TorannMagicDefOf.TM_GuardianSpirit));
            }
            return(false);
        }
Exemple #5
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();
        }
        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;

            GenClamor.DoClamor(this, 2.1f, ClamorDefOf.Impact);
            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 (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(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("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
                    {
                        Projectile_SummonExplosive.SingleSpawnLoop(tempPod, shiftPos, map, this.launcher, this.duration);
                    }
                    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);
                    if (comp.Mana != null)
                    {
                        comp.Mana.CurLevel += 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);

            if (!initialized)
            {
                SpawnThings spawnThing = new SpawnThings();
                Pawn        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");
                        try
                        {
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        catch
                        {
                            this.age            = this.duration;
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonMinion);
                            Log.Message("TM_Exception".Translate(new object[]
                            {
                                pawn.LabelShort,
                                this.def.defName
                            }));
                        }
                    }
                    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");
                        try
                        {
                            SingleSpawnLoop(spawnThing, centerCell, map);
                        }
                        catch
                        {
                            this.age            = this.duration;
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonMinion);
                            Log.Message("TM_Exception".Translate(new object[]
                            {
                                pawn.LabelShort,
                                this.def.defName
                            }));
                        }
                    }
                    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;
            }
        }
Exemple #8
0
        public void SingleSpawnLoop(SpawnThings spawnables, IntVec3 position, Map map)
        {
            bool flag = spawnables.def != null;

            if (flag)
            {
                Faction faction = pawn.Faction;
                bool    flag2   = spawnables.def.race != null;
                if (flag2)
                {
                    bool flag3 = spawnables.kindDef == null;
                    if (flag3)
                    {
                        Log.Error("Missing kinddef");
                    }
                    else
                    {
                        newPawn = (TMPawnSummoned)PawnGenerator.GeneratePawn(spawnables.kindDef, faction);
                        newPawn.validSummoning = true;
                        newPawn.Spawner        = this.Caster;
                        newPawn.Temporary      = true;
                        newPawn.TicksToDestroy = this.duration;
                        //if (newPawn.Faction != Faction.OfPlayerSilentFail)
                        //{
                        //    newPawn.SetFaction(this.Caster.Faction, null);
                        //}
                        //newPawn.playerSettings.master = this.Caster;
                        if (comp.summonedMinions.Count >= 4)
                        {
                            Thing dismissMinion = comp.summonedMinions[0];
                            if (dismissMinion != null && dismissMinion.Position.IsValid)
                            {
                                MoteMaker.ThrowSmoke(dismissMinion.Position.ToVector3(), base.Map, 1);
                                MoteMaker.ThrowHeatGlow(dismissMinion.Position, base.Map, 1);
                            }
                            comp.summonedMinions.Remove(comp.summonedMinions[0]);
                            if (!dismissMinion.Destroyed)
                            {
                                dismissMinion.Destroy();
                                Messages.Message("TM_SummonedCreatureLimitExceeded".Translate(
                                                     this.launcher.LabelShort
                                                     ), MessageTypeDefOf.NeutralEvent);
                            }
                            if (comp.summonedMinions.Count > 4)
                            {
                                while (comp.summonedMinions.Count > 4)
                                {
                                    Pawn excessMinion = comp.summonedMinions[comp.summonedMinions.Count - 1] as Pawn;
                                    comp.summonedMinions.Remove(excessMinion);
                                    if (excessMinion != null && !excessMinion.Dead && !excessMinion.Destroyed)
                                    {
                                        excessMinion.Destroy();
                                    }
                                }
                            }
                        }
                        try
                        {
                            GenSpawn.Spawn(newPawn, position, this.Map);
                        }
                        catch
                        {
                            this.age            = this.duration;
                            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_SummonMinion);
                            Log.Message("TM_Exception".Translate(
                                            pawn.LabelShort,
                                            this.def.defName
                                            ));
                            this.Destroy(DestroyMode.Vanish);
                        }

                        comp.summonedMinions.Add(newPawn);
                        if (newPawn.Faction != null && newPawn.Faction != Faction.OfPlayer)
                        {
                            Lord lord = null;
                            if (newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction).Any((Pawn p) => p != newPawn))
                            {
                                Predicate <Thing> validator = (Thing p) => p != newPawn && ((Pawn)p).GetLord() != null;
                                Pawn p2 = (Pawn)GenClosest.ClosestThing_Global(newPawn.Position, newPawn.Map.mapPawns.SpawnedPawnsInFaction(faction), 99999f, validator, null);
                                lord = p2.GetLord();
                            }
                            bool flag4 = lord == null;
                            if (flag4)
                            {
                                LordJob_DefendPoint lordJob = new LordJob_DefendPoint(newPawn.Position);
                                lord = LordMaker.MakeNewLord(faction, lordJob, this.Map, null);
                            }
                            else
                            {
                                try
                                {
                                    //PawnDuty duty = this.pawn.mindState.duty;
                                    //newPawn.mindState.duty = duty;
                                    newPawn.mindState.duty = new PawnDuty(DutyDefOf.Defend);
                                }
                                catch
                                {
                                    Log.Message("error attempting to assign a duty to minion");
                                }
                            }
                            lord.AddPawn(newPawn);
                        }
                    }
                }
                else
                {
                    Log.Message("Missing race");
                }
            }
        }
        private bool ChoseWorldTarget(GlobalTargetInfo target)
        {
            if (!target.IsValid)
            {
                Messages.Message("TM_InvalidGatewaySelection".Translate(), MessageTypeDefOf.RejectInput);
                return(false);
            }
            int num = Find.WorldGrid.TraversalDistanceBetween(base.CasterPawn.Map.Tile, target.Tile);

            if (num > this.MaxLaunchDistance)
            {
                Messages.Message("TM_GatewayBeyondMaximumRange".Translate(), MessageTypeDefOf.RejectInput);
                return(false);
            }
            MapParent mapParent = target.WorldObject as MapParent;

            if (mapParent != null && mapParent.HasMap)
            {
                Map myMap = base.CasterPawn.Map;
                Map map   = mapParent.Map;
                Current.Game.CurrentMap = map;
                TargetingParameters portalTarget = new TargetingParameters();
                portalTarget.canTargetLocations = true;
                portalTarget.canTargetSelf      = false;
                portalTarget.canTargetPawns     = false;
                portalTarget.canTargetFires     = false;
                portalTarget.canTargetBuildings = false;
                portalTarget.canTargetItems     = false;
                portalTarget.validator          = ((TargetInfo x) => x.IsValid && !x.Cell.Fogged(map) && x.Cell.InBounds(map) && x.Cell.Walkable(map));
                Find.Targeter.BeginTargeting(portalTarget, delegate(LocalTargetInfo x)
                {
                    InitiateMassSummon(map, x);
                }, null, delegate
                {
                    if (Find.Maps.Contains(myMap))
                    {
                        Current.Game.CurrentMap = myMap;
                    }
                }, Verb_FoldReality.TargeterMouseAttachment);
                return(true);
            }
            bool flag;

            if (mapParent != null)
            {
                Settlement             settlement = mapParent as Settlement;
                List <FloatMenuOption> list       = new List <FloatMenuOption>();
                if (settlement != null && settlement.Visitable)
                {
                    Messages.Message("TM_InvalidGatewayNotOccupied".Translate(), MessageTypeDefOf.RejectInput);
                    return(false);
                }
                //if (mapParent.TransportPodsCanLandAndGenerateMap)
                //{
                //    Messages.Message("TM_InvalidGatewayNotOccupied".Translate(), MessageTypeDefOf.RejectInput);
                //    return false;
                //}
                if (list.Any <FloatMenuOption>())
                {
                    Find.WorldTargeter.closeWorldTabWhenFinished = false;
                    Find.WindowStack.Add(new FloatMenu(list));
                    return(true);
                }
                flag = true;
            }
            else
            {
                flag = true;
            }
            if (!flag)
            {
                return(false);
            }
            if (Find.World.Impassable(target.Tile))
            {
                Messages.Message("TM_InvalidGatewaySelection".Translate(), MessageTypeDefOf.RejectInput);
                return(false);
            }
            comp.Mana.CurLevel += comp.ActualManaCost(TorannMagicDefOf.TM_FoldReality);
            Messages.Message("TM_InvalidGatewayNotOccupied".Translate(), MessageTypeDefOf.RejectInput);
            return(false);
        }
Exemple #10
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            CompAbilityUserMagic comp = this.pawn.GetComp <CompAbilityUserMagic>();
            Toil discordance          = new Toil();
            Pawn target = this.TargetThingA as Pawn;

            discordance.initAction = delegate
            {
                if (age > duration)
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
                if (target.DestroyedOrNull())
                {
                    this.EndJobWith(JobCondition.Errored);
                }
                if (target.Map == null)
                {
                    this.EndJobWith(JobCondition.Errored);
                }
                if (target.Dead)
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
                Map map = this.pawn.Map;
                ticksLeftThisToil = 10;
                headDamageCount   = 0;
            };
            discordance.tickAction = delegate
            {
                if (Find.TickManager.TicksGame % this.moteFrequency == 0)
                {
                    TM_MoteMaker.ThrowCastingMote(pawn.DrawPos, pawn.Map, Rand.Range(1.2f, 2f));
                    float    angle = Rand.Range(0, 360);
                    ThingDef mote  = TorannMagicDefOf.Mote_Psi_Grayscale;
                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Psi_Grayscale, this.pawn.DrawPos, this.pawn.Map, Rand.Range(.25f, .6f), .1f, .05f, .05f, 0, Rand.Range(4f, 6f), angle, angle);
                }
                if (Find.TickManager.TicksGame % this.discordFrequency == 0)
                {
                    Vector3 headPos = target.DrawPos;
                    headPos.z += .3f;
                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_Bolt, headPos, target.Map, .6f, .5f, .1f, .5f, Rand.Range(-10, 10), Rand.Range(.4f, .6f), Rand.Range(-90, 90), Rand.Range(0, 360));
                    float manaCost = comp.ActualManaCost(TorannMagicDefOf.TM_Discord);
                    if (comp.Mana.CurLevel >= manaCost && !target.DestroyedOrNull() && !target.Dead && target.Map != null)
                    {
                        comp.Mana.CurLevel -= manaCost;
                        float ch = TM_Calc.GetSpellSuccessChance(this.pawn, target, true);
                        if (target.Faction == this.pawn.Faction)
                        {
                            HealthUtility.AdjustSeverity(target, TorannMagicDefOf.TM_DiscordSafeHD, .4f * ch);
                            Hediff hd = target.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_DiscordHD);
                            if (hd != null && hd.Severity > 5)
                            {
                                if (Rand.Chance(.2f))
                                {
                                    TM_Action.DamageEntities(target, null, 6, DamageDefOf.Stun, this.pawn);
                                }
                            }
                        }
                        else
                        {
                            HealthUtility.AdjustSeverity(target, TorannMagicDefOf.TM_DiscordHD, .4f * ch);
                            Hediff hd = target.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_DiscordHD);
                            if (hd != null && hd.Severity > 5)
                            {
                                BodyPartRecord bpr  = target.health.hediffSet.GetBrain();
                                BodyPartRecord head = target.health.hediffSet.GetNotMissingParts().FirstOrDefault((BodyPartRecord x) => x.def == BodyPartDefOf.Head);
                                if (bpr != null)
                                {
                                    if (Rand.Chance(.22f * ch))
                                    {
                                        for (int i = 0; i < 2; i++)
                                        {
                                            TM_MoteMaker.ThrowBloodSquirt(headPos, target.Map, Rand.Range(.6f, 1f));
                                        }
                                        TM_Action.DamageEntities(target, bpr, Rand.Range(1, 3), 2f, TMDamageDefOf.DamageDefOf.TM_DistortionDD, this.pawn);
                                        headDamageCount++;
                                    }
                                    else if (Rand.Chance((.07f * ch) + (headDamageCount * .3f)) && head != null)
                                    {
                                        for (int i = 0; i < 3; i++)
                                        {
                                            TM_MoteMaker.ThrowBloodSquirt(headPos, target.Map, Rand.Range(.6f, 1f));
                                        }
                                        for (int i = 0; i < 3; i++)
                                        {
                                            float moteSize      = Rand.Range(.5f, .8f);
                                            float solidTime     = Rand.Range(.6f, .8f);
                                            float fadeOutTime   = Rand.Range(.2f, .4f);
                                            float velocity      = Rand.Range(1.5f, 2.5f);
                                            float velocityAngle = Rand.Range(0f, 360f);
                                            for (int j = 0; j < 3; j++)
                                            {
                                                TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_BloodSquirt, headPos, target.Map, moteSize - (.1f * j), solidTime + (.1f * j), 0f, fadeOutTime + (.05f * j), Rand.Range(-50, 50), velocity + (.5f * j), velocityAngle, Rand.Range(0, 360));
                                            }
                                        }
                                        TM_Action.DamageEntities(target, head, Rand.Range(50, 80), 2f, TMDamageDefOf.DamageDefOf.TM_DistortionDD, this.pawn);
                                    }
                                }
                            }
                        }
                        if (target.Dead)
                        {
                            this.age = this.duration;
                        }
                    }
                    else
                    {
                        this.age = this.duration;
                    }
                }
                age++;
                ticksLeftThisToil = Mathf.RoundToInt(((float)(duration - age) / (float)duration) * 100f);
                if (age > duration)
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
            };
            discordance.defaultCompleteMode = ToilCompleteMode.Delay;
            discordance.defaultDuration     = this.duration;
            discordance.WithProgressBar(TargetIndex.A, delegate
            {
                if (this.pawn.DestroyedOrNull() || this.pawn.Dead || this.pawn.Downed)
                {
                    return(1f);
                }
                return(1f - (float)discordance.actor.jobs.curDriver.ticksLeftThisToil / 100);
            }, false, 0f);
            discordance.AddFinishAction(delegate
            {
            });
            yield return(discordance);
        }