Exemple #1
0
        public static void GenerateItems(bool isFirstLoad = false)
        {
            if (isFirstLoad)
            {
                Logger.InfoPrint("Generating items, (this may take awhile on a fresh database!)");
            }
            else
            {
                Logger.InfoPrint("Generating items.");
            }

            int newItems = 0;

            foreach (Item.ItemInformation item in Item.Items)
            {
                int count = GetCountOfItem(item);
                do
                {
                    if (count < item.SpawnParamaters.SpawnCap)
                    {
                        count++;
                        int despawnTimer = 1440;
                        if (isFirstLoad)
                        {
                            despawnTimer = GameServer.RandomNumberGenerator.Next(0, 1440 + 1);
                        }

                        if (item.SpawnParamaters.SpawnInZone != null)
                        {
                            World.Zone spawnArea = World.GetZoneByName(item.SpawnParamaters.SpawnInZone);

                            while (true)
                            {
                                // Pick a random location inside the zone
                                int tryX = GameServer.RandomNumberGenerator.Next(spawnArea.StartX, spawnArea.EndX);
                                int tryY = GameServer.RandomNumberGenerator.Next(spawnArea.StartY, spawnArea.EndY);


                                if (World.InSpecialTile(tryX, tryY))
                                {
                                    continue;
                                }


                                if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
                                {
                                    int    TileID   = Map.GetTileId(tryX, tryY, false);
                                    string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?

                                    if (item.SpawnParamaters.SpawnOnTileType == TileType)
                                    {
                                        if (GetItemsAt(tryX, tryY).Length > 25) // Max items in one tile.
                                        {
                                            continue;
                                        }

                                        ItemInstance instance = new ItemInstance(item.Id);
                                        AddItem(instance, tryX, tryY, despawnTimer);
                                        Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + tryX + " Y: " + tryY);
                                        newItems++;
                                        break;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
                        {
                            while (true)
                            {
                                // Pick a random special tile
                                World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnOnSpecialTile);
                                World.SpecialTile   spawnOn      = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];

                                if (Map.CheckPassable(spawnOn.X, spawnOn.Y))
                                {
                                    if (GetItemsAt(spawnOn.X, spawnOn.Y).Length > 25) // Max items in one tile.
                                    {
                                        continue;
                                    }

                                    ItemInstance instance = new ItemInstance(item.Id);
                                    AddItem(instance, spawnOn.X, spawnOn.Y, despawnTimer);
                                    Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + spawnOn.X + " Y: " + spawnOn.Y);
                                    newItems++;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
                        {
                            while (true)
                            {
                                // Pick a random special tile
                                World.SpecialTile[] possileTiles  = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnNearSpecialTile);
                                World.SpecialTile   spawnNearTile = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];

                                // Pick a direction to try spawn in

                                int direction = GameServer.RandomNumberGenerator.Next(0, 4);
                                int tryX      = 0;
                                int tryY      = 0;
                                if (direction == 0)
                                {
                                    tryX = spawnNearTile.X + 1;
                                    tryY = spawnNearTile.Y;
                                }
                                else if (direction == 1)
                                {
                                    tryX = spawnNearTile.X - 1;
                                    tryY = spawnNearTile.Y;
                                }
                                else if (direction == 3)
                                {
                                    tryX = spawnNearTile.X;
                                    tryY = spawnNearTile.Y + 1;
                                }
                                else if (direction == 4)
                                {
                                    tryX = spawnNearTile.X;
                                    tryY = spawnNearTile.Y - 1;
                                }
                                if (World.InSpecialTile(tryX, tryY))
                                {
                                    World.SpecialTile tile = World.GetSpecialTile(tryX, tryY);
                                    if (tile.Code != null)
                                    {
                                        continue;
                                    }
                                }

                                if (Map.CheckPassable(tryX, tryY))
                                {
                                    if (GetItemsAt(tryX, tryY).Length > 25) // Max here
                                    {
                                        continue;
                                    }

                                    ItemInstance instance = new ItemInstance(item.Id);
                                    AddItem(instance, tryX, tryY, despawnTimer);
                                    Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + tryX + " Y: " + tryY);
                                    newItems++;
                                    break;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        else if (item.SpawnParamaters.SpawnOnTileType != null)
                        {
                            while (true)
                            {
                                // Pick a random location:
                                int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
                                int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);

                                if (World.InSpecialTile(tryX, tryY))
                                {
                                    continue;
                                }

                                if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
                                {
                                    int    TileID   = Map.GetTileId(tryX, tryY, false);
                                    string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?

                                    if (item.SpawnParamaters.SpawnOnTileType == TileType)
                                    {
                                        if (GetItemsAt(tryX, tryY).Length > 25) // Max here
                                        {
                                            continue;
                                        }

                                        ItemInstance instance = new ItemInstance(item.Id);
                                        AddItem(instance, tryX, tryY, despawnTimer);
                                        Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + tryX + " Y: " + tryY);
                                        newItems++;
                                        break;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                } while (isFirstLoad && (count < item.SpawnParamaters.SpawnCap));
            }
        }
Exemple #2
0
        public TackShopGiveaway()
        {
            List <World.SpecialTile> specialTiles = new List <World.SpecialTile>();

            foreach (World.SpecialTile sTile in World.SpecialTiles)
            {
                if (sTile.Code != null)
                {
                    if (sTile.Code.StartsWith("STORE-"))
                    {
                        int  storeId  = int.Parse(sTile.Code.Split("-")[1]);
                        Shop shopData = Shop.GetShopById(storeId);

                        if (shopData.BuysItemTypes.Contains("TACK"))
                        {
                            Npc.NpcEntry[] npcShop = Npc.GetNpcByXAndY(sTile.X, sTile.Y);
                            if (npcShop.Length > 0)
                            {
                                specialTiles.Add(sTile);
                            }
                        }
                    }
                }
            }

            string npcName = "ERROR";
            string npcDesc = "OBTAINING NAME";

            int shpIdx = GameServer.RandomNumberGenerator.Next(0, specialTiles.Count);

            Location = specialTiles[shpIdx];
            Npc.NpcEntry[] npcShops = Npc.GetNpcByXAndY(Location.X, Location.Y);

            npcName = npcShops[0].Name.Split(" ")[0];
            if (npcShops[0].ShortDescription.ToLower().Contains("tack"))
            {
                npcDesc  = npcShops[0].ShortDescription.Substring(npcShops[0].ShortDescription.ToLower().IndexOf("tack"));
                ShopName = npcName + "'s " + npcDesc;
            }
            else
            {
                ShopName = npcName + "'s Gear";
            }


            while (true)
            {
                int             hrsIdx = GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Count);
                HorseInfo.Breed breed  = HorseInfo.Breeds[hrsIdx];
                if (breed.SpawnInArea == "none")
                {
                    continue;
                }

                HorseGiveaway      = new HorseInstance(breed);
                HorseGiveaway.Name = "Tack Shop Giveaway";
                break;
            }

            if (World.InTown(Location.X, Location.Y))
            {
                Town = World.GetTown(Location.X, Location.Y);
            }
        }