Fix map data hopefully.

This commit is contained in:
SilicaAndPina 2021-02-24 09:52:36 +13:00
parent b80984b92e
commit 83e274c828
7 changed files with 170 additions and 144 deletions

Binary file not shown.

View file

@ -105,7 +105,7 @@ namespace HISP.Game.Items
public static void DespawnItems()
{
Database.DecrementDroppedItemDespawnTimer();
Database.RemoveDespawningItems(); // GO-GO-GO-GOGOGOGO GOTTA GO FAST!!!
for (int i = 0; i < droppedItemsList.Count; i++)
{
if (droppedItemsList[i] == null) // Item removed in another thread.
@ -120,7 +120,7 @@ namespace HISP.Game.Items
Logger.DebugPrint("Despawned Item at " + droppedItemsList[i].X + ", " + droppedItemsList[i].Y);
droppedItemsList.Remove(droppedItemsList[i]);
Database.RemoveDroppedItem(droppedItemsList[i].Instance.RandomId);
}
}
}
@ -134,49 +134,86 @@ namespace HISP.Game.Items
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
}
public static void GenerateItems()
public static void GenerateItems(bool isFirstLoad=false)
{
Logger.InfoPrint("Generating items, (this may take awhile on a fresh database!)");
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);
while (count < item.SpawnParamaters.SpawnCap)
do
{
count++;
int despawnTimer = 1440;
if (item.SpawnParamaters.SpawnInZone != null)
if (count < item.SpawnParamaters.SpawnCap)
{
World.Zone spawnArea = World.GetZoneByName(item.SpawnParamaters.SpawnInZone);
while(true)
count++;
int despawnTimer = 1440;
if (isFirstLoad)
despawnTimer = GameServer.RandomNumberGenerator.Next(0, 1440 + 1);
if (item.SpawnParamaters.SpawnInZone != null)
{
// 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);
World.Zone spawnArea = World.GetZoneByName(item.SpawnParamaters.SpawnInZone);
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
while (true)
{
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?
// 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 (item.SpawnParamaters.SpawnOnTileType == TileType)
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
{
if (GetItemsAt(tryX, tryY).Length > 25) // Max items in one tile.
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, tryX, tryY, despawnTimer);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + tryX + " Y: " + tryY);
AddItem(instance, spawnOn.X, spawnOn.Y, despawnTimer);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + spawnOn.X + " Y: " + spawnOn.Y);
newItems++;
break;
}
@ -185,115 +222,49 @@ namespace HISP.Game.Items
continue;
}
}
else
{
continue;
}
}
}
else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
{
while(true)
else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
{
// 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))
while (true)
{
if (GetItemsAt(spawnOn.X, spawnOn.Y).Length > 25) // Max items in one tile.
continue;
// Pick a random special tile
World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnNearSpecialTile);
World.SpecialTile spawnNearTile = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];
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;
}
}
// Pick a direction to try spawn in
}
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)];
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;
}
// 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 (Map.CheckPassable(tryX, tryY))
{
if (GetItemsAt(tryX, tryY).Length > 25) // Max here
continue;
@ -303,32 +274,67 @@ namespace HISP.Game.Items
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + tryX + " Y: " + tryY);
newItems++;
break;
}
else
{
continue;
}
}
else
}
else if (item.SpawnParamaters.SpawnOnTileType != null)
{
while (true)
{
continue;
// 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));
}
}
}
public static void Init()
{
ReadFromDatabase();
GenerateItems();
GenerateItems(true);
}
}

View file

@ -107,7 +107,7 @@ namespace HISP.Game
Logger.ErrorPrint("Map file not found.");
return;
}
Logger.InfoPrint("Loading Map Data (" + ConfigReader.MapFile + ")");
byte[] worldMap = File.ReadAllBytes(ConfigReader.MapFile);
@ -118,7 +118,6 @@ namespace HISP.Game
oMapData = new byte[Width * Height];
int ii = 8;
for (int i = 0; i < MapData.Length; i++)
{
oMapData[i] = worldMap[ii];
@ -127,6 +126,7 @@ namespace HISP.Game
}
worldMap = null;
Logger.InfoPrint("Map Data Loaded!");
}
}

View file

@ -191,7 +191,11 @@ namespace HISP.Game
return;
if (UdlrScriptPos >= UDLRScript.Length)
{
X = UDLRStartX;
Y = UDLRStartY;
UdlrScriptPos = 0;
}
switch (UDLRScript.ToLower()[UdlrScriptPos])
{

View file

@ -3936,6 +3936,21 @@ namespace HISP.Server
}
}
public static void RemoveDespawningItems()
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "DELETE FROM droppeditems WHERE despawnTimer <=0";
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void RemoveDroppedItem(int randomId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -3984,7 +3999,7 @@ namespace HISP.Server
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-5";
sqlCommand.CommandText = "UPDATE DroppedItems SET DespawnTimer=DespawnTimer-1";
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();

View file

@ -222,7 +222,7 @@ namespace HISP.Server
item.Effects = effectsList;
item.SpawnParamaters = new Item.SpawnRules();
item.SpawnParamaters.SpawnCap = gameData.item.item_list[i].spawn_parameters.spawn_cap;
item.SpawnParamaters.SpawnInZone = gameData.item.item_list[i].spawn_parameters.spawn_in_zone;
item.SpawnParamaters.SpawnInZone = gameData.item.item_list[i].spawn_parameters.spawn_in_area;
item.SpawnParamaters.SpawnOnTileType = gameData.item.item_list[i].spawn_parameters.spawn_on_tile_type;
item.SpawnParamaters.SpawnOnSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_on_special_tile;
item.SpawnParamaters.SpawnNearSpecialTile = gameData.item.item_list[i].spawn_parameters.spawn_near_special_tile;

View file

@ -130,8 +130,6 @@ namespace HISP.Server
if (totalMinutesElapsed % 5 == 0)
{
Treasure.AddValue();
DroppedItems.DespawnItems();
DroppedItems.GenerateItems();
}
@ -171,6 +169,9 @@ namespace HISP.Server
Database.TpOfflinePlayersBackToUniterForOfflinePlayers();
Database.DeleteExpiredLeasedHorsesForOfflinePlayers();
DroppedItems.DespawnItems();
DroppedItems.GenerateItems();
WildHorse.Update();
Npc.WanderNpcs();