예제 #1
0
    public PathAction Pop()
    {
        PathAction ret = queue[0];

        queue.RemoveAt(0);
        return(ret);
    }
        private void HandleNewPath(Tile[] path, PathAction action)
        {
            mFilter.mesh.Clear();

            Vector3[] verts = new Vector3[Mathf.Max(0, (path.Length - 1) * 12) + Mathf.Max(0, (path.Length - 1) * 6)];
            Vector2[] uv    = new Vector2[verts.Length];

            int pos = 0;

            for (int i = 0; i < path.Length - 1; i++)
            {
                System.Array.Copy(GetLinker(path[i].PathPoint, path[i + 1].PathPoint, path[i].transform.up, i == path.Length - 2), 0, verts, pos, 12);
                System.Array.Copy(LinkerUV, 0, uv, pos, 12);
                pos += 12;
                if (i > 0)
                {
                    System.Array.Copy(GetMidPoint(path[i].PathPoint, path[i - 1].PathPoint, path[i + 1].PathPoint, path[i].transform.up), 0, verts, pos, 6);
                    System.Array.Copy(PointUV, 0, uv, pos, 6);
                    pos += 6;
                }

                if (i == path.Length - 2)
                {
                    System.Array.Copy(GetEndPoint(path[i].PathPoint, path[i + 1].PathPoint, path[i + 1].transform.up), 0, verts, pos, 6);
                    System.Array.Copy(PointUV, 0, uv, pos, 6);
                    pos += 6;
                }
            }

            mFilter.mesh.vertices  = verts;
            mFilter.mesh.triangles = Enumerable.Range(0, verts.Length).ToArray();
            mFilter.mesh.uv        = uv;
            mFilter.mesh.RecalculateNormals();
            mFilter.mesh.RecalculateBounds();
        }
예제 #3
0
    private void explorePath(MoveAction move, Vector2 target, PathAction parent, PriorityQueue front, Hashtable map, ContactFilter2D filter)
    {
        RaycastHit2D[] hits   = new RaycastHit2D[1];
        Vector2        newPos = centerVector(parent.pos + move.dir.normalized * move.dist);

        //Debug.Log(parent.pos + " -> " + newPos);
        if (!map.Contains(newPos))
        {
            if (MoveSets.checkMove(move.type, parent.pos, move, filter))
            {
                PathAction newAct = new PathAction(newPos, parent, move, target);
                map.Add(newPos, newAct);
                front.Push(newAct);
            }
        }
        else
        {
            //check if should update value in frontier
            if (MoveSets.checkMove(move.type, parent.pos, move, filter) /*Physics2D.Raycast(parent.pos, move.dir, filter, hits, move.dist+.1f) <= 0*/)
            {
                PathAction oldAct = (PathAction)map[newPos];
                if (parent.dist + move.dist < oldAct.dist)
                {
                    oldAct.move   = move;
                    oldAct.parent = parent;
                    front.Update(oldAct, parent.dist + move.dist);
                }
            }
        }
    }
 private void HandleNewPath(Tile[] path, PathAction action)
 {
     Debug.Log("New path action " + action);
     if (action == PathAction.Finalized)
     {
         this.path = path;
         Show();
     }
 }
예제 #5
0
 public Actions()
 {
     Right = new PathAction("R", 1, 0);
     Left  = new PathAction("L", -1, 0);
     Down  = new PathAction("D", 0, 1);
     Up    = new PathAction("U", 0, -1);
     Click = new PathAction("#", 0, 0);
     Space = new PathAction("S", 0, 0);
 }
예제 #6
0
 public PathAction(Vector2 pos, PathAction parent, MoveAction move)
 {
     this.pos    = pos;
     this.parent = parent;
     this.move   = move;
     if (parent != null)
     {
         dist = parent.dist + move.dist;
     }
 }
예제 #7
0
 public PathAction(Vector2 pos, PathAction parent, MoveAction move, Vector2 target)
 {
     this.pos    = pos;
     this.parent = parent;
     this.move   = move;
     if (parent != null)
     {
         dist = parent.dist + move.dist;
     }
     heuristic = Vector2.Distance(pos, target);
 }
예제 #8
0
    private IEnumerator doRotate(PathAction action)
    {
        float time       = 0;
        float startAngle = transform.eulerAngles.z;

        while (time < action.duration)
        {
            time += Time.deltaTime;
            float angle = Mathf.LerpAngle(startAngle, action.value, time / action.duration);
            transform.eulerAngles = new Vector3(0, 0, angle);

            yield return(null);
        }
    }
예제 #9
0
      public static Boolean TryCreateDirectory(String path, PathAction remove, out DirectoryInfo directoryInfo)
      {
          directoryInfo = null;

          try
          {
              if (Directory.Exists(path))
              {
                  return(true);
              }

              directoryInfo = Directory.CreateDirectory(path);

              return(Directory.Exists(path));
          }
          catch (Exception)
          {
              return(false);
          }
          finally
          {
              try
              {
                  switch (remove)
                  {
                  case PathAction.Standart:
                      if (GetFiles(path).All(file => file.Equals("desktop.ini", StringComparison.OrdinalIgnoreCase)) &&
                          !GetDirectories(path).Any())
                      {
                          Directory.Delete(path, true);
                          $"{path}\nExist: {Directory.Exists(path)}".ToMessageBox();
                      }

                      break;

                  case PathAction.Force:
                      Directory.Delete(path, true);
                      break;

                  default:
                      break;
                  }
              }
              catch (Exception)
              {
                  // ignored
              }
          }
      }
예제 #10
0
        public void JoinFigure(int figureIndex, int targetFigureIndex)
        {
            PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex);
            PathFigure       figure           = this.PathGeometry.Figures[targetFigureIndex];
            int count1 = pathFigureEditor.PathFigure.Segments.Count;
            int num1   = figureIndex < targetFigureIndex ? 0 : -1;
            int count2 = this.changeList.Changes.Count;

            pathFigureEditor.Join(figure);
            while (this.changeList.Changes.Count > count2)
            {
                this.changeList.Changes.RemoveAt(this.changeList.Changes.Count - 1);
            }
            PathAction pathAction = new PathAction();

            pathAction.Action     = PathActionType.Join;
            pathAction.Figure     = figureIndex;
            pathAction.PointIndex = targetFigureIndex;
            pathAction.PathStructureChanges.Add(new PathStructureChange(count1 - 1, count1, figureIndex, figureIndex + num1, (DependencyProperty)null, BezierSegment.Point1Property, PathChangeType.Copy));
            pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, count1, targetFigureIndex, figureIndex + num1, PathFigure.StartPointProperty, BezierSegment.Point2Property, PathChangeType.Copy));
            pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, count1, targetFigureIndex, figureIndex + num1, PathFigure.StartPointProperty, BezierSegment.Point3Property, PathChangeType.Move));
            int num2 = count1 + 1;

            for (int oldIndex = 0; oldIndex < this.path.Figures[targetFigureIndex].Segments.Count; ++oldIndex)
            {
                pathAction.PathStructureChanges.Add(new PathStructureChange(oldIndex, num2 + oldIndex, targetFigureIndex, figureIndex + num1));
            }
            this.path.Figures.RemoveAt(targetFigureIndex);
            for (int newFigure = targetFigureIndex; newFigure < this.path.Figures.Count; ++newFigure)
            {
                pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, PathStructureChange.StartPointIndex, newFigure + 1, newFigure));
                int num3 = this.path.Figures[newFigure].Segments.Count;
                if (newFigure + 1 == figureIndex)
                {
                    num3 = count1;
                }
                for (int index = 0; index < num3; ++index)
                {
                    pathAction.PathStructureChanges.Add(new PathStructureChange(index, index, newFigure + 1, newFigure));
                }
            }
            this.changeList.Changes.Add(pathAction);
        }
예제 #11
0
    public void Update(PathAction act, float newDist)
    {
        //binary search to find action in queue
        int   high    = queue.Count - 1;
        float highVal = queue[high].getValue();
        int   low     = 0;
        float lowVal  = queue[low].getValue();
        float actVal  = act.getValue();

        while (highVal > lowVal)
        {
            int   mid    = (high + low) / 2;
            float midVal = queue[mid].getValue();
            if (midVal >= actVal)
            {
                high    = mid;
                highVal = midVal;
            }
            else
            {
                low    = mid + 1;
                lowVal = queue[low].getValue();
            }
        }

        int   curr    = low;
        float currVal = lowVal;

        while (currVal <= highVal && curr < queue.Count)
        {
            if (act == queue[curr])
            {
                queue.RemoveAt(curr);
                break;
            }
            curr++;
            currVal = queue[curr].getValue();
        }

        act.dist = newDist;
        Push(act);
    }
예제 #12
0
        public void RemoveFigure(int figureIndex)
        {
            PathAction pathAction = new PathAction();

            pathAction.Action = PathActionType.RemoveFigure;
            pathAction.Figure = figureIndex;
            pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, PathStructureChange.DeletedPointIndex, figureIndex, figureIndex));
            for (int oldIndex = 0; oldIndex < this.path.Figures[figureIndex].Segments.Count; ++oldIndex)
            {
                pathAction.PathStructureChanges.Add(new PathStructureChange(oldIndex, PathStructureChange.DeletedPointIndex, figureIndex, figureIndex));
            }
            this.path.Figures.RemoveAt(figureIndex);
            for (int newFigure = figureIndex; newFigure < this.path.Figures.Count; ++newFigure)
            {
                pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, PathStructureChange.StartPointIndex, newFigure + 1, newFigure));
                for (int index = 0; index < this.path.Figures[newFigure].Segments.Count; ++index)
                {
                    pathAction.PathStructureChanges.Add(new PathStructureChange(index, index, newFigure + 1, newFigure));
                }
            }
            this.changeList.Changes.Add(pathAction);
        }
예제 #13
0
    public void Push(PathAction act)
    {
        if (queue.Count <= 0)
        {
            queue.Add(act);
            return;
        }
        int   high   = queue.Count - 1;
        int   low    = 0;
        float actVal = act.getValue();

        //Binary search for insertion location
        while (high - low > 1)
        {
            int mid = (high + low) / 2;
            if (queue[mid].getValue() > actVal)
            {
                high = mid;
            }
            else
            {
                low = mid;
            }
        }
        if (queue[low].getValue() > actVal)
        {
            queue.Insert(low, act);
        }
        else if (queue[high].getValue() < actVal)
        {
            queue.Insert(high + 1, act);
        }
        else
        {
            queue.Insert(low + 1, act);
        }
    }
예제 #14
0
 { public static Boolean TryCreateDirectory(String path, PathAction remove = PathAction.Standart)
   {
       return(TryCreateDirectory(path, remove, out _));
   }
예제 #15
0
        public async Task <PathMinDisplayed> CreatePath(PathModel path)
        {
            int           mapId  = 0;
            List <string> zones  = new List <string>();
            string        userId = User.Claims.First(c => c.Type == "UserID").Value;
            var           user   = await _userManager.FindByIdAsync(userId);

            TrajetDB trajetDB = new TrajetDB()
            {
                Name               = path.Name,
                Type               = (TypePath)path.Type,
                GroupLevelMax      = path.GroupLevelMax,
                GroupLevelMin      = path.GroupLevelMin,
                CaptureItem        = path.CaptureItem,
                Fk_User            = new Guid(userId),
                MaxPod             = path.MaxPod,
                MonsterQuantityMin = path.MonsterQuantityMin,
                MonsterQuantityMax = path.MonsterQuantityMax,
                LeaderBank         = path.LeaderBank,
                IsCapture          = path.IsCapture,
                ListRessource      = path.ListRessource,
                Key = Guid.NewGuid()
            };

            foreach (var monstreLevel in path.MonsterLevel)
            {
                if (trajetDB.MonsterLevel == null)
                {
                    trajetDB.MonsterLevel = new List <SpecificMonsterLevel>();
                }

                trajetDB.MonsterLevel.Add(new SpecificMonsterLevel()
                {
                    MonsterId       = monstreLevel.MonsterId,
                    MonsterLevelMax = monstreLevel.MonsterLevelmax,
                    MonsterLevelMin = monstreLevel.MonsterLevelMin
                });
            }
            foreach (var monstreQuantity in path.MonsterQuantity)
            {
                if (trajetDB.MonsterQuantity == null)
                {
                    trajetDB.MonsterQuantity = new List <SpecificMonsterQuantity>();
                }
                trajetDB.MonsterQuantity.Add(new SpecificMonsterQuantity()
                {
                    MonsterId          = monstreQuantity.MonsterId,
                    MonsterQuantityMax = monstreQuantity.MonsterQuantityMax,
                    MontserQuantityMin = monstreQuantity.MonsterQuantityMin
                });
            }
            foreach (var monstreCapture in path.MonsterCapture)
            {
                if (trajetDB.MonsterCapture == null)
                {
                    trajetDB.MonsterCapture = new List <CaptureMonsterQuantity>();
                }
                trajetDB.MonsterCapture.Add(new CaptureMonsterQuantity()
                {
                    MonsterId       = monstreCapture.MonsterId,
                    MonsterQuantity = monstreCapture.MonsterQuantity
                });
            }
            /* actions du trajet */
            trajetDB.PathAction = new List <PathAction>();
            foreach (PathActionModel action in path.PathAction)
            {
                PathAction pathActionToCreate = new PathAction();
                if (!ListBank.Contains(action.MapPos))
                {
                    MapDB map = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First();

                    mapId = map.Key;
                    if (!zones.Contains(map.AreaName))
                    {
                        zones.Add(map.AreaName);
                    }

                    pathActionToCreate.MapId = mapId;
                    foreach (MapActionModel item in action.Actions)
                    {
                        if (pathActionToCreate.Actions == null)
                        {
                            pathActionToCreate.Actions = new List <MapAction>();
                        }

                        if (item.FightAction != null)
                        {
                            FightAction fightActionToCreate = new FightAction()
                            {
                                Order   = item.Order,
                                IsAlone = item.FightAction.IsAlone
                            };
                            pathActionToCreate.Actions.Add(fightActionToCreate);
                        }
                        else if (item.GatherAction != null)
                        {
                            GatherAction GatherActionToCreate = new GatherAction()
                            {
                                Order = item.Order
                            };
                            pathActionToCreate.Actions.Add(GatherActionToCreate);
                        }
                        else if (item.InteractionAction != null)
                        {
                            InteractionAction InteractionActionToCreate = new InteractionAction()
                            {
                                Order = item.Order,
                                InteractiveIdObject   = item.InteractionAction.InteractiveidObject,
                                InteractiveIdResponse = item.InteractionAction.InteractiveIdResponse,
                                ToBackBank            = item.InteractionAction.ToBackBank,
                                ToGoBank = item.InteractionAction.ToGoBank
                            };
                            pathActionToCreate.Actions.Add(InteractionActionToCreate);
                        }
                        else if (item.moveAction != null)
                        {
                            MoveAction MoveActionToCreate = new MoveAction()
                            {
                                Order      = item.Order,
                                ToBackBank = item.moveAction.ToBackBank,
                                ToGoBank   = item.moveAction.ToGoBank,
                                CellId     = item.moveAction.Cellid
                            };
                            if (item.moveAction.Direction != null)
                            {
                                foreach (string direc in item.moveAction.Direction)
                                {
                                    if (MoveActionToCreate.Direction == null)
                                    {
                                        MoveActionToCreate.Direction = new List <MovementDirectionEnum>();
                                    }
                                    MoveActionToCreate.Direction.Add((MovementDirectionEnum)System.Enum.Parse(typeof(MovementDirectionEnum), direc.ToUpper()));
                                }
                            }
                            pathActionToCreate.Actions.Add(MoveActionToCreate);
                        }
                        else if (item.UseItemAction != null)
                        {
                            UseItemAction UseItemActionToCreate = new UseItemAction()
                            {
                                Order      = item.Order,
                                ItemId     = item.UseItemAction.ItemId,
                                ToBackBank = item.UseItemAction.ToBackBank,
                                ToGoBank   = item.UseItemAction.ToGoBank
                            };
                            pathActionToCreate.Actions.Add(UseItemActionToCreate);
                        }
                        else if (item.ZaapAction != null)
                        {
                            int zaapDestination = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First().Key;

                            ZaapAction UseItemActionctionToCreate = new ZaapAction()
                            {
                                Order       = item.Order,
                                Destination = zaapDestination,
                                ZaapId      = item.ZaapAction.ZaapId,
                                ToBackBank  = item.ZaapAction.ToBackBank,
                                ToGoBank    = item.ZaapAction.ToGoBank
                            };
                            pathActionToCreate.Actions.Add(UseItemActionctionToCreate);
                        }
                        else if (item.ZaapiAction != null)
                        {
                            int        zaapiDestination           = Database.Maps.Find(o => o.Coordinate == ("[" + action.MapPos.Replace(';', ',') + "]")).First().Key;
                            ZaapAction UseItemActionctionToCreate = new ZaapAction()
                            {
                                Order       = item.Order,
                                Destination = zaapiDestination,
                                ZaapId      = item.ZaapiAction.ZaapiId,
                                ToBackBank  = item.ZaapiAction.ToBackBank,
                                ToGoBank    = item.ZaapiAction.ToGoBank
                            };
                            pathActionToCreate.Actions.Add(UseItemActionctionToCreate);
                        }
                    }
                    trajetDB.PathAction.Add(pathActionToCreate);
                }
                else
                {
                    foreach (MapActionModel item in action.Actions)
                    {
                        pathActionToCreate = new PathAction();
                        if (item.moveAction != null)
                        {
                            mapId = item.moveAction.MapId.Value;
                            pathActionToCreate.MapId = mapId;
                            MoveAction MoveActionToCreate = new MoveAction()
                            {
                                Order      = item.Order,
                                ToBackBank = item.moveAction.ToBackBank,
                                ToGoBank   = item.moveAction.ToGoBank,
                                CellId     = item.moveAction.Cellid,
                                MapId      = mapId
                            };
                            if (item.moveAction.Direction != null)
                            {
                                foreach (string direc in item.moveAction.Direction)
                                {
                                    if (MoveActionToCreate.Direction == null)
                                    {
                                        MoveActionToCreate.Direction = new List <MovementDirectionEnum>();
                                    }
                                    MoveActionToCreate.Direction.Add((MovementDirectionEnum)System.Enum.Parse(typeof(MovementDirectionEnum), direc.ToUpper()));
                                }
                            }

                            if (trajetDB.PathAction.Exists(o => o.MapId == mapId))
                            {
                                trajetDB.PathAction.Find(o => o.MapId == mapId).Actions.Add(MoveActionToCreate);
                            }
                            else
                            {
                                pathActionToCreate.Actions = new List <MapAction>();
                                pathActionToCreate.Actions.Add(MoveActionToCreate);
                                trajetDB.PathAction.Add(pathActionToCreate);
                            }
                        }
                        else if (item.BankAction != null)
                        {
                            mapId = item.BankAction.MapId.Value;
                            pathActionToCreate.MapId = mapId;
                            BankAction BankActionToCreate = new BankAction()
                            {
                                MapId = mapId,
                                Order = item.Order
                            };
                            if (trajetDB.PathAction.Exists(o => o.MapId == mapId))
                            {
                                trajetDB.PathAction.Find(o => o.MapId == mapId).Actions.Add(BankActionToCreate);
                            }
                            else
                            {
                                pathActionToCreate.Actions = new List <MapAction>();
                                pathActionToCreate.Actions.Add(BankActionToCreate);
                                trajetDB.PathAction.Add(pathActionToCreate);
                            }
                        }
                    }
                }
            }
            trajetDB.Zones = zones;
            PathMinDisplayed retourPath = new PathMinDisplayed()
            {
                IsCapture  = trajetDB.IsCapture,
                Key        = trajetDB.Key,
                Name       = trajetDB.Name,
                Type       = trajetDB.Type,
                UsedNumber = 0,
                Zones      = trajetDB.Zones
            };

            await Database.Paths.InsertOneAsync(trajetDB);

            return(retourPath);
        }
        public void Action_Is_Correct(string path, PathAction expectedAction)
        {
            var output = ClassInTest.DecideAction(path);

            Assert.That(output, Is.EqualTo(expectedAction), $"{path} - {expectedAction}");
        }
예제 #17
0
 public Path(IList <MapNode> path, PathAction action)
 {
     _path  = path.ToArray();
     Action = action;
 }
예제 #18
0
파일: Default.aspx.cs 프로젝트: kyvkri/MG
 public WMPreventIISRestart(List<string> paths, PathAction action)
 {
     _paths = paths;
     _action = action;
 }
예제 #19
0
파일: Default.aspx.cs 프로젝트: kyvkri/MG
 public WMPreventIISRestart(string path, PathAction action)
 {
     _paths = new List<string>();
     _paths.Add(path);
     _action = action;
 }
예제 #20
0
        internal IEnumerable <Tuple <string, PathAction> > GetActions(MethodInfo[] targetMethods,
                                                                      MethodInfo[] interfaceMethods,
                                                                      IList <Type> definitionsTypesList)
        {
            int methodsCounts = interfaceMethods.Count();

            for (int index = 0; index < methodsCounts; index++)
            {
                MethodInfo implementation = targetMethods[index];
                MethodInfo declaration    = interfaceMethods[index];

                //if the method is marked Hidden anywhere, skip it
                if (implementation.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null ||
                    declaration.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null)
                {
                    continue;
                }

                //if a tag from either implementation or declaration is marked as not visible, skip it
                List <SwaggerWcfTagAttribute> methodTags =
                    implementation.GetCustomAttributes <SwaggerWcfTagAttribute>().ToList();
                methodTags =
                    methodTags.Concat(declaration.GetCustomAttributes <SwaggerWcfTagAttribute>()).ToList();
                methodTags = methodTags.Distinct().ToList();

                if (methodTags.Select(t => t.TagName).Any(HiddenTags.Contains))
                {
                    continue;
                }

                //find the WebGet/Invoke attributes, or skip if neither is present
                WebGetAttribute    wg = declaration.GetCustomAttribute <WebGetAttribute>();
                WebInvokeAttribute wi = declaration.GetCustomAttribute <WebInvokeAttribute>();
                if (wg == null && wi == null)
                {
                    continue;
                }

                string httpMethod  = (wi == null) ? "GET" : wi.Method ?? "POST";
                string uriTemplate = (wi == null) ? (wg.UriTemplate ?? "") : (wi.UriTemplate ?? "");

                //implementation description overrides interface description
                string description =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "Description") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "Description") ??
                    Helpers.GetCustomAttributeValue <string, DescriptionAttribute>(implementation, "Description") ??
                    Helpers.GetCustomAttributeValue <string, DescriptionAttribute>(declaration, "Description") ??
                    "";

                string summary =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "Summary") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "Summary") ??
                    "";

                string operationId =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "OperationId") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "OperationId") ??
                    "";
                if (operationId == "")
                {
                    if (implementation.DeclaringType != null)
                    {
                        operationId = implementation.DeclaringType.FullName + ".";
                    }
                    operationId += implementation.Name;
                }

                string externalDocsDescription =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation,
                                                                                      "ExternalDocsDescription") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration,
                                                                                      "ExternalDocsDescription") ??
                    "";

                string externalDocsUrl =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "ExternalDocsUrl") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "ExternalDocsUrl") ??
                    "";

                ExternalDocumentation externalDocs = null;
                if (!string.IsNullOrWhiteSpace(externalDocsDescription) || !string.IsNullOrWhiteSpace(externalDocsUrl))
                {
                    externalDocs = new ExternalDocumentation
                    {
                        Description = HttpUtility.HtmlEncode(externalDocsDescription),
                        Url         = HttpUtility.HtmlEncode(externalDocsUrl)
                    };
                }

                bool deprecated =
                    Helpers.GetCustomAttributeValue <SwaggerWcfPathAttribute>(implementation, "Deprecated");
                if (!deprecated)
                {
                    deprecated = Helpers.GetCustomAttributeValue <SwaggerWcfPathAttribute>(declaration, "Deprecated");
                }

                PathAction operation = new PathAction
                {
                    Id          = httpMethod.ToLowerInvariant(),
                    Summary     = HttpUtility.HtmlEncode(summary),
                    Description = HttpUtility.HtmlEncode(description),
                    Tags        =
                        methodTags.Where(t => !t.HideFromSpec).Select(t => HttpUtility.HtmlEncode(t.TagName)).ToList(),
                    Consumes     = new List <string>(GetConsumes(implementation, declaration)),
                    Produces     = new List <string>(GetProduces(implementation, declaration)),
                    Deprecated   = deprecated,
                    OperationId  = HttpUtility.HtmlEncode(operationId),
                    ExternalDocs = externalDocs,
                    Responses    = GetResponseCodes(implementation, declaration, definitionsTypesList)
                                   // Schemes = TODO: how to get available schemes for this WCF service? (schemes: http/https)
                };

                //try to map each implementation parameter to the uriTemplate.
                ParameterInfo[] parameters = declaration.GetParameters();
                if (parameters.Any())
                {
                    operation.Parameters = new List <ParameterBase>();
                }
                foreach (ParameterInfo parameter in parameters)
                {
                    TypeFormat typeFormat = Helpers.MapSwaggerType(parameter.ParameterType, definitionsTypesList);

                    SwaggerWcfParameterAttribute settings =
                        implementation.GetParameters()
                        .First(p => p.Position.Equals(parameter.Position))
                        .GetCustomAttribute <SwaggerWcfParameterAttribute>() ??
                        parameter.GetCustomAttribute <SwaggerWcfParameterAttribute>();

                    if (implementation.GetParameters()
                        .First(p => p.Position.Equals(parameter.Position))
                        .GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null ||
                        parameter.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null)
                    {
                        continue;
                    }

                    List <SwaggerWcfTagAttribute> piTags =
                        methodTags.Concat(parameter.GetCustomAttributes <SwaggerWcfTagAttribute>())
                        .ToList();

                    if (piTags.Select(t => t.TagName).Any(HiddenTags.Contains))
                    {
                        continue;
                    }

                    operation.Parameters.Add(GetParameter(typeFormat, parameter, settings, uriTemplate,
                                                          definitionsTypesList));
                }

                if (!string.IsNullOrWhiteSpace(uriTemplate))
                {
                    int indexOfQuestionMark = uriTemplate.IndexOf('?');
                    if (indexOfQuestionMark >= 0)
                    {
                        uriTemplate = uriTemplate.Substring(0, indexOfQuestionMark);
                    }
                }
                yield return(new Tuple <string, PathAction>(uriTemplate, operation));
            }
        }
예제 #21
0
    public bool calcPath()
    {
        Hashtable pathMap = new Hashtable();
        LinkedList <MoveAction> moveActionsBuild = new LinkedList <MoveAction>();
        //Queue<PathAction> frontier = new Queue<PathAction>();
        PriorityQueue frontier  = new PriorityQueue();
        Vector2       myPos     = centerVector(myBase.myRigid.position);
        Vector2       playerPos = centerVector(myBase.player.transform.position);

        //Adjust enemy and player position so that player/enemy not located inside 2.5D wall
        RaycastHit2D wallStartCheck = Physics2D.Raycast(myPos + Vector2.down * .2f, Vector2.up, .4f, LayerMask.GetMask("Wall"));

        if (wallStartCheck.collider != null)
        {
            myPos = myPos + Vector2.down;
        }
        wallStartCheck = Physics2D.Raycast(playerPos + Vector2.down * .2f, Vector2.up, .4f, LayerMask.GetMask("Wall"));
        if (wallStartCheck.collider != null)
        {
            playerPos = playerPos + Vector2.down;
        }

        PathAction startAct = new PathAction(new Vector2(myPos.x, myPos.y), null, new MoveAction(Vector2.zero, 0));

        pathMap.Add(myPos, startAct);
        //frontier.Enqueue(startAct);
        frontier.Push(startAct);
        ContactFilter2D filter = new ContactFilter2D();

        filter.SetLayerMask(1 << 8);

        //Debug.Log("Start: " + myPos);
        MoveAction[] nextMoves = MoveSets.getDirections(moveTypes);

        while (frontier.Count() > 0)
        {
            PathAction curr = frontier.Pop();
            if (Mathf.Abs(curr.pos.x - playerPos.x) <= targetProximity + .1 && Mathf.Abs(curr.pos.y - playerPos.y) <= targetProximity + .1)
            {
                while (curr.parent != null)
                {
                    //Debug.Log(curr.pos + " dir: "+curr.move.dir+ " dist: " + curr.dist);
                    moveActionsBuild.AddFirst(curr.move.copy());
                    curr = curr.parent;
                }
                break;
            }
            if (Vector2.Distance(curr.pos, playerPos) < maxDist)
            {
                foreach (MoveAction direction in nextMoves)
                {
                    explorePath(direction, playerPos, curr, frontier, pathMap, filter);
                }
            }
        }
        moveActions = moveActionsBuild;
        if (moveActionsBuild.Count > 0)
        {
            return(true);
        }
        return(false);
    }
예제 #22
0
        internal IEnumerable <Tuple <string, PathAction> > GetActions(MethodInfo[] targetMethods,
                                                                      MethodInfo[] interfaceMethods,
                                                                      IList <Type> definitionsTypesList)
        {
            int methodsCounts = interfaceMethods.Length;

            for (int index = 0; index < methodsCounts; index++)
            {
                MethodInfo implementation = targetMethods[index];
                MethodInfo declaration    = interfaceMethods[index];

                //if a tag from either implementation or declaration is marked as not visible, skip it
                List <SwaggerWcfTagAttribute> methodTags =
                    implementation.GetCustomAttributes <SwaggerWcfTagAttribute>().ToList();
                methodTags =
                    methodTags.Concat(declaration.GetCustomAttributes <SwaggerWcfTagAttribute>()).ToList();

                methodTags = methodTags.Distinct().ToList();

                // If no tags on the method - check declared Type/Interface itself
                if (methodTags.Count < 1)
                {
                    methodTags = implementation.DeclaringType.GetCustomAttributes <SwaggerWcfTagAttribute>()
                                 .Concat(declaration.DeclaringType.GetCustomAttributes <SwaggerWcfTagAttribute>())
                                 .ToList();
                }

                if ((methodTags.Count == 0 && HiddenTags.Contains("default")) ||
                    methodTags.Any(t => HiddenTags.Contains(t.TagName)))
                {
                    continue;
                }

                //if the method is marked Hidden anywhere, skip it (even if methods tags listed as visible).
                if ((implementation.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null ||
                     declaration.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null)
                    )
                {
                    continue;
                }

                //find the WebGet/Invoke attributes, or skip if neither is present
                WebGetAttribute    wg = declaration.GetCustomAttribute <WebGetAttribute>();
                WebInvokeAttribute wi = declaration.GetCustomAttribute <WebInvokeAttribute>();
                if (wg == null && wi == null)
                {
                    continue;
                }

                string httpMethod  = (wi == null) ? "GET" : wi.Method ?? "POST";
                string uriTemplate = GetUriTemplate(wi, wg, declaration);

                bool wrappedRequest  = IsRequestWrapped(wg, wi);
                bool wrappedResponse = IsResponseWrapped(wg, wi);

                var wcfPathAttribute = (implementation.GetCustomAttribute(typeof(SwaggerWcfPathAttribute), false) as SwaggerWcfPathAttribute)
                                       ?? (declaration.GetCustomAttribute(typeof(SwaggerWcfPathAttribute), false) as SwaggerWcfPathAttribute);
                int sortOrder = (wcfPathAttribute?.SortOrder).GetValueOrDefault();


                //implementation description overrides interface description
                string description =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "Description") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "Description") ??
                    Helpers.GetCustomAttributeValue <string, DescriptionAttribute>(implementation, "Description") ??
                    Helpers.GetCustomAttributeValue <string, DescriptionAttribute>(declaration, "Description") ??
                    "";

                string summary =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "Summary") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "Summary") ??
                    "";

                string operationId =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "OperationId") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "OperationId") ??
                    "";
                if (operationId == "")
                {
                    if (implementation.DeclaringType != null)
                    {
                        operationId = implementation.DeclaringType.FullName + ".";
                    }
                    operationId += implementation.Name;
                }

                string externalDocsDescription =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation,
                                                                                      "ExternalDocsDescription") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration,
                                                                                      "ExternalDocsDescription") ??
                    "";

                string externalDocsUrl =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "ExternalDocsUrl") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "ExternalDocsUrl") ??
                    "";

                ExternalDocumentation externalDocs = null;
                if (!string.IsNullOrWhiteSpace(externalDocsDescription) || !string.IsNullOrWhiteSpace(externalDocsUrl))
                {
                    externalDocs = new ExternalDocumentation
                    {
                        Description = externalDocsDescription,
                        Url         = HttpUtility.HtmlEncode(externalDocsUrl)
                    };
                }

                bool deprecated =
                    Helpers.GetCustomAttributeValue <SwaggerWcfPathAttribute>(implementation, "Deprecated");
                if (!deprecated)
                {
                    deprecated = Helpers.GetCustomAttributeValue <SwaggerWcfPathAttribute>(declaration, "Deprecated");
                }

                string operationPath =
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(implementation, "OperationPath") ??
                    Helpers.GetCustomAttributeValue <string, SwaggerWcfPathAttribute>(declaration, "OperationPath");
                if (!string.IsNullOrWhiteSpace(operationPath))
                {
                    uriTemplate = ConcatPaths(operationPath, uriTemplate);
                }

                PathAction operation = new PathAction
                {
                    Id          = httpMethod.ToLowerInvariant(),
                    SortOrder   = sortOrder,
                    Summary     = summary,
                    Description = description,
                    Tags        =
                        methodTags.Where(t => !t.HideFromSpec).Select(t => HttpUtility.HtmlEncode(t.TagName)).ToList(),
                    Consumes     = new List <string>(GetConsumes(implementation, declaration)),
                    Produces     = new List <string>(GetProduces(implementation, declaration)),
                    Deprecated   = deprecated,
                    OperationId  = HttpUtility.HtmlEncode(operationId),
                    ExternalDocs = externalDocs,
                    Responses    = GetResponseCodes(implementation, declaration, wrappedResponse, definitionsTypesList),
                    Security     = GetMethodSecurity(implementation, declaration)
                                   // Schemes = TODO: how to get available schemes for this WCF service? (schemes: http/https)
                };

                //try to map each implementation parameter to the uriTemplate.
                ParameterInfo[] parameters = declaration.GetParameters();
                if (parameters.Any())
                {
                    operation.Parameters = new List <ParameterBase>();
                }

                List <SwaggerWcfHeaderAttribute> headers =
                    implementation.GetCustomAttributes <SwaggerWcfHeaderAttribute>().ToList();
                headers = headers.Concat(declaration.GetCustomAttributes <SwaggerWcfHeaderAttribute>()).ToList();

                // remove duplicates
                headers = headers.GroupBy(h => h.Name).Select(g => g.First()).ToList();

                // parameters - headers
                foreach (SwaggerWcfHeaderAttribute attr in headers)
                {
                    operation.Parameters.Add(new ParameterPrimitive
                    {
                        Name        = attr.Name,
                        Description = attr.Description,
                        Default     = attr.DefaultValue,
                        In          = InType.Header,
                        Required    = attr.Required,
                        TypeFormat  = new TypeFormat(ParameterType.String, null)
                    });
                }

                bool        isGetRequest       = httpMethod == "GET";
                int         bodyParameterCount = parameters.Where(p => GetInType(uriTemplate, p.Name) == InType.Body).Count();
                TypeBuilder typeBuilder        = null;
                if (!wrappedRequest && !isGetRequest && bodyParameterCount > 1)
                {
                    wrappedRequest = true;
                }
                if (wrappedRequest)
                {
                    typeBuilder = new TypeBuilder(implementation.GetWrappedName(declaration));
                }

                var declarationName = declaration.Name;
                foreach (ParameterInfo parameter in parameters)
                {
                    SwaggerWcfParameterAttribute settings =
                        implementation.GetParameters()
                        .First(p => p.Position.Equals(parameter.Position))
                        .GetCustomAttribute <SwaggerWcfParameterAttribute>() ??
                        parameter.GetCustomAttribute <SwaggerWcfParameterAttribute>();

                    if (implementation.GetParameters()
                        .First(p => p.Position.Equals(parameter.Position))
                        .GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null ||
                        parameter.GetCustomAttribute <SwaggerWcfHiddenAttribute>() != null)
                    {
                        continue;
                    }

                    List <SwaggerWcfTagAttribute> piTags =
                        methodTags.Concat(parameter.GetCustomAttributes <SwaggerWcfTagAttribute>())
                        .ToList();

                    InType inType = GetInType(uriTemplate, parameter.Name);

                    if (inType == InType.Body && wrappedRequest)
                    {
                        bool required = settings != null && settings.Required;

                        if (!required && !parameter.HasDefaultValue)
                        {
                            required = true;
                        }

                        typeBuilder.AddField(parameter.Name, parameter.ParameterType, required);

                        continue;
                    }

                    if (piTags.Any(t => HiddenTags.Contains(t.TagName)))
                    {
                        continue;
                    }

                    Type type = settings == null || settings.ParameterType == null
                        ? parameter.ParameterType
                        : settings.ParameterType;

                    TypeFormat typeFormat = Helpers.MapSwaggerType(type, definitionsTypesList);

                    operation.Parameters.Add(GetParameter(typeFormat, declaration, implementation, parameter, settings, uriTemplate, wrappedRequest,
                                                          definitionsTypesList, inType));
                }

                if (wrappedRequest)
                {
                    TypeFormat typeFormat = Helpers.MapSwaggerType(typeBuilder.Type, definitionsTypesList);

                    operation.Parameters.Add(new ParameterSchema
                    {
                        Name      = implementation.GetWrappedName(declaration) + "Wrapper",
                        In        = InType.Body,
                        Required  = true,
                        SchemaRef = typeFormat.Format
                    });
                }

                if (!string.IsNullOrWhiteSpace(uriTemplate))
                {
                    int indexOfQuestionMark = uriTemplate.IndexOf('?');
                    if (indexOfQuestionMark >= 0)
                    {
                        uriTemplate = uriTemplate.Substring(0, indexOfQuestionMark);
                    }

                    uriTemplate = RemoveParametersDefaultValuesFromUri(uriTemplate);
                }

                yield return(new Tuple <string, PathAction>(uriTemplate, operation));
            }
        }
예제 #23
0
 public PathActionMapItem(string path, PathAction pathAction)
 {
     this.Path       = path;
     this.PathAction = pathAction;
 }