make DroppedItems spawning faster,

Database.cs like 2000 lines shorter
This commit is contained in:
olebeck 2021-11-07 02:48:42 +01:00
parent 947a23f613
commit 67225251a2
6 changed files with 2591 additions and 4753 deletions

@ -1 +1 @@
Subproject commit 82cffb522d1ebdb3d4c00da52087461a8068fa36
Subproject commit 1f9bc06a178dc61964b989a44231c263cdd4edbb

View file

@ -15,6 +15,17 @@ namespace HISP.Game.Items
throw new NullReferenceException("How could this happen?");
Instance = itmInstance;
}
public DroppedItem(ItemInstance Instance, int X, int Y, int DespawnTimer)
{
if (Instance == null)
throw new NullReferenceException("How could this happen?");
this.Instance = Instance;
this.X = X;
this.Y = Y;
this.DespawnTimer = DespawnTimer;
}
public int X;
public int Y;
public int DespawnTimer;
@ -134,6 +145,13 @@ namespace HISP.Game.Items
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
}
public static void AddDroppedItemsBatch(DroppedItem[] item)
{
droppedItemsList.AddRange(item);
Database.AddDroppedItemBatch(item);
}
public static void GenerateItems(bool isFirstLoad=false)
{
if (isFirstLoad)
@ -142,6 +160,7 @@ namespace HISP.Game.Items
Logger.DebugPrint("Generating items.");
int newItems = 0;
List<DroppedItem> items = new();
foreach (Item.ItemInformation item in Item.Items)
{
int count = GetCountOfItem(item);
@ -165,36 +184,26 @@ namespace HISP.Game.Items
int tryX = GameServer.RandomNumberGenerator.Next(spawnArea.StartX, spawnArea.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(spawnArea.StartY, spawnArea.EndY);
if (!Map.CheckPassable(tryX, tryY)) // Can the player walk here?
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?
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
{
if (item.SpawnParamaters.SpawnOnTileType != TileType)
continue;
}
if (GetItemsAt(tryX, tryY).Length > 25) // Max items in one tile.
continue;
ItemInstance instance = new(item.Id);
items.Add(new(instance, tryX, tryY, despawnTimer));
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + tryX + " Y: " + tryY);
newItems++;
break;
}
}
@ -206,21 +215,17 @@ namespace HISP.Game.Items
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
{
if (!Map.CheckPassable(spawnOn.X, spawnOn.Y))
continue;
}
if (GetItemsAt(spawnOn.X, spawnOn.Y).Length > 25) // Max items in one tile.
continue;
ItemInstance instance = new(item.Id);
items.Add(new(instance, spawnOn.X, spawnOn.Y, despawnTimer));
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + spawnOn.X + " Y: " + spawnOn.Y);
newItems++;
break;
}
}
@ -264,21 +269,17 @@ namespace HISP.Game.Items
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
{
if (!Map.CheckPassable(tryX, tryY))
continue;
}
if (GetItemsAt(tryX, tryY).Length > 25) // Max here
continue;
ItemInstance instance = new(item.Id);
items.Add(new(instance, tryX, tryY, despawnTimer));
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + tryX + " Y: " + tryY);
newItems++;
break;
}
}
@ -291,43 +292,33 @@ namespace HISP.Game.Items
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
if (!Map.CheckPassable(tryX, tryY)) // Can the player walk here?
continue;
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?
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
{
if (item.SpawnParamaters.SpawnOnTileType != TileType)
continue;
}
if (GetItemsAt(tryX, tryY).Length > 25) // Max here
continue;
ItemInstance instance = new ItemInstance(item.Id);
items.Add(new(instance, tryX, tryY, despawnTimer));
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + tryX + " Y: " + tryY);
newItems++;
break;
}
}
}
} while (isFirstLoad && (count < item.SpawnParamaters.SpawnCap));
}
AddDroppedItemsBatch(items.ToArray());
}

View file

@ -247,70 +247,13 @@ namespace HISP.Game
}
private void updateBuildings()
{
if (buildings[0] != null)
Database.SetRanchBuilding1(this.Id, buildings[0].Id);
else
Database.SetRanchBuilding1(this.Id, 0);
if (buildings[1] != null)
Database.SetRanchBuilding2(this.Id, buildings[1].Id);
else
Database.SetRanchBuilding2(this.Id, 0);
if (buildings[2] != null)
Database.SetRanchBuilding3(this.Id, buildings[2].Id);
else
Database.SetRanchBuilding3(this.Id, 0);
if (buildings[3] != null)
Database.SetRanchBuilding4(this.Id, buildings[3].Id);
else
Database.SetRanchBuilding4(this.Id, 0);
if (buildings[4] != null)
Database.SetRanchBuilding5(this.Id, buildings[4].Id);
else
Database.SetRanchBuilding5(this.Id, 0);
if (buildings[5] != null)
Database.SetRanchBuilding6(this.Id, buildings[5].Id);
else
Database.SetRanchBuilding6(this.Id, 0);
if (buildings[6] != null)
Database.SetRanchBuilding7(this.Id, buildings[6].Id);
else
Database.SetRanchBuilding7(this.Id, 0);
if (buildings[7] != null)
Database.SetRanchBuilding8(this.Id, buildings[7].Id);
else
Database.SetRanchBuilding8(this.Id, 0);
if (buildings[8] != null)
Database.SetRanchBuilding9(this.Id, buildings[8].Id);
else
Database.SetRanchBuilding9(this.Id, 0);
if (buildings[9] != null)
Database.SetRanchBuilding10(this.Id, buildings[9].Id);
else
Database.SetRanchBuilding10(this.Id, 0);
if (buildings[10] != null)
Database.SetRanchBuilding11(this.Id, buildings[10].Id);
else
Database.SetRanchBuilding11(this.Id, 0);
if (buildings[11] != null)
Database.SetRanchBuilding12(this.Id, buildings[11].Id);
else
Database.SetRanchBuilding12(this.Id, 0);
if (buildings[12] != null)
Database.SetRanchBuilding13(this.Id, buildings[12].Id);
else
Database.SetRanchBuilding13(this.Id, 0);
if (buildings[13] != null)
Database.SetRanchBuilding14(this.Id, buildings[13].Id);
else
Database.SetRanchBuilding14(this.Id, 0);
if (buildings[14] != null)
Database.SetRanchBuilding15(this.Id, buildings[14].Id);
else
Database.SetRanchBuilding15(this.Id, 0);
if (buildings[15] != null)
Database.SetRanchBuilding16(this.Id, buildings[15].Id);
else
Database.SetRanchBuilding16(this.Id, 0);
for(int i = 0; i < buildings.Length; i++)
{
if (buildings[i] != null)
Database.SetRanchBuilding(Id, i + 1, buildings[i].Id);
else
Database.SetRanchBuilding(Id, i + 1, 0);
}
}
public RanchBuilding GetBuilding(int buildingId)
{
@ -360,56 +303,13 @@ namespace HISP.Game
title = Database.GetRanchTitle(id);
description = Database.GetRanchDescription(id);
ownerId = Database.GetRanchOwner(id);
int b1 = Database.GetRanchBuilding1(id);
int b2 = Database.GetRanchBuilding2(id);
int b3 = Database.GetRanchBuilding3(id);
int b4 = Database.GetRanchBuilding4(id);
int b5 = Database.GetRanchBuilding5(id);
int b6 = Database.GetRanchBuilding6(id);
int b7 = Database.GetRanchBuilding7(id);
int b8 = Database.GetRanchBuilding8(id);
int b9 = Database.GetRanchBuilding9(id);
int b10 = Database.GetRanchBuilding10(id);
int b11 = Database.GetRanchBuilding11(id);
int b12 = Database.GetRanchBuilding12(id);
int b13 = Database.GetRanchBuilding13(id);
int b14 = Database.GetRanchBuilding14(id);
int b15 = Database.GetRanchBuilding15(id);
int b16 = Database.GetRanchBuilding16(id);
if (RanchBuilding.RanchBuildingExists(b1))
buildings[0] = RanchBuilding.GetRanchBuildingById(b1);
if (RanchBuilding.RanchBuildingExists(b2))
buildings[1] = RanchBuilding.GetRanchBuildingById(b2);
if (RanchBuilding.RanchBuildingExists(b3))
buildings[2] = RanchBuilding.GetRanchBuildingById(b3);
if (RanchBuilding.RanchBuildingExists(b4))
buildings[3] = RanchBuilding.GetRanchBuildingById(b4);
if (RanchBuilding.RanchBuildingExists(b5))
buildings[4] = RanchBuilding.GetRanchBuildingById(b5);
if (RanchBuilding.RanchBuildingExists(b6))
buildings[5] = RanchBuilding.GetRanchBuildingById(b6);
if (RanchBuilding.RanchBuildingExists(b7))
buildings[6] = RanchBuilding.GetRanchBuildingById(b7);
if (RanchBuilding.RanchBuildingExists(b8))
buildings[7] = RanchBuilding.GetRanchBuildingById(b8);
if (RanchBuilding.RanchBuildingExists(b9))
buildings[8] = RanchBuilding.GetRanchBuildingById(b9);
if (RanchBuilding.RanchBuildingExists(b10))
buildings[9] = RanchBuilding.GetRanchBuildingById(b10);
if (RanchBuilding.RanchBuildingExists(b11))
buildings[10] = RanchBuilding.GetRanchBuildingById(b11);
if (RanchBuilding.RanchBuildingExists(b12))
buildings[11] = RanchBuilding.GetRanchBuildingById(b12);
if (RanchBuilding.RanchBuildingExists(b13))
buildings[12] = RanchBuilding.GetRanchBuildingById(b13);
if (RanchBuilding.RanchBuildingExists(b14))
buildings[13] = RanchBuilding.GetRanchBuildingById(b14);
if (RanchBuilding.RanchBuildingExists(b15))
buildings[14] = RanchBuilding.GetRanchBuildingById(b15);
if (RanchBuilding.RanchBuildingExists(b16))
buildings[15] = RanchBuilding.GetRanchBuildingById(b16);
for (int i = 1; i <= 16; i++)
{
int bid = Database.GetRanchBuilding(id, i);
if(RanchBuilding.RanchBuildingExists(bid))
buildings[i - 1] = RanchBuilding.GetRanchBuildingById(bid);
}
InvestedMoney = Database.GetRanchInvestment(id);
}

File diff suppressed because it is too large Load diff

0
HorseIsleTest/main.py Normal file
View file

@ -1 +1 @@
Subproject commit 007bccccbc19fe4469ad7ac4aba63effeb520128
Subproject commit fb0a78cf76266bc4feab0da809b71f453e1cb3e6