Esempio n. 1
0
        private static void ProcessDisplayCase(Map map, StaticTile[] tiles, int x, int y)
        {
            ShopFlags flags = tiles.Aggregate(ShopFlags.None, (current, t) => current | ProcessDisplayedItem(t.ID));

            if (flags != ShopFlags.None)
            {
                Point2D p = new Point2D(x, y);

                if (m_ShopTable.TryGetValue(p, out ShopInfo si))
                {
                    si.m_Flags |= flags;
                }
                else
                {
                    List <Point2D> floor = new List <Point2D>();

                    RecurseFindFloor(map, x, y, floor);

                    if (floor.Count == 0)
                    {
                        return;
                    }

                    si = new ShopInfo {
                        m_Flags = flags, m_Floor = floor
                    };
                    m_ShopList.Add(si);

                    for (int i = 0; i < floor.Count; ++i)
                    {
                        m_ShopTable[floor[i]] = si;
                    }
                }
            }
        }
Esempio n. 2
0
        private static void ProcessDisplayCase(Map map, StaticTile[] tiles, int x, int y)
        {
            ShopFlags flags = ShopFlags.None;

            for (int i = 0; i < tiles.Length; ++i)
            {
                flags |= ProcessDisplayedItem(tiles[i].ID);
            }

            if (flags != ShopFlags.None)
            {
                Point2D  p  = new Point2D(x, y);
                ShopInfo si = (ShopInfo)m_ShopTable[p];

                if (si == null)
                {
                    ArrayList floor = new ArrayList();

                    RecurseFindFloor(map, x, y, floor);

                    if (floor.Count == 0)
                    {
                        return;
                    }

                    si = new ShopInfo
                    {
                        m_Flags = flags,
                        m_Floor = floor
                    };
                    m_ShopList.Add(si);

                    for (int i = 0; i < floor.Count; ++i)
                    {
                        m_ShopTable[(Point2D)floor[i]] = si;
                    }
                }
                else
                {
                    si.m_Flags |= flags;
                }
            }
        }
Esempio n. 3
0
        private static ShopFlags ProcessDisplayedItem(int itemID)
        {
            itemID &= TileData.MaxItemValue;

            ShopFlags res = ShopFlags.None;

            ItemData id    = TileData.ItemTable[itemID];
            TileFlag flags = id.Flags;

            if ((flags & TileFlag.Wearable) != 0)
            {
                if (IsClothes(itemID))
                {
                    res |= ShopFlags.Clothes;
                }
                else if (IsArmor(itemID))
                {
                    res |= ShopFlags.Armor;
                }
                else if (IsMetalWeapon(itemID))
                {
                    res |= ShopFlags.MetalWeapon;
                }
                else if (IsArcheryWeapon(itemID))
                {
                    res |= ShopFlags.ArcheryWeapon;
                }
            }

            if (itemID == 0x98C || itemID == 0x103B || itemID == 0x103C)
            {
                res |= ShopFlags.Bread;
            }

            if (itemID >= 0xF0F && itemID <= 0xF30)
            {
                res |= ShopFlags.Jewel;
            }

            if (itemID >= 0xEFB && itemID <= 0xF0D)
            {
                res |= ShopFlags.Potion;
            }

            if (itemID >= 0xF78 && itemID <= 0xF91)
            {
                res |= ShopFlags.Reagent;
            }

            if ((itemID >= 0xE35 && itemID <= 0xE3A) || (itemID >= 0xEF4 && itemID <= 0xEF9) || (itemID >= 0x1F2D && itemID <= 0x1F72))
            {
                res |= ShopFlags.Scroll;
            }

            if (itemID == 0xE38 || itemID == 0xEFA)
            {
                res |= ShopFlags.Spellbook;
            }

            return(res);
        }
Esempio n. 4
0
        private static void Process(Map map, Rectangle2D[] regions)
        {
            m_ShopTable = new Hashtable();
            m_ShopList  = new ArrayList();

            World.Broadcast(0x35, true, "Generating vendor spawns for {0}, please wait.", map);

            for (int i = 0; i < regions.Length; ++i)
            {
                for (int x = 0; x < map.Width; ++x)
                {
                    for (int y = 0; y < map.Height; ++y)
                    {
                        CheckPoint(map, regions[i].X + x, regions[i].Y + y);
                    }
                }
            }

            for (int i = 0; i < m_ShopList.Count; ++i)
            {
                ShopInfo si = (ShopInfo)m_ShopList[i];

                int xTotal = 0;
                int yTotal = 0;

                bool hasSpawner = false;

                for (int j = 0; !hasSpawner && j < si.m_Floor.Count; ++j)
                {
                    Point2D fp = (Point2D)si.m_Floor[j];

                    xTotal += fp.X;
                    yTotal += fp.Y;

                    IPooledEnumerable eable = map.GetItemsInRange(new Point3D(fp.X, fp.Y, 0), 0);

                    foreach (Item item in eable)
                    {
                        if (item is Spawner)
                        {
                            hasSpawner = true;
                            break;
                        }
                    }

                    eable.Free();

                    if (hasSpawner)
                    {
                        break;
                    }
                }

                if (hasSpawner)
                {
                    continue;
                }

                int xAvg = xTotal / si.m_Floor.Count;
                int yAvg = yTotal / si.m_Floor.Count;

                ArrayList names = new ArrayList();
                ShopFlags flags = si.m_Flags;

                if ((flags & ShopFlags.Armor) != 0)
                {
                    names.Add("armorer");
                }

                if ((flags & ShopFlags.MetalWeapon) != 0)
                {
                    names.Add("weaponsmith");
                }

                if ((flags & ShopFlags.ArcheryWeapon) != 0)
                {
                    names.Add("bowyer");
                }

                if ((flags & ShopFlags.Scroll) != 0)
                {
                    names.Add("mage");
                }

                if ((flags & ShopFlags.Spellbook) != 0)
                {
                    names.Add("mage");
                }

                if ((flags & ShopFlags.Bread) != 0)
                {
                    names.Add("baker");
                }

                if ((flags & ShopFlags.Jewel) != 0)
                {
                    names.Add("jeweler");
                }

                if ((flags & ShopFlags.Potion) != 0)
                {
                    names.Add("herbalist");
                    names.Add("alchemist");
                    names.Add("mage");
                }

                if ((flags & ShopFlags.Reagent) != 0)
                {
                    names.Add("mage");
                    names.Add("herbalist");
                }

                if ((flags & ShopFlags.Clothes) != 0)
                {
                    names.Add("tailor");
                    names.Add("weaver");
                }

                for (int j = 0; j < names.Count; ++j)
                {
                    Point2D cp   = Point2D.Zero;
                    int     dist = 100000;
                    int     tz;

                    for (int k = 0; k < si.m_Floor.Count; ++k)
                    {
                        Point2D fp = (Point2D)si.m_Floor[k];

                        int rx = fp.X - xAvg;
                        int ry = fp.Y - yAvg;
                        int fd = (int)Math.Sqrt(rx * rx + ry * ry);

                        if (fd > 0 && fd < 5)
                        {
                            fd -= Utility.Random(10);
                        }

                        if (fd < dist && GetFloorZ(map, fp.X, fp.Y, out tz))
                        {
                            dist = fd;
                            cp   = fp;
                        }
                    }

                    if (cp == Point2D.Zero)
                    {
                        continue;
                    }

                    int z;

                    if (!GetFloorZ(map, cp.X, cp.Y, out z))
                    {
                        continue;
                    }

                    new Spawner(1, 1, 1, 0, 4, (string)names[j]).MoveToWorld(new Point3D(cp.X, cp.Y, z), map);
                }
            }

            World.Broadcast(0x35, true, "Generation complete. {0} spawners generated.", m_ShopList.Count);
        }