Implement duplicate login checks,

and fix item spawning.
This commit is contained in:
SilicaAndPina 2020-12-19 16:14:06 +13:00
parent 519355a231
commit 18201596c8
9 changed files with 225 additions and 9 deletions

View file

@ -143,16 +143,141 @@ namespace HISP.Game
int despawnTimer = GameServer.RandomNumberGenerator.Next(900, 1500);
if (item.SpawnParamaters.SpawnInArea != null)
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)
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
droppedItem.Y = tryY;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
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))
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = spawnOn.X;
droppedItem.Y = spawnOn.Y;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.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))
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
droppedItem.Y = tryY;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
}
else
{
continue;
}
}
}
else if (item.SpawnParamaters.SpawnOnTileType != null)
@ -169,7 +294,7 @@ namespace HISP.Game
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
if (World.InTown(tryX, tryY) || World.InSpecialTile(tryX, tryY))
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?

View file

@ -13,7 +13,7 @@ namespace HISP.Game
public struct SpawnRules
{
public int SpawnCap;
public string SpawnInArea;
public string SpawnInZone;
public string SpawnOnTileType;
public string SpawnOnSpecialTile;
public string SpawnNearSpecialTile;

View file

@ -79,8 +79,6 @@ namespace HISP.Game
Logger.DebugPrint("Overlay: " + otileId + " Terrain: " + tileId);
return passable;
}

View file

@ -144,6 +144,7 @@ namespace HISP.Game
// Disconnect Messages
public static string BanMessage;
public static string DuplicateLogin;
public static string IdleKickMessageFormat;
// Swf

View file

@ -32,6 +32,15 @@ namespace HISP.Game
public string Name;
}
public struct Zone
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public string Name;
}
public struct Time
{
@ -60,6 +69,8 @@ namespace HISP.Game
public static List<Isle> Isles = new List<Isle>();
public static List<Town> Towns = new List<Town>();
public static List<Area> Areas = new List<Area>();
public static List<Zone> Zones = new List<Zone>();
public static List<SpecialTile> SpecialTiles = new List<SpecialTile>();
public static void TickWorldClock()
{
@ -93,6 +104,18 @@ namespace HISP.Game
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
}
public static bool InZone(int x, int y)
{
try
{
GetZone(x, y);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static bool InArea(int x, int y)
{
try
@ -144,6 +167,27 @@ namespace HISP.Game
return false;
}
}
public static Zone GetZoneByName(string name)
{
foreach(Zone zone in Zones)
{
if (zone.Name == name)
return zone;
}
throw new KeyNotFoundException("Zone not found.");
}
public static SpecialTile[] GetSpecialTilesByName(string name)
{
List<SpecialTile> tiles = new List<SpecialTile>();
foreach(SpecialTile tile in SpecialTiles)
{
if(tile.Title == name)
{
tiles.Add(tile);
}
}
return tiles.ToArray();
}
public static SpecialTile GetSpecialTile(int x, int y)
{
foreach(SpecialTile specialTile in SpecialTiles)
@ -168,6 +212,18 @@ namespace HISP.Game
throw new KeyNotFoundException("x,y not in an isle!");
}
public static Zone GetZone(int x, int y)
{
foreach (Zone zone in Zones)
{
if (zone.StartX <= x && zone.EndX >= x && zone.StartY <= y && zone.EndY >= y)
{
return zone;
}
}
throw new KeyNotFoundException("x,y not in an zone!");
}
public static Area GetArea(int x, int y)
{
foreach (Area area in Areas)