コード例 #1
0
ファイル: MapLocation.cs プロジェクト: caleb-dp/Phoenix
        public CallbackResult OnMapInfo(byte[] data, CallbackResult prevResult)
        {
            PacketReader reader = new PacketReader(data);

            reader.Skip(1); // opcode
            uint   serial = reader.ReadUInt32();
            ushort gump   = reader.ReadUInt16();
            ushort ux     = reader.ReadUInt16();
            ushort uy     = reader.ReadUInt16();
            ushort lx     = reader.ReadUInt16();
            ushort ly     = reader.ReadUInt16();
            ushort width  = reader.ReadUInt16();
            ushort height = reader.ReadUInt16();

            ushort x = (ushort)(ux + 180 * (lx - ux > 361 ? -1 : 1));
            ushort y = (ushort)(uy + 180 * (ly - uy > 361 ? -1 : 1));

            UOPositionBase pos = new UOPositionBase(x, y, 0);

            if (!OpenedMapsLoc.ContainsKey(pos.ToString()))
            {
                OpenedMapsLoc.Add(pos.ToString(), new List <uint>());
                OpenedMapsLoc[pos.ToString()].Add(serial);
            }
            else
            {
                OpenedMapsLoc[pos.ToString()].Add(serial);
            }

            Game.PrintMessage(String.Format("Poklad je na {0},{1} - {2}", x, y, serial));

            return(CallbackResult.Normal);// CallbackResult.Sent;
        }
コード例 #2
0
ファイル: MapLocation.cs プロジェクト: caleb-dp/Phoenix
        public static void SortMap(int maxDistance)
        {
            openedMapsLoc = null;

            Game.PrintMessage("Bagl s mapkami >");
            UOItem containerFrom = new UOItem(UIManager.TargetObject());

            if (containerFrom.Serial.IsValid && containerFrom.Exist)
            {
                foreach (UOItem item in containerFrom.Items)
                {
                    if (item.Graphic == mapka.Graphic)
                    {
                        item.Move(1, World.Player.Backpack);
                        Game.Wait();
                    }
                }
            }

            foreach (UOItem item in World.Player.Backpack.Items)
            {
                if (item.Graphic == mapka.Graphic)
                {
                    item.Use();
                    Game.Wait();
                }
            }

            Game.PrintMessage("OpenedMapsLoc: " + OpenedMapsLoc.Count);

            Dictionary <string, List <uint> > groups = new Dictionary <string, List <uint> >();

            foreach (KeyValuePair <string, List <uint> > kvp in OpenedMapsLoc)
            {
                string[]       pos    = kvp.Key.Split(',');
                UOPositionBase mapPos = new UOPositionBase(ushort.Parse(pos[0]), ushort.Parse(pos[1]), 0);

                bool found = false;
                foreach (KeyValuePair <string, List <uint> > groupkvp in groups)
                {
                    string[]       gruppos     = groupkvp.Key.Split(',');
                    UOPositionBase groupmapPos = new UOPositionBase(ushort.Parse(gruppos[0]), ushort.Parse(gruppos[1]), 0);

                    if (Robot.GetRelativeVectorLength(groupmapPos, mapPos) < maxDistance)
                    {
                        groups[groupkvp.Key].AddRange(kvp.Value);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    if (groups.ContainsKey(mapPos.ToString()))
                    {
                        groups[mapPos.ToString()].AddRange(kvp.Value);
                    }
                    else
                    {
                        groups.Add(mapPos.ToString(), kvp.Value);
                    }
                }
            }

            //pytlik obyc 5 rad 20;
            //4 sloupce po 20

            ushort currentCol = 10;
            ushort currentRow = 1;


            foreach (KeyValuePair <string, List <uint> > kvp in groups)
            {
                ushort colItemPos = currentCol;
                foreach (uint serial in kvp.Value)
                {
                    UOItem item = new UOItem(serial);
                    item.Move(1, containerFrom, colItemPos, currentRow);

                    colItemPos++;
                    Game.Wait();
                }

                currentCol = (ushort)(currentCol + 20);

                if (currentCol > 120)
                {
                    currentCol = 10;
                    currentRow = (ushort)(currentRow + 16);
                }
            }
        }