fBaseXtensions.Targeting.TargetingClass.Refresh C# (CSharp) Method

Refresh() public method

public Refresh ( ) : bool
return bool
        public virtual bool Refresh()
        {
            // Make sure we reset unstucker stuff here
            PlayerMover.iTimesReachedStuckPoint = 0;
            PlayerMover.vSafeMovementLocation = Vector3.Zero;
            PlayerMover.timeLastRecordedPosition = DateTime.Now;

            // Let's calculate whether or not we want a new target list...
            #region NewtargetChecks
            // Whether we should refresh the target list or not
            bool bShouldRefreshDiaObjects = false;

            if (!Cache.bWholeNewTarget && !Cache.bWaitingForPower && !Cache.bWaitingForPotion)
            {
                // Update targets at least once every 80 milliseconds
                if (Cache.bForceTargetUpdate
                    || Cache.TravellingAvoidance
                    || ((DateTime.Now.Subtract(Cache.lastRefreshedObjects).TotalMilliseconds >= 80 && !ObjectCache.CheckFlag(Cache.CurrentTarget.targetType.Value, TargetType.AvoidanceMovements | TargetType.NoMovement))
                    || DateTime.Now.Subtract(Cache.lastRefreshedObjects).TotalMilliseconds >= 1200))
                {
                    bShouldRefreshDiaObjects = true;
                }

                // If we AREN'T getting new targets - find out if we SHOULD because the current unit has died etc.
                if (!bShouldRefreshDiaObjects && Cache.CurrentTarget.targetType.Value == TargetType.Unit && !Cache.CurrentTarget.IsStillValid())
                    bShouldRefreshDiaObjects = true;

            }

            // So, after all that, do we actually want a new target list?
            if (!Cache.bWholeNewTarget && !Cache.bWaitingForPower && !Cache.bWaitingForPotion)
            {
                // If we *DO* want a new target list, do this...
                if (bShouldRefreshDiaObjects)
                {
                    // Now call the function that refreshes targets
                    Cache.Refresh();

                    // No target, return success
                    if (Cache.CurrentTarget == null)
                    {
                        CurrentState = RunStatus.Success;
                        return false;
                    }

                    // Been trying to handle the same target for more than 30 seconds without damaging/reaching it? Blacklist it!
                    if (!ObjectCache.CheckFlag(Cache.CurrentTarget.targetType.Value, TargetType.AvoidanceMovements | TargetType.NoMovement | TargetType.LineOfSight | TargetType.Backtrack)
                          && ((Cache.CurrentTarget.targetType.Value != TargetType.Unit && DateTime.Now.Subtract(Cache.LastChangeOfTarget).TotalSeconds > 12)
                          || (Cache.CurrentTarget.targetType.Value == TargetType.Unit &&
                              Cache.CurrentUnitTarget != null &&
                              !Cache.CurrentTarget.IsBoss &&
                              DateTime.Now.Subtract(Cache.LastChangeOfTarget).TotalSeconds > 20)))
                    {
                        bool bBlacklistThis = true;
                        if (Cache.CurrentTarget.targetType.Value == TargetType.Unit)
                        {
                            if (Cache.CurrentTarget.IsTreasureGoblin && FunkyBaseExtension.Settings.Targeting.GoblinPriority >= 3)
                                bBlacklistThis = false;

                            //Do not ignore when..
                            //A Health changed occured less than 10 secs ago..
                            //or we have not used a combat skill in at least 10 secs
                            if (DateTime.Now.Subtract(Cache.CurrentUnitTarget.LastHealthChange).TotalSeconds < 10 ||
                                DateTime.Now.Subtract(FunkyGame.Hero.Class.LastUsedACombatAbility).TotalSeconds > 10)
                            {
                                bBlacklistThis = false;
                            }

                        }

                        if (bBlacklistThis)
                        {
                            if (Cache.CurrentTarget.targetType.Value == TargetType.Unit && Cache.CurrentUnitTarget != null)
                            {

                                Logger.DBLog.DebugFormat("[Funky] Blacklisting Unit after 20 seconds of no new target! {0}",
                                    Cache.CurrentUnitTarget.DebugString);

                                Logger.DBLog.DebugFormat("{0}", FunkyGame.Targeting.DebugString());

                            }
                            else
                            {
                                Logger.DBLog.DebugFormat("[Funky] Blacklisting Object after no new target! {0}", Cache.CurrentTarget.DebugStringSimple);
                            }

                            Cache.CurrentTarget.NeedsRemoved = true;
                            Cache.CurrentTarget.BlacklistLoops = -1;
                            Cache.CurrentTarget.BlacklistFlag = BlacklistType.Temporary;
                        }
                    }
                    // Make sure we start trying to move again should we need to!
                    Cache.bPickNewAbilities = true;

                    cMovement.NewTargetResetVars();
                }
            }
            #endregion

            // This variable just prevents an instant 2-target update after coming here from the main decorator function above
            Cache.bWholeNewTarget = false;

            //Update CurrentUnitTarget
            if (Cache.CurrentTarget.targetType.Value == TargetType.Unit)
            {
                //Update CurrentUnitTarget Variable.
                if (Cache.CurrentUnitTarget == null) Cache.CurrentUnitTarget = (CacheUnit)Cache.CurrentTarget;

                Cache.CurrentTarget.UpdatePosition(true);

                if (!Cache.CurrentUnitTarget.CurrentHealthPct.HasValue || Cache.CurrentUnitTarget.CurrentHealthPct.Value > 1d)
                {
                    Logger.DBLog.DebugFormat("Current Unit Target health exceedes 100%! {0}",
                        Cache.CurrentTarget.DebugStringSimple);
                }

            }

            //Make sure we are not incapacitated..
            if (FunkyGame.Hero.bIsIncapacitated)
            {
                CurrentState = RunStatus.Running;
                return false;
            }

            //We are ready for the specific object type interaction
            return true;
        }