mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Fix bugz
This commit is contained in:
parent
7216ade563
commit
5e460923dc
8 changed files with 132 additions and 99 deletions
|
@ -50,6 +50,7 @@
|
|||
"sec_code":{
|
||||
"invalid_sec_code":"Data Code Error. You did not get the bonus. You should reconnect if you get this message again.",
|
||||
"item_earned":"You Earned a %ITEM%!",
|
||||
"item_earned_full_inv":"You Earned a %ITEM% but DID NOT have room for it!",
|
||||
"item_deleted":"You Lost an %ITEM%!",
|
||||
"money_earned":"You Earned $%MONEY%!",
|
||||
"highscore_beaten":"You just beat your best score! New high score: %SCORE%.",
|
||||
|
|
|
@ -12,6 +12,45 @@ namespace HISP.Game.Horse
|
|||
public class WildHorse
|
||||
{
|
||||
|
||||
public bool CanHorseBeHere(int x, int y, bool checkSpawnLocationValid=true)
|
||||
{
|
||||
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(x, y))
|
||||
return false;
|
||||
if (World.InSpecialTile(x, y))
|
||||
return false;
|
||||
|
||||
// Check area
|
||||
if(checkSpawnLocationValid)
|
||||
{
|
||||
if (this.Instance.Breed.SpawnInArea != null)
|
||||
{
|
||||
if (World.InArea(x, y))
|
||||
{
|
||||
if (World.GetArea(x, y).Name != this.Instance.Breed.SpawnInArea)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check Tile Type
|
||||
int TileID = Map.GetTileId(x, y, false);
|
||||
string TileType = Map.TerrainTiles[TileID - 1].Type;
|
||||
if(checkSpawnLocationValid)
|
||||
{
|
||||
if (TileType != this.Instance.Breed.SpawnOn)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (Map.CheckPassable(x, y)) // Can the player stand over here?
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public WildHorse(HorseInstance horse, int MapX = -1, int MapY = -1, int despawnTimeout=60, bool addToDatabase = true)
|
||||
{
|
||||
Instance = horse;
|
||||
|
@ -24,31 +63,20 @@ namespace HISP.Game.Horse
|
|||
if (horse.Breed.SpawnInArea == null)
|
||||
{
|
||||
|
||||
// Pick a random isle.
|
||||
int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
|
||||
World.Isle isle = World.Isles[isleId];
|
||||
|
||||
// Pick x/y in isle.
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
|
||||
// Pick x/y
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
|
||||
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(tryX, tryY))
|
||||
continue;
|
||||
if (World.InSpecialTile(tryX, tryY))
|
||||
continue;
|
||||
|
||||
// Check Tile Type
|
||||
int TileID = Map.GetTileId(tryX, tryY, false);
|
||||
string TileType = Map.TerrainTiles[TileID - 1].Type;
|
||||
if (TileType == horse.Breed.SpawnOn)
|
||||
if (CanHorseBeHere(tryX, tryY))
|
||||
{
|
||||
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
|
||||
{
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -58,23 +86,15 @@ namespace HISP.Game.Horse
|
|||
int tryX = GameServer.RandomNumberGenerator.Next(zone.StartX, zone.EndX);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(zone.StartY, zone.EndY);
|
||||
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(tryX, tryY))
|
||||
continue;
|
||||
if (World.InSpecialTile(tryX, tryY))
|
||||
continue;
|
||||
|
||||
// Check Tile Type
|
||||
int TileID = Map.GetTileId(tryX, tryY, false);
|
||||
string TileType = Map.TerrainTiles[TileID - 1].Type;
|
||||
if (TileType == horse.Breed.SpawnOn)
|
||||
if (CanHorseBeHere(tryX, tryY))
|
||||
{
|
||||
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
|
||||
{
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -93,42 +113,38 @@ namespace HISP.Game.Horse
|
|||
|
||||
public void RandomWander()
|
||||
{
|
||||
while(true)
|
||||
if (GameServer.GetUsersAt(this.X, this.Y, true, true).Length > 0)
|
||||
return;
|
||||
|
||||
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
|
||||
int tryX = this.X;
|
||||
int tryY = this.Y;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
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?
|
||||
{
|
||||
X = tryX;
|
||||
Y = tryY;
|
||||
case 0:
|
||||
tryX += 1;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
tryX -= 1;
|
||||
break;
|
||||
case 2:
|
||||
tryY += 1;
|
||||
break;
|
||||
case 3:
|
||||
tryY -= 1;
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
bool check = CanHorseBeHere(this.X, this.Y); // if the horse is allready in an invalid position..
|
||||
|
||||
if (CanHorseBeHere(tryX, tryY, check))
|
||||
{
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Escape()
|
||||
|
@ -138,13 +154,9 @@ namespace HISP.Game.Horse
|
|||
int tryX = X + GameServer.RandomNumberGenerator.Next(-15, 15);
|
||||
int tryY = Y + GameServer.RandomNumberGenerator.Next(-15, 15);
|
||||
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(tryX, tryY))
|
||||
continue;
|
||||
if (World.InSpecialTile(tryX, tryY))
|
||||
continue;
|
||||
bool check = CanHorseBeHere(this.X, this.Y); // if the horse is allready in an invalid position..
|
||||
|
||||
if (Map.CheckPassable(tryX, tryY))
|
||||
if (CanHorseBeHere(tryX, tryY, check))
|
||||
{
|
||||
X = tryX;
|
||||
Y = tryY;
|
||||
|
|
|
@ -65,6 +65,9 @@ namespace HISP.Game.Inventory
|
|||
|
||||
public void AddInfinity(Item.ItemInformation itemInfo)
|
||||
{
|
||||
if (HasItemId(itemInfo.Id))
|
||||
return;
|
||||
|
||||
InventoryItem inventoryItem = new InventoryItem();
|
||||
inventoryItem.ItemId = itemInfo.Id;
|
||||
inventoryItem.Infinite = true;
|
||||
|
|
|
@ -451,6 +451,7 @@ namespace HISP.Game
|
|||
// Sec Codes
|
||||
public static string InvalidSecCodeError;
|
||||
public static string YouEarnedAnItemFormat;
|
||||
public static string YouEarnedAnItemButInventoryWasFullFormat;
|
||||
public static string YouLostAnItemFormat;
|
||||
public static string YouEarnedMoneyFormat;
|
||||
public static string BeatHighscoreFormat;
|
||||
|
@ -1245,6 +1246,10 @@ namespace HISP.Game
|
|||
{
|
||||
return YouLostAnItemFormat.Replace("%ITEM%", itemName);
|
||||
}
|
||||
public static string FormatYouEarnedAnItemButInventoryFullMessage(string itemName)
|
||||
{
|
||||
return YouEarnedAnItemButInventoryWasFullFormat.Replace("%ITEM%", itemName);
|
||||
}
|
||||
public static string FormatYouEarnedAnItemMessage(string itemName)
|
||||
{
|
||||
return YouEarnedAnItemFormat.Replace("%ITEM%", itemName);
|
||||
|
|
|
@ -181,12 +181,12 @@ namespace HISP.Game
|
|||
// Give quest points
|
||||
user.QuestPoints += quest.QuestPointsEarned;
|
||||
|
||||
if (quest.ChainedQuestId != 0)
|
||||
ActivateQuest(user, GetQuestById(quest.ChainedQuestId));
|
||||
|
||||
|
||||
if (quest.Tracked)
|
||||
user.Quests.TrackQuest(quest.Id);
|
||||
|
||||
if (quest.ChainedQuestId != 0)
|
||||
ActivateQuest(user, Quest.GetQuestById(quest.ChainedQuestId), npcActivation);
|
||||
|
||||
if (quest.SuccessMessage != null)
|
||||
{
|
||||
|
@ -205,6 +205,7 @@ namespace HISP.Game
|
|||
|
||||
|
||||
|
||||
|
||||
// Check if award unlocked
|
||||
int questPointsPercent = Convert.ToInt32(Math.Floor(((decimal)user.QuestPoints / (decimal)GetTotalQuestPoints()) * (decimal)100.0));
|
||||
if (questPointsPercent >= 25)
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace HISP.Server
|
|||
private bool receivePackets()
|
||||
{
|
||||
// HI1 Packets are terminates by 0x00 so we have to read until we receive that terminator
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
||||
|
||||
while(ClientSocket.Connected)
|
||||
{
|
||||
|
@ -146,29 +146,29 @@ namespace HISP.Server
|
|||
|
||||
try
|
||||
{
|
||||
if (ClientSocket.Available >= 1)
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
byte[] buffer = new byte[ClientSocket.Available];
|
||||
ClientSocket.Receive(buffer);
|
||||
|
||||
|
||||
foreach (Byte b in buffer)
|
||||
if (ClientSocket.Available >= 1)
|
||||
{
|
||||
if(isDisconnecting)
|
||||
break;
|
||||
byte[] buffer = new byte[ClientSocket.Available];
|
||||
ClientSocket.Receive(buffer);
|
||||
|
||||
ms.WriteByte(b);
|
||||
if (b == 0x00)
|
||||
foreach (Byte b in buffer)
|
||||
{
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] fullPacket = ms.ToArray();
|
||||
parsePackets(fullPacket);
|
||||
if (isDisconnecting)
|
||||
break;
|
||||
|
||||
ms.Close();
|
||||
ms = new MemoryStream();
|
||||
ms.WriteByte(b);
|
||||
if (b == 0x00)
|
||||
{
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] fullPacket = ms.ToArray();
|
||||
parsePackets(fullPacket);
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
ms.SetLength(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch(SocketException e)
|
||||
|
|
|
@ -1064,6 +1064,7 @@ namespace HISP.Server
|
|||
|
||||
Messages.InvalidSecCodeError = gameData.messages.sec_code.invalid_sec_code;
|
||||
Messages.YouEarnedAnItemFormat = gameData.messages.sec_code.item_earned;
|
||||
Messages.YouEarnedAnItemButInventoryWasFullFormat = gameData.messages.sec_code.item_earned_full_inv;
|
||||
Messages.YouLostAnItemFormat = gameData.messages.sec_code.item_deleted;
|
||||
Messages.YouEarnedMoneyFormat = gameData.messages.sec_code.money_earned;
|
||||
Messages.BeatHighscoreFormat = gameData.messages.sec_code.highscore_beaten;
|
||||
|
|
|
@ -2296,9 +2296,19 @@ namespace HISP.Server
|
|||
if (Item.ItemIdExist(value))
|
||||
{
|
||||
ItemInstance itm = new ItemInstance(value);
|
||||
sender.LoggedinUser.Inventory.Add(itm);
|
||||
|
||||
Item.ItemInformation itemInfo = Item.GetItemById(value);
|
||||
byte[] earnedItemMessage = PacketBuilder.CreateChat(Messages.FormatYouEarnedAnItemMessage(itemInfo.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
string messageToSend = Messages.FormatYouEarnedAnItemMessage(itemInfo.Name);
|
||||
try
|
||||
{
|
||||
sender.LoggedinUser.Inventory.Add(itm);
|
||||
}
|
||||
catch(InventoryException)
|
||||
{
|
||||
messageToSend = Messages.FormatYouEarnedAnItemButInventoryFullMessage(itemInfo.Name);
|
||||
}
|
||||
|
||||
byte[] earnedItemMessage = PacketBuilder.CreateChat(messageToSend, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
sender.SendPacket(earnedItemMessage);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Reference in a new issue