Ejemplo n.º 1
0
        public GPArea(Vector3 startingLocation)
        {
            StartingLocation = startingLocation;

            //Creation and Cache base
            centerGPRect = new GPRectangle(startingLocation, 5);
            GPRectangle centerClone = centerGPRect.Clone();

            //Get all valid points (besides current point) from our current location GPR
            GridPoint[] SearchPoints = centerGPRect.Points.Keys.Where(gp => !gp.Ignored).ToArray();
            gridpointrectangles_ = new List <GPRectangle>();
            if (SearchPoints.Length > 1)
            {
                Vector3 LastSearchVector3 = FunkyGame.Navigation.LastSearchVector;
                // LastSearchVector3.Normalize();

                //we should check our surrounding points to see if we can even move into any of them first!
                for (int i = 1; i < SearchPoints.Length - 1; i++)
                {
                    GridPoint curGP  = SearchPoints[i];
                    Vector3   thisV3 = (Vector3)curGP;
                    //thisV3.Normalize();

                    //Its a valid point for direction testing!
                    float          DirectionDegrees = Navigation.FindDirection(LastSearchVector3, thisV3);
                    DirectionPoint P = new DirectionPoint((Vector3)curGP, DirectionDegrees, 125f);

                    if (P.Range > 5f)
                    {
                        gridpointrectangles_.Add(new GPRectangle(P, centerGPRect));
                    }
                }
                gridpointrectangles_.Add(centerClone);
                gridpointrectangles_ = gridpointrectangles_.OrderByDescending(gpr => gpr.Count).ToList();
            }
        }
Ejemplo n.º 2
0
 public bool GridPointContained(GridPoint point)
 {
     return(centerGPRect.Contains(point));
 }
Ejemplo n.º 3
0
        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)
        }
Ejemplo n.º 4
0
 public void UpdateRange(Vector3 start)
 {
     StartingPoint = start;
     update_(start);
 }
Ejemplo n.º 5
0
        private bool CheckPoint(GridPoint point, Vector3 LoSCheckV3, PointCheckingFlags flags)
        {
            //Check blacklisted points and ignored
            if (point.Ignored)
            {
                return(false);
            }

            //Check if this point is in a blocked direction
            if (flags.HasFlag(PointCheckingFlags.BlockedDirection))
            {
                if (FunkyGame.Navigation.CheckPointAgainstBlockedDirection(point))
                {
                    return(false);
                }
            }

            //Create Vector3
            Vector3 pointVectorReturn = (Vector3)point;
            Vector3 pointVector       = pointVectorReturn;
            Vector3 botcurpos         = FunkyGame.Hero.Position;

            //2D Obstacle Navigation Check
            bool ZCheck = false;

            if (this.AreaIsFlat)
            {
                if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap))
                {
                    if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(point)))
                    {
                        return(false);
                    }
                }

                if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection))
                {
                    if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, point)))
                    {
                        return(false);
                    }
                }

                ZCheck = true;
            }



            //Check if we already within this "point".
            if (botcurpos.Distance2D(pointVector) < 2.5f)
            {
                return(false);
            }

            //3D Obstacle Navigation Check
            if (!ZCheck)
            {
                //Because Z Variance we need to check if we can raycast walk to the location.
                if (!Navigation.CanRayCast(botcurpos, pointVector))
                {
                    return(false);
                }
                if (!Navigation.MGP.CanStandAt(pointVector))
                {
                    return(false);
                }

                if (flags.HasFlag(PointCheckingFlags.ObstacleOverlap))
                {
                    if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.PointInside(pointVector)))
                    {
                        return(false);
                    }
                }
                if (flags.HasFlag(PointCheckingFlags.ObstacleIntersection))
                {
                    if (ObjectCache.Obstacles.Values.OfType <CacheServerObject>().Any(obj => ObjectCache.CheckFlag(ObstacleType.Navigation, obj.Obstacletype.Value) && obj.TestIntersection(botcurpos, pointVector)))
                    {
                        return(false);
                    }
                }
            }

            if (!Navigation.CheckVectorFlags(botcurpos, pointVector, flags))
            {
                return(false);
            }

            LastSafespotFound      = pointVectorReturn;
            LastSafeGridPointFound = point.Clone();
            return(true);
        }