Example #1
0
        public void UpdateAction(SoLAction withAction = SoLAction.Pending)
        {
            SoLAction inAction   = this.solAction;
            Vector3   destTarget = this.ExactPosition;

            this.curveVariance = 0;
            //Log.Message("action for " + solAction.ToString() + " queued action: " + queuedAction.ToString());
            if (queuedAction != SoLAction.Null)
            {
                solAction    = queuedAction;
                queuedAction = SoLAction.Null;
            }
            if (solAction == SoLAction.Pending || solAction == SoLAction.Goto)
            {
                if (this.pawn.GetPosture() == PawnPosture.LayingInBed || this.pawn.CurJobDef == JobDefOf.LayDown)
                {
                    if (!pawn.Awake() && LightEnergy > 5f)
                    {
                        Action_Sleeping(out destTarget);
                    }
                    //pawn injured?
                }
                else if (this.pawn.Drafted)
                {
                    this.delayCount++;
                    if (LightEnergy > 20 && EnergyChance && this.delayCount > 2)
                    {
                        Pawn p = TM_Calc.FindNearbyEnemy(this.pawn, (int)AttackTarget_ShortRange);
                        if (p != null && TM_Calc.HasLoSFromTo(pawn.Position, p, pawn, 0, AttackTarget_ShortRange))
                        {
                            Action_AttackCharge(p, out destTarget);
                            queuedAction = SoLAction.Limbo;
                        }
                        else
                        {
                            if (LightEnergy > 30 && this.delayCount > 6)
                            {
                                p = TM_Calc.FindNearbyEnemy(this.pawn.Position, this.pawn.Map, this.pawn.Faction, AttackTarget_MaxRange, AttackTarget_ShortRange);
                                if (p != null && TM_Calc.HasLoSFromTo(pawn.Position, p, pawn, 0, AttackTarget_MaxRange))
                                {
                                    Action_Attack(p, out destTarget);
                                    queuedAction = SoLAction.Returning;
                                }
                                else
                                {
                                    Action_Hover(out destTarget);
                                }
                            }
                            else
                            {
                                Action_Hover(out destTarget);
                            }
                        }
                    }
                    else
                    {
                        Action_Hover(out destTarget);
                    }
                }
                else if (this.pawn.Downed && this.pawn.health.hediffSet.GetInjuriesTendable().Count() > 0 && LightEnergy > 10)
                {
                    Action_GotoTarget(this.pawn.DrawPos, speed_jog, out destTarget);
                    this.assignedTarget = this.pawn;
                    queuedAction        = SoLAction.Guarding;
                }
                else if (this.shouldGlow)
                {
                    this.shouldGlow = false;
                    Action_GotoTarget(this.glowCenter.ToVector3Shifted(), this.speed_jog, out destTarget);
                    queuedAction = SoLAction.Glow;
                }
                else if (LightEnergy > 20 && EnergyChance)
                {
                    Pawn p = TM_Calc.FindNearbyInjuredPawnOther(this.pawn, 10, 10f);
                    this.delayCount++;
                    if (this.delayCount > 1 && p != null && p.Downed && TM_Calc.HasLoSFromTo(this.pawn.Position, p, this.pawn, 0, 10) && p.health.hediffSet.GetInjuriesTendable().Count() > 0)
                    {
                        Action_GotoTarget(p.DrawPos, speed_dash, out destTarget);
                        queuedAction        = SoLAction.Guarding;
                        this.assignedTarget = p;
                    }
                    else if (LightEnergy > 60 && EnergyChance)
                    {
                        if (this.delayCount > 2)
                        {
                            p = TM_Calc.FindNearbyPawn(this.pawn, 10);
                            if (p != null && p.needs != null && TM_Calc.HasLoSFromTo(this.pawn.Position, p, this.pawn, 0, 10))
                            {
                                if ((this.pawn.CurJobDef.joyKind != null || this.pawn.CurJobDef == JobDefOf.Wait_Wander || this.pawn.CurJobDef == JobDefOf.GotoWander) && this.pawn.needs.joy.CurLevelPercentage < .5f)
                                {
                                    this.delayCount = 0;
                                    Action_JoyBurst(this.pawn.DrawPos, out destTarget);
                                }
                                else if (p.needs.joy != null && (p.CurJobDef.joyKind != null || p.CurJobDef == JobDefOf.Wait_Wander || p.CurJobDef == JobDefOf.GotoWander) && p.needs.joy.CurLevelPercentage < .5f)
                                {
                                    this.delayCount = 0;
                                    Action_JoyBurst(p.DrawPos, out destTarget);
                                }
                                else if (this.delayCount > 3 && p.needs.mood != null && p.needs.mood.thoughts != null && p.needs.mood.thoughts.memories != null && p.needs.mood.thoughts.memories.GetFirstMemoryOfDef(TorannMagicDefOf.TM_BrightDayTD) == null)
                                {
                                    this.delayCount = 0;
                                    Action_GotoTarget(p.DrawPos, speed_jog, out destTarget);
                                    this.assignedTarget = p;
                                    queuedAction        = SoLAction.BrightenDay;
                                    //action circle target
                                }
                                else
                                {
                                    Action_Hover(out destTarget);
                                }
                            }
                            else
                            {
                                Action_Hover(out destTarget);
                            }
                        }
                        else
                        {
                            Action_Hover(out destTarget);
                        }
                    }
                    else
                    {
                        Action_Hover(out destTarget);
                    }
                }
                //else if(LightEnergy > 90 && (EnergyChance && EnergyChance && EnergyChance))
                //{
                //    Action_Clean(out destTarget);
                //}
                else
                {
                    this.delayCount = 0;
                    Action_Hover(out destTarget);
                }
            }
            else if (solAction == SoLAction.BrightenDay)
            {
                if (this.assignedTarget != null && this.assignedTarget is Pawn)
                {
                    Pawn p = this.assignedTarget as Pawn;
                    ActualLightCost(6f);
                    p.needs.mood.thoughts.memories.TryGainMemory(TorannMagicDefOf.TM_BrightDayTD);
                    Action_CircleTarget(this.assignedTarget, out destTarget);
                    queuedAction = SoLAction.Returning;
                }
            }
            else if (solAction == SoLAction.Glow)
            {
                if (this.glowing)
                {
                    StopGlow();
                }
                else
                {
                    DoGlow();
                }
                Action_Return();
            }
            else if (solAction == SoLAction.Returning)
            {
                Action_Return();
            }
            else if (solAction == SoLAction.Guarding)
            {
                if (LightEnergy > 10 && this.assignedTarget != null && this.assignedTarget is Pawn)
                {
                    Pawn p = this.assignedTarget as Pawn;
                    if (p.health.hediffSet.GetInjuriesTendable().Count() > 0)
                    {
                        this.ticksToImpact = 300;
                        ActualLightCost(2f);
                        CauterizeWounds(p);
                        queuedAction = SoLAction.Guarding;
                    }
                    else
                    {
                        Action_Hover(out destTarget);
                    }
                }
                else
                {
                    Action_Hover(out destTarget);
                }
            }
            else if (solAction == SoLAction.Limbo)
            {
                Action_FromLimbo(out destTarget);
            }

            if (solAction != SoLAction.Attacking && solAction != SoLAction.Returning && solAction != SoLAction.Guarding && solAction != SoLAction.Circling)
            {
                this.destination   = destTarget;
                this.ticksToImpact = this.StartingTicksToImpact;
            }
            //Log.Message("ending update action, new action: " + solAction.ToString() + " speed: " + this.speed + " delay action: " + this.delayCount + " light energy: "+ LightEnergy);

            if (this.solAction != inAction && this.solAction != SoLAction.Hovering && this.solAction != SoLAction.Sleeping)
            {
                this.delayCount = 0;
            }
        }