/// <summary> /// Internal implementation of creating a path from an entity to a point /// </summary> private PathEntity CreateEntityPathTo(Entity par1Entity, double par2, double par4, double par6, float par8) { Path.ClearPath(); PointMap.ClearMap(); bool flag = IsPathingInWater; int i = MathHelper2.Floor_double(par1Entity.BoundingBox.MinY + 0.5D); if (CanEntityDrown && par1Entity.IsInWater()) { i = (int)par1Entity.BoundingBox.MinY; for (int j = WorldMap.GetBlockId(MathHelper2.Floor_double(par1Entity.PosX), i, MathHelper2.Floor_double(par1Entity.PosZ)); j == Block.WaterMoving.BlockID || j == Block.WaterStill.BlockID; j = WorldMap.GetBlockId(MathHelper2.Floor_double(par1Entity.PosX), i, MathHelper2.Floor_double(par1Entity.PosZ))) { i++; } flag = IsPathingInWater; IsPathingInWater = false; } else { i = MathHelper2.Floor_double(par1Entity.BoundingBox.MinY + 0.5D); } PathPoint pathpoint = OpenPoint(MathHelper2.Floor_double(par1Entity.BoundingBox.MinX), i, MathHelper2.Floor_double(par1Entity.BoundingBox.MinZ)); PathPoint pathpoint1 = OpenPoint(MathHelper2.Floor_double(par2 - (double)(par1Entity.Width / 2.0F)), MathHelper2.Floor_double(par4), MathHelper2.Floor_double(par6 - (double)(par1Entity.Width / 2.0F))); PathPoint pathpoint2 = new PathPoint(MathHelper2.Floor_float(par1Entity.Width + 1.0F), MathHelper2.Floor_float(par1Entity.Height + 1.0F), MathHelper2.Floor_float(par1Entity.Width + 1.0F)); PathEntity pathentity = AddToPath(par1Entity, pathpoint, pathpoint1, pathpoint2, par8); IsPathingInWater = flag; return(pathentity); }
public override bool Continue() { if (!CanContinue()) { theEntity.SetInvestigatePosition(Vector3.zero, 0); return(false); } PathNavigate navigator = theEntity.navigator; PathEntity path = navigator.getPath(); if (hadPath && path == null) { return(false); } if (++investigateTicks > 40) { investigateTicks = 0; return(false); } //float sqrMagnitude2 = (seekPos - theEntity.position).sqrMagnitude; //if(sqrMagnitude2 <= 4f || (path != null && path.isFinished())) //{ // return PerformAction(); //} return(true); }
public override void Update() { PathEntity path = this.theEntity.navigator.getPath(); if (path != null) { this.hadPath = true; this.theEntity.moveHelper.CalcIfUnreachablePos(this.seekPos); } Vector3 lookPosition = this.investigatePos; lookPosition.y += 0.8f; this.theEntity.SetLookPosition(lookPosition); // if the entity is blocked by anything, switch it around and tell it to find a new path. if (this.theEntity.moveHelper.BlockedTime > 1f) { this.pathRecalculateTicks = 0; this.theEntity.SetLookPosition(lookPosition - Vector3.back); } if (--this.pathRecalculateTicks <= 0) { this.updatePath(); } }
public override bool Continue() { DisplayLog("CanContinue()"); bool result = false; if (entityAliveSDX) { result = entityAliveSDX.CanExecuteTask(EntityAliveSDX.Orders.Loot); DisplayLog("CanContinue() Loot Task? " + result); if (result == false) { return(false); } } PathNavigate navigator = this.theEntity.navigator; PathEntity path = navigator.getPath(); if (this.hadPath && path == null) { DisplayLog(" Not Path to continue looting."); return(false); } if (++this.investigateTicks > 40) { this.investigateTicks = 0; if (!this.theEntity.HasInvestigatePosition) { result = FindNearestContainer(); } //float sqrMagnitude = (this.investigatePos - this.theEntity.InvestigatePosition).sqrMagnitude; //if (sqrMagnitude > 4f) //{ // DisplayLog(" Too far away from my investigate Position: " + sqrMagnitude); // return false; //} } float sqrMagnitude2 = (this.seekPos - this.theEntity.position).sqrMagnitude; DisplayLog(" Seek Position: " + this.seekPos + " My Location: " + this.theEntity.position + " Magnitude: " + sqrMagnitude2); if (sqrMagnitude2 < 4f) { DisplayLog("I'm at the loot container: " + sqrMagnitude2); CheckContainer(); result = FindNearestContainer(); } else if (path != null && path.isFinished()) { result = FindNearestContainer(); } DisplayLog(" Blocked Time: " + this.theEntity.getMoveHelper().BlockedTime); if (this.theEntity.getMoveHelper().BlockedTime > 2) { } DisplayLog("Continue() End: " + result); return(result); }
public PathEntity InsertData(PathEntity entity) { int id = _data.Count; entity.Id = ++id; bool check = CheckIfExists(entity.Value); if (check) { return(_data .Where(x => x.Value.SequenceEqual(entity.Value)) .FirstOrDefault()); } else { _data.Add(entity); var jsonData = JsonSerializer .Serialize(_data, _options); File.WriteAllText("data.json", jsonData); return(entity); } }
public PathEntity Create(int[] array) { var entry = PathUtilities.FindPath(array); var entity = new PathEntity(); if (entry != null) { entity = _pathRepository.Create(entry.ToEntity(array)); } return(entity); }
public static void CreateDirectories(PathEntity entity) { switch (entity) { case PathEntity.MultiThreading: MultiThread multy = new MultiThread(); foreach (var item in multy.AllPaths) { if (!Directory.Exists(item)) { Directory.CreateDirectory(item); } } break; } }
private void updatePath() { if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { PathEntity path = this.theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { this.pathCounter = 0; } } if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { this.pathCounter = 6 + this.theEntity.rand.RandomRange(10); PathFinderThread.Instance.FindPath(this.theEntity, this.seekPos, this.theEntity.GetMoveSpeedAggro(), true, this); } }
public PathEntity FindShortestPath(Node origin, Node destination, Func <Node, IEnumerable <NeighborhoodInfo> > funcGetNeighbors) { var vistingControl = new VisitingDataControl(); vistingControl.UpdateWeight(origin, new Weight(null, 0)); vistingControl.ScheduleVisitTo(origin); while (vistingControl.HasScheduledVisits) { var visitingNode = vistingControl.GetNodeToVisit(); var visitingNodeWeight = vistingControl.QueryWeight(visitingNode); vistingControl.RegisterVisitTo(visitingNode); foreach (var neighborhoodInfo in funcGetNeighbors(visitingNode)) { if (!vistingControl.WasVisited(neighborhoodInfo.Node)) { vistingControl.ScheduleVisitTo(neighborhoodInfo.Node); } var neighborWeight = vistingControl.QueryWeight(neighborhoodInfo.Node); var probableWeight = visitingNodeWeight.Value + neighborhoodInfo.WeightToNode; if (neighborWeight.Value > probableWeight) { vistingControl.UpdateWeight(neighborhoodInfo.Node, new Weight(visitingNode, probableWeight)); } } } PathEntity pathEntity; if (vistingControl.HasComputedPathToOrigin(destination)) { pathEntity = new PathEntity { NodeVisit = vistingControl.ComputedPathToOrigin(destination).Reverse().ToList(), Distance = vistingControl.QueryWeight(destination).Value }; } else { pathEntity = new PathEntity(); } return(pathEntity); }
private PathEntity createEntityPathTo(Entity entity, double d, double d1, double d2, float f) { path.clearPath(); pointMap.clearMap(); PathPoint pathpoint = openPoint(MathHelper.floor_double(entity.boundingBox.minX), MathHelper.floor_double(entity.boundingBox.minY), MathHelper.floor_double(entity.boundingBox.minZ)); PathPoint pathpoint1 = openPoint(MathHelper.floor_double(d - (entity.width / 2.0F)), MathHelper.floor_double(d1), MathHelper.floor_double(d2 - (entity.width / 2.0F))); var pathpoint2 = new PathPoint(MathHelper.floor_float(entity.width + 1.0F), MathHelper.floor_float(entity.height + 1.0F), MathHelper.floor_float(entity.width + 1.0F)); PathEntity pathentity = addToPath(entity, pathpoint, pathpoint1, pathpoint2, f); return(pathentity); }
public virtual bool Func_48647_a(PathEntity par1PathEntity) { if (par1PathEntity == null) { return(false); } if (par1PathEntity.Points.Length != Points.Length) { return(false); } for (int i = 0; i < Points.Length; i++) { if (Points[i].XCoord != par1PathEntity.Points[i].XCoord || Points[i].YCoord != par1PathEntity.Points[i].YCoord || Points[i].ZCoord != par1PathEntity.Points[i].ZCoord) { return(false); } } return(true); }
private bool Func_48375_a(EntityLiving par1EntityLiving) { Field_48377_f = 10 + TaskOwner.GetRNG().Next(5); PathEntity pathentity = TaskOwner.GetNavigator().Func_48679_a(par1EntityLiving); if (pathentity == null) { return(false); } PathPoint pathpoint = pathentity.GetFinalPathPoint(); if (pathpoint == null) { return(false); } else { int i = pathpoint.XCoord - MathHelper2.Floor_double(par1EntityLiving.PosX); int j = pathpoint.ZCoord - MathHelper2.Floor_double(par1EntityLiving.PosZ); return((double)(i * i + j * j) <= 2.25D); } }
public override bool Continue() { if (!CanContinue()) { this.theEntity.SetInvestigatePosition(Vector3.zero, 0); return(false); } PathNavigate navigator = this.theEntity.navigator; PathEntity path = navigator.getPath(); if (this.hadPath && path == null) { return(false); } if (++this.investigateTicks > 40) { this.investigateTicks = 0; return(false); //if (!this.theEntity.HasInvestigatePosition) // return false; // no invesitgative position //float sqrMagnitude = (this.investigatePos - this.theEntity.InvestigatePosition).sqrMagnitude; //if (sqrMagnitude >= 4f) //{ // return false; // not close enough. //} } float sqrMagnitude2 = (this.seekPos - this.theEntity.position).sqrMagnitude; if (sqrMagnitude2 <= 4f || (path != null && path.isFinished())) { return(PerformAction()); } return(true); }
public PathEntity Create(PathEntity entity) { return(_jsonUtilities.InsertData(entity)); }
public override void Update() { // No entity, so no need to do anything. if (this.entityTarget == null || this.entityTargetPos == null) { DisplayLog(" Entity Target or EntityTarget Position is null"); return; } // Let the entity keep looking at you, otherwise it may just sping around. this.theEntity.SetLookPosition(this.entityTargetPos); this.theEntity.RotateTo(this.entityTargetPos.x, this.entityTargetPos.y + 2, this.entityTargetPos.z, 30f, 30f); if (this.theEntity is EntityAliveSDX) { if (EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.SetPatrolPoint)) { // Make them a lot closer to you when they are following you. (this.theEntity as EntityAliveSDX).UpdatePatrolPoints(this.theEntity.world.FindSupportingBlockPos(this.entityTarget.position)); } } Vector3 a = this.theEntity.position - this.entityTargetPos; if (a.sqrMagnitude < 2f) { DisplayLog("Entity is too close. Ending pathing."); this.pathCounter = 0; return; } this.theEntity.moveHelper.CalcIfUnreachablePos(this.entityTargetPos); // if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low. if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { PathEntity path = this.theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { this.pathCounter = 0; } } if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { DisplayLog(" Path Counter is 0: Finding new path to " + this.entityTargetPos); // If its still not calculating a path, find a new path to the leader this.pathCounter = 6 + this.theEntity.rand.RandomRange(10); PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } if (this.theEntity.Climbing) { return; } // If there's no path, calculate one. if (this.theEntity.navigator.noPathAndNotPlanningOne()) { DisplayLog("No Path and Not Planning One. Searching for new path to : " + this.entityTargetPos); PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } }
private void backRunWork(object sender, DoWorkEventArgs e) { MethodInvoker method = null; MethodInvoker invoker3 = null; try { if (this.pathType == 1) { if (method == null) { method = new MethodInvoker(this.execClearAllPath); } base.Invoke(method); } else if (this.pathType == 2) { if (invoker3 == null) { invoker3 = new MethodInvoker(this.execClearAllPolygon); } base.Invoke(invoker3); } int count = this.dict.Count; int num2 = 0; if (count > 0) { if (this.pathType == 1) { using (Dictionary <string, string> .KeyCollection.Enumerator enumerator = this.dict.Keys.GetEnumerator()) { PathInfo pathInfo = new PathInfo(); while (enumerator.MoveNext()) { pathInfo.PathName = enumerator.Current; PathEntity pathEntity = new PathEntity { locals8 = pathInfo, this_4 = this, Lons = "", Lats = "" }; string[] strArray = this.dict[pathInfo.PathName].Split(new char[] { '/' }); for (int i = 0; i < strArray.Length; i++) { string[] strArray2 = strArray[i].Split(new char[] { '*' }); if (strArray2.Length == 2) { pathEntity.Lons = pathEntity.Lons + strArray2[0] + ","; pathEntity.Lats = pathEntity.Lats + strArray2[1] + ","; } } pathEntity.Lons.Trim(new char[] { ',' }); pathEntity.Lats.Trim(new char[] { ',' }); base.Invoke(new MethodInvoker(pathEntity.worker_DoWork__2)); num2++; this.backgroundWorker.ReportProgress((int)((((double)num2) / ((double)count)) * 100.0)); } return; } } using (Dictionary <string, string> .KeyCollection.Enumerator enumerator2 = this.dict.Keys.GetEnumerator()) { OOll00ll0l0O11101l olllllol = new OOll00ll0l0O11101l(); while (enumerator2.MoveNext()) { olllllol.PathName = enumerator2.Current; MethodInvoker invoker = null; O01l0ll1O0OOl1OO1O olooo = new O01l0ll1O0OOl1OO1O { localsc = olllllol, this_4 = this, Lons = "", Lats = "" }; string str2 = this.dict[olllllol.PathName]; if (Check.isRoundness(str2)) { OO1l0001O1OO1O1Ol01 ol2 = new OO1l0001O1OO1O1Ol01 { localsf = olooo, localsc = olllllol }; string[] strArray4 = str2.Trim(new char[] { '*' }).Split(new char[] { '*' })[0].Split(new char[] { '\\' }); ol2.sCenterPointX = double.Parse(strArray4[0]); ol2.sCenterPointY = double.Parse(strArray4[1]); ol2.sRadius = int.Parse(strArray4[2]); base.Invoke(new MethodInvoker(ol2.worker_DoWork__3)); } else { string[] strArray5 = str2.Split(new char[] { '*' }); for (int j = 0; j < strArray5.Length; j++) { string[] strArray6 = strArray5[j].Split(new char[] { '\\' }); if (strArray6.Length == 2) { olooo.Lons = olooo.Lons + strArray6[0] + ","; olooo.Lats = olooo.Lats + strArray6[1] + ","; } } olooo.Lons.Trim(new char[] { ',' }); olooo.Lats.Trim(new char[] { ',' }); if (invoker == null) { invoker = new MethodInvoker(olooo.worker_DoWork__4); } base.Invoke(invoker); } num2++; this.backgroundWorker.ReportProgress((int)((((double)num2) / ((double)count)) * 100.0)); } } } } catch (Exception exception) { Record.execFileRecord("Type:" + this.pathType + ",设置偏移路线区域显示控制-->", exception.Message); } }
public PathEntity GetPathEntity(Vector2 scale) { float scaleD = (scale.X + scale.Y) / 2; PathEntity pathEntity = new PathEntity(); List <Shape> shapes = new List <Shape>(); Body b = Body.GetPhysicsBody(scale); foreach (var fix in b.FixtureList) { shapes.Add(fix.Shape); } Path p = new Path(); foreach (Vector2 node in Path) { p.Add(UnitsConverter.ToSimUnits(node) * scale); } pathEntity.Bodies = PathManager.EvenlyDistributeShapesAlongPath( Platform.Instance.PhysicsWorld, p, shapes, Body.Static ? BodyType.Static : BodyType.Dynamic, BodyCount + 1 ); foreach (var link in pathEntity.Bodies) { link.CollisionGroup = b.FixtureList[0].CollisionGroup; } Platform.Instance.PhysicsWorld.RemoveBody(b); switch (JointType) { case JointType.Revolute: pathEntity.Joints = new List <Joint>(PathManager.AttachBodiesWithRevoluteJoint( Platform.Instance.PhysicsWorld, pathEntity.Bodies, UnitsConverter.ToSimUnits(Anchor1) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale, ConnectFirstAndLast, CollideConnected )); return(pathEntity); case JointType.Slider: pathEntity.Joints = new List <Joint>(PathManager.AttachBodiesWithSliderJoint( Platform.Instance.PhysicsWorld, pathEntity.Bodies, UnitsConverter.ToSimUnits(Anchor1) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale, ConnectFirstAndLast, CollideConnected, UnitsConverter.ToSimUnits(MaxLength) * scaleD, UnitsConverter.ToSimUnits(MinLength) * scaleD )); return(pathEntity); } return(new PathEntity()); }
private void backRunWork(object sender, DoWorkEventArgs e) { MethodInvoker method = null; MethodInvoker invoker3 = null; try { if (this.pathType == 1) { if (method == null) { method = new MethodInvoker(this.execClearAllPath); } base.Invoke(method); } else if (this.pathType == 2) { if (invoker3 == null) { invoker3 = new MethodInvoker(this.execClearAllPolygon); } base.Invoke(invoker3); } int count = this.dict.Count; int num2 = 0; if (count > 0) { if (this.pathType == 1) { using (Dictionary<string, string>.KeyCollection.Enumerator enumerator = this.dict.Keys.GetEnumerator()) { PathInfo pathInfo = new PathInfo(); while (enumerator.MoveNext()) { pathInfo.PathName = enumerator.Current; PathEntity pathEntity = new PathEntity { locals8 = pathInfo, this_4 = this, Lons = "", Lats = "" }; string[] strArray = this.dict[pathInfo.PathName].Split(new char[] { '/' }); for (int i = 0; i < strArray.Length; i++) { string[] strArray2 = strArray[i].Split(new char[] { '*' }); if (strArray2.Length == 2) { pathEntity.Lons = pathEntity.Lons + strArray2[0] + ","; pathEntity.Lats = pathEntity.Lats + strArray2[1] + ","; } } pathEntity.Lons.Trim(new char[] { ',' }); pathEntity.Lats.Trim(new char[] { ',' }); base.Invoke(new MethodInvoker(pathEntity.worker_DoWork__2)); num2++; this.backgroundWorker.ReportProgress((int)((((double)num2) / ((double)count)) * 100.0)); } return; } } using (Dictionary<string, string>.KeyCollection.Enumerator enumerator2 = this.dict.Keys.GetEnumerator()) { OOll00ll0l0O11101l olllllol = new OOll00ll0l0O11101l(); while (enumerator2.MoveNext()) { olllllol.PathName = enumerator2.Current; MethodInvoker invoker = null; O01l0ll1O0OOl1OO1O olooo = new O01l0ll1O0OOl1OO1O { localsc = olllllol, this_4 = this, Lons = "", Lats = "" }; string str2 = this.dict[olllllol.PathName]; if (Check.isRoundness(str2)) { OO1l0001O1OO1O1Ol01 ol2 = new OO1l0001O1OO1O1Ol01 { localsf = olooo, localsc = olllllol }; string[] strArray4 = str2.Trim(new char[] { '*' }).Split(new char[] { '*' })[0].Split(new char[] { '\\' }); ol2.sCenterPointX = double.Parse(strArray4[0]); ol2.sCenterPointY = double.Parse(strArray4[1]); ol2.sRadius = int.Parse(strArray4[2]); base.Invoke(new MethodInvoker(ol2.worker_DoWork__3)); } else { string[] strArray5 = str2.Split(new char[] { '*' }); for (int j = 0; j < strArray5.Length; j++) { string[] strArray6 = strArray5[j].Split(new char[] { '\\' }); if (strArray6.Length == 2) { olooo.Lons = olooo.Lons + strArray6[0] + ","; olooo.Lats = olooo.Lats + strArray6[1] + ","; } } olooo.Lons.Trim(new char[] { ',' }); olooo.Lats.Trim(new char[] { ',' }); if (invoker == null) { invoker = new MethodInvoker(olooo.worker_DoWork__4); } base.Invoke(invoker); } num2++; this.backgroundWorker.ReportProgress((int)((((double)num2) / ((double)count)) * 100.0)); } } } } catch (Exception exception) { Record.execFileRecord("Type:" + this.pathType + ",设置偏移路线区域显示控制-->", exception.Message); } }
public override bool Continue() { DisplayLog("CanContinue()"); bool result = false; if (entityAliveSDX) { result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Loot); DisplayLog("CanContinue() Loot Task? " + result); if (result == false) { return(false); } } if (++this.taskTimeOut > 40) { this.taskTimeOut = 0; return(false); } if (this.theEntity.Buffs.HasCustomVar("Owner")) { DisplayLog(" Checking my Leader"); // Find out who the leader is. int PlayerID = (int)this.theEntity.Buffs.GetCustomVar("Owner"); Entity myLeader = this.theEntity.world.GetEntity(PlayerID); float distance = this.theEntity.GetDistance(myLeader); DisplayLog(" Distance: " + distance); if (distance > this.theEntity.GetSeeDistance()) { DisplayLog("I am too far away from my leader. Teleporting...."); this.theEntity.SetPosition(myLeader.position, true); EntityUtilities.ExecuteCMD(this.theEntity.entityId, "FollowMe", myLeader as EntityPlayer); } } PathNavigate navigator = this.theEntity.navigator; PathEntity path = navigator.getPath(); if (this.hadPath && path == null) { DisplayLog(" Not Path to continue looting."); return(false); } if (++this.investigateTicks > 40) { this.investigateTicks = 0; if (!this.theEntity.HasInvestigatePosition) { result = FindNearestContainer(); } //float sqrMagnitude = (this.investigatePos - this.theEntity.InvestigatePosition).sqrMagnitude; //if (sqrMagnitude > 4f) //{ // DisplayLog(" Too far away from my investigate Position: " + sqrMagnitude); // return false; //} } float sqrMagnitude2 = (this.seekPos - this.theEntity.position).sqrMagnitude; DisplayLog(" Seek Position: " + this.seekPos + " My Location: " + this.theEntity.position + " Magnitude: " + sqrMagnitude2); if (sqrMagnitude2 < 4f) { DisplayLog("I'm at the loot container: " + sqrMagnitude2); CheckContainer(); result = FindNearestContainer(); } else if (path != null && path.isFinished()) { result = FindNearestContainer(); } DisplayLog("Continue() End: " + result); return(result); }
public void SetMovementGoal(MovementGoalType movementGoalType) { _movementGoalType = movementGoalType; if (movementGoalType == MovementGoalType.PLAYER_ROOM) { _roomOfInterest = _levelLoadingManager .RoomGraphManager .GetRoomContainingObject(_player); movementGoalType = MovementGoalType.ROOM; } switch (movementGoalType) { case MovementGoalType.FOOTSTEP: SetMovementGoal(_footStepFactory.FirstFootStep, null); Task.current.Complete(true); break; case MovementGoalType.FOOTSTEP_PATH: SetMovementGoal(_footStepFactory.LatestFootStep, _footStepFactory.Path); Task.current.Complete(true); break; case MovementGoalType.HEARD_NOISE: SetMovementGoal(_heardNoise); Task.current.Complete(true); break; case MovementGoalType.LOCKER: { if (_lockerManager.CurrentLocker != null) { SetMovementGoal(_lockerManager.CurrentLocker.gameObject.transform.parent.transform.GetChild(1).transform.gameObject.GetComponent <DestinationSearch>()); } Task.current.Complete(true); break; } case MovementGoalType.TARGET: SetMovementGoal(_target); Task.current.Complete(true); break; case MovementGoalType.PLAYER: SetMovementGoal(_player); Task.current.Complete(true); break; case MovementGoalType.DEAD_GUARD: SetMovementGoal(_deadGuardController); Task.current.Complete(true); break; case MovementGoalType.COVER_TARGET: case MovementGoalType.COVER_SELF: { if (Task.current.isStarting) { _coverPointFound = false; _coverPoint = null; List <PathObjectPair> pops = new List <PathObjectPair> (); List <Vector2> blockedCoordinates = GetBlockedCoordinates(); AsyncListOperation <CoverPoint> listOperation = new AsyncListOperation <CoverPoint>( _coverPoints, ( CoverPoint coverPoint, System.Action callbackOperation ) => { _pathManager.RequestTask( this, coverPoint, ( PathObjectPair pop ) => { pops.Add(pop); callbackOperation(); }, blockedCoordinates ); }, () => { pops.Sort((PathObjectPair a, PathObjectPair b) => { float distanceA = a.GetPathLength(); float distanceB = b.GetPathLength(); if (distanceA == 0) { distanceA = 999999; } if (distanceB == 0) { distanceB = 999999; } return((int)distanceA - (int)distanceB); }); GameObject coverFrom = gameObject; if (movementGoalType == MovementGoalType.COVER_TARGET) { coverFrom = _target.gameObject; } foreach (var pop in pops) { RaycastHit2D hit = _mapHelper.Probe( coverFrom, ((MonoBehaviour)pop.GetObject2()).gameObject, new string[] { "CeilingLayer", "WallLayer" } ); if (hit.collider != null) { _coverPoint = (CoverPoint)pop.GetObject2(); SetMovementGoal(_coverPoint); _preComputedPathToMovementGoal = pop.GetPath(); _coverPointFound = true; break; } } } ); listOperation.RunParallel(); } else if (_coverPointFound) { Task.current.Complete(true); } // _coverPoints.Sort( (CoverPoint a, CoverPoint b) => // { // float distanceA = (a.transform.position - transform.position).magnitude; // float distanceB = (b.transform.position - transform.position).magnitude; // return (int) distanceA - (int) distanceB; // }); // GameObject coverFrom = gameObject; // if( movementGoalType == MovementGoalType.COVER_TARGET ) // { // coverFrom = _target.gameObject; // } // foreach( CoverPoint coverPoint in _coverPoints ) // { // RaycastHit2D hit = _mapHelper.Probe( // coverFrom, // coverPoint.gameObject, // new string[] {"CeilingLayer", "WallLayer"} // ); // if( hit.collider != null ) // { // _coverPoint = coverPoint; // break; // } // } // // if no cover was found we should probably be more aggressive. // SetMovementGoal(_coverPoint); // Task.current.Complete(true); }; break; case MovementGoalType.ROOM: { if (Task.current.isStarting) { PerformRoomExitPathFinding(); } else if (_roomExitFindingComplete) { SetMovementGoal( _pathObjectPairsForRoomRoomExitFinding[0].GetObject2(), _pathObjectPairsForRoomRoomExitFinding[0].GetPath() ); Task.current.Complete(true); } }; break; } }
public override void Update() { Vector3 position = Vector3.zero; float targetXZDistanceSq = 0f; // No entity, so no need to do anything. if (this.entityTarget == null) { return; } // Let the entity keep looking at you, otherwise it may just sping around. this.theEntity.SetLookPosition(this.entityTarget.getHeadPosition()); this.theEntity.RotateTo(this.entityTarget.position.x, this.entityTarget.position.y + 2, this.entityTarget.position.z, 30f, 30f); // Find the location of the entity, and figure out where it's at. position = this.entityTarget.position; targetXZDistanceSq = base.GetTargetXZDistanceSq(6); if (entityAliveSDX) { if (entityAliveSDX.CanExecuteTask(EntityAliveSDX.Orders.SetPatrolPoint)) { // Make them a lot closer to you when they are following you. this.distanceToEntity = 1f; entityAliveSDX.UpdatePatrolPoints(this.theEntity.world.FindSupportingBlockPos(this.entityTarget.position)); } } Vector3 a = position - this.entityTargetPos; if (a.sqrMagnitude < 1f) { this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f; } this.entityTargetPos = position; this.theEntity.moveHelper.CalcIfUnreachablePos(position); // num is used to determine how close and comfortable the entity approaches you, so let's make sure they respect some personal space if (distanceToEntity < 1) { distanceToEntity = 3; } // if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low. if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { PathEntity path = this.theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { this.pathCounter = 0; } } if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { // If its still not calculating a path, find a new path to the leader this.pathCounter = 6 + this.theEntity.GetRandom().Next(10); PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } if (this.theEntity.Climbing) { return; } // If there's no path, calculate one. if (this.theEntity.navigator.noPathAndNotPlanningOne()) { PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } }
/// <summary> /// Sets the movement goal to a specific Monobehaviour. Use this method if a path has already been found as part of another process. /// </summary> /// <param name="movementGoal"></param> /// <param name="preComputedPath"></param> public void SetMovementGoal(MonoBehaviour movementGoal, PathEntity preComputedPath = null) { _preComputedPathToMovementGoal = preComputedPath; _movementGoal = movementGoal; }
public void MoveToMovementGoal(bool movingTarget = false, bool useBlockedCoordinates = false) { if (Task.current.isStarting || _needResetPathFind) { _needResetPathFind = false; if (_preComputedPathToMovementGoal == null) { List <Vector2> blockedCoordinates = null; if (useBlockedCoordinates) { blockedCoordinates = GetBlockedCoordinates(); } _pathIsFound = false; //_movementCoordinator.UnlockDir(); _pathManager.RequestTask( this, _movementGoal, (PathObjectPair pop) => { _pathIsFound = true; _path = pop.GetPath(); _pathIndex = 0; _aiPathFindCompleteSignal.Fire(_path); // _path.PaintPath(); }, blockedCoordinates ); if (movingTarget) { StartCoroutine(ResetPathFindNeed()); _needResetPathFind = false; } } else { _path = _preComputedPathToMovementGoal; _pathIndex = 0; _pathIsFound = true; _aiPathFindCompleteSignal.Fire(_preComputedPathToMovementGoal); } } if (_pathIsFound) { if (_path.GetLength() != 0) { _pathIndex = _movementController.StepPath(_path, _pathIndex); if (_pathIndex == -1) { Task.current.Complete(true); } } else { Task.current.Complete(false); } } }