public PathPoint GetPoint(float position) { position = Math.ClampInRange(position, 0f, fullLength); PathPoint res = new PathPoint(); PathPoint beg = null; bool found = false; foreach(var pt in pathPoints) { if (pt.distance < position) continue; if (!found) { found = true; beg = pt; continue; } float coef = Mathf.Clamp01((position - beg.distance + beg.length)/beg.length); res.position = Vector3.Lerp(beg.position, pt.position, coef); res.xAxis = Vector3.Lerp(beg.xAxis, pt.xAxis, coef); res.yAxis = Vector3.Lerp(beg.yAxis, pt.yAxis, coef); res.zAxis = Vector3.Lerp(beg.zAxis, pt.zAxis, coef); res.length = beg.length; res.distance = position; break; } return res; }
private PathEntity addToPath(Entity entity, PathPoint pathpoint, PathPoint pathpoint1, PathPoint pathpoint2, float f) { pathpoint.totalPathDistance = 0.0F; pathpoint.distanceToNext = pathpoint.distanceTo(pathpoint1); pathpoint.distanceToTarget = pathpoint.distanceToNext; path.clearPath(); path.addPoint(pathpoint); PathPoint pathpoint3 = pathpoint; while (!path.isPathEmpty()) { PathPoint pathpoint4 = path.dequeue(); if (pathpoint4.Equals(pathpoint1)) { return createEntityPath(pathpoint, pathpoint1); } if (pathpoint4.distanceTo(pathpoint1) < pathpoint3.distanceTo(pathpoint1)) { pathpoint3 = pathpoint4; } pathpoint4.isFirst = true; int i = findPathOptions(entity, pathpoint4, pathpoint2, pathpoint1, f); int j = 0; while (j < i) { PathPoint pathpoint5 = pathOptions[j]; float f1 = pathpoint4.totalPathDistance + pathpoint4.distanceTo(pathpoint5); if (!pathpoint5.isAssigned() || f1 < pathpoint5.totalPathDistance) { pathpoint5.previous = pathpoint4; pathpoint5.totalPathDistance = f1; pathpoint5.distanceToNext = pathpoint5.distanceTo(pathpoint1); if (pathpoint5.isAssigned()) { path.changeDistance(pathpoint5, pathpoint5.totalPathDistance + pathpoint5.distanceToNext); } else { pathpoint5.distanceToTarget = pathpoint5.totalPathDistance + pathpoint5.distanceToNext; path.addPoint(pathpoint5); } } j++; } } if (pathpoint3 == pathpoint) { return null; } else { return createEntityPath(pathpoint, pathpoint3); } }
private int findPathOptions(Entity entity, PathPoint pathpoint, PathPoint pathpoint1, PathPoint pathpoint2, float f) { int i = 0; int j = 0; if (getVerticalOffset(entity, pathpoint.xCoord, pathpoint.yCoord + 1, pathpoint.zCoord, pathpoint1) > 0) { j = 1; } PathPoint pathpoint3 = getSafePoint(entity, pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord + 1, pathpoint1, j); PathPoint pathpoint4 = getSafePoint(entity, pathpoint.xCoord - 1, pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j); PathPoint pathpoint5 = getSafePoint(entity, pathpoint.xCoord + 1, pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j); PathPoint pathpoint6 = getSafePoint(entity, pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord - 1, pathpoint1, j); if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint3; } if (pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint4; } if (pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint5; } if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint6; } return(i); }
bool Search(PathPoint current, PathPoint target, List <PathPoint> currentList = null) { if (current == target) { path = currentList; return(true); } if (currentList == null) { currentList = new List <PathPoint>(); possiblePaths.Add(currentList); currentList.Add(current); } current.target = target; current.state = PathPoint.State.Closed; List <PathPoint> nexts = findNextPoints(current); possiblePaths.Remove(currentList); foreach (var next in nexts) { List <PathPoint> nextList = new List <PathPoint>(); nextList.AddRange(currentList); possiblePaths.Add(nextList); nextList.Add(next); } if (possiblePaths.Count == 0) { return(false); } return(Search(target)); }
/// <summary> /// populates pathOptions with available points and returns the number of options found (args: unused1, currentPoint, /// unused2, targetPoint, maxDistance) /// </summary> private int FindPathOptions(Entity par1Entity, PathPoint par2PathPoint, PathPoint par3PathPoint, PathPoint par4PathPoint, float par5) { int i = 0; int j = 0; if (GetVerticalOffset(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord + 1, par2PathPoint.ZCoord, par3PathPoint) == 1) { j = 1; } PathPoint pathpoint = GetSafePoint(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord, par2PathPoint.ZCoord + 1, par3PathPoint, j); PathPoint pathpoint1 = GetSafePoint(par1Entity, par2PathPoint.XCoord - 1, par2PathPoint.YCoord, par2PathPoint.ZCoord, par3PathPoint, j); PathPoint pathpoint2 = GetSafePoint(par1Entity, par2PathPoint.XCoord + 1, par2PathPoint.YCoord, par2PathPoint.ZCoord, par3PathPoint, j); PathPoint pathpoint3 = GetSafePoint(par1Entity, par2PathPoint.XCoord, par2PathPoint.YCoord, par2PathPoint.ZCoord - 1, par3PathPoint, j); if (pathpoint != null && !pathpoint.IsFirst && pathpoint.DistanceTo(par4PathPoint) < par5) { PathOptions[i++] = pathpoint; } if (pathpoint1 != null && !pathpoint1.IsFirst && pathpoint1.DistanceTo(par4PathPoint) < par5) { PathOptions[i++] = pathpoint1; } if (pathpoint2 != null && !pathpoint2.IsFirst && pathpoint2.DistanceTo(par4PathPoint) < par5) { PathOptions[i++] = pathpoint2; } if (pathpoint3 != null && !pathpoint3.IsFirst && pathpoint3.DistanceTo(par4PathPoint) < par5) { PathOptions[i++] = pathpoint3; } return(i); }
public void InitMap() { map = new PathPoint[width, height]; mPathMaterial = new MeshRenderer[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { float x = PathRoot.transform.localPosition.x + i * girdWidth; float y = PathRoot.transform.localPosition.z + j * girdHeight; var Obj = Instantiate(prefab, new Vector3(x, PathRoot.transform.localPosition.y, y), Quaternion.identity); Obj.transform.parent = PathRoot.transform; map[i, j] = new PathPoint(i, j, Obj.transform); mPathMaterial[i, j] = Obj.GetComponent <MeshRenderer>(); } } for (int i = 10; i < 46; i++) { SetObjstacle(i, 31); } for (int i = 20; i < 50; i++) { SetObjstacle(i, 20); } SetPathStartPos((int)startTrans.localPosition.x, (int)startTrans.localPosition.z); SetPathEndPos((int)targetTrans.localPosition.x, (int)targetTrans.localPosition.z); pathList = FindPath(); if (pathList == null) { return; } ShowPath(pathList); }
//查找周围相邻节点列表 private List <PathPoint> FindAround_Point(PathPoint node) { List <PathPoint> list = new List <PathPoint>(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int x = node.X + i; int y = node.Y + j; if (node.isObstacle) { continue; } if (x >= 0 && x < width - 1 && y >= 0 && y < height - 1) { list.Add(map[x, y]); } } } return(list); }
public List <GameEntity> GetGameEntitiesByEntityType(PathEntityType type) { List <GameEntity> ret = new List <GameEntity>(); for (int i = 0; i < path_points.Count; ++i) { PathPoint curr_tile = path_points[i]; if (curr_tile.entity.type == type) { if (curr_tile.entity.go != null) { GameEntity ge = curr_tile.entity.go.GetComponent <GameEntity>(); if (ge != null) { ret.Add(ge); } } } } return(ret); }
public GameEntity GetGameEntityByEntityType(PathEntityType type) { GameEntity ret = null; for (int i = 0; i < path_points.Count; ++i) { PathPoint curr_tile = path_points[i]; if (curr_tile.entity.type == type) { if (curr_tile.entity.go != null) { GameEntity ge = curr_tile.entity.go.GetComponent <GameEntity>(); if (ge != null) { ret = ge; } } } } return(ret); }
void OnDrawGizmos() { if (!transform.IsSelected()) { vizualize = false; } if (!vizualize) { if (!Application.isPlaying) { _list = null; } return; } if (!Application.isPlaying) { instance = this; } if (_list == null) { GeneratePathfinding(); } for (int i = 0; i < _list.Count; i++) { PathPoint point = _list[i]; Gizmos.color = Color.red; Gizmos.DrawRay(point.asVector3, Vector3.down * Mathf.Max(rayCastHeight, 1)); Gizmos.color = Color.cyan; foreach (var c in point.connections) { Gizmos.DrawLine(point.asVector3, c.asVector3); } } }
public void createRoverPath_TestExamples() { //RoverPath constructor uses plateau size not upper right coordinates //plateau size is 1 unit bigger var upperRightX = 5; var upperRightY = 5; var startX = 1; var startY = 2; var startDir = "N"; var instructions = "LMLMLMLMM"; var startPoint = new PathPoint(startX, startY, startDir); roverPath = new RoverPath(upperRightX + 1, upperRightY + 1, startPoint); roverPath.createRoverPath(instructions); var numPositions = roverPath.GetNumPositions(); Assert.AreEqual(1, roverPath.GetPathPoint(numPositions - 1).X); Assert.AreEqual(3, roverPath.GetPathPoint(numPositions - 1).Y); Assert.AreEqual(PathDirection.North, roverPath.GetPathPoint(numPositions - 1).Dir); startX = 3; startY = 3; startDir = "E"; instructions = "MMRMMRMRRM"; startPoint = new PathPoint(startX, startY, startDir); roverPath = new RoverPath(upperRightX + 1, upperRightY + 1, startPoint); roverPath.createRoverPath(instructions); numPositions = roverPath.GetNumPositions(); Assert.AreEqual(5, roverPath.GetPathPoint(numPositions - 1).X); Assert.AreEqual(1, roverPath.GetPathPoint(numPositions - 1).Y); Assert.AreEqual(PathDirection.East, roverPath.GetPathPoint(numPositions - 1).Dir); }
/// <summary> /// 显示Resource子Resources的子目录和子文件 /// </summary> /// <param name="pathPoint"></param> /// <param name="n_level"></param> void ShowSubFolderBundle(PathPoint pathPoint, int n_level) { if (pathPoint.s_nowPathPoint != null) { //文件夹节点 EditorGUI.indentLevel = n_level; pathPoint.isFold = EditorGUILayout.Foldout(pathPoint.isFold, "<folder> " + pathPoint.s_nowPathPoint); if (pathPoint.isFold) { if (pathPoint.nextPathPoint != null) { foreach (var nextPathPoint in pathPoint.nextPathPoint) { ShowSubFolderBundle(nextPathPoint.Value, (n_level + 1)); } } if (pathPoint.bundles != null) { for (int i = 0; i < pathPoint.bundles.Count; i++) { EditPackageConfig bundle = pathPoint.bundles[i]; //bundle节点 EditorGUI.indentLevel = n_level + 1; EditorGUILayout.BeginHorizontal(); bundle.isFold = EditorGUILayout.Foldout(bundle.isFold, bundle.name); //删除视图 if (GUILayout.Button("删除", GUILayout.Width(ButtonWidth))) { bundles.Remove(bundle); pathPoint.bundles.Remove(bundle); continue; } EditorGUILayout.EndHorizontal(); if (bundle.isFold) { ShowSingleBundleGUI(bundle, n_level + 1); } EditorGUI.indentLevel = n_level + 2; //消息视图 MessageView(bundle); } } } } }
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 RelativeToPointConverter(PathPoint pathPoint) { this.pathPoint = pathPoint; }
protected virtual PathThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index, PathPoint pathpoint, Transform transform) { var designerThumb = new PathThumb(index, pathpoint) { Cursor = cursor }; designerThumb.OperationMenu = BuildMenu(pathpoint); designerThumb.InnerRenderTransform = ((Transform)transform.Inverse); if (pathpoint.TargetPathPoint != null) { designerThumb.IsEllipse = true; designerThumb.Foreground = Brushes.Blue; var bnd = new Binding("TranslatedPoint") { Source = pathpoint.TargetPathPoint, Mode = BindingMode.OneWay, Converter = new RelativeToPointConverter(pathpoint) }; designerThumb.SetBinding(PathThumb.RelativeToPointProperty, bnd); } AdornerPanel.SetPlacement(designerThumb, designerThumb.AdornerPlacement); adornerPanel.Children.Add(designerThumb); DragListener drag = new DragListener(designerThumb); drag.Transform = transform; WeakEventManager <DesignerThumb, MouseButtonEventArgs> .AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); //drag.MouseDown += drag_MouseDown; drag.Started += drag_Started; drag.Changed += drag_Changed; drag.Completed += drag_Completed; return(designerThumb); }
private void PathAssignTaxiRoute(GameClient client, string[] args) { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty <object>(TEMP_PATH_LAST, null); if (args.Length < 2) { DisplayMessage(client, "Usage: /path assigntaxiroute <destination>"); return; } if (path == null) { DisplayMessage(client, "No path created yet! Use /path create first!"); return; } GameMerchant merchant = null; if (client.Player.TargetObject is GameStableMaster) { merchant = client.Player.TargetObject as GameStableMaster; } if (client.Player.TargetObject is GameBoatStableMaster) { merchant = client.Player.TargetObject as GameBoatStableMaster; } if (merchant == null) { DisplayMessage(client, "You must select a stable master to assign a taxi route!"); return; } string target = string.Join(" ", args, 2, args.Length - 2);; bool ticketFound = false; string ticket = "Ticket to " + target; // Most // // With the new horse system, the stablemasters are using the item.Id_nb to find the horse route in the database // So we have to save a path in the database with the Id_nb as a PathID // The following string will contain the item Id_nb if it is found in the merchant list string pathname = string.Empty; if (merchant.TradeItems != null) { foreach (ItemTemplate template in merchant.TradeItems.GetAllItems().Values) { if (template != null && template.Name.ToLower() == ticket.ToLower()) { ticketFound = true; pathname = template.Id_nb; break; } } } if (!ticketFound) { DisplayMessage(client, "Stablemaster has no {0}!", ticket); return; } MovementMgr.SavePath(pathname, path); DisplayMessage(client, "Taxi route set to path '{0}'!", pathname); }
/// <summary> /// Called when the living is about to get an item from someone /// else /// </summary> /// <param name="source">Source from where to get the item</param> /// <param name="item">Item to get</param> /// <returns>true if the item was successfully received</returns> public override bool ReceiveItem(GameLiving source, InventoryItem item) { if (source == null || item == null) { return(false); } if (source is GamePlayer) { GamePlayer player = (GamePlayer)source; if (item.Item_Type == 40 && isItemInMerchantList(item)) { PathPoint path = MovementMgr.LoadPath(item.Id_nb); if ((path != null) && ((Math.Abs(path.X - this.X)) < 500) && ((Math.Abs(path.Y - this.Y)) < 500)) { player.Inventory.RemoveCountFromStack(item, 1); InventoryLogging.LogInventoryAction(player, this, eInventoryActionType.Merchant, item.Template); GameTaxi mount; // item.Color of ticket is used for npctemplate. defaults to standard horse if item.color is 0 if (item.Color > 0) { mount = new GameTaxi(NpcTemplateMgr.GetTemplate(item.Color)); } else { mount = new GameTaxi(); foreach (GameNPC npc in GetNPCsInRadius(400)) { if (npc.Name == LanguageMgr.GetTranslation(ServerProperties.Properties.DB_LANGUAGE, "GameStableMaster.ReceiveItem.HorseName")) { mount.Model = npc.Model; mount.Name = npc.Name; break; } } } switch ((eRace)player.Race) { case eRace.Lurikeen: mount.Size = 31; break; case eRace.Kobold: mount.Size = 38; break; case eRace.Dwarf: mount.Size = 42; break; case eRace.Inconnu: mount.Size = 45; break; case eRace.Frostalf: case eRace.Shar: mount.Size = 48; break; case eRace.Briton: case eRace.Saracen: case eRace.Celt: mount.Size = 50; break; case eRace.Valkyn: mount.Size = 52; break; case eRace.Avalonian: case eRace.Highlander: case eRace.Norseman: case eRace.Elf: case eRace.Sylvan: mount.Size = 55; break; case eRace.Firbolg: mount.Size = 62; break; case eRace.HalfOgre: case eRace.AlbionMinotaur: case eRace.MidgardMinotaur: case eRace.HiberniaMinotaur: mount.Size = 65; break; case eRace.Troll: mount.Size = 67; break; default: mount.Size = 55; break; } mount.Realm = source.Realm; mount.X = path.X; mount.Y = path.Y; mount.Z = path.Z; mount.CurrentRegion = CurrentRegion; mount.Heading = path.GetHeading(path.Next); mount.AddToWorld(); mount.CurrentWayPoint = path; GameEventMgr.AddHandler(mount, GameNPCEvent.PathMoveEnds, new DOLEventHandler(OnHorseAtPathEnd)); new MountHorseAction(player, mount).Start(400); new HorseRideAction(mount).Start(4000); return(true); } } else { player.Out.SendMessage(LanguageMgr.GetTranslation(player.Client.Account.Language, "GameStableMaster.Receive.UnknownWay"), eChatType.CT_System, eChatLoc.CL_SystemWindow); } } return(false); }
private PathEntity createEntityPath(PathPoint pathpoint, PathPoint pathpoint1) { int i = 1; for (PathPoint pathpoint2 = pathpoint1; pathpoint2.previous != null; pathpoint2 = pathpoint2.previous) { i++; } var apathpoint = new PathPoint[i]; PathPoint pathpoint3 = pathpoint1; for (apathpoint[--i] = pathpoint3; pathpoint3.previous != null; apathpoint[--i] = pathpoint3) { pathpoint3 = pathpoint3.previous; } return new PathEntity(apathpoint); }
/// <summary> /// This function assigns the reccam parameters saved to a waypoint /// </summary> /// <param name="rc"> The reccamparameters to assign</param> /// <param name="point">Waypoint that will get reccam parameters assigned</param> void reSetRecCamGuis(RecCamParameters rc, PathPoint point) { //This switch is based on messagecodes RCamCommandType for (int i = 0; i < rc.reccam_parameters.Count; i++) { switch (rc.reccam_parameters[i].array[0]) { case 6: point.Rc.active = true; point.Rc.switchToRec = 1; break; case 7: point.Rc.active = true; point.Rc.switchToRec = 0; break; case 9: point.Rc.active = true; point.Rc.switchToRec = 1; break; case 10: point.Rc.active = false; break; case 11: point.Rc.active = true; point.Rc.switchToRec = 0; break; case 12: point.Rc.active = true; point.Rc.switchToRec = 0; break; case 17: //This switch is based on RCamConfigParameter switch (rc.reccam_parameters[i].array[1]) { case 0: point.Rc.resolution = (rc.reccam_parameters[i].array[2]); break; case 1: point.Rc.megaPixels = rc.reccam_parameters[i].array[2]; break; case 2: point.Rc.autoManualWB = rc.reccam_parameters[i].array[2]; break; case 54: point.Rc.WBTint = rc.reccam_parameters[i].array[2]; break; case 3: point.Rc.ISO = rc.reccam_parameters[i].array[2]; break; case 4: point.Rc.sharpness = rc.reccam_parameters[i].array[2]; break; case 5: point.Rc.contrast = new byte[] { rc.reccam_parameters[i].array[2], rc.reccam_parameters[i].array[3], rc.reccam_parameters[i].array[4], rc.reccam_parameters[i].array[5] }; break; case 6: point.Rc.AE = rc.reccam_parameters[i].array[2]; break; case 12: point.Rc.AF = 1; break; case 14: point.Rc.saturation = new byte[] { rc.reccam_parameters[i].array[2], rc.reccam_parameters[i].array[3], rc.reccam_parameters[i].array[4], rc.reccam_parameters[i].array[5] }; break; case 15: point.Rc.brightness = new byte[] { rc.reccam_parameters[i].array[2], rc.reccam_parameters[i].array[3], rc.reccam_parameters[i].array[4], rc.reccam_parameters[i].array[5] }; break; case 17: point.Rc.photoQuality = rc.reccam_parameters[i].array[2]; break; case 19: point.Rc.upsideDown = rc.reccam_parameters[i].array[2]; break; case 21: point.Rc.irisAperture = rc.reccam_parameters[i].array[2]; break; case 36: point.Rc.burstMode = rc.reccam_parameters[i].array[2]; break; case 64: point.Rc.burstSpeed = rc.reccam_parameters[i].array[2]; break; default: break; } break; case 32: point.Rc.active = true; point.Rc.switchToRec = 0; break; case 33: point.Rc.active = false; break; default: break; } } point.Rc.edited = true; }
private PathPoint openPoint(int i, int j, int k) { int l = PathPoint.func_22203_a(i, j, k); var pathpoint = (PathPoint) pointMap.lookup(l); if (pathpoint == null) { pathpoint = new PathPoint(i, j, k); pointMap.addKey(l, pathpoint); } return pathpoint; }
private IEnumerator Travel(PathPoint[] path) { foreach (PathPoint p in path) { GetComponentInChildren<Animator>().SetFloat("Moving", 1.0f); while (Vector3.Distance(transform.position, p.point) > 0.1f) { transform.position = Vector3.MoveTowards(transform.position, p.point, Time.deltaTime); lookTarget = p.point; yield return null; } if (p.canLookAtPainting) { GetComponentInChildren<Animator>().SetFloat("Moving", 0.0f); lookTarget = p.targetPainting.transform.position; yield return new WaitForSeconds(0.3f); yield return StartCoroutine(ExaminePainting(p.targetPainting)); } if(!p.callEvent.Equals("")) SendMessage(p.callEvent, SendMessageOptions.DontRequireReceiver); } Debug.Log ("Bye!"); PlayBye (); SendMessageUpwards("OnCustomerExit", this); }
private int getVerticalOffset(Entity entity, int i, int j, int k, PathPoint pathpoint) { for (int l = i; l < i + pathpoint.xCoord; l++) { for (int i1 = j; i1 < j + pathpoint.yCoord; i1++) { for (int j1 = k; j1 < k + pathpoint.zCoord; j1++) { Material material = worldMap.getBlockMaterial(l, i1, j1); if (material.getIsSolid()) { return 0; } if (material == Material.water || material == Material.lava) { return -1; } } } } return 1; }
private PathPoint getSafePoint(Entity entity, int i, int j, int k, PathPoint pathpoint, int l) { PathPoint pathpoint1 = null; if (getVerticalOffset(entity, i, j, k, pathpoint) > 0) { pathpoint1 = openPoint(i, j, k); } if (pathpoint1 == null && l > 0 && getVerticalOffset(entity, i, j + l, k, pathpoint) > 0) { pathpoint1 = openPoint(i, j + l, k); j += l; } if (pathpoint1 != null) { int i1 = 0; for (int j1 = 0; j > 0 && (j1 = getVerticalOffset(entity, i, j - 1, k, pathpoint)) > 0; j--) { if (j1 < 0) { return null; } if (++i1 >= 4) { return null; } } if (j > 0) { pathpoint1 = openPoint(i, j, k); } } return pathpoint1; }
private int findPathOptions(Entity entity, PathPoint pathpoint, PathPoint pathpoint1, PathPoint pathpoint2, float f) { int i = 0; int j = 0; if (getVerticalOffset(entity, pathpoint.xCoord, pathpoint.yCoord + 1, pathpoint.zCoord, pathpoint1) > 0) { j = 1; } PathPoint pathpoint3 = getSafePoint(entity, pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord + 1, pathpoint1, j); PathPoint pathpoint4 = getSafePoint(entity, pathpoint.xCoord - 1, pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j); PathPoint pathpoint5 = getSafePoint(entity, pathpoint.xCoord + 1, pathpoint.yCoord, pathpoint.zCoord, pathpoint1, j); PathPoint pathpoint6 = getSafePoint(entity, pathpoint.xCoord, pathpoint.yCoord, pathpoint.zCoord - 1, pathpoint1, j); if (pathpoint3 != null && !pathpoint3.isFirst && pathpoint3.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint3; } if (pathpoint4 != null && !pathpoint4.isFirst && pathpoint4.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint4; } if (pathpoint5 != null && !pathpoint5.isFirst && pathpoint5.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint5; } if (pathpoint6 != null && !pathpoint6.isFirst && pathpoint6.distanceTo(pathpoint2) < f) { pathOptions[i++] = pathpoint6; } return i; }
public void SetPrev(PathPoint prev) { this._prev = prev; }
/****************************************************** * MonoBehaviour methods, FixedUpdate ******************************************************/ void FixedUpdate() { if (isMoving && !stuckDisable) { Vector3 current3dPos = myTransform.position; Vector2 current2dPos = new Vector2(current3dPos.x, current3dPos.z); float angle = Vector2.Angle(pathPointNextClosest.Pos2d - pathPoint.Pos2d, current2dPos - pathPoint.Pos2d); //Debug.Log(angle); // if the distance between current pos to pathpoint + pathpoint to next pathpoint // is greater than going from current to next pathpoint if ((Vector2.Distance(pathPoint.Pos2d, current2dPos) + Vector2.Distance(pathPoint.Pos2d, pathPointNextClosest.Pos2d) > Vector2.Distance(pathPointNextClosest.Pos2d, current2dPos) + SMOOTH_MARGIN || Vector2.Distance(pathPoint.Pos2d, current2dPos) < SMOOTH_MARGIN || (angle < 120)) && Vector2.Distance(pathPoint.Pos2d, current2dPos) < SMOOTH_MARGIN * 4 || (angle < 100) ) { pathPoint = pathPoint.getNextWeightedPathPoint(); pathPointNextClosest = pathPoint.getNextClosestPathPoint(); } Quaternion saveRotation = myTransform.rotation; Vector2 direction = new Vector2(rigidbody.velocity.x, rigidbody.velocity.z); Vector3 relativePoint = transform.InverseTransformPoint(pathPoint.transform.position); Vector3 forward = myTransform.forward; transform.rotation = saveRotation; Vector3 targetDir = pathPoint.transform.position - transform.position; Vector3 normal = rigidbody.velocity.normalized; angle = Vector3.Angle(targetDir, forward); bool hasTurned = false; // collision turning rays Ray forwardRay = new Ray(current3dPos, rigidbody.velocity.normalized); Ray forwardDownRay = new Ray(current3dPos + (rigidbody.velocity.normalized * GAP_MARGIN), -Vector3.up); Ray leftRay = new Ray(current3dPos, -myTransform.right); Ray leftDownRay = new Ray(current3dPos + (-myTransform.right * GAP_MARGIN), -Vector3.up); Ray rightRay = new Ray(current3dPos, myTransform.right); Ray rightDownRay = new Ray(current3dPos + (myTransform.right * GAP_MARGIN), -Vector3.up); bool forwardTest = Physics.Raycast(forwardRay, GAP_MARGIN, layerMask); bool forwardDownTest = Physics.Raycast(forwardDownRay, PIT_MARGIN, layerMask); bool leftTest = Physics.Raycast(leftRay, GAP_MARGIN, layerMask); bool leftDownTest = Physics.Raycast(leftDownRay, PIT_MARGIN, layerMask); bool rightTest = Physics.Raycast(rightRay, GAP_MARGIN, layerMask); bool rightDownTest = Physics.Raycast(rightDownRay, PIT_MARGIN, layerMask); // pit detection turning if (!forwardDownTest && !hasTurned) { if (!leftDownTest) { player.turnRight(); hasTurned = true; } else if (!rightDownTest) { player.turnLeft(); hasTurned = true; } } // obstacle turning if (forwardTest && !hasTurned) { bool stopLeftTesting = false; bool stopRightTesting = false; for (int i = 1; i <= NUM_OF_INTERVALS; i++) { if (!stopLeftTesting) { if (!Physics.Raycast(leftRay, INTERVAL_MARGIN * i, layerMask)) { Vector3 leftPoint = current3dPos + (-myTransform.right * INTERVAL_MARGIN * i); Vector3 leftVector = leftPoint - pathPoint.Pos3d; Ray leftFollowIntervalRay = new Ray(leftPoint, leftVector.normalized); if (Physics.Raycast(leftFollowIntervalRay, leftVector.magnitude)) { Ray leftIntervalDownRay = new Ray(leftPoint, -Vector3.up); if (!Physics.Raycast(leftIntervalDownRay, PIT_MARGIN)) { player.turnLeft(); hasTurned = true; break; } } } else { stopLeftTesting = true; } } if (!stopRightTesting) { if (!Physics.Raycast(rightRay, INTERVAL_MARGIN * i, layerMask)) { Vector3 rightPoint = current3dPos + (myTransform.right * INTERVAL_MARGIN * i); Vector3 rightVector = rightPoint - pathPoint.Pos3d; Ray rightIntervalRay = new Ray(rightPoint, rightVector.normalized); if (Physics.Raycast(rightIntervalRay, rightVector.magnitude)) { Ray rightIntervalDownRay = new Ray(rightPoint, Vector3.up); if (!Physics.Raycast(rightIntervalDownRay, PIT_MARGIN)) { player.turnRight(); hasTurned = true; break; } else { stopRightTesting = true; } } } else { stopRightTesting = true; } } } /* * if (!hasTurned) * { * if (!leftTest) * { * if (leftDownTest) * { * player.turnRight(); * hasTurned = true; * } * } * else if (!rightTest) * { * if (rightDownTest) * { * player.turnLeft(); * hasTurned = true; * } * } * }*/ } // normal turning if (!hasTurned) { if (relativePoint.x < 0f && angle > 15) { player.turnLeft(); } else if (relativePoint.x > 0f && angle > 15) { player.turnRight(); } else { player.turnCenter(); } } // normal accelerate if (angle < 90) { player.applyAcceleration(); } else { player.applyIdleMotion(); } stuckTimeCounter += Time.deltaTime; stuckMoveCounter += Vector3.Distance(myTransform.position, lastUpdatePosition); lastUpdatePosition = myTransform.position; if (stuckMoveCounter >= REQUIRED_MOVE_RESET) { stuckTimeCounter = 0; stuckMoveCounter = 0; } else if (stuckTimeCounter >= REQUIRED_STUCK_TIME) { stuckTimeCounter = 0; stuckMoveCounter = 0; stuckDisable = true; } } else if (stuckDisable) { stuckDisableTimeCounter += Time.deltaTime; player.applyReverse(); if (stuckDisableTimeCounter >= STUCK_DISABLE_TIME) { stuckDisableTimeCounter = 0; stuckDisable = false; } } else if (isMoving == false) { player.applyIdleMotion(); player.turnCenter(); } }
public void SetNext(PathPoint next) { this._next = next; }
public PathThumb(int index, PathPoint pathpoint) : base() { this.Index = index; this.PathPoint = pathpoint; var bnd = new Binding("TranslatedPoint") { Source = this.PathPoint, Mode=BindingMode.OneWay }; this.SetBinding(PointProperty, bnd); }
//Function called in the pathfinding algorithms in CreateTileGrid.cs. Clears this path point's previous point and the fact that it's been checked public void ClearPathfinding() { this.previousPoint = null; this.hasBeenChecked = false; this.currentMovement = 0; }
protected virtual Control[] BuildMenu(PathPoint pathpoint) { var menuList = new List<Control>(); MenuItem menuItem = null; if (pathpoint.TargetPathPoint == null && (pathpoint.Object is LineSegment || pathpoint.Object is PolyLineSegment || pathpoint.Object is BezierSegment || pathpoint.Object is QuadraticBezierSegment || pathpoint.Object is ArcSegment)) { menuItem = new MenuItem() { Header = "insert Point", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.insertPoint); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Line Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToLineSegment); menuList.Add(menuItem); menuItem = new MenuItem() {Header = "to Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToBezierSegment); menuList.Add(menuItem); menuItem = new MenuItem() {Header = "to Quadric Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToQuadricBezierSegment); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Arc Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent<PathThumb>(), PathPartConvertType.ToArcSegment); menuList.Add(menuItem); menuList.Add(new Separator()); menuItem = new MenuItem() { Header = "is Stroked", IsChecked = ((PathSegment)pathpoint.Object).IsStroked, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsStroked(((DependencyObject)s).TryFindParent<PathThumb>(), (MenuItem)s); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "is Smooth Join", IsChecked = ((PathSegment)pathpoint.Object).IsSmoothJoin, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is ArcSegment) { menuItem = new MenuItem() { Header = "is large Arc", IsChecked = ((ArcSegment)pathpoint.Object).IsLargeArc, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); menuItem = new MenuItem() { Header = "Rotation Angle", IsChecked = true, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); menuItem = new MenuItem() { Header = "Clockwise SweepDirection", IsChecked = ((ArcSegment)pathpoint.Object).SweepDirection == SweepDirection.Clockwise, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is PathFigure) { menuItem = new MenuItem() { Header = "is Closed", IsChecked = ((PathFigure)pathpoint.Object).IsClosed, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsClosed(((DependencyObject)s).TryFindParent<PathThumb>(), (MenuItem)s); menuList.Add(menuItem); } if (!menuList.Any()) return null; return menuList.ToArray(); }
public void GeneratePointsOnBezier() { if (pathPoints == null) { return; } if (spline == null) { return; } DeleteAllPoints(); float progress = 0; for (int i = 0; i < splinePoinsAmount; i++) { if (i > 0) { progress = 1f / splinePoinsAmount * (i); } PathPoint newPoint = new PathPoint(); newPoint.position = spline.GetPoint(progress); newPoint.rotation = Quaternion.LookRotation(spline.GetDirection(progress)); newPoint.gravity = gravity; // Create PathPoing Collider GameObject go = new GameObject("Path collider " + i); go.transform.parent = gameObject.transform; go.transform.position = newPoint.position; go.transform.rotation = newPoint.rotation; BoxCollider colliderNormal = go.AddComponent <BoxCollider>(); colliderNormal.size = new Vector3(10f, 10f, 0.05f); colliderNormal.isTrigger = true; PathNodeCollider pn = go.AddComponent <PathNodeCollider>(); pn.indexGravityNode = i; // Create Reverse collider GameObject goReverse = new GameObject("Reverse Path collider " + i); goReverse.transform.parent = gameObject.transform; goReverse.transform.position = spline.GetPoint(progress + 0.001f); goReverse.transform.rotation = newPoint.rotation; BoxCollider colliderReverse = goReverse.AddComponent <BoxCollider>(); colliderReverse.size = new Vector3(10f, 10f, 0.05f); colliderReverse.isTrigger = true; PathNodeReverseCollider pnReverse = goReverse.AddComponent <PathNodeReverseCollider>(); pn.reverseCollider = pnReverse; pnReverse.normalCollider = pn; newPoint.collider = colliderNormal; newPoint.colliderReverse = colliderReverse; pathPoints.pointsList.Add(newPoint); } if (pathPoints.pointsList.Count > 0) { activeIndex = 0; } UpdateActivePoint(); }
protected void AddGeometryPoints(List<PathPoint> list, Geometry geometry, Shape shape, Action saveDesignItem) { if (geometry is CombinedGeometry) { var g = geometry as CombinedGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) saveDesignItem = () => { d.Properties["Geometry1"].SetValue(((CombinedGeometry)d.Component).Geometry1); d.Properties["Geometry2"].SetValue(((CombinedGeometry)d.Component).Geometry2); }; AddGeometryPoints(list, g.Geometry1, shape, saveDesignItem); AddGeometryPoints(list, g.Geometry2, shape, saveDesignItem); } else if (geometry is GeometryGroup) { var gg = geometry as GeometryGroup; foreach (var g in gg.Children.ToList()) { AddGeometryPoints(list, g, shape, saveDesignItem); } } else if (geometry is StreamGeometry) { var sg = geometry as StreamGeometry; var pg = sg.GetFlattenedPathGeometry().Clone(); var d = ExtendedItem.Services.Component.GetDesignItem(sg); if (d != null) saveDesignItem = () => { d.ParentProperty.SetValue(Geometry.Parse(pg.ToString())); }; if (d != null) { if (!d.ParentProperty.IsCollection) ((DependencyObject)d.ParentProperty.DesignItem.Component).SetValue(d.ParentProperty.DependencyProperty, pg); else { var collection = ((DependencyObject)d.ParentProperty.DesignItem.Component) as GeometryGroup; var i = collection.Children.IndexOf(geometry); collection.Children.RemoveAt(i); collection.Children.Insert(i, pg); } } else ((Path)shape).Data = pg; AddGeometryPoints(list, pg, shape, saveDesignItem); } else if (geometry is PathGeometry) { var g = geometry as PathGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) saveDesignItem = () => { d.Properties["Figures"].SetValue(((PathGeometry)d.Component).Figures); }; if (geometry!=null) { foreach(var figure in g.Figures) { var dd = ExtendedItem.Services.Component.GetDesignItem(figure); if (dd != null) saveDesignItem = () => { dd.Properties["StartPoint"].SetValue(((PathFigure)dd.Component).StartPoint); //dd.Properties["Segments"].SetValue(((PathFigure)dd.Component).Segments); }; list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p, saveDesignItem, shape)); foreach (var s in figure.Segments) { var parentp = list.Last(); if (s is LineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Point"].SetValue(((LineSegment)ds.Component).Point); }; list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }); } else if (s is PolyLineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Points"].SetValue(((PolyLineSegment)ds.Component).Points); }; var poly = s as PolyLineSegment; for (int n = 0; n < poly.Points.Count; n++) { var closure_n = n; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); parentp = list.Last(); } } else if (s is BezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Point1"].SetValue(((BezierSegment)ds.Component).Point1); ds.Properties["Point2"].SetValue(((BezierSegment)ds.Component).Point2); ds.Properties["Point3"].SetValue(((BezierSegment)ds.Component).Point3); }; var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; var previous = list.Last(); list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = previous }); list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Points"].SetValue(((PolyBezierSegment)ds.Component).Points); }; var poly = s as PolyBezierSegment; for (int n = 0; n < poly.Points.Count; n+=3) { var closure_n = n; var previous = list.Last(); var pathp = new PathPoint(poly.Points[closure_n+2], s, figure, (p) => poly.Points[closure_n+2] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+2, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = previous }); list.Add(new PathPoint(poly.Points[closure_n+1], s, figure, (p) => poly.Points[closure_n+1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+1, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is QuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Point1"].SetValue(((QuadraticBezierSegment)ds.Component).Point1); ds.Properties["Point2"].SetValue(((QuadraticBezierSegment)ds.Component).Point2); }; var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyQuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Points"].SetValue(((PolyQuadraticBezierSegment)ds.Component).Points); }; var poly = s as PolyQuadraticBezierSegment; for (int n = 0; n < poly.Points.Count; n+=2) { var closure_n = n; var previous = list.Last(); var pathp = new PathPoint(poly.Points[closure_n+1], s, figure, (p) => poly.Points[closure_n+1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n+1, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is ArcSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) saveDesignItem = () => { ds.Properties["Size"].SetValue(((ArcSegment)ds.Component).Size); }; var arc = ((ArcSegment)s); var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y)), saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } } } } } else if (geometry is RectangleGeometry) { var g = geometry as RectangleGeometry; list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Left = p.X)); list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Width = p.X)); list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Top = p.Y)); list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Height = p.Y)); } else if (geometry is EllipseGeometry) { var g = geometry as EllipseGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) saveDesignItem = () => d.Properties["Center"].SetValue(((EllipseGeometry)d.Component).Center); list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p, saveDesignItem, shape)); } else if (geometry is LineGeometry) { var g = geometry as LineGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) saveDesignItem = () => { d.Properties["StartPoint"].SetValue(((LineGeometry)d.Component).StartPoint); d.Properties["EndPoint"].SetValue(((LineGeometry)d.Component).EndPoint); }; list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p, saveDesignItem, shape)); list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p, saveDesignItem, shape)); } }
protected virtual Control[] BuildMenu(PathPoint pathpoint) { var menuList = new List <Control>(); MenuItem menuItem = null; if (pathpoint.TargetPathPoint == null && (pathpoint.Object is LineSegment || pathpoint.Object is PolyLineSegment || pathpoint.Object is BezierSegment || pathpoint.Object is QuadraticBezierSegment || pathpoint.Object is ArcSegment)) { menuItem = new MenuItem() { Header = "insert Point", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent <PathThumb>(), PathPartConvertType.insertPoint); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Line Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent <PathThumb>(), PathPartConvertType.ToLineSegment); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent <PathThumb>(), PathPartConvertType.ToBezierSegment); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Quadric Bezier Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent <PathThumb>(), PathPartConvertType.ToQuadricBezierSegment); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "to Arc Segment", HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ConvertPart(((DependencyObject)s).TryFindParent <PathThumb>(), PathPartConvertType.ToArcSegment); menuList.Add(menuItem); menuList.Add(new Separator()); menuItem = new MenuItem() { Header = "is Stroked", IsChecked = ((PathSegment)pathpoint.Object).IsStroked, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsStroked(((DependencyObject)s).TryFindParent <PathThumb>(), (MenuItem)s); menuList.Add(menuItem); menuItem = new MenuItem() { Header = "is Smooth Join", IsChecked = ((PathSegment)pathpoint.Object).IsSmoothJoin, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is ArcSegment) { menuItem = new MenuItem() { Header = "is large Arc", IsChecked = ((ArcSegment)pathpoint.Object).IsLargeArc, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); menuItem = new MenuItem() { Header = "Rotation Angle", IsChecked = true, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); menuItem = new MenuItem() { Header = "Clockwise SweepDirection", IsChecked = ((ArcSegment)pathpoint.Object).SweepDirection == SweepDirection.Clockwise, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuList.Add(menuItem); } if (pathpoint.Object is PathFigure) { menuItem = new MenuItem() { Header = "is Closed", IsChecked = ((PathFigure)pathpoint.Object).IsClosed, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center }; menuItem.Click += (s, e) => ChangeIsClosed(((DependencyObject)s).TryFindParent <PathThumb>(), (MenuItem)s); menuList.Add(menuItem); } if (!menuList.Any()) { return(null); } return(menuList.ToArray()); }
/* Calculating the computer's move */ public void GetAiTurn(out BaseChecker selectedChecker, out PathPoint toPosition) { selectedChecker = null; toPosition = null; List <PathPoint> possibleTurns = new List <PathPoint>(); // List of possible moves // Building a list of possible moves foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers : Game.gameplayController.state.BlackCheckers) { PathPoint turn = checker.GetPossibleTurns(); if (!turn.IsDeadEnd()) // If not a dead-end point, add a route to the list { possibleTurns.Add(turn); } } // If no moves are found - a loss if (possibleTurns.Count == 0) { selectedChecker = null; toPosition = null; return; } // Trying to find aggressive moves foreach (PathPoint chain in possibleTurns) { List <int> eatableDirections = chain.TryGetAggresiveDirections(); if (eatableDirections.Count > 0) { // Aggressive move found toPosition = chain; // We find out the path belonging to the checker and leave the method foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers : Game.gameplayController.state.BlackCheckers) { PathPoint turn = checker.GetPossibleTurns(); if (turn.Position == chain.Position) { selectedChecker = checker; return; } } } } // There are no "edible" moves, we are looking for peaceful ones in a random way Random rnd = new Random(); toPosition = possibleTurns[rnd.Next(possibleTurns.Count - 1)]; // Matching the move with the checker foreach (BaseChecker checker in Side == CheckerSide.White ? Game.gameplayController.state.WhiteCheckers : Game.gameplayController.state.BlackCheckers) { PathPoint turn = checker.GetPossibleTurns(); if (turn.Position == toPosition.Position) { selectedChecker = checker; } } return; }
protected void AddGeometryPoints(List <PathPoint> list, Geometry geometry, Shape shape, Action saveDesignItem) { if (geometry is CombinedGeometry) { var g = geometry as CombinedGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { var dClosure = d; saveDesignItem = () => { dClosure.Properties["Geometry1"].SetValue(((CombinedGeometry)dClosure.Component).Geometry1); dClosure.Properties["Geometry2"].SetValue(((CombinedGeometry)dClosure.Component).Geometry2); }; } AddGeometryPoints(list, g.Geometry1, shape, saveDesignItem); AddGeometryPoints(list, g.Geometry2, shape, saveDesignItem); } else if (geometry is GeometryGroup) { var gg = geometry as GeometryGroup; foreach (var g in gg.Children.ToList()) { AddGeometryPoints(list, g, shape, saveDesignItem); } } else if (geometry is StreamGeometry) { var sg = geometry as StreamGeometry; var pg = sg.GetFlattenedPathGeometry().Clone(); var d = ExtendedItem.Services.Component.GetDesignItem(sg); if (d != null) { var dClosure = d; saveDesignItem = () => { dClosure.ParentProperty.SetValue(Geometry.Parse(new GeometryConverter().ConvertToInvariantString(pg))); }; } if (d != null) { if (!d.ParentProperty.IsCollection) { ((DependencyObject)d.ParentProperty.DesignItem.Component).SetValue(d.ParentProperty.DependencyProperty, pg); } else { var collection = ((DependencyObject)d.ParentProperty.DesignItem.Component) as GeometryGroup; var i = collection.Children.IndexOf(geometry); collection.Children.RemoveAt(i); collection.Children.Insert(i, pg); } } else { ((Path)shape).Data = pg; } AddGeometryPoints(list, pg, shape, saveDesignItem); } else if (geometry is PathGeometry) { var g = geometry as PathGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { var dClosure = d; saveDesignItem = () => { dClosure.Properties["Figures"].SetValue(((PathGeometry)dClosure.Component).Figures); }; } if (geometry != null) { foreach (var figure in g.Figures) { var dd = ExtendedItem.Services.Component.GetDesignItem(figure); if (dd != null) { var ddClosure = dd; saveDesignItem = () => { ddClosure.Properties["StartPoint"].SetValue(((PathFigure)ddClosure.Component).StartPoint); }; } list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p, saveDesignItem, shape)); foreach (var s in figure.Segments) { var parentp = list.Last(); if (s is LineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Point"].SetValue(((LineSegment)dsClosure.Component).Point); }; } list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }); } else if (s is PolyLineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Points"].SetValue(((PolyLineSegment)dsClosure.Component).Points); }; } var poly = s as PolyLineSegment; for (int n = 0; n < poly.Points.Count; n++) { var closure_n = n; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); parentp = list.Last(); } } else if (s is BezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Point1"].SetValue(((BezierSegment)dsClosure.Component).Point1); dsClosure.Properties["Point2"].SetValue(((BezierSegment)dsClosure.Component).Point2); dsClosure.Properties["Point3"].SetValue(((BezierSegment)dsClosure.Component).Point3); }; } var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; var previous = list.Last(); list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = previous }); list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Points"].SetValue(((PolyBezierSegment)dsClosure.Component).Points); }; } var poly = s as PolyBezierSegment; for (int n = 0; n < poly.Points.Count; n += 3) { var closure_n = n; var previous = list.Last(); var pathp = new PathPoint(poly.Points[closure_n + 2], s, figure, (p) => poly.Points[closure_n + 2] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 2, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = previous }); list.Add(new PathPoint(poly.Points[closure_n + 1], s, figure, (p) => poly.Points[closure_n + 1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 1, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is QuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Point1"].SetValue(((QuadraticBezierSegment)dsClosure.Component).Point1); dsClosure.Properties["Point2"].SetValue(((QuadraticBezierSegment)dsClosure.Component).Point2); }; } var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyQuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Points"].SetValue(((PolyQuadraticBezierSegment)dsClosure.Component).Points); }; } var poly = s as PolyQuadraticBezierSegment; for (int n = 0; n < poly.Points.Count; n += 2) { var closure_n = n; var pathp = new PathPoint(poly.Points[closure_n + 1], s, figure, (p) => poly.Points[closure_n + 1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 1, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is ArcSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { var dsClosure = ds; saveDesignItem = () => { dsClosure.Properties["Size"].SetValue(((ArcSegment)dsClosure.Component).Size); }; } var arc = ((ArcSegment)s); var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y)), saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } } } } } else if (geometry is RectangleGeometry) { var g = geometry as RectangleGeometry; list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Left = p.X)); list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Width = p.X)); list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Top = p.Y)); list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Height = p.Y)); } else if (geometry is EllipseGeometry) { var g = geometry as EllipseGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { var dClosure = d; saveDesignItem = () => dClosure.Properties["Center"].SetValue(((EllipseGeometry)dClosure.Component).Center); } list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p, saveDesignItem, shape)); } else if (geometry is LineGeometry) { var g = geometry as LineGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { var dClosure = d; saveDesignItem = () => { dClosure.Properties["StartPoint"].SetValue(((LineGeometry)dClosure.Component).StartPoint); dClosure.Properties["EndPoint"].SetValue(((LineGeometry)dClosure.Component).EndPoint); }; } list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p, saveDesignItem, shape)); list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p, saveDesignItem, shape)); } }
public void BeginTraversingPath(PathPoint[] path) { StartCoroutine(Travel(path)); StartCoroutine (WaitForGreeting ()); }
/****************************************************** * repathPoints ******************************************************/ /// <summary> set the path to the closest node </summary> public void repathPoints() { pathPoint = PathManager.FindClosestPoint(this.transform.position); pathPointNextClosest = pathPoint.getNextClosestPathPoint(); }
public BriefRouteModel() { PathRoute = new PathPoint(); }
public void Submit(string key, PositionType position, PathPoint point, int durationMillis) { // nothing to do }
protected void AddGeometryPoints(List <PathPoint> list, Geometry geometry, Shape shape, Action saveDesignItem) { if (geometry is CombinedGeometry) { var g = geometry as CombinedGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { saveDesignItem = () => { d.Properties["Geometry1"].SetValue(((CombinedGeometry)d.Component).Geometry1); d.Properties["Geometry2"].SetValue(((CombinedGeometry)d.Component).Geometry2); } } ; AddGeometryPoints(list, g.Geometry1, shape, saveDesignItem); AddGeometryPoints(list, g.Geometry2, shape, saveDesignItem); } else if (geometry is GeometryGroup) { var gg = geometry as GeometryGroup; foreach (var g in gg.Children.ToList()) { AddGeometryPoints(list, g, shape, saveDesignItem); } } else if (geometry is StreamGeometry) { var sg = geometry as StreamGeometry; var pg = sg.GetFlattenedPathGeometry().Clone(); var d = ExtendedItem.Services.Component.GetDesignItem(sg); if (d != null) { saveDesignItem = () => { d.ParentProperty.SetValue(Geometry.Parse(pg.ToString())); } } ; if (d != null) { if (!d.ParentProperty.IsCollection) { ((DependencyObject)d.ParentProperty.DesignItem.Component).SetValue( d.ParentProperty.DependencyProperty, pg); } else { var collection = ((DependencyObject)d.ParentProperty.DesignItem.Component) as GeometryGroup; var i = collection.Children.IndexOf(geometry); collection.Children.RemoveAt(i); collection.Children.Insert(i, pg); } } else { ((Path)shape).Data = pg; } AddGeometryPoints(list, pg, shape, saveDesignItem); } else if (geometry is PathGeometry) { var g = geometry as PathGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { saveDesignItem = () => { d.Properties["Figures"].SetValue(((PathGeometry)d.Component).Figures); } } ; if (geometry != null) { foreach (var figure in g.Figures) { var dd = ExtendedItem.Services.Component.GetDesignItem(figure); if (dd != null) { saveDesignItem = () => { dd.Properties["StartPoint"].SetValue(((PathFigure)dd.Component).StartPoint); //dd.Properties["Segments"].SetValue(((PathFigure)dd.Component).Segments); } } ; list.Add(new PathPoint(figure.StartPoint, figure, null, (p) => figure.StartPoint = p, saveDesignItem, shape)); foreach (var s in figure.Segments) { var parentp = list.Last(); if (s is LineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Point"].SetValue(((LineSegment)ds.Component).Point); } } ; list.Add(new PathPoint(((LineSegment)s).Point, s, figure, (p) => ((LineSegment)s).Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }); } else if (s is PolyLineSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Points"].SetValue(((PolyLineSegment)ds.Component).Points); } } ; var poly = s as PolyLineSegment; for (int n = 0; n < poly.Points.Count; n++) { var closure_n = n; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, ParentPathPoint = parentp }); parentp = list.Last(); } } else if (s is BezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Point1"].SetValue(((BezierSegment)ds.Component).Point1); ds.Properties["Point2"].SetValue(((BezierSegment)ds.Component).Point2); ds.Properties["Point3"].SetValue(((BezierSegment)ds.Component).Point3); } } ; var pathp = new PathPoint(((BezierSegment)s).Point3, s, figure, (p) => ((BezierSegment)s).Point3 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; var previous = list.Last(); list.Add(new PathPoint(((BezierSegment)s).Point1, s, figure, (p) => ((BezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = previous }); list.Add(new PathPoint(((BezierSegment)s).Point2, s, figure, (p) => ((BezierSegment)s).Point2 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Points"].SetValue(((PolyBezierSegment)ds.Component).Points); } } ; var poly = s as PolyBezierSegment; for (int n = 0; n < poly.Points.Count; n += 3) { var closure_n = n; var previous = list.Last(); var pathp = new PathPoint(poly.Points[closure_n + 2], s, figure, (p) => poly.Points[closure_n + 2] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 2, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = previous }); list.Add(new PathPoint(poly.Points[closure_n + 1], s, figure, (p) => poly.Points[closure_n + 1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 1, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is QuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Point1"] .SetValue(((QuadraticBezierSegment)ds.Component).Point1); ds.Properties["Point2"] .SetValue(((QuadraticBezierSegment)ds.Component).Point2); } } ; var pathp = new PathPoint(((QuadraticBezierSegment)s).Point2, s, figure, (p) => ((QuadraticBezierSegment)s).Point2 = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(((QuadraticBezierSegment)s).Point1, s, figure, (p) => ((QuadraticBezierSegment)s).Point1 = p, saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } else if (s is PolyQuadraticBezierSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Points"] .SetValue(((PolyQuadraticBezierSegment)ds.Component).Points); } } ; var poly = s as PolyQuadraticBezierSegment; for (int n = 0; n < poly.Points.Count; n += 2) { var closure_n = n; var previous = list.Last(); var pathp = new PathPoint(poly.Points[closure_n + 1], s, figure, (p) => poly.Points[closure_n + 1] = p, saveDesignItem, shape) { PolyLineIndex = closure_n + 1, ParentPathPoint = parentp }; list.Add(new PathPoint(poly.Points[closure_n], s, figure, (p) => poly.Points[closure_n] = p, saveDesignItem, shape) { PolyLineIndex = closure_n, TargetPathPoint = pathp }); list.Add(pathp); parentp = pathp; } } else if (s is ArcSegment) { var ds = ExtendedItem.Services.Component.GetDesignItem(s); if (ds != null) { saveDesignItem = () => { ds.Properties["Size"].SetValue(((ArcSegment)ds.Component).Size); } } ; var arc = ((ArcSegment)s); var pathp = new PathPoint(arc.Point, s, figure, (p) => arc.Point = p, saveDesignItem, shape) { ParentPathPoint = parentp }; list.Add(new PathPoint(arc.Point - new Vector(arc.Size.Width, arc.Size.Height), s, figure, (p) => arc.Size = new Size(Math.Abs(arc.Point.X - p.X), Math.Abs(arc.Point.Y - p.Y)), saveDesignItem, shape) { TargetPathPoint = pathp }); list.Add(pathp); } } } } } else if (geometry is RectangleGeometry) { var g = geometry as RectangleGeometry; list.Add(new PathPoint(g.Rect.TopLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Left = p.X)); list.Add(new PathPoint(g.Rect.TopRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Width = p.X)); list.Add(new PathPoint(g.Rect.BottomLeft, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Top = p.Y)); list.Add(new PathPoint(g.Rect.BottomRight, geometry, null, null, saveDesignItem, shape)); //(p) => g.Rect.Height = p.Y)); } else if (geometry is EllipseGeometry) { var g = geometry as EllipseGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { saveDesignItem = () => d.Properties["Center"].SetValue(((EllipseGeometry)d.Component).Center); } list.Add(new PathPoint(g.Center, geometry, null, (p) => g.Center = p, saveDesignItem, shape)); } else if (geometry is LineGeometry) { var g = geometry as LineGeometry; var d = ExtendedItem.Services.Component.GetDesignItem(g); if (d != null) { saveDesignItem = () => { d.Properties["StartPoint"].SetValue(((LineGeometry)d.Component).StartPoint); d.Properties["EndPoint"].SetValue(((LineGeometry)d.Component).EndPoint); } } ; list.Add(new PathPoint(g.StartPoint, geometry, null, (p) => g.StartPoint = p, saveDesignItem, shape)); list.Add(new PathPoint(g.EndPoint, geometry, null, (p) => g.EndPoint = p, saveDesignItem, shape)); } } void MovePoints(double displacementX, double displacementY, bool useContainerBehavior = true) { var relativeTo = new Vector(operation.PlacedItems[0].Bounds.TopLeft.X, operation.PlacedItems[0].Bounds.TopLeft.Y); //iterate all selected points foreach (int i in _selectedPoints.Keys) { Point p = pathPoints[i].TranslatedPoint; //x and y is calculated from the currentl point double x = _selectedPoints[i].X + displacementX; double y = _selectedPoints[i].Y + displacementY; p.X = x; p.Y = y; if (useContainerBehavior) { p = operation.CurrentContainerBehavior.PlacePoint(p + relativeTo) - relativeTo; } pathPoints[i].TranslatedPoint = p; } }
public PathEntity(PathPoint[] apathpoint) { points = apathpoint; pathLength = apathpoint.Length; }
protected virtual PathThumb CreateThumb(PlacementAlignment alignment, Cursor cursor, int index, PathPoint pathpoint, Transform transform) { var designerThumb = new PathThumb(index, pathpoint) {Cursor = cursor}; designerThumb.OperationMenu = BuildMenu(pathpoint); designerThumb.InnerRenderTransform = ((Transform)transform.Inverse); if (pathpoint.TargetPathPoint != null) { designerThumb.IsEllipse = true; designerThumb.Foreground = Brushes.Blue; var bnd = new Binding("TranslatedPoint") { Source = pathpoint.TargetPathPoint, Mode = BindingMode.OneWay, Converter = new RelativeToPointConverter(pathpoint) }; designerThumb.SetBinding(PathThumb.RelativeToPointProperty, bnd); } AdornerPanel.SetPlacement(designerThumb, designerThumb.AdornerPlacement); adornerPanel.Children.Add(designerThumb); DragListener drag = new DragListener(designerThumb); drag.Transform = transform; WeakEventManager<DesignerThumb, MouseButtonEventArgs>.AddHandler(designerThumb, "PreviewMouseLeftButtonDown", ResizeThumbOnMouseLeftButtonUp); drag.MouseDown += drag_MouseDown; drag.Started += drag_Started; drag.Changed += drag_Changed; drag.Completed += drag_Completed; return designerThumb; }
/// <summary> /// Находит ближайшую доступную ключевую точку /// </summary> void FindClosePathPoint(char[,] _pointsMap, PathPoint pp, Move.MoveState direction) { int dx = 0, dy = 0; int cx = (int)pp.transform.localPosition.x; int cy = -(int)pp.transform.localPosition.z; switch (direction) { case Move.MoveState.right: dx = 1; break; case Move.MoveState.down: dy = 1; break; default: break; } bool blockray = false; bool findPP = false; int raylength = 0; while (!blockray) { switch (_pointsMap[cx = ((cx + dx) % prm.CurrentMap.width), cy = ((cy + dy) % prm.CurrentMap.height)]) { case 'X': raylength++; findPP = true; blockray = true; break; case '0': blockray = true; break; default: raylength++; break; } } if (findPP) { PathPoint tempPP = PathPoints.Find(p => p.transform.localPosition == new Vector3(cx, 0, -cy)); switch (direction) { case Move.MoveState.right: pp.RightPoint = tempPP; tempPP.LeftPoint = pp; pp.DistanceToRight = raylength; tempPP.DistanceToLeft = raylength; break; case Move.MoveState.down: pp.DownPoint = tempPP; tempPP.UpPoint = pp; pp.DistanceToDown = raylength; tempPP.DistanceToUp = raylength; break; default: break; } } }
/// <summary> /// The command handler itself /// </summary> /// <param name="client">The client using the command</param> /// <param name="args">The command arguments</param> public void OnCommand(GameClient client, string[] args) { if (args.Length == 1) { DisplaySyntax(client); return; } switch (args[1].ToLower()) { #region Create case "create": { GameKeepGuard guard = null; if (args.Length < 3) { DisplaySyntax(client); return; } switch (args[2].ToLower()) { #region Lord case "lord": { guard = new GuardLord(); break; } #endregion Lord #region Fighter case "fighter": { guard = new GuardFighter(); break; } #endregion Fighter #region Archer case "archer": { if (args.Length > 3) { guard = new GuardStaticArcher(); } else { guard = new GuardArcher(); } break; } #endregion Archer #region Healer case "healer": { guard = new GuardHealer(); break; } #endregion Healer #region Stealther case "stealther": { guard = new GuardStealther(); break; } #endregion Stealther #region Caster case "caster": { if (args.Length > 3) { guard = new GuardStaticCaster(); } else { guard = new GuardCaster(); } break; } #endregion Caster #region Hastener case "hastener": { guard = new FrontierHastener(); break; } #endregion Hastener #region Mission case "mission": { guard = new MissionMaster(); break; } #endregion Mission #region Patrol case "patrol": { if (args.Length < 4) { DisplayMessage(client, "You need to provide a name for this patrol."); return; } AbstractGameKeep.eKeepType keepType = AbstractGameKeep.eKeepType.Any; if (args.Length < 5) { DisplayMessage(client, "You need to provide the type of keep this patrol works with."); int i = 0; foreach (string str in Enum.GetNames(typeof(Keeps.AbstractGameKeep.eKeepType))) { DisplayMessage(client, "#" + i + ": " + str); i++; } return; } try { keepType = (AbstractGameKeep.eKeepType)Convert.ToInt32(args[4]); } catch { DisplayMessage(client, "Type of keep specified was not valid."); return; } if (client.Player.TargetObject is GameKeepComponent == false) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Create.NoKCompTarget")); return; } GameKeepComponent c = client.Player.TargetObject as GameKeepComponent;; Patrol p = new Patrol(c); p.PatrolID = args[3]; p.KeepType = keepType; p.SpawnPosition = PositionMgr.CreatePatrolPosition(p.PatrolID, c, client.Player, keepType); p.PatrolID = p.SpawnPosition.TemplateID; p.InitialiseGuards(); DisplayMessage(client, "Patrol created for Keep Type " + Enum.GetName(typeof(AbstractGameKeep.eKeepType), keepType)); return; } #endregion Patrol } if (guard == null) { DisplaySyntax(client); return; } GameKeepComponent component = client.Player.TargetObject as GameKeepComponent; if (component != null) { int height = component.Height; if (args.Length > 4) { int.TryParse(args[4], out height); } DBKeepPosition pos = PositionMgr.CreatePosition(guard.GetType(), height, client.Player, Guid.NewGuid().ToString(), component); //PositionMgr.AddPosition(pos); //PositionMgr.FillPositions(); DBKeepPosition[] list = component.Positions[pos.TemplateID] as DBKeepPosition[]; if (list == null) { list = new DBKeepPosition[4]; component.Positions[pos.TemplateID] = list; } list[pos.Height] = pos; component.LoadPositions(); component.FillPositions(); } else { guard.CurrentRegion = client.Player.CurrentRegion; guard.X = client.Player.X; guard.Y = client.Player.Y; guard.Z = client.Player.Z; guard.Heading = client.Player.Heading; guard.Realm = guard.CurrentZone.Realm; guard.LoadedFromScript = false; guard.SaveIntoDatabase(); foreach (AbstractArea area in guard.CurrentAreas) { if (area is KeepArea) { AbstractGameKeep keep = (area as KeepArea).Keep; guard.Component = new GameKeepComponent(); guard.Component.Keep = keep; break; } } TemplateMgr.RefreshTemplate(guard); guard.AddToWorld(); if (guard.Component != null && guard.Component.Keep != null) { guard.Component.Keep.Guards.Add(DOL.Database.UniqueID.IDGenerator.GenerateID(), guard); } } PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Create.GuardAdded")); break; } #endregion Create #region Position case "position": { switch (args[2].ToLower()) { #region Add case "add": { if (!(client.Player.TargetObject is GameKeepGuard)) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.TargetGuard")); return; } if (args.Length != 4) { DisplaySyntax(client); return; } byte height = byte.Parse(args[3]); //height = KeepMgr.GetHeightFromLevel(height); GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; if (PositionMgr.GetPosition(guard) != null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.PAlreadyAss", height)); return; } DBKeepPosition pos = PositionMgr.CreatePosition(guard.GetType(), height, client.Player, guard.TemplateID, guard.Component); PositionMgr.AddPosition(pos); PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.GuardPAdded")); break; } #endregion Add #region Remove case "remove": { if (!(client.Player.TargetObject is GameKeepGuard)) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.TargetGuard")); return; } GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; DBKeepPosition pos = guard.Position; if (pos != null) { PositionMgr.RemovePosition(pos); if (guard.LoadedFromScript) { if (guard.PatrolGroup != null) { foreach (GameKeepGuard g in guard.PatrolGroup.PatrolGuards) { g.Delete(); } } else { guard.Delete(); } } } PositionMgr.FillPositions(); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Position.GuardRemoved")); break; } #endregion Remove #region Default default: { DisplaySyntax(client); return; } #endregion Default } break; } #endregion Position #region Path case "path": { switch (args[2].ToLower()) { #region Create case "create": { RemoveAllTempPathObjects(client); PathPoint startpoint = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, 100000, ePathType.Once); client.Player.TempProperties.setProperty(TEMP_PATH_FIRST, startpoint); client.Player.TempProperties.setProperty(TEMP_PATH_LAST, startpoint); client.Player.Out.SendMessage(LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.CreationStarted"), eChatType.CT_System, eChatLoc.CL_SystemWindow); CreateTempPathObject(client, startpoint, "TMP PP 1"); break; } #endregion Create #region Add case "add": { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty <object>(TEMP_PATH_LAST, null); if (path == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoPathCreatedYet")); return; } int speedlimit = 1000; if (args.Length == 4) { try { speedlimit = int.Parse(args[3]); } catch { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoValidSpLimit", args[2])); return; } } PathPoint newpp = new PathPoint(client.Player.X, client.Player.Y, client.Player.Z, speedlimit, path.Type); path.Next = newpp; newpp.Prev = path; client.Player.TempProperties.setProperty(TEMP_PATH_LAST, newpp); int len = 0; while (path.Prev != null) { len++; path = path.Prev; } len += 2; CreateTempPathObject(client, newpp, "TMP PP " + len); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.PPAdded", len)); break; } #endregion Add #region Save case "save": { PathPoint path = (PathPoint)client.Player.TempProperties.getProperty <object>(TEMP_PATH_LAST, null); if (path == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.NoPathCreatedYet")); return; } GameKeepGuard guard = client.Player.TargetObject as GameKeepGuard; if (guard == null || guard.PatrolGroup == null) { DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.TargPatrolGuard")); return; } path.Type = ePathType.Loop; PositionMgr.SavePatrolPath(guard.TemplateID, path, guard.Component); DisplayMessage(client, LanguageMgr.GetTranslation(client.Account.Language, "GMCommands.KeepGuard.Path.Saved")); RemoveAllTempPathObjects(client); guard.PatrolGroup.InitialiseGuards(); PositionMgr.FillPositions(); DisplayMessage(client, "Patrol groups initialized!"); break; } #endregion Save #region Default default: { DisplaySyntax(client); return; } #endregion Default } break; } #endregion Path #region Default default: { DisplaySyntax(client); return; } #endregion Default } }
public PathPriceResponse() { PathRoute = new PathPoint(); }
/// <summary> /// Method to Change a Patrol's Level /// /// This method handles the add and removing of guards /// </summary> public void ChangePatrolLevel() { int guardsToPatrol = 1; if (Component != null && Component.AbstractKeep != null && Component.AbstractKeep is GameKeep) { guardsToPatrol++; if (Component.AbstractKeep.Level > 4) { guardsToPatrol++; } } PatrolPath = PositionMgr.LoadPatrolPath(PatrolID, Component); // Console.WriteLine(PatrolID + " guardstopatrol = " + guardsToPatrol + ", count = " + PatrolGuards.Count); while (guardsToPatrol > PatrolGuards.Count) { CreatePatrolGuard(PatrolGuards.Count); } int x = 0; int y = 0; List <GameKeepGuard> guardsToKeep = new List <GameKeepGuard>(); for (int i = 0; i < PatrolGuards.Count; i++) { GameKeepGuard guard = PatrolGuards[i] as GameKeepGuard; // Console.WriteLine(PatrolID + " loading guard " + guard.Name); if (i < guardsToPatrol) { // we need to reposition the patrol at their spawn point plus variation if (x == 0) { x = guard.SpawnPoint.X; y = guard.SpawnPoint.Y; } else { x += Util.Random(250, 350); y += Util.Random(250, 350); } if (guard.IsAlive) { if (guard.IsMovingOnPath) { guard.StopMovingOnPath(); } guard.MoveTo(guard.CurrentRegionID, x, y, guard.SpawnPoint.Z, guard.SpawnHeading); } guardsToKeep.Add(guard); } else { guard.Delete(); } } PatrolGuards = guardsToKeep; StartPatrol(); }
//整理资源路径 private void ArrangeBundlesByLayer() { allBundlesLayerInfo = new PathPoint(); allBundlesLayerInfo.s_nowPathPoint = "Resourse"; allBundlesLayerInfo.lastPathPoint = null; allBundlesLayerInfo.nextPathPoint = new Dictionary<string, PathPoint>(); allBundlesLayerInfo.bundles = null; for (int i = 0; i < bundles.Count; i++) { EditPackageConfig nowBundle = bundles[i]; string s_bundlePath = nowBundle.path; string[] t_pathPoints = s_bundlePath.Split('/'); int n_nowPoints = 0; PathPoint endPathPoint = allBundlesLayerInfo; while (n_nowPoints < t_pathPoints.Length - 1) { //如果下一个节点中没有需要的节点 if (endPathPoint.nextPathPoint.ContainsKey(t_pathPoints[n_nowPoints]) == false) { PathPoint nextPoint = new PathPoint(); nextPoint.s_nowPathPoint = t_pathPoints[n_nowPoints]; nextPoint.lastPathPoint = endPathPoint; nextPoint.nextPathPoint = new Dictionary<string, PathPoint>(); endPathPoint.nextPathPoint.Add(t_pathPoints[n_nowPoints], nextPoint); endPathPoint = nextPoint; } else { endPathPoint = endPathPoint.nextPathPoint[t_pathPoints[n_nowPoints]]; } n_nowPoints++; }; if (endPathPoint.bundles == null) { endPathPoint.bundles = new List<EditPackageConfig>(); } endPathPoint.bundles.Add(nowBundle); } }