Ejemplo n.º 1
0
        private Point findPointOfItem(int itemID)
        {
            ItemLocation itemLocation = game.FindItem(itemID);

            if (itemLocation == null)
            {
                return(new Point(-1, -1));
            }

            if (itemLocation.GetType() == typeof(ItemLocationContainer))
            {
                ItemLocationContainer containerLoc = (ItemLocationContainer)itemLocation;
                return(client.ContainerPosition(containerLoc.Slot, containerLoc.ContainerIndex));
            }
            if (itemLocation.GetType() == typeof(ItemLocationInventory))
            {
                ItemLocationInventory inventoryLoc = (ItemLocationInventory)itemLocation;
                return(client.InventoryPosition(inventoryLoc.SlotId));
            }
            return(new Point(-1, -1));
        }
Ejemplo n.º 2
0
        internal static Item LocationToSearchResult(SectorMap.Milieu map, ResourceManager resourceManager, ItemLocation location)
        {
            if (location is WorldLocation)
            {
                Sector sector;
                World  world;
                ((WorldLocation)location).Resolve(map, resourceManager, out sector, out world);

                if (sector == null || world == null)
                {
                    return(null);
                }

                WorldResult r = new WorldResult();
                r.SectorX    = sector.X;
                r.SectorY    = sector.Y;
                r.SectorTags = sector.TagString;
                r.HexX       = world.X;
                r.HexY       = world.Y;
                r.Name       = world.Name;
                r.Sector     = sector.Names[0].Text;
                r.Uwp        = world.UWP;
                r.Importance = world.ImportanceValue;

                return(r);
            }

            if (location is SubsectorLocation)
            {
                Sector    sector;
                Subsector subsector;
                ((SubsectorLocation)location).Resolve(map, out sector, out subsector);

                if (sector == null || subsector == null)
                {
                    return(null);
                }

                SubsectorResult r = new SubsectorResult();
                r.SectorX    = sector.X;
                r.SectorY    = sector.Y;
                r.SectorTags = sector.TagString;
                r.Name       = subsector.Name;
                r.Index      = subsector.Index;
                r.Sector     = sector.Names[0].Text;

                return(r);
            }

            if (location is SectorLocation)
            {
                Sector sector = ((SectorLocation)location).Resolve(map);

                if (sector == null)
                {
                    return(null);
                }

                SectorResult r = new SectorResult();
                r.SectorX    = sector.X;
                r.SectorY    = sector.Y;
                r.SectorTags = sector.TagString;
                r.Name       = sector.Names[0].Text;

                return(r);
            }

            if (location is LabelLocation)
            {
                LabelLocation label  = location as LabelLocation;
                Location      l      = Astrometrics.CoordinatesToLocation(label.Coords);
                Sector        sector = label.Resolve(map);

                LabelResult r = new LabelResult();
                r.Name    = label.Label;
                r.SectorX = l.Sector.X;
                r.SectorY = l.Sector.Y;
                r.HexX    = l.Hex.X;;
                r.HexY    = l.Hex.Y;
                r.Scale   =
                    label.Radius > 80 ? 4 :
                    label.Radius > 40 ? 8 :
                    label.Radius > 20 ? 32 : 64;
                r.SectorTags = sector.TagString;

                return(r);
            }

            throw new ArgumentException(string.Format("Unexpected result type: {0}", location.GetType().Name), "location");
        }
Ejemplo n.º 3
0
        internal static Item LocationToSearchResult(SectorMap.Milieu map, ResourceManager resourceManager, ItemLocation location)
        {
            if (location is WorldLocation)
            {
                Sector sector;
                World world;
                ((WorldLocation)location).Resolve(map, resourceManager, out sector, out world);

                if (sector == null || world == null)
                    return null;

                WorldResult r = new WorldResult();
                r.SectorX = sector.X;
                r.SectorY = sector.Y;
                r.SectorTags = sector.TagString;
                r.HexX = world.X;
                r.HexY = world.Y;
                r.Name = world.Name;
                r.Sector = sector.Names[0].Text;
                r.Uwp = world.UWP;
                r.Importance = world.ImportanceValue;

                return r;
            }

            if (location is SubsectorLocation)
            {
                Sector sector;
                Subsector subsector;
                ((SubsectorLocation)location).Resolve(map, out sector, out subsector);

                if (sector == null || subsector == null)
                    return null;

                SubsectorResult r = new SubsectorResult();
                r.SectorX = sector.X;
                r.SectorY = sector.Y;
                r.SectorTags = sector.TagString;
                r.Name = subsector.Name;
                r.Index = subsector.Index;
                r.Sector = sector.Names[0].Text;

                return r;
            }

            if (location is SectorLocation)
            {
                Sector sector = ((SectorLocation)location).Resolve(map);

                if (sector == null)
                    return null;

                SectorResult r = new SectorResult();
                r.SectorX = sector.X;
                r.SectorY = sector.Y;
                r.SectorTags = sector.TagString;
                r.Name = sector.Names[0].Text;

                return r;
            }

            if (location is LabelLocation)
            {
                LabelLocation label = location as LabelLocation;
                Location l = Astrometrics.CoordinatesToLocation(label.Coords);
                Sector sector = label.Resolve(map);

                LabelResult r = new LabelResult();
                r.Name = label.Label;
                r.SectorX = l.Sector.X;
                r.SectorY = l.Sector.Y;
                r.HexX = l.Hex.X;;
                r.HexY = l.Hex.Y;
                r.Scale =
                    label.Radius > 80 ? 4 :
                    label.Radius > 40 ? 8 :
                    label.Radius > 20 ? 32 : 64;
                r.SectorTags = sector.TagString;

                return r;
            }

            throw new ArgumentException(string.Format("Unexpected result type: {0}", location.GetType().Name), "location");
        }
Ejemplo n.º 4
0
        internal void MoveItems(int itemId, string to, string from)
        {
            ItemLocationContainer locationContainer = null;
            ItemLocationInventory locationInventory = null;

            if (string.IsNullOrEmpty(from))
            {
                ItemLocation itemLocation = game.FindItem(itemId);
                if (itemLocation != null && itemLocation.GetType() == typeof(ItemLocationContainer))
                {
                    locationContainer = (ItemLocationContainer)itemLocation;
                    from = "" + locationContainer.ContainerIndex;
                }
                else if (itemLocation != null && itemLocation.GetType() == typeof(ItemLocationInventory))
                {
                    locationInventory = (ItemLocationInventory)itemLocation;
                    from = locationInventory.SlotName;
                }
                else
                {
                    Console.WriteLine("MoveItems not found item: " + itemId);
                }
            }

            //from container
            if (ItemLocation.IsContainer(from))
            {
                if (locationContainer == null)
                {
                    //Console.WriteLine("moveItem: Trying to move item: from container " + from + " to: " + to);
                    int containerIndex = ItemLocationContainer.GetContainerIndex(from);
                    if (containerIndex < 0)
                    {
                        Console.WriteLine("moveItem: Invalid container index");
                        return;
                    }
                    locationContainer = game.FindItemOnContainers(itemId, containerIndex);
                    if (locationContainer == null)
                    {
                        Console.WriteLine("moveItem: Item " + itemId + " not found on container index: " + containerIndex);
                        return;
                    }
                }


                //container to container
                if (ItemLocation.IsContainer(to))
                {
                    fromContainer.ToContainer(itemId, to, locationContainer);
                    return;
                }
                //container to inventory
                if (ItemLocation.IsInventory(to))
                {
                    fromContainer.ToInventory(itemId, to, locationContainer);
                    return;
                }
                //container to ground
                if (ItemLocation.IsGround(to))
                {
                    fromContainer.ToGround(itemId, to, locationContainer);
                    return;
                }
            }

            //from inventory
            if (ItemLocation.IsInventory(from))
            {
                //inventory to inventory
                if (ItemLocation.IsInventory(to))
                {
                    fromInventory.ToInventory(itemId, to, from);
                    return;
                }
                //inventory to container
                if (ItemLocation.IsContainer(to))
                {
                    fromInventory.ToContainer(itemId, to, from);
                    return;
                }
                //inventory to ground
                if (ItemLocation.IsGround(to))
                {
                    fromInventory.ToGround(itemId, to, from);
                    return;
                }
            }

            //from ground
            if (ItemLocation.IsGround(from))
            {
                //ground to ground
                if (ItemLocation.IsGround(to))
                {
                    fromGround.ToGround(itemId, to, from);
                    return;
                }
                //ground to container
                if (ItemLocation.IsContainer(to))
                {
                    fromGround.ToContainer(itemId, to, from);
                    return;
                }
                //ground to inventory
                if (ItemLocation.IsInventory(to))
                {
                    fromGround.ToInventory(itemId, to, from);
                    return;
                }
            }


            Console.WriteLine("Item move: Invalid location: " + from + " " + to);
        }