Change Dropped Items spawning Algorithm

This commit is contained in:
SilicaAndPina 2021-02-04 20:00:06 +13:00
parent 02f5af9995
commit 29fe3ec024
9 changed files with 311 additions and 57 deletions

View file

@ -7,4 +7,8 @@ namespace HISP.Game
public class InventoryException : Exception { };
public class InventoryFullException : InventoryException { };
public class InventoryMaxStackException : InventoryException { };
// Drawingroom
public class DrawingroomException : Exception { };
public class DrawingroomFullException : DrawingroomException { };
}

View file

@ -93,40 +93,43 @@ namespace HISP.Game.Horse
public void RandomWander()
{
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
int tryX = this.X;
int tryY = this.Y;
switch(direction)
while(true)
{
case 0:
tryX += 1;
break;
case 1:
tryX -= 1;
break;
case 2:
tryY += 1;
break;
case 3:
tryY -= 1;
break;
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
int tryX = this.X;
int tryY = this.Y;
switch (direction)
{
case 0:
tryX += 1;
break;
case 1:
tryX -= 1;
break;
case 2:
tryY += 1;
break;
case 3:
tryY -= 1;
break;
}
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player stand here?
{
Logger.DebugPrint(this.Instance.Breed.Name + " Randomly wandered to: " + tryX.ToString() + ", " + tryY.ToString());
X = tryX;
Y = tryY;
break;
}
}
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
return;
if (World.InSpecialTile(tryX, tryY))
return;
if (Map.CheckPassable(tryX, tryY))
{
X = tryX;
Y = tryY;
return;
}
}
public void Escape()
@ -239,9 +242,8 @@ namespace HISP.Game.Horse
if (wildHorse.Timeout <= 0)
Despawn(wildHorse);
if(wildHorse.Timeout % 5 == 0)
if (GameServer.RandomNumberGenerator.Next(0, 100) > 50)
wildHorse.RandomWander();
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
wildHorse.RandomWander();
}
if(WildHorses.Length < 40)
{

View file

@ -112,6 +112,7 @@ namespace HISP.Game.Items
{
if(GameServer.GetUsersAt(item.X, item.Y,true,true).Length == 0)
{
Logger.DebugPrint("Despawned Item at " + item.X + ", " + item.Y);
RemoveDroppedItem(item);
removedCount++;
}
@ -132,6 +133,9 @@ namespace HISP.Game.Items
}
public static void GenerateItems()
{
Logger.InfoPrint("Generating items, (this may take awhile on a fresh database!)");
int newItems = 0;
foreach (Item.ItemInformation item in Item.Items)
{
@ -165,6 +169,9 @@ namespace HISP.Game.Items
if (item.SpawnParamaters.SpawnOnTileType == TileType)
{
if (GetItemsAt(tryX, tryY).Length > 26) // Max here
continue;
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
@ -199,6 +206,9 @@ namespace HISP.Game.Items
if (Map.CheckPassable(spawnOn.X, spawnOn.Y))
{
if (GetItemsAt(spawnOn.X, spawnOn.Y).Length > 26) // Max here
continue;
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = spawnOn.X;
@ -260,6 +270,8 @@ namespace HISP.Game.Items
if (Map.CheckPassable(tryX, tryY))
{
if (GetItemsAt(tryX, tryY).Length > 26) // Max here
continue;
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
@ -286,13 +298,14 @@ namespace HISP.Game.Items
while (true)
{
// Pick a random isle:
int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
World.Isle isle = World.Isles[isleId];
//int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
//World.Isle isle = World.Isles[isleId];
// Pick a random location inside the isle
int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
//int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
//int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
if (World.InSpecialTile(tryX, tryY))
continue;
@ -304,6 +317,9 @@ namespace HISP.Game.Items
if (item.SpawnParamaters.SpawnOnTileType == TileType)
{
if (GetItemsAt(tryX, tryY).Length > 26) // Max here
continue;
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
@ -312,7 +328,7 @@ namespace HISP.Game.Items
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in " + isle.Name + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
@ -340,7 +356,6 @@ namespace HISP.Game.Items
public static void Init()
{
ReadFromDatabase();
Logger.InfoPrint("Generating items, (this may take awhile on a fresh database!)");
GenerateItems();
}

View file

@ -155,6 +155,7 @@ namespace HISP.Game
public static string GrabbedAllItemsButInventoryFull;
public static string GrabbedAllItemsMessage;
public static string DroppedAnItemMessage;
public static string DroppedItemTileIsFull;
public static string ItemInformationFormat;
// Pond

View file

@ -0,0 +1,43 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.SwfModules
{
class Drawingroom
{
private string drawing;
public string Drawing
{
get
{
return drawing;
}
set
{
if(value.Length < 65535)
{
Database.SetDrawingRoomDrawing(Id, value);
drawing = value;
}
else
{
throw new DrawingroomFullException();
}
}
}
public int Id;
public Drawingroom(int roomId)
{
if (!Database.DrawingRoomExists(roomId))
Database.CreateDrawingRoom(roomId);
drawing = Database.GetDrawingRoomDrawing(roomId);
Id = roomId;
}
}
}