Ejemplo n.º 1
0
        //public static List<int> getShortestPathBetween(SiteMap map, int start, int dest, int distMax)
        //{
        //    try
        //    {
        //        List<int> curPath = new List<int>();
        //        List<int> curPath2 = new List<int>();
        //        List<int> closeCells = new List<int>();
        //        int limit = 1000;

        //        SiteMap.Case curCase = map.getCase(start);
        //        int stepNum = 0;
        //        bool stop = false;

        //        while ((!stop) && (stepNum++ <= limit))
        //        {
        //            int nearestCell = getNearestCellAround(map, curCase.getID(), dest, closeCells);
        //            if (nearestCell == -1)
        //            {
        //                closeCells.add(curCase);
        //                if (curPath.size() > 0)
        //                {
        //                    curPath.remove(curPath.size() - 1);
        //                    if (curPath.size() > 0) curCase = (SiteMap.Case)curPath.get(curPath.size() - 1);
        //                    else
        //                        curCase = map.getCase(start);
        //                }
        //                else
        //                {
        //                    curCase = map.getCase(start);
        //                }
        //            }
        //            else
        //            {
        //                if ((distMax == 0) && (nearestCell == dest))
        //                {
        //                    curPath.add(map.getCase(dest));
        //                    break;
        //                } if (distMax > getDistanceBetween(map, nearestCell, dest))
        //                {
        //                    curPath.add(map.getCase(dest));
        //                    break;
        //                }

        //                curCase = map.getCase(nearestCell);
        //                closeCells.add(curCase);
        //                curPath.add(curCase);
        //            }
        //        }

        //        curCase = map.getCase(start);
        //        closeCells.clear();
        //        closeCells.add((SiteMap.Case)curPath.get(0));

        //        while ((!stop) && (stepNum++ <= limit))
        //        {
        //            int nearestCell = getNearestCellAround(map, curCase.getID(), dest, closeCells);
        //            if (nearestCell == -1)
        //            {
        //                closeCells.add(curCase);
        //                if (curPath2.size() > 0)
        //                {
        //                    curPath2.remove(curPath2.size() - 1);
        //                    if (curPath2.size() > 0) curCase = (SiteMap.Case)curPath2.get(curPath2.size() - 1);
        //                    else
        //                        curCase = map.getCase(start);
        //                }
        //                else
        //                {
        //                    curCase = map.getCase(start);
        //                }
        //            }
        //            else
        //            {
        //                if ((distMax == 0) && (nearestCell == dest))
        //                {
        //                    curPath2.add(map.getCase(dest));
        //                    break;
        //                } if (distMax > getDistanceBetween(map, nearestCell, dest))
        //                {
        //                    curPath2.add(map.getCase(dest));
        //                    break;
        //                }

        //                curCase = map.getCase(nearestCell);
        //                closeCells.add(curCase);
        //                curPath2.add(curCase);
        //            }
        //        }
        //        if (((curPath2.size() < curPath.size()) && (curPath2.size() > 0)) || (curPath.isEmpty()))
        //        {
        //            curPath = curPath2;
        //        }
        //        return curPath;
        //    }
        //    catch (Exception e)
        //    {
        //    }
        //    return null;
        //}


        private MovementPath findpath(Map Map, int cell1, int cell2)
        {
            int HeuristicEstimate = 20;
            int current           = 0;
            int i = 0;

            openlist.Add(cell1);

            var NodeBegin = new Node();

            NodeBegin.G      = 0;
            NodeBegin.H      = Pathfinder.GoalDistanceNoSqrt(Map, current, cell2) * HeuristicEstimate;
            NodeBegin.F      = NodeBegin.G + NodeBegin.H;
            NodeBegin.Parent = cell1;
            this.myNodes.Add(cell1, NodeBegin);


            var Test1 = Pathfinder.GoalDistanceScore(Map, cell1, cell2);
            var Test2 = Pathfinder.GoalDistanceEstimate(Map, cell1, cell2);
            var Test3 = Pathfinder.GoalDistanceNoSqrt(Map, cell1, cell2);

            current = cell1;

            while (!(openlist.Contains(cell2)))
            {
                if (i++ > 1000)
                {
                    return(null);
                }

                if (current == cell2)
                {
                    break; // TODO: might not be correct. Was : Exit Do
                }
                closelist.Add(current);
                openlist.Remove(current);

                var cell = Map.GetBestCellBetween(current, cell2, closelist);
                if (cell != -1)
                {
                    if (!closelist.Contains(cell))
                    {
                        if (openlist.Contains(cell))
                        {
                            if (this.myNodes[cell].G > this.myNodes[current].G)
                            {
                                var Node = this.myNodes[cell];
                                Node.Parent = current;
                                Node.G      = this.myNodes[current].G + 1;
                                Node.H      = Pathfinder.GoalDistanceScore(Map, cell, cell2) * HeuristicEstimate;
                                Node.F      = Node.G + Node.H;
                            }
                        }
                        else
                        {
                            openlist.Add(cell);
                            openlist[openlist.Count - 1] = cell;
                            var Node = new Node();
                            Node.G      = this.myNodes[current].G + 1;
                            Node.H      = Pathfinder.GoalDistanceScore(Map, cell, cell2) * HeuristicEstimate;
                            Node.F      = Node.G + Node.H;
                            Node.Parent = current;
                            this.myNodes.Add(cell, Node);
                        }
                    }

                    current = cell;
                }
            }

            return(getParent(Map, cell1, cell2));
        }
Ejemplo n.º 2
0
        public MonsterGroup(List <MonsterLevel> PossibleMonsters, int MaxSize, long GroupId)
        {
            this.ItemLoot   = new List <ItemLoot>();
            this.ActorId    = GroupId;
            this.Alignement = -1;
            this.IsFix      = false;

            this.Monsters = new Dictionary <int, MonsterLevel>();

            var MonsterNum = 0;
            var RandomNum  = 0;


            switch (MaxSize)
            {
            case 0:
                return;

            case 1:
                MonsterNum = 1;
                break;

            case 2:
                MonsterNum = RANDOM.Next(1, 2);
                break;

            case 3:
                MonsterNum = RANDOM.Next(1, 3);
                break;

            case 4:
                RandomNum = RANDOM.Next(0, 99);
                if (RandomNum < 22)     //1:22%
                {
                    MonsterNum = 1;
                }
                else if (RandomNum < 48)     //2:26%
                {
                    MonsterNum = 2;
                }
                else if (RandomNum < 74)     //3:26%
                {
                    MonsterNum = 3;
                }
                else     //4:26%
                {
                    MonsterNum = 4;
                }
                break;

            case 5:
                RandomNum = RANDOM.Next(0, 99);
                if (RandomNum < 15)     //1:22%
                {
                    MonsterNum = 1;
                }
                else if (RandomNum < 38)     //2:26%
                {
                    MonsterNum = 2;
                }
                else if (RandomNum < 60)     //3:26%
                {
                    MonsterNum = 3;
                }
                else if (RandomNum < 85)     //3:26%
                {
                    MonsterNum = 4;
                }
                else     //4:26%
                {
                    MonsterNum = 5;
                }
                break;

            case 6:
                RandomNum = RANDOM.Next(0, 99);
                if (RandomNum < 10)     //1:22%
                {
                    MonsterNum = 1;
                }
                else if (RandomNum < 25)     //2:26%
                {
                    MonsterNum = 2;
                }
                else if (RandomNum < 45)     //3:26%
                {
                    MonsterNum = 3;
                }
                else if (RandomNum < 65)     //3:26%
                {
                    MonsterNum = 4;
                }
                else if (RandomNum < 85)     //3:26%
                {
                    MonsterNum = 5;
                }
                else     //4:26%
                {
                    MonsterNum = 6;
                }
                break;

            case 7:
                RandomNum = RANDOM.Next(0, 99);
                if (RandomNum < 9)     //1:22%
                {
                    MonsterNum = 1;
                }
                else if (RandomNum < 20)     //2:26%
                {
                    MonsterNum = 2;
                }
                else if (RandomNum < 35)     //3:26%
                {
                    MonsterNum = 3;
                }
                else if (RandomNum < 55)     //3:26%
                {
                    MonsterNum = 4;
                }
                else if (RandomNum < 75)     //3:26%
                {
                    MonsterNum = 5;
                }
                else if (RandomNum < 90)     //3:26%
                {
                    MonsterNum = 6;
                }
                else     //4:26%
                {
                    MonsterNum = 7;
                }
                break;

            default:
                RandomNum = RANDOM.Next(0, 99);
                if (RandomNum < 9)     //1:22%
                {
                    MonsterNum = 1;
                }
                else if (RandomNum < 20)     //2:26%
                {
                    MonsterNum = 2;
                }
                else if (RandomNum < 33)     //3:26%
                {
                    MonsterNum = 3;
                }
                else if (RandomNum < 50)     //3:26%
                {
                    MonsterNum = 4;
                }
                else if (RandomNum < 67)     //3:26%
                {
                    MonsterNum = 5;
                }
                else if (RandomNum < 80)     //3:26%
                {
                    MonsterNum = 6;
                }
                else if (RandomNum < 91)     //3:26%
                {
                    MonsterNum = 7;
                }
                else     //4:26%
                {
                    MonsterNum = 8;
                }
                break;
            }

            // Aucun monstre de l'alignement demandé
            if (!PossibleMonsters.Any(x => x.Monster.Alignement == Alignement))
            {
                return;
            }

            var MonsterGUID = -1;
            var MaxLevel    = 0;

            for (int i = 0; i < MonsterNum; i++)
            {
                MonsterLevel MonsterGrade = null;

                do
                {
                    var RandIndex = RANDOM.Next(0, PossibleMonsters.Count - 1);
                    MonsterGrade = PossibleMonsters[RandIndex];
                }while (MonsterGrade.Monster.Alignement != this.Alignement);

                if (MonsterGrade.Level > MaxLevel)
                {
                    MaxLevel = MonsterGrade.Level;
                }

                this.Monsters.Add(MonsterGUID--, MonsterGrade);
            }

            this.Aggrodistance = Pathfinder.GetAggroDistanceByLevel(MaxLevel);
            this.Orientation   = Pathfinder.ForViewOrientation(RANDOM.Next(0, 7));
        }