Exemplo n.º 1
0
        protected override bool TryCastShot()
        {
            bool flag = false;

            this.TargetsAoE.Clear();
            //this.UpdateTargets();
            this.FindTargets();
            MagicPowerSkill ver = base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Rend.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Rend_ver");

            verVal = ver.level;
            bool friendlyTarget = this.currentTarget != null && this.currentTarget.Thing != null && this.currentTarget.Thing.Faction != null && this.currentTarget.Thing.Faction == this.CasterPawn.Faction && this.currentTarget.Thing != this.CasterPawn;
            bool flag2          = (this.UseAbilityProps.AbilityTargetCategory != AbilityTargetCategory.TargetAoE && this.TargetsAoE.Count > 1) || friendlyTarget;

            if (flag2)
            {
                this.TargetsAoE.RemoveRange(0, this.TargetsAoE.Count - 1);
            }
            if (friendlyTarget)
            {
                Pawn pawn = this.currentTarget.Thing as Pawn;
                if (pawn != null && pawn.RaceProps.Humanlike && pawn.needs != null && pawn.needs.mood.thoughts != null)
                {
                    if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, pawn, true)))
                    {
                        List <Thought_Memory> thoughts = pawn.needs.mood.thoughts.memories.Memories;
                        pawn.mindState.mentalStateHandler.TryStartMentalState(TorannMagicDefOf.WanderConfused, null, false, false, null, false);
                        for (int i = 0; i < thoughts.Count; i++)
                        {
                            pawn.needs.mood.thoughts.memories.RemoveMemory(thoughts[i]);
                            i--;
                        }
                        pawn.needs.mood.thoughts.memories.TryGainMemory(TorannMagicDefOf.TM_MemoryWipe, null);
                        Effects(pawn.Position);
                    }
                    else
                    {
                        MoteMaker.ThrowText(pawn.DrawPos, pawn.Map, "TM_ResistedSpell".Translate(), -1);
                    }
                }
            }
            else
            {
                for (int i = 0; i < this.TargetsAoE.Count; i++)
                {
                    Pawn newPawn = this.TargetsAoE[i].Thing as Pawn;
                    if (newPawn.RaceProps.IsFlesh && newPawn.RaceProps.Humanlike && newPawn.Faction != this.CasterPawn.Faction)
                    {
                        if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, newPawn, true)))
                        {
                            TM_Action.DamageEntities(newPawn, null, 30, DamageDefOf.Stun, this.CasterPawn);
                            Effects(newPawn.Position);
                        }
                        else
                        {
                            MoteMaker.ThrowText(newPawn.DrawPos, newPawn.Map, "TM_ResistedSpell".Translate(), -1);
                        }
                    }
                }
            }
            this.PostCastShot(flag, out flag);
            return(flag);
        }
Exemplo n.º 2
0
        public override void Tick()
        {
            age++;
            Vector3 exactPosition = this.ExactPosition;

            this.ticksToImpact--;

            if (!initialized)
            {
                Initialize();
                if (this.glowing && this.glowCenter != default(IntVec3))
                {
                    this.shouldGlow = true;
                }
            }

            if (Find.TickManager.TicksGame % this.chargeFrequency == 0)
            {
                LightEnergy += ChargeAmount;
            }

            bool dFlag = false;

            if (this.pawn.DestroyedOrNull())
            {
                dFlag = true;
                this.Destroy(DestroyMode.Vanish);
            }
            else if (!this.pawn.Spawned || this.pawn.Map != this.Map || this.pawn.Map == null)
            {
                solAction = SoLAction.Limbo;
                dFlag     = true;
                this.delayCount++;
                if (delayCount >= 300)
                {
                    StopGlow();
                    this.shouldGlow = false;
                    this.Destroy(DestroyMode.Vanish);
                }
                if (this.delayCount == 10)
                {
                    MoteMaker.ThrowLightningGlow(this.ExactPosition, this.Map, 1f);
                    MoteMaker.ThrowLightningGlow(this.ExactPosition, this.Map, .7f);
                    MoteMaker.ThrowLightningGlow(this.ExactPosition, this.Map, .4f);
                }
            }
            else if (this.shouldDismiss)
            {
                if (this.glowing)
                {
                    this.glowCenter = default(IntVec3);
                    StopGlow();
                    this.Destroy(DestroyMode.Vanish);
                }
            }

            if (!dFlag)
            {
                bool flag = !this.ExactPosition.InBounds(base.Map);
                if (flag)
                {
                    if (!this.pawn.DestroyedOrNull() && this.pawn.Spawned)
                    {
                        base.Position      = pawn.Position;
                        this.destination   = GetCasterOffset_Exact;
                        this.speed         = speed_dash;
                        this.ticksToImpact = this.StartingTicksToImpact;
                    }
                    this.ticksToImpact++;
                    base.Position = this.ExactPosition.ToIntVec3();
                }
                else if (this.solAction == SoLAction.Limbo)
                {
                    UpdateAction(this.solAction);
                }
                else
                {
                    base.Position = this.ExactPosition.ToIntVec3();
                    if (Find.TickManager.TicksGame % ActionDelay == 0)
                    {
                        DoAction();
                    }
                    bool flag2 = this.ticksToImpact <= 0;
                    if (flag2)
                    {
                        if (this.shouldDismiss)
                        {
                            bool flag3 = this.DestinationCell.InBounds(base.Map);
                            if (flag3)
                            {
                                base.Position = this.DestinationCell;
                            }
                            this.ImpactSomething();
                        }
                        else
                        {
                            UpdateSoLPower();
                            if (this.curveVariance > 0)
                            {
                                if ((this.curvePoints.Count() - 1) > this.destinationCurvePoint)
                                {
                                    this.origin = curvePoints[destinationCurvePoint];
                                    this.destinationCurvePoint++;
                                    this.destination   = this.curvePoints[this.destinationCurvePoint];
                                    this.ticksToImpact = this.StartingTicksToImpact;
                                }
                                else
                                {
                                    bool flag3 = this.DestinationCell.InBounds(base.Map);
                                    if (flag3)
                                    {
                                        base.Position = this.DestinationCell;
                                    }
                                    this.origin = this.ExactPosition;
                                    solAction   = SoLAction.Pending;
                                    UpdateAction(solAction);
                                }
                            }
                            else
                            {
                                bool flag3 = this.DestinationCell.InBounds(base.Map);
                                if (flag3)
                                {
                                    base.Position = this.DestinationCell;
                                }
                                if (this.solAction == SoLAction.ChargeAttacking)
                                {
                                    ActualLightCost(5f);
                                    int moteAngle = Mathf.RoundToInt(Vector3Utility.ToAngleFlat(this.origin - this.destination) - 90f);
                                    TM_Action.DamageEntities(this.assignedTarget, null, Rand.Range(10f, 15f) * LightPotency, TMDamageDefOf.DamageDefOf.TM_BurningLight, this.pawn);
                                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_LightShield, this.ExactPosition, this.Map, 1.5f, .1f, 0f, .2f, 0, 2f, moteAngle, moteAngle);
                                }

                                this.origin = this.destination;
                                solAction   = SoLAction.Pending;
                                UpdateAction(solAction);
                            }
                        }
                    }

                    if (this.nextMoteTick <= this.age && solAction != SoLAction.Limbo)
                    {
                        DrawMotes();
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void Tick()
        {
            if (this.triggered)
            {
                if (this.age >= this.lastStrike + this.strikeDelay)
                {
                    try
                    {
                        IntVec3 curCell;
                        IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(base.Position, this.radius, true);
                        for (int i = 0; i < targets.Count(); i++)
                        {
                            curCell = targets.ToArray <IntVec3>()[i];

                            if (curCell.InBounds(base.Map) && curCell.IsValid)
                            {
                                Pawn victim = curCell.GetFirstPawn(base.Map);
                                if (victim != null && !victim.Dead && victim.RaceProps.IsFlesh)
                                {
                                    BodyPartRecord bpr = null;
                                    bpr = victim.def.race.body.AllParts.InRandomOrder().FirstOrDefault <BodyPartRecord>((BodyPartRecord x) => x.def.tags.Contains(BodyPartTagDefOf.BreathingSource));
                                    TM_Action.DamageEntities(victim, bpr, Rand.Range(1f, 2f), 2f, TMDamageDefOf.DamageDefOf.TM_Poison, this);
                                }
                            }
                        }
                    }
                    catch
                    {
                        Log.Message("Debug: poison trap failed to process triggered event - terminating poison trap");
                        this.Destroy(DestroyMode.Vanish);
                    }
                    this.lastStrike = this.age;
                }
                this.age++;
                if (this.age > this.duration)
                {
                    CheckForAgent();
                    if (destroyAfterUse)
                    {
                        Destroy();
                    }
                    else
                    {
                        this.age        = 0;
                        triggered       = false;
                        rearming        = true;
                        this.lastStrike = 0;
                    }
                }
            }
            else if (rearming)
            {
                this.age++;
                if (this.age > this.ticksTillReArm)
                {
                    this.age  = 0;
                    rearming  = false;
                    triggered = false;
                }
            }
            else
            {
                try
                {
                    if (this.Armed)
                    {
                        IntVec3 curCell;
                        IEnumerable <IntVec3> targets = GenRadial.RadialCellsAround(base.Position, 2, true);
                        for (int i = 0; i < targets.Count(); i++)
                        {
                            curCell = targets.ToArray <IntVec3>()[i];
                            List <Thing> thingList = curCell.GetThingList(base.Map);
                            for (int j = 0; j < thingList.Count; j++)
                            {
                                Pawn pawn = thingList[j] as Pawn;
                                if (pawn != null && !this.touchingPawns.Contains(pawn))
                                {
                                    if (!pawn.RaceProps.Animal && pawn.Faction != null && pawn.Faction != this.Faction && pawn.HostileTo(this.Faction))
                                    {
                                        this.touchingPawns.Add(pawn);
                                        this.CheckSpring(pawn);
                                    }
                                }
                            }
                        }
                    }
                    for (int j = 0; j < this.touchingPawns.Count; j++)
                    {
                        Pawn pawn2 = this.touchingPawns[j];
                        if (!pawn2.Spawned || pawn2.Position != base.Position)
                        {
                            this.touchingPawns.Remove(pawn2);
                        }
                    }
                }
                catch
                {
                    Log.Message("Debug: poison trap failed to process armed event - terminating poison trap");
                    this.Destroy(DestroyMode.Vanish);
                }
            }
            base.Tick();
        }
Exemplo n.º 4
0
        protected override bool TryCastShot()
        {
            bool result = false;
            bool arg_40_0;

            Pawn pawn = this.CasterPawn;
            Map  map  = this.CasterPawn.Map;
            CompAbilityUserMagic comp = pawn.GetComp <CompAbilityUserMagic>();
            int verVal    = pawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodGift.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodGift_ver").level;
            int bloodGain = 0;
            List <BodyPartRecord> bodyparts = new List <BodyPartRecord>();

            bodyparts.Clear();
            bodyparts = this.CasterPawn.def.race.body.AllParts;
            HashSet <ThingDef> bloodDefs = TM_Calc.AllRaceBloodTypes;

            ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
            if (pawn != null && !pawn.Downed && bodyparts != null && bloodDefs != null)
            {
                if (verVal > 0)
                {
                    IEnumerable <IntVec3> cellList = GenRadial.RadialCellsAround(this.CasterPawn.Position, (2 * verVal) - 1, true);
                    foreach (var curCell in cellList)
                    {
                        List <Thing> thingList = curCell.GetThingList(this.CasterPawn.Map);
                        for (int j = 0; j < thingList.Count; j++)
                        {
                            if (thingList[j].def == ThingDefOf.Filth_Blood || (settingsRef.unrestrictedBloodTypes && bloodDefs.Contains(thingList[j].def)))
                            {
                                bloodGain += thingList[j].stackCount;
                                thingList[j].Destroy(DestroyMode.Vanish);
                            }
                        }
                    }
                }

                List <BodyPartRecord> validParts = new List <BodyPartRecord>();
                for (int i = 0; i < bodyparts.Count; i++)
                {
                    if (bodyparts[i].def.bleedRate != 0 && bodyparts[i].depth == BodyPartDepth.Outside && bodyparts[i].coverageAbs > 0)
                    {
                        validParts.Add(bodyparts[i]);
                    }
                }

                if (validParts.Count > 0)
                {
                    if (this.CasterPawn.RaceProps.BloodDef != null && (this.CasterPawn.RaceProps.BloodDef == ThingDefOf.Filth_Blood || settingsRef.unrestrictedBloodTypes))
                    {
                        BodyPartRecord damagePart = validParts.RandomElement();
                        TM_Action.DamageEntities(this.CasterPawn, damagePart, 4f, 10f, TMDamageDefOf.DamageDefOf.TM_BloodyCut, this.CasterPawn);
                        damagePart = validParts.RandomElement();
                        TM_Action.DamageEntities(this.CasterPawn, damagePart, 2f, 10f, TMDamageDefOf.DamageDefOf.TM_BloodyCut, this.CasterPawn);
                        bloodGain += 18;
                        List <Need> needs = this.CasterPawn.needs.AllNeeds;
                        for (int n = 0; n < needs.Count; n++)
                        {
                            Need need = needs[n];
                            if (need.def.defName == "ROMV_Blood")
                            {
                                need.CurLevel--;
                            }
                        }
                        TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_CrossStrike"), this.CasterPawn.DrawPos, this.CasterPawn.Map, Rand.Range(.4f, 0.6f), .45f, .05f, .20f, 0, 0, 0, Rand.Range(0, 360));
                        for (int j = 0; j < 4; j++)
                        {
                            IntVec3 rndPos = this.CasterPawn.Position;
                            rndPos.x += Mathf.RoundToInt(Rand.Range(-1.5f, 1.5f));
                            rndPos.z += Mathf.RoundToInt(Rand.Range(-1.5f, 1.5f));
                            FilthMaker.TryMakeFilth(rndPos, this.CasterPawn.Map, this.CasterPawn.RaceProps.BloodDef, Rand.RangeInclusive(1, 2));
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodSquirt"), this.CasterPawn.DrawPos, this.CasterPawn.Map, Rand.Range(.7f, 1.1f), .15f, .05f, .66f, Rand.Range(-100, 100), Rand.Range(1, 2), Rand.Range(0, 360), Rand.Range(0, 360));
                        }
                    }
                }
                else
                {
                    if (bloodGain == 0)
                    {
                        Messages.Message("TM_NoExternalBodyPartsCanBleed".Translate(this.CasterPawn.LabelShort), MessageTypeDefOf.RejectInput, false);
                    }
                }
                HealthUtility.AdjustSeverity(this.CasterPawn, HediffDef.Named("TM_BloodHD"), bloodGain * (1 + (.1f * verVal)) * comp.arcaneDmg);
                arg_40_0 = true;
            }
            else
            {
                arg_40_0 = false;
            }
            bool flag = arg_40_0;

            if (flag)
            {
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            this.burstShotsLeft = 0;

            return(result);
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            if (!this.initialized)
            {
                this.bloodCircleOuterCells = new List <IntVec3>();
                this.bloodCircleOuterCells.Clear();
                this.victimHitTick = new List <int>();
                this.victimHitTick.Clear();
                this.victims = new List <Pawn>();
                this.victims.Clear();
                this.wolfDmg = new List <float>();
                this.wolfDmg.Clear();

                caster = this.launcher as Pawn;
                CompAbilityUserMagic comp = caster.GetComp <CompAbilityUserMagic>();
                MagicPowerSkill      bpwr = comp.MagicData.MagicPowerSkill_BloodGift.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodGift_pwr");
                pwrVal                = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_pwr").level;
                verVal                = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_ver").level;
                effVal                = caster.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_BloodMoon.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_BloodMoon_eff").level;
                this.arcaneDmg        = comp.arcaneDmg;
                this.arcaneDmg       *= 1f + (.1f * bpwr.level);
                this.attackFrequency *= 1 - (.05f * effVal);
                this.duration         = Mathf.RoundToInt(this.duration + (this.duration * .1f * verVal));

                this.angle  = Rand.Range(-2f, 2f);
                this.radius = this.def.projectile.explosionRadius;

                IntVec3 curCell = base.Position;

                this.CheckSpawnSustainer();

                if (curCell.InBounds(map) && curCell.IsValid)
                {
                    IEnumerable <IntVec3> cellList = GenRadial.RadialCellsAround(base.Position, this.radius, true);
                    foreach (var cell in cellList)
                    {
                        curCell = cell;
                        if (curCell.InBounds(map) && curCell.IsValid)
                        {
                            this.bloodCircleCells.Add(curCell);
                        }
                    }
                    cellList = GenRadial.RadialCellsAround(base.Position, this.radius + 1, true);
                    List <IntVec3> outerRing = new List <IntVec3>();
                    foreach (var cell in cellList)
                    {
                        curCell = cell;
                        if (curCell.InBounds(map) && curCell.IsValid)
                        {
                            outerRing.Add(curCell);
                        }
                    }
                    this.bloodCircleOuterCells = outerRing.Except(this.bloodCircleCells).ToList();
                }

                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, this.duration / 60 * .9f, this.duration / 60 * .06f, this.duration / 60 * .08f, Rand.Range(-50, -50), 0, 0, Rand.Range(0, 360));
                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, this.duration / 60 * .9f, this.duration / 60 * .06f, this.duration / 60 * .08f, Rand.Range(50, 50), 0, 0, Rand.Range(0, 360));
                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodCircle"), base.Position.ToVector3Shifted(), caster.Map, this.radius + 2, this.duration / 60 * .9f, this.duration / 60 * .06f, this.duration / 60 * .08f, Rand.Range(-50, 50), 0, 0, Rand.Range(0, 360));
                caster.Map.weatherManager.eventHandler.AddEvent(new TM_WeatherEvent_BloodMoon(caster.Map, this.duration, 2f - (this.pwrVal * .1f)));
                this.initialized = true;
            }

            if (this.initialized && this.Map != null && this.age > 15)
            {
                if (this.victims.Count > 0)
                {
                    for (int i = 0; i < this.victims.Count; i++)
                    {
                        if (this.victimHitTick[i] < this.age)
                        {
                            TM_Action.DamageEntities(victims[i], null, Mathf.RoundToInt(Rand.Range(5, 8) * this.wolfDmg[i] * this.arcaneDmg), DamageDefOf.Bite, this.launcher);
                            TM_MoteMaker.ThrowBloodSquirt(victims[i].DrawPos, victims[i].Map, Rand.Range(.6f, 1f));
                            this.victims.Remove(this.victims[i]);
                            this.victimHitTick.Remove(this.victimHitTick[i]);
                            this.wolfDmg.Remove(this.wolfDmg[i]);
                        }
                    }
                }

                if (Find.TickManager.TicksGame % this.bloodFrequency == 0)
                {
                    Filth filth = (Filth)ThingMaker.MakeThing(ThingDefOf.Filth_Blood);
                    GenSpawn.Spawn(filth, this.bloodCircleOuterCells.RandomElement(), this.Map);
                }

                if (this.nextAttack < this.age && !this.caster.DestroyedOrNull() && !this.caster.Dead)
                {
                    Pawn victim = TM_Calc.FindNearbyEnemy(base.Position, this.Map, this.caster.Faction, this.radius, 0);
                    if (victim != null)
                    {
                        IntVec3 rndPos = victim.Position;
                        while (rndPos == victim.Position)
                        {
                            rndPos = this.bloodCircleCells.RandomElement();
                        }
                        Vector3 wolf      = rndPos.ToVector3Shifted();
                        Vector3 direction = TM_Calc.GetVector(wolf, victim.DrawPos);
                        float   angle     = direction.ToAngleFlat();
                        float   fadeIn    = .1f;
                        float   fadeOut   = .25f;
                        float   solidTime = .10f;
                        float   drawSize  = Rand.Range(.7f, 1.2f) + (this.pwrVal * .1f);
                        float   velocity  = (victim.DrawPos - wolf).MagnitudeHorizontal();
                        if (angle >= -135 && angle < -45) //north
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfNorth"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0);
                        }
                        else if (angle >= 45 && angle < 135) //south
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfSouth"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0);
                        }
                        else if (angle >= -45 && angle < 45) //east
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfEast"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0);
                        }
                        else //west
                        {
                            TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_BloodWolfWest"), wolf, this.Map, drawSize, solidTime, fadeIn, fadeOut, 0, 2 * velocity, (Quaternion.AngleAxis(90, Vector3.up) * direction).ToAngleFlat(), 0);
                        }
                        int      hitDelay          = this.age + this.delayTicks;
                        Effecter BloodShieldEffect = TorannMagicDefOf.TM_BloodShieldEffecter.Spawn();
                        BloodShieldEffect.Trigger(new TargetInfo(wolf.ToIntVec3(), this.Map, false), new TargetInfo(wolf.ToIntVec3(), this.Map, false));
                        BloodShieldEffect.Cleanup();
                        this.victims.Add(victim);
                        this.victimHitTick.Add(hitDelay);
                        this.wolfDmg.Add(drawSize);
                        if (Rand.Chance(.1f))
                        {
                            if (Rand.Chance(.65f))
                            {
                                SoundInfo info = SoundInfo.InMap(new TargetInfo(wolf.ToIntVec3(), this.Map, false), MaintenanceType.None);
                                SoundDef.Named("TM_DemonCallHigh").PlayOneShot(info);
                            }
                            else
                            {
                                SoundInfo info = SoundInfo.InMap(new TargetInfo(wolf.ToIntVec3(), this.Map, false), MaintenanceType.None);
                                info.pitchFactor  = .8f;
                                info.volumeFactor = .8f;
                                SoundDef.Named("TM_DemonPain").PlayOneShot(info);
                            }
                        }
                    }
                    this.nextAttack = this.age + Mathf.RoundToInt(Rand.Range(.4f * (float)this.attackFrequency, .8f * (float)this.attackFrequency));
                }
            }
        }
Exemplo n.º 6
0
        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 = new List <IntVec3>();
                targetCells.Clear();
                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++)
                {
                    if (Rand.Chance(.5f + (.1f * verVal)))
                    {
                        float rnd = Rand.Range(0, 1f);
                        targetPawn = this.targetCells[i].GetFirstPawn(this.Map);
                        if (targetPawn != null)
                        {
                            if (TM_Calc.IsRobotPawn(targetPawn))
                            {
                                if (Rand.Chance(TM_Calc.GetSpellSuccessChance(caster, targetPawn, true)))
                                {
                                    if (rnd <= .33f)
                                    {
                                        TM_Action.DamageEntities(targetPawn, null, Rand.Range(8, 15) + pwrVal, TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, this.launcher);
                                    }
                                    else if (rnd <= .66f)
                                    {
                                        if (targetPawn.mindState != null)
                                        {
                                            targetPawn.mindState.mentalStateHandler.TryStartMentalState(MentalStateDefOf.Berserk, "logic circuits sabotaged", true, false, null, true);
                                        }
                                        else
                                        {
                                            targetPawn.TryStartAttack(TM_Calc.FindNearbyPawn(targetPawn, 10));
                                        }
                                    }
                                    else if (rnd <= 1f)
                                    {
                                        int rndCount = Rand.Range(2, 5);
                                        for (int j = 0; j < rndCount; j++)
                                        {
                                            TM_Action.DamageEntities(targetPawn, null, Rand.Range(3, 5) + pwrVal, TMDamageDefOf.DamageDefOf.TM_ElectricalBurn, this.launcher);
                                        }
                                    }
                                }
                                else
                                {
                                    MoteMaker.ThrowText(targetPawn.DrawPos, targetPawn.Map, "TM_ResistedSpell".Translate(), -1);
                                }
                                this.age = this.duration;
                            }
                            else
                            {
                                targetPawn = null;
                                //Log.Message("pawn not a robot, mechanoid, or android");
                            }
                        }

                        targetBuilding = this.targetCells[i].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 if (rnd <= .66f)
                                {
                                    //electrical burn short circuit
                                }
                                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;
            }
        }
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);
            if (!this.initialized)
            {
                this.caster = this.launcher as Pawn;
                CompAbilityUserMight comp = caster.GetComp <CompAbilityUserMight>();
                //pwrVal = caster.GetComp<CompAbilityUserMight>().MightData.MightPowerSkill_GraveBlade.FirstOrDefault((MightPowerSkill x) => x.label == "TM_GraveBlade_pwr").level;
                //verVal = caster.GetComp<CompAbilityUserMight>().MightData.MightPowerSkill_GraveBlade.FirstOrDefault((MightPowerSkill x) => x.label == "TM_GraveBlade_ver").level;
                verVal = TM_Calc.GetMightSkillLevel(caster, comp.MightData.MightPowerSkill_GraveBlade, "TM_GraveBlade", "_ver", true);
                pwrVal = TM_Calc.GetMightSkillLevel(caster, comp.MightData.MightPowerSkill_GraveBlade, "TM_GraveBlade", "_pwr", true);
                //ModOptions.SettingsRef settingsRef = new ModOptions.SettingsRef();
                this.arcaneDmg = comp.mightPwr;
                //if (settingsRef.AIHardMode && !caster.IsColonist)
                //{
                //    pwrVal = 3;
                //    verVal = 3;
                //}
                this.radius        = this.def.projectile.explosionRadius;
                this.duration      = 10 + (int)(this.radius * 20);
                this.innerCellList = GenRadial.RadialCellsAround(base.Position, this.radius, true).ToList();
                this.ringCellList  = GenRadial.RadialCellsAround(base.Position, this.radius + 1, false).Except(innerCellList).ToList();
                this.effectIndex2  = ringCellList.Count / 2;
                this.initialized   = true;
            }

            if (this.Map != null)
            {
                if (Find.TickManager.TicksGame % this.effectDelay == 0)
                {
                    Vector3 drawIndex1 = this.ringCellList[effectIndex1].ToVector3Shifted();
                    drawIndex1.x += Rand.Range(-.35f, .35f);
                    drawIndex1.z += Rand.Range(-.35f, .35f);
                    Vector3 drawIndex2 = this.ringCellList[effectIndex2].ToVector3Shifted();
                    drawIndex2.x += Rand.Range(-.35f, .35f);
                    drawIndex2.z += Rand.Range(-.35f, .35f);
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritFlame"), drawIndex1, this.Map, Rand.Range(.4f, .8f), .1f, 0, .6f, 0, Rand.Range(.4f, 1f), Rand.Range(-20, 20), Rand.Range(-20, 20));
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritFlame"), drawIndex2, this.Map, Rand.Range(.4f, .8f), .1f, 0, .6f, 0, Rand.Range(.4f, 1f), Rand.Range(-20, 20), Rand.Range(-20, 20));
                    this.effectIndex1++;
                    this.effectIndex2++;
                    if (this.effectIndex1 >= ringCellList.Count)
                    {
                        this.effectIndex1 = 0;
                    }
                    if (this.effectIndex2 >= ringCellList.Count)
                    {
                        this.effectIndex2 = 0;
                    }
                }
                if (Find.TickManager.TicksGame % this.strikeDelay == 0 && !this.caster.DestroyedOrNull())
                {
                    IntVec3 centerCell = innerCellList.RandomElement();
                    IEnumerable <IntVec3> targetCells = GenRadial.RadialCellsAround(centerCell, 2f, true);
                    foreach (var target in targetCells)
                    {
                        IntVec3 curCell = target;
                        Pawn    victim  = curCell.GetFirstPawn(this.Map);
                        if (victim != null && !victim.Destroyed && !victim.Dead && victim != this.caster)
                        {
                            TM_Action.DamageEntities(victim, null, (Rand.Range(10, 16) + (2 * pwrVal)) * this.arcaneDmg, TMDamageDefOf.DamageDefOf.TM_Spirit, this.launcher);
                            if (!this.caster.DestroyedOrNull() && !this.caster.Dead && Rand.Chance(verVal))
                            {
                                TM_Action.DoAction_HealPawn(this.caster, this.caster, 1, (Rand.Range(6, 10) + (2 * verVal)) * this.arcaneDmg);
                                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritRetaliation"), this.caster.DrawPos, this.caster.Map, Rand.Range(1f, 1.2f), Rand.Range(.1f, .15f), 0, Rand.Range(.1f, .2f), -600, 0, 0, Rand.Range(0, 360));
                                TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_SpiritRetaliation"), this.caster.DrawPos, this.caster.Map, Rand.Range(1f, 1.2f), Rand.Range(.1f, .15f), 0, Rand.Range(.1f, .2f), 600, 0, 0, Rand.Range(0, 360));
                            }
                            if (Rand.Chance(verVal))
                            {
                                if (!victim.IsWildMan() && victim.RaceProps.Humanlike && victim.mindState != null && !victim.InMentalState)
                                {
                                    try
                                    {
                                        Job job = new Job(JobDefOf.FleeAndCower);
                                        //victim.mindState.mentalStateHandler.TryStartMentalState(TorannMagicDefOf.TM_PanicFlee);
                                    }
                                    catch (NullReferenceException)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    TM_MoteMaker.ThrowGenericMote(ThingDef.Named("Mote_GraveBlade"), centerCell.ToVector3Shifted(), this.Map, Rand.Range(1f, 1.6f), .15f, .1f, .2f, 0, Rand.Range(4f, 6f), 0, 0);
                }
            }
        }
Exemplo n.º 8
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);
        }
        public void DoStrike(Thing target)
        {
            if (target != null && target is Pawn)
            {
                Pawn t = target as Pawn;
                if (t.Faction == null || (t.Faction != null && t.Faction != caster.Faction))
                {
                    //List<BodyPartRecord> partList = new List<BodyPartRecord>();
                    //partList.Clear();
                    //for (int i = 0; i < t.RaceProps.body.AllParts.Count; i++)
                    //{
                    //    BodyPartRecord part = t.RaceProps.body.AllParts[i];
                    //    if (part.depth == BodyPartDepth.Outside)
                    //    {
                    //        partList.Add(part);
                    //    }
                    //}
                    for (int i = 0; i < 4; i++)
                    {
                        if (!t.DestroyedOrNull() && !t.Dead && t.Map != null)
                        {
                            int dmg = Mathf.RoundToInt(this.weaponDamage);
                            if (Rand.Chance(critChance))
                            {
                                dmg *= 3;
                            }
                            BodyPartRecord bpr = t.health.hediffSet.GetRandomNotMissingPart(DamageDefOf.Stab, BodyPartHeight.Undefined, BodyPartDepth.Outside);
                            TM_Action.DamageEntities(target, bpr, dmg, Rand.Range(0f, .5f), DamageDefOf.Stab, this.caster);
                            Vector3 rndPos = t.DrawPos;
                            rndPos.x += Rand.Range(-.2f, .2f);
                            rndPos.z += Rand.Range(-.2f, .2f);
                            TM_MoteMaker.ThrowBloodSquirt(rndPos, t.Map, Rand.Range(.6f, 1f));
                            TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_CrossStrike, rndPos, t.Map, Rand.Range(.6f, 1f), .4f, 0f, Rand.Range(.2f, .5f), 0, 0, 0, Rand.Range(0, 360));
                        }
                    }
                    if (!t.DestroyedOrNull() && !t.Dead && !t.Downed && caster.IsColonist)
                    {
                        caster.drafter.Drafted = true;
                        Job job = new Job(JobDefOf.AttackMelee, t);
                        caster.jobs.TryTakeOrderedJob(job, JobTag.DraftedOrder);
                    }
                }
            }
            if (verVal >= 1)
            {
                int invisDuration = 120;
                if (verVal >= 2)
                {
                    invisDuration = 180;
                }
                HealthUtility.AdjustSeverity(caster, TorannMagicDefOf.TM_ShadowCloakHD, .2f);

                HediffComp_Disappears hdComp = caster.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ShadowCloakHD).TryGetComp <HediffComp_Disappears>();
                if (hdComp != null)
                {
                    hdComp.ticksToDisappear = invisDuration;
                }
            }
            if (verVal >= 3)
            {
                int radius = 2;
                if (verVal >= 5)
                {
                    radius = 3;
                }
                float sev = 1.5f;
                if (verVal >= 4)
                {
                    sev = 2.2f;
                }
                List <Pawn> targetList = TM_Calc.FindPawnsNearTarget(caster, radius, caster.Position, true);
                if (targetList != null && targetList.Count > 0)
                {
                    for (int i = 0; i < targetList.Count; i++)
                    {
                        if (targetList[i].RaceProps.IsFlesh)
                        {
                            HealthUtility.AdjustSeverity(targetList[i], TorannMagicDefOf.TM_NightshadeToxinHD, Rand.Range(.7f * sev, 1.3f * sev));
                        }
                    }
                }
                ThingDef fog = TorannMagicDefOf.Fog_Shadows;
                fog.gas.expireSeconds.min = 2;
                fog.gas.expireSeconds.max = 3;
                GenExplosion.DoExplosion(caster.Position, caster.Map, radius, TMDamageDefOf.DamageDefOf.TM_Toxin, caster, 0, 0, TMDamageDefOf.DamageDefOf.TM_Toxin.soundExplosion, null, null, null, fog, 1f, 1, false, null, 0f, 0, 0.0f, false);

                for (int i = 0; i < 6; i++)
                {
                    Vector3 rndPos = caster.DrawPos;
                    rndPos.x += Rand.Range(-.5f, .5f);
                    rndPos.z += Rand.Range(-.5f, .5f);
                    TM_MoteMaker.ThrowGenericMote(TorannMagicDefOf.Mote_ShadowCloud, rndPos, caster.Map, Rand.Range(.6f, 1f), .4f, .05f, Rand.Range(.2f, .5f), Rand.Range(-40, 40), Rand.Range(1, 2f), Rand.Range(0, 360), Rand.Range(0, 360));
                }
            }
            ApplyHaste(caster);
        }
Exemplo n.º 10
0
        protected override bool TryCastShot()
        {
            bool result = false;
            bool arg_40_0;

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

            if (flag)
            {
                if (flag2 & flag3)
                {
                    Pawn    p         = this.CasterPawn;
                    Map     map       = this.CasterPawn.Map;
                    IntVec3 cell      = this.CasterPawn.Position;
                    bool    draftFlag = this.CasterPawn.Drafted;
                    try
                    {
                        if (this.CasterPawn.IsColonist)
                        {
                            ModOptions.Constants.SetPawnInFlight(true);
                            ThingSelectionUtility.SelectNextColonist();
                            this.CasterPawn.DeSpawn();
                            //p.SetPositionDirect(this.currentTarget.Cell);
                            GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                            p.drafter.Drafted = draftFlag;
                            if (base.CasterPawn.GetComp <CompAbilityUserMagic>().MagicData.MagicPowerSkill_Cantrips.FirstOrDefault((MagicPowerSkill x) => x.label == "TM_Cantrips_ver").level >= 1)
                            {
                                List <Pawn> eList = TM_Calc.FindPawnsNearTarget(p, 2, this.currentTarget.Cell, true);
                                if (eList != null && eList.Count > 0)
                                {
                                    for (int i = 0; i < eList.Count; i++)
                                    {
                                        Pawn e = eList[i];
                                        TM_Action.DamageEntities(e, null, 5f, DamageDefOf.Stun, p);
                                    }
                                }
                            }
                            CameraJumper.TryJumpAndSelect(p);
                            ModOptions.Constants.SetPawnInFlight(false);
                        }
                        else
                        {
                            ModOptions.Constants.SetPawnInFlight(true);
                            this.CasterPawn.DeSpawn();
                            GenSpawn.Spawn(p, this.currentTarget.Cell, map);
                            ModOptions.Constants.SetPawnInFlight(false);
                        }
                    }
                    catch
                    {
                        if (!this.CasterPawn.Spawned)
                        {
                            GenSpawn.Spawn(p, cell, map);
                            Log.Message("Exception occured when trying to blink - recovered pawn at position ability was used from.");
                        }
                    }
                    //this.Ability.PostAbilityAttempt();
                    //this.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                    //base.CasterPawn.SetPositionDirect(this.currentTarget.Cell);
                    //this.CasterPawn.pather.ResetToCurrentPosition();
                    result = true;
                }
                else
                {
                    Messages.Message("InvalidTargetLocation".Translate(), MessageTypeDefOf.RejectInput);
                }
            }
            else
            {
                Log.Warning("failed to TryCastShot");
            }
            this.burstShotsLeft = 0;
            //this.ability.TicksUntilCasting = (int)base.UseAbilityProps.SecondsToRecharge * 60;
            return(result);
        }
Exemplo n.º 11
0
        protected override bool TryCastShot()
        {
            Pawn p   = this.CasterPawn;
            Map  map = this.CasterPawn.Map;
            CompAbilityUserMagic comp = this.CasterPawn.GetComp <CompAbilityUserMagic>();

            pawns.Clear();
            plants.Clear();
            GenClamor.DoClamor(p, this.UseAbilityProps.TargetAoEProperties.range, ClamorDefOf.Ability);
            Effecter snapeFreezeED = TorannMagicDefOf.TM_SnapFreezeED.Spawn();

            snapeFreezeED.Trigger(new TargetInfo(this.currentTarget.Cell, map, false), new TargetInfo(this.currentTarget.Cell, map, false));
            snapeFreezeED.Cleanup();
            SoundInfo info = SoundInfo.InMap(new TargetInfo(this.currentTarget.Cell, map, false), MaintenanceType.None);

            info.pitchFactor  = .4f;
            info.volumeFactor = 1.2f;
            TorannMagicDefOf.TM_WindLowSD.PlayOneShot(info);
            TargetInfo ti = new TargetInfo(this.currentTarget.Cell, map, false);

            TM_MoteMaker.MakeOverlay(ti, TorannMagicDefOf.TM_Mote_PsycastAreaEffect, map, Vector3.zero, 3f, 0f, .1f, .4f, 1.2f, -3f);
            if (this.currentTarget != null && p != null && comp != null)
            {
                this.arcaneDmg = comp.arcaneDmg;
                this.TargetsAoE.Clear();
                this.FindTargets();
                float energy = -125000 * this.arcaneDmg;
                GenTemperature.PushHeat(this.currentTarget.Cell, p.Map, energy);
                for (int i = 0; i < pawns.Count; i++)
                {
                    if (!pawns[i].RaceProps.IsMechanoid && pawns[i].RaceProps.body.AllPartsVulnerableToFrostbite.Count > 0)
                    {
                        float distanceModifier = 1f / (pawns[i].Position - currentTarget.Cell).LengthHorizontal;
                        if (distanceModifier > 1f)
                        {
                            distanceModifier = 1f;
                        }
                        int bites = Rand.Range(1, 5);
                        for (int j = 0; j < bites; j++)
                        {
                            if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, pawns[i], true)) && Rand.Chance(distanceModifier))
                            {
                                TM_Action.DamageEntities(pawns[i], pawns[i].def.race.body.AllPartsVulnerableToFrostbite.RandomElement(), Rand.Range(10, 20) * distanceModifier, 1f, DamageDefOf.Frostbite, p);
                            }
                            if (Rand.Chance(TM_Calc.GetSpellSuccessChance(this.CasterPawn, pawns[i], true)) && Rand.Chance(distanceModifier))
                            {
                                HealthUtility.AdjustSeverity(pawns[i], HediffDefOf.Hypothermia, distanceModifier / 5f);
                            }
                        }
                    }
                }
                for (int i = 0; i < plants.Count; i++)
                {
                    float distanceModifier = 1f / (plants[i].Position - currentTarget.Cell).LengthHorizontal;
                    if (distanceModifier > 1f)
                    {
                        distanceModifier = 1f;
                    }
                    if (plants[i].def.plant.IsTree)
                    {
                        if (Rand.Chance(distanceModifier / 2f))
                        {
                            plants[i].MakeLeafless(Plant.LeaflessCause.Cold);
                        }
                    }
                    else
                    {
                        if (Rand.Chance(distanceModifier))
                        {
                            plants[i].MakeLeafless(Plant.LeaflessCause.Cold);
                        }
                    }
                    plants[i].Notify_ColorChanged();
                }
                List <IntVec3> cellList = GenRadial.RadialCellsAround(this.currentTarget.Cell, this.UseAbilityProps.TargetAoEProperties.range, true).ToList();
                bool           raining  = map.weatherManager.RainRate > 0f || map.weatherManager.SnowRate > 0f;
                for (int i = 0; i < cellList.Count; i++)
                {
                    cellList[i] = cellList[i].ClampInsideMap(map);
                    SnowUtility.AddSnowRadial(cellList[i], map, 2.4f, Rand.Range(.08f, .13f));
                    TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_AirPuff, cellList[i].ToVector3Shifted(), map, 2.5f, .05f, .05f, Rand.Range(2f, 3f), Rand.Range(-60, 60), .5f, -70, Rand.Range(0, 360));
                }
                List <IntVec3> windList = GenRadial.RadialCellsAround(this.currentTarget.Cell, this.UseAbilityProps.TargetAoEProperties.range + 1, true).Except(cellList).ToList();
                for (int i = 0; i < windList.Count; i++)
                {
                    windList[i] = windList[i].ClampInsideMap(map);
                    Vector3 angle = TM_Calc.GetVector(windList[i], this.currentTarget.Cell);
                    TM_MoteMaker.ThrowGenericMote(ThingDefOf.Mote_AirPuff, windList[i].ToVector3Shifted(), map, Rand.Range(1.2f, 2f), .45f, Rand.Range(0f, .25f), .5f, -200, Rand.Range(3, 5), (Quaternion.AngleAxis(90, Vector3.up) * angle).ToAngleFlat(), Rand.Range(0, 360));
                }
            }

            this.burstShotsLeft = 0;
            return(true);
        }