fBaseXtensions.Navigation.Gridpoint.GPQuadrant.UpdateWeight C# (CSharp) Method

UpdateWeight() public method

public UpdateWeight ( int &monstercount, int &avoidcount, List &UsedRAGUIDs, bool ResetIndex = false ) : double
monstercount int
avoidcount int
UsedRAGUIDs List
ResetIndex bool
return double
        public double UpdateWeight(out int monstercount, out int avoidcount, ref List<int> UsedRAGUIDs, bool ResetIndex = false)
        {
            monstercount = 0;
            avoidcount = 0;
            if (ResetIndex) LastIndexUsed = 0;

            OccupiedObjects.Clear();

            Vector3 sectorCenter = this.Center;
            //Get the Diagonal Length between start and end, multiply by 2.5 since each point represents an area of 5f than Divide the total by 2 for the radius range.
            double range = GridPoint.GetDistanceBetweenPoints(this.StartPoint, this.CornerPoint);

            int TotalGridPoints = this.ContainedPoints.Count;
            this.ThisWeight = 0d;

            //We use 2D Distance and subtract the obstacles radius
            IEnumerable<CacheObstacle> obstaclesContained = ObjectCache.Obstacles.Values
                  .Where(obs => Math.Max(0f, sectorCenter.Distance2D(obs.Position) - obs.Radius) <= range);

            double maxaverage = ObjectCache.Objects.MaximumHitPointAverage;
            if (obstaclesContained.Any())
            {
                //reset weight
                this.ThisWeight = 0;

                //copy SectorPoints
                //GridPoint[] SectorPoints=new GridPoint[this.ContainedPoints.Count];
                //this.ContainedPoints.CopyTo(SectorPoints);

                List<GridPoint> NonNavPoints = new List<GridPoint>();

                foreach (CacheObstacle item in obstaclesContained)
                {
                    OccupiedObjects.Add(item.RAGUID);

                    if (item is CacheServerObject)
                    {

                        //Monsters should add 10% of its weight
                        //if (item.Obstacletype.Value==ObstacleType.Monster)
                        //{
                        //	if (FunkyBaseExtension.Settings.Fleeing.EnableFleeingBehavior&& FunkyGame.Targeting.Environment.FleeTrigeringRAGUIDs.Contains(item.RAGUID))
                        //	{

                        //	}

                        //}
                        if (item.Obstacletype.Value == ObstacleType.ServerObject)
                        {
                            //give +1 to weight
                            this.ThisWeight++;
                        }
                    }
                    else if (item is CacheAvoidance)
                    {
                        if (!UsedRAGUIDs.Contains(item.RAGUID))
                        {
                            AvoidanceType thisAvoidanceType = ((CacheAvoidance)item).AvoidanceType;
                            if (AvoidanceCache.IgnoringAvoidanceType(thisAvoidanceType)) continue;
                            AvoidanceValue AV = FunkyBaseExtension.Settings.Avoidance.Avoidances[(int)thisAvoidanceType];

                            avoidcount++;
                            float BaseWeight = AV.Weight;

                            //if ((AvoidanceType.ArcaneSentry|AvoidanceType.Dececrator|AvoidanceType.MoltenCore|AvoidanceType.TreeSpore).HasFlag(thisAvoidanceType))
                            //	 BaseWeight=1f;
                            //else
                            //	 BaseWeight=0.5f;

                            this.ThisWeight += (BaseWeight / FunkyGame.Hero.dCurrentHealthPct);

                            UsedRAGUIDs.Add(item.RAGUID);
                        }
                    }
                }

                ////Now add a base score for non-nav points. (25 being 100% non-navigable)
                //int PointMultiplier=(25/TotalGridPoints);
                //int RemainingPoints=SectorPoints.Length;
                //this.ThisWeight+=25-(RemainingPoints*PointMultiplier);

                //Logger.DBLog.InfoFormat("Weight assigned to this sector {0}. \r\n"
                //+"Total Points {1} with {2} Remaining points Valid!", this.ThisWeight, this.ContainedPoints.Count, SectorPoints.Length);
            }

            return this.ThisWeight;

            //(Total Points / Non-Navigable Points Ratio)
        }