public WildHorse(HorseInstance horse, int MapX = -1, int MapY = -1, int despawnTimeout = 1440, bool addToDatabase = true) { Instance = horse; timeout = despawnTimeout; if (MapX == -1 && MapY == -1) { while (true) { if (horse.Breed.SpawnInArea == null) { // Pick x/y int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width); int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height); if (CanHorseBeHere(tryX, tryY)) { x = tryX; y = tryY; break; } else { continue; } } else { World.Zone zone = World.GetZoneByName(horse.Breed.SpawnInArea); // Pick x/y in zone. int tryX = GameServer.RandomNumberGenerator.Next(zone.StartX, zone.EndX); int tryY = GameServer.RandomNumberGenerator.Next(zone.StartY, zone.EndY); if (CanHorseBeHere(tryX, tryY)) { x = tryX; y = tryY; break; } else { continue; } } } } else { x = MapX; y = MapY; } wildHorses.Add(this); if (addToDatabase) { Database.AddWildHorse(this); } }
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)); } }