private void GetSecondTarget()
 {
     Find.Targeter.StopTargeting();
     this.BeginTargetingWithVerb(WizardryDefOf.CompVerb, WizardryDefOf.CompVerb.MainVerb.targetParams, delegate(LocalTargetInfo info)
     {
         CompWizardry comp = caster.GetComp <CompWizardry>();
         comp.SecondTarget = info;
     }, caster, null, null);
 }
        public virtual void Effect()
        {
            try
            {
                CompWizardry comp = this.CasterPawn.GetComp <CompWizardry>();
                comp.SecondTarget = null;

                LocalTargetInfo t          = this.currentTarget;
                IntVec3         targetCell = t.Cell;

                launchableThing = t.Cell.GetFirstPawn(this.CasterPawn.Map);

                if (launchableThing == null)
                {
                    List <Thing> cellThings = t.Cell.GetThingList(this.CasterPawn.Map);
                    for (int i = 0; i < cellThings.Count(); i++)
                    {
                        if (cellThings[i].def.EverHaulable)
                        {
                            launchableThing = cellThings[i];
                            i = cellThings.Count();
                        }
                    }
                }

                if (launchableThing != null)
                {
                    bool flag = targetCell.InBounds(base.CasterPawn.Map) && targetCell.IsValid;
                    if (flag)
                    {
                        LongEventHandler.QueueLongEvent(delegate
                        {
                            Manwe_FlyingObject_WindControl flyingObject = (Manwe_FlyingObject_WindControl)GenSpawn.Spawn(ThingDef.Named("FlyingObject_WindControl"), this.currentTarget.Cell, this.CasterPawn.Map);
                            flyingObject.Launch(this.CasterPawn, t.Cell, launchableThing);
                        }, "LaunchingFlyer", false, null);
                    }
                    else
                    {
                        Log.Message("invalid map or cell");
                    }

                    Find.Targeter.StopTargeting();
                    this.BeginTargetingWithVerb(WizardryDefOf.CompVerb, WizardryDefOf.CompVerb.MainVerb.targetParams, delegate(LocalTargetInfo info)
                    {
                        this.action       = info;
                        comp              = this.CasterPawn.GetComp <CompWizardry>();
                        comp.SecondTarget = info;
                    }, this.CasterPawn, null, null);
                }
            }
            catch (NullReferenceException ex)
            {
                Log.Message(ex.ToString());
            }
        }
        public override void PostCastShot(bool inResult, out bool outResult)
        {
            CompWizardry comp = base.CasterPawn.GetComp <CompWizardry>();

            comp.SecondTarget = null;

            Find.Targeter.StopTargeting();
            this.BeginTargetingWithVerb(WizardryDefOf.CompVerb, WizardryDefOf.CompVerb.MainVerb.targetParams, delegate(LocalTargetInfo info)
            {
                this.action       = info;
                comp              = this.CasterPawn.GetComp <CompWizardry>();
                comp.SecondTarget = info;
            }, this.CasterPawn, null, null);
            outResult = inResult;
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            bool result = false;
            Pawn pawn2  = t as Pawn;

            if (pawn.story.traits.HasTrait(WizardryDefOf.LotRW_Istari))
            {
                CompWizardry comp        = pawn.GetComp <CompWizardry>();
                PawnAbility  pawnAbility = comp.AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == WizardryDefOf.LotRW_Nienna_HealingTouch);
                if (pawn2 != null && (!this.def.tendToHumanlikesOnly || pawn2.RaceProps.Humanlike) && (!this.def.tendToAnimalsOnly || pawn2.RaceProps.Animal) && WorkGiver_Tend.GoodLayingStatusForTend(pawn2, pawn) && HasHediffInjuries(pawn2) && pawn != pawn2 && pawnAbility.CooldownTicksLeft <= 0)
                {
                    LocalTargetInfo target = pawn2;
                    if (pawn.CanReserve(target, 1, -1, null, forced))
                    {
                        return(true);
                    }
                }
            }
            return(result);
        }
        public void Launch(Thing launcher, Vector3 origin, LocalTargetInfo targ, Thing flyingThing, DamageInfo?newDamageInfo = null)
        {
            this.Initialize();
            bool spawned = flyingThing.Spawned;

            pawn = launcher as Pawn;
            if (spawned)
            {
                flyingThing.DeSpawn();
            }

            this.launcher     = launcher;
            this.origin       = origin;
            this.impactDamage = newDamageInfo;
            this.flyingThing  = flyingThing;

            CompWizardry comp = pawn.GetComp <CompWizardry>();

            if (comp.SecondTarget != null)
            {
                if (comp.SecondTarget.Thing != null)
                {
                    this.destination    = comp.SecondTarget.Thing.Position.ToVector3Shifted();
                    this.assignedTarget = comp.SecondTarget.Thing;
                }
                else
                {
                    this.destination = comp.SecondTarget.CenterVector3;
                }
            }
            else
            {
                this.destination = targ.Cell.ToVector3Shifted();
            }

            this.ticksToImpact = this.StartingTicksToImpact;
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            if (!this.initialized)
            {
                caster = this.launcher as Pawn;
                GetSecondTarget();
                //todo: determine thingdef based on ground type, not random
                float rnd = Rand.Range(0f, 3f);
                if (rnd < 1)
                {
                    spawnDef = ThingDef.Named("Sandstone");
                }
                else if (rnd < 2)
                {
                    spawnDef = ThingDef.Named("Granite");
                }
                else if (rnd < 3)
                {
                    spawnDef = ThingDef.Named("Slate");
                }
                else if (rnd < 4)
                {
                    spawnDef = ThingDef.Named("Limestone");
                }
                else
                {
                    spawnDef = ThingDef.Named("Marble");
                }
                this.initialized = true;
            }

            CompWizardry comp = caster.GetComp <CompWizardry>();

            if (!this.wallActive && comp.SecondTarget != null)
            {
                this.age          = 0;
                this.duration     = 2400;
                this.wallActive   = true;
                this.wallPos      = base.Position.ToVector3Shifted();
                this.wallDir      = GetVector(base.Position.ToVector3Shifted(), comp.SecondTarget.Cell.ToVector3Shifted());
                this.wallEnd      = comp.SecondTarget.Cell;
                comp.SecondTarget = null;
            }

            if (!wallActive)
            {
                if (Find.TickManager.TicksGame % 6 == 0)
                {
                    EffectMaker.MakeEffect(ThingDef.Named("Mote_ThickDust"), base.Position.ToVector3Shifted(), this.Map, Rand.Range(.4f, .6f), Rand.Range(0, 360), Rand.Range(.8f, 1.6f), Rand.Range(-20, 20), 0, Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), false);
                }
            }
            else
            {
                if (wallLength < wallLengthMax)
                {
                    float magnitude = (base.Position.ToVector3Shifted() - Find.Camera.transform.position).magnitude;
                    Find.CameraDriver.shaker.DoShake(10 / magnitude);
                    for (int k = 0; k < wallLengthMax; k++)
                    {
                        List <Thing> cellList = this.wallPos.ToIntVec3().GetThingList(caster.Map);
                        bool         hasWall  = false;
                        for (int i = 0; i < cellList.Count(); i++)
                        {
                            if (cellList[i].def.designationCategory == DesignationCategoryDefOf.Structure)
                            {
                                hasWall = true;
                            }
                        }

                        if (!hasWall)
                        {
                            bool spawnWall = true;
                            for (int i = 0; i < cellList.Count(); i++)
                            {
                                if (!cellList[i].def.EverHaulable && !(cellList[i] is Pawn))
                                {
                                    if (cellList[i].def.altitudeLayer == AltitudeLayer.Building || cellList[i].def.altitudeLayer == AltitudeLayer.Item || cellList[i].def.altitudeLayer == AltitudeLayer.ItemImportant)
                                    {
                                        //Log.Message("bypassing object and setting wall spawn to false");
                                        spawnWall = false;
                                    }
                                    else
                                    {
                                        if (cellList[i].def.defName.Contains("Mote") || (cellList[i].def.defName == "LotRW_Projectile_RockWall"))
                                        {
                                            //Log.Message("avoided storing " + cellList[i].def.defName);
                                        }
                                        else
                                        {
                                            this.despawnedThingList.Add(cellList[i]);
                                            cellList[i].DeSpawn();
                                        }
                                    }
                                }
                                else
                                {
                                    int launchDir = -90;
                                    if (Rand.Chance(.5f))
                                    {
                                        launchDir = 90;
                                    }
                                    LaunchFlyingObect(cellList[i].Position + (Quaternion.AngleAxis(launchDir, Vector3.up) * wallDir).ToIntVec3(), cellList[i]);
                                }
                            }
                            if (spawnWall && Rand.Chance(this.wallSpawnChance))
                            {
                                AbilityUser.SpawnThings tempSpawn = new SpawnThings()
                                {
                                    def        = spawnDef,
                                    spawnCount = 1
                                };
                                SingleSpawnLoop(tempSpawn, wallPos.ToIntVec3(), caster.Map);
                                this.wallLength++;
                                this.wallPositions.Add(wallPos.ToIntVec3());
                                EffectMaker.MakeEffect(ThingDef.Named("Mote_ThickDust"), this.wallPos, this.Map, Rand.Range(.6f, .8f), Rand.Range(0, 360), Rand.Range(1f, 2f), Rand.Range(-20, 20), 0, Rand.Range(.2f, .3f), .05f, Rand.Range(.4f, .6f), false);
                            }
                        }

                        this.wallPos += this.wallDir;
                        EffectMaker.MakeEffect(ThingDef.Named("Mote_ThickDust"), this.wallPos, this.Map, Rand.Range(.6f, 1f), Rand.Range(0, 360), Rand.Range(.6f, 1f), Rand.Range(-20, 20), 0, Rand.Range(.4f, .6f), Rand.Range(.05f, .3f), Rand.Range(.4f, 1f), false);

                        if (this.wallPos.ToIntVec3() == this.wallEnd)
                        {
                            this.wallPos   -= this.wallDir;
                            this.wallLength = this.wallLengthMax;
                        }
                    }
                }
            }
        }
        protected override void Impact(Thing hitThing)
        {
            Map map = base.Map;

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

            if (!this.initialized)
            {
                caster = this.launcher as Pawn;
                GetSecondTarget();
                this.initialized = true;
            }

            CompWizardry comp = caster.GetComp <CompWizardry>();

            if (!this.wallActive && comp.SecondTarget != null)
            {
                this.age          = 0;
                this.duration     = 1200;
                this.wallActive   = true;
                this.wallPos      = base.Position.ToVector3Shifted();
                this.wallDir      = GetVector(base.Position.ToVector3Shifted(), comp.SecondTarget.Cell.ToVector3Shifted());
                this.wallEnd      = comp.SecondTarget.Cell;
                comp.SecondTarget = null;
            }

            if (!wallActive)
            {
                if (Find.TickManager.TicksGame % 6 == 0)
                {
                    MoteMaker.ThrowDustPuff(base.Position, caster.Map, Rand.Range(.6f, .9f));
                }
            }
            else
            {
                if (Find.TickManager.TicksGame % 3 == 0)
                {
                    if (wallLength < wallLengthMax)
                    {
                        List <Thing> cellList = this.wallPos.ToIntVec3().GetThingList(caster.Map);
                        bool         hasWall  = false;
                        for (int i = 0; i < cellList.Count(); i++)
                        {
                            if (cellList[i].def.defName == "LotRW_WindWall")
                            {
                                hasWall = true;
                            }
                        }

                        if (!hasWall)
                        {
                            bool spawnWall = true;
                            for (int i = 0; i < cellList.Count(); i++)
                            {
                                if (!cellList[i].def.EverHaulable)
                                {
                                    if (cellList[i].def.altitudeLayer == AltitudeLayer.Building || cellList[i].def.altitudeLayer == AltitudeLayer.Item || cellList[i].def.altitudeLayer == AltitudeLayer.ItemImportant)
                                    {
                                        //Log.Message("bypassing object and setting wall spawn to false");
                                        spawnWall = false;
                                    }
                                    else
                                    {
                                        if (cellList[i].def.defName.Contains("Mote") || (cellList[i].def.defName == "LotRW_Projectile_AirWall"))
                                        {
                                            //Log.Message("avoided storing " + cellList[i].def.defName);
                                        }
                                        else
                                        {
                                            this.despawnedThingList.Add(cellList[i]);
                                            cellList[i].DeSpawn();
                                        }
                                    }
                                }
                                else
                                {
                                    int launchDir = -90;
                                    if (Rand.Chance(.5f))
                                    {
                                        launchDir = 90;
                                    }
                                    LaunchFlyingObect(cellList[i].Position + (Quaternion.AngleAxis(launchDir, Vector3.up) * wallDir).ToIntVec3(), cellList[i]);
                                }
                            }
                            if (spawnWall)
                            {
                                AbilityUser.SpawnThings tempSpawn = new SpawnThings()
                                {
                                    def        = ThingDef.Named("LotRW_WindWall"),
                                    spawnCount = 1
                                };
                                SingleSpawnLoop(tempSpawn, wallPos.ToIntVec3(), caster.Map);
                                this.wallLength++;
                                this.wallPositions.Add(wallPos.ToIntVec3());
                            }
                        }

                        this.wallPos += this.wallDir;

                        if (!this.wallPos.ToIntVec3().Walkable(caster.Map) || this.wallPos.ToIntVec3() == this.wallEnd)
                        {
                            this.wallPos   -= this.wallDir;
                            this.wallLength = this.wallLengthMax;
                        }
                    }

                    for (int j = 0; j < this.wallPositions.Count(); j++)
                    {
                        int launchDir = Rand.Range(-100, -80);
                        if (Rand.Chance(.5f))
                        {
                            launchDir = Rand.Range(80, 100);
                        }
                        EffectMaker.MakeEffect(ThingDef.Named("Mote_DustPuff"), this.wallPositions.RandomElement().ToVector3Shifted(), caster.Map, Rand.Range(.6f, .8f), (Quaternion.AngleAxis(launchDir, Vector3.up) * wallDir).ToAngleFlat(), Rand.Range(2f, 5f), Rand.Range(100, 200), .04f, .03f, .8f, false);
                    }
                }
            }
        }
        public override void Tick()
        {
            base.Tick();
            this.age++;
            Vector3 exactPosition = this.ExactPosition;

            this.ticksToImpact--;
            bool flag = !this.ExactPosition.InBounds(base.Map);

            if (flag)
            {
                this.ticksToImpact++;
                base.Position = this.ExactPosition.ToIntVec3();
                this.Destroy(DestroyMode.Vanish);
            }
            else if (!this.ExactPosition.ToIntVec3().Walkable(base.Map))
            {
                this.earlyImpact = true;
                this.impactForce = (this.DestinationCell - this.ExactPosition.ToIntVec3()).LengthHorizontal + (this.speed * .2f);
                this.ImpactSomething();
            }
            else
            {
                base.Position = this.ExactPosition.ToIntVec3();
                if (Find.TickManager.TicksGame % 3 == 0)
                {
                    MoteMaker.ThrowDustPuff(base.Position, base.Map, Rand.Range(0.8f, 1f));
                    this.rotation++;
                    if (this.rotation >= 4)
                    {
                        this.rotation = 0;
                    }

                    CompWizardry comp = pawn.GetComp <CompWizardry>();
                    if (comp.SecondTarget != null && !this.secondTarget)
                    {
                        this.origin = this.ExactPosition;
                        if (comp.SecondTarget.Thing != null)
                        {
                            this.destination    = comp.SecondTarget.Thing.Position.ToVector3Shifted();
                            this.assignedTarget = comp.SecondTarget.Thing;
                        }
                        else
                        {
                            this.destination = comp.SecondTarget.CenterVector3;
                        }
                        this.speed           = 22f;
                        this.ticksToImpact   = this.StartingTicksToImpact;
                        this.flyingDirection = GetVector(this.origin.ToIntVec3(), this.destination.ToIntVec3());
                        comp.SecondTarget    = null;
                        this.secondTarget    = true;
                    }
                }
                if (Find.TickManager.TicksGame % 12 == 0 && this.secondTarget == true)
                {
                    DoFlyingObjectDamage();
                }

                bool flag2 = this.ticksToImpact <= 0;
                if (flag2)
                {
                    bool flag4 = this.age > this.duration;
                    if (flag4 || this.secondTarget)
                    {
                        bool flag3 = this.DestinationCell.InBounds(base.Map);
                        if (flag3)
                        {
                            base.Position = this.DestinationCell;
                        }
                        this.ImpactSomething();
                    }
                    else
                    {
                        this.origin = this.destination;
                        this.speed  = 5f;
                        if (this.floatDir == 0)
                        {
                            this.destination.x += -.25f;
                            this.destination.z += .25f;
                        }
                        else if (this.floatDir == 1)
                        {
                            this.destination.x += .25f;
                            this.destination.z += .25f;
                        }
                        else if (this.floatDir == 2)
                        {
                            this.destination.x += .25f;
                            this.destination.z += -.25f;
                        }
                        else
                        {
                            this.destination.x += -.25f;
                            this.destination.z += -.25f;
                        }
                        this.floatDir++;
                        if (floatDir > 3)
                        {
                            this.floatDir = 0;
                        }
                        this.ticksToImpact = this.StartingTicksToImpact;
                    }
                }
            }
        }
コード例 #9
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Pawn patient     = TargetA.Thing as Pawn;
            Toil gotoPatient = new Toil()
            {
                initAction = () =>
                {
                    pawn.pather.StartPath(TargetA, PathEndMode.Touch);
                },
                defaultCompleteMode = ToilCompleteMode.PatherArrival
            };

            yield return(gotoPatient);

            Toil doHealing = new Toil();

            doHealing.initAction = delegate
            {
                if (age > duration)
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
                if (patient.DestroyedOrNull() || patient.Dead)
                {
                    this.EndJobWith(JobCondition.Incompletable);
                }
            };
            doHealing.tickAction = delegate
            {
                if (patient.DestroyedOrNull() || patient.Dead)
                {
                    this.EndJobWith(JobCondition.Incompletable);
                }
                if (Find.TickManager.TicksGame % 1 == 0)
                {
                    EffectMaker.MakeEffect(ThingDef.Named("Mote_HealingMote"), this.pawn.DrawPos, this.Map, Rand.Range(.3f, .5f), (Quaternion.AngleAxis(90, Vector3.up) * GetVector(this.pawn.Position, patient.Position)).ToAngleFlat() + Rand.Range(-10, 10), 5f, 0);
                }
                if (age > (lastHeal + ticksTillNextHeal))
                {
                    DoHealingEffect(patient);
                    EffectMaker.MakeEffect(ThingDef.Named("Mote_HealingCircles"), patient.DrawPos, this.Map, Rand.Range(.3f, .4f), 0, 0, Rand.Range(400, 500), Rand.Range(0, 360), .08f, .01f, .24f, false);
                    lastHeal = age;
                    if (this.injuryCount == 0)
                    {
                        this.EndJobWith(JobCondition.Succeeded);
                    }
                }
                if (!patient.Drafted && patient.CurJobDef != JobDefOf.Wait)
                {
                    if (patient.jobs.posture == PawnPosture.Standing)
                    {
                        Job job = new Job(JobDefOf.Wait, patient);
                        patient.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                    }
                }
                age++;
                ticksLeftThisToil = duration - age;
                if (age > duration)
                {
                    this.EndJobWith(JobCondition.Succeeded);
                }
            };
            doHealing.defaultCompleteMode = ToilCompleteMode.Delay;
            doHealing.defaultDuration     = this.duration;
            doHealing.WithProgressBar(TargetIndex.B, delegate
            {
                if (this.pawn.DestroyedOrNull() || this.pawn.Dead)
                {
                    return(1f);
                }
                return(1f - (float)doHealing.actor.jobs.curDriver.ticksLeftThisToil / this.duration);
            }, false, 0f);
            doHealing.AddFinishAction(delegate
            {
                CompWizardry comp       = pawn.GetComp <CompWizardry>();
                PawnAbility pawnAbility = comp.AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == WizardryDefOf.LotRW_Nienna_HealingTouch);
                pawnAbility.PostAbilityAttempt();
                patient.jobs.EndCurrentJob(JobCondition.Succeeded, true);
            });
            yield return(doHealing);
        }