mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-06 05:05:40 +12:00
Add movement (basic)
This commit is contained in:
parent
1b9be5036e
commit
3183bf2b3e
5 changed files with 142 additions and 7 deletions
|
@ -96,6 +96,12 @@ namespace Horse_Isle_Server
|
|||
case PacketBuilder.PACKET_LOGIN:
|
||||
Server.OnUserInfoRequest(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_MOVE:
|
||||
Server.OnMovementPacket(this, Packet);
|
||||
break;
|
||||
default:
|
||||
Logger.ErrorPrint("Unimplemented Packet: " + BitConverter.ToString(Packet).Replace('-', ' '));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ namespace Horse_Isle_Server
|
|||
else
|
||||
return MapData.GetPixel(x, y).B;
|
||||
}
|
||||
public static bool CheckPassable(int x, int y)
|
||||
{
|
||||
return true; // not implemented yet
|
||||
}
|
||||
|
||||
public static void OpenMap()
|
||||
{
|
||||
|
|
|
@ -23,14 +23,29 @@ namespace Horse_Isle_Server
|
|||
public const byte PACKET_PLACE_INFO = 0x1E;
|
||||
public const byte PACKET_AREA_DEFS = 0x79;
|
||||
public const byte PACKET_TILE_FLAGS = 0x75;
|
||||
|
||||
public const byte AREA_SEPERATOR = 0x5E;
|
||||
|
||||
private const byte CHAT_BOTTOM_LEFT = 0x14;
|
||||
private const byte CHAT_BOTTOM_RIGHT = 0x15;
|
||||
public const byte MOVE_UP = 0x14;
|
||||
public const byte MOVE_DOWN = 0x15;
|
||||
public const byte MOVE_RIGHT = 0x16;
|
||||
public const byte MOVE_LEFT = 0x17;
|
||||
public const byte MOVE_EXIT = 0x10;
|
||||
|
||||
public const byte CHAT_BOTTOM_LEFT = 0x14;
|
||||
public const byte CHAT_BOTTOM_RIGHT = 0x15;
|
||||
|
||||
public const byte LOGIN_INVALID_USER_PASS = 0x15;
|
||||
public const byte LOGIN_SUCCESS = 0x14;
|
||||
|
||||
public const byte DIRECTION_UP = 0;
|
||||
public const byte DIRECTION_RIGHT = 1;
|
||||
public const byte DIRECTION_DOWN = 2;
|
||||
public const byte DIRECTION_LEFT = 3;
|
||||
public const byte DIRECTION_LOGIN = 4;
|
||||
|
||||
|
||||
|
||||
public static byte[] CreateLoginPacket(bool Success)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
@ -48,7 +63,7 @@ namespace Horse_Isle_Server
|
|||
return Packet;
|
||||
}
|
||||
|
||||
public static byte[] CreateMovementPacket(int x, int y,int charId, int facing, int direction, bool walk)
|
||||
public static byte[] CreateMovementPacket(int x, int y,int charId,int facing, int direction, bool walk)
|
||||
{
|
||||
// Header information
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
@ -77,11 +92,78 @@ namespace Horse_Isle_Server
|
|||
}
|
||||
|
||||
int ystart = y - 3;
|
||||
|
||||
int xstart = x - 2;
|
||||
|
||||
|
||||
if (direction == 4)
|
||||
if (direction == DIRECTION_UP)
|
||||
{
|
||||
for (int relx = 0; relx <= 12; relx++)
|
||||
{
|
||||
int tileId = Map.GetTileId(xstart + relx, ystart, false);
|
||||
int otileId = Map.GetTileId(xstart + relx, ystart, true);
|
||||
|
||||
if (tileId == 290)
|
||||
tileId -= 100;
|
||||
if (otileId == 290)
|
||||
otileId -= 100;
|
||||
|
||||
ms.WriteByte((byte)tileId);
|
||||
ms.WriteByte((byte)otileId);
|
||||
}
|
||||
}
|
||||
|
||||
if (direction == DIRECTION_LEFT)
|
||||
{
|
||||
for (int rely = 0; rely <= 9; rely++)
|
||||
{
|
||||
int tileId = Map.GetTileId(xstart, ystart + rely, false);
|
||||
int otileId = Map.GetTileId(xstart, ystart + rely, true);
|
||||
|
||||
if (tileId == 290)
|
||||
tileId -= 100;
|
||||
if (otileId == 290)
|
||||
otileId -= 100;
|
||||
|
||||
ms.WriteByte((byte)tileId);
|
||||
ms.WriteByte((byte)otileId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (direction == DIRECTION_RIGHT)
|
||||
{
|
||||
for (int rely = 0; rely <= 9; rely++)
|
||||
{
|
||||
int tileId = Map.GetTileId(xstart + 12, ystart + rely, false);
|
||||
int otileId = Map.GetTileId(xstart + 12, ystart + rely, true);
|
||||
|
||||
if (tileId == 290)
|
||||
tileId -= 100;
|
||||
if (otileId == 290)
|
||||
otileId -= 100;
|
||||
|
||||
ms.WriteByte((byte)tileId);
|
||||
ms.WriteByte((byte)otileId);
|
||||
}
|
||||
}
|
||||
|
||||
if (direction == DIRECTION_DOWN)
|
||||
{
|
||||
for (int relx = 0; relx <= 12; relx++)
|
||||
{
|
||||
int tileId = Map.GetTileId(xstart + relx, ystart + 9, false);
|
||||
int otileId = Map.GetTileId(xstart + relx, ystart + 9, true);
|
||||
|
||||
if (tileId == 290)
|
||||
tileId -= 100;
|
||||
if (otileId == 290)
|
||||
otileId -= 100;
|
||||
|
||||
ms.WriteByte((byte)tileId);
|
||||
ms.WriteByte((byte)otileId);
|
||||
}
|
||||
}
|
||||
if (direction == DIRECTION_LOGIN)
|
||||
{
|
||||
for(int rely = 0; rely <= 9; rely++)
|
||||
{
|
||||
|
@ -292,7 +374,7 @@ namespace Horse_Isle_Server
|
|||
throw new Exception("Client is not logged in.");
|
||||
User user = client.LoggedinUser;
|
||||
|
||||
byte[] MovementPacket = CreateMovementPacket(user.X, user.Y, user.CharacterId, 2, 4, false);
|
||||
byte[] MovementPacket = CreateMovementPacket(user.X, user.Y, user.CharacterId, DIRECTION_DOWN, DIRECTION_LOGIN, false);
|
||||
ms.Write(MovementPacket, 0x00, MovementPacket.Length);
|
||||
|
||||
byte[] LoginMessage = CreateLoginMessage(user.Username);
|
||||
|
|
|
@ -30,10 +30,52 @@ namespace Horse_Isle_Server
|
|||
Logger.ErrorPrint(sender.RemoteIp + " Requested user information when not logged in.");
|
||||
return;
|
||||
}
|
||||
Logger.DebugPrint(sender.RemoteIp + " Requesting user information.");
|
||||
Logger.DebugPrint(sender.LoggedinUser.Username + " Requesting user information.");
|
||||
byte[] userInfoPackets = PacketBuilder.CreateUserInfo(sender);
|
||||
sender.SendPacket(userInfoPackets);
|
||||
}
|
||||
|
||||
public static void OnMovementPacket(Client sender, byte[] packet)
|
||||
{
|
||||
if (!sender.LoggedIn)
|
||||
{
|
||||
Logger.ErrorPrint(sender.RemoteIp + " Sent movement packet when not logged in.");
|
||||
return;
|
||||
}
|
||||
|
||||
User loggedInUser = sender.LoggedinUser;
|
||||
byte movementDirection = packet[1];
|
||||
switch(movementDirection)
|
||||
{
|
||||
case PacketBuilder.MOVE_UP:
|
||||
if(Map.CheckPassable(loggedInUser.X, loggedInUser.Y+1))
|
||||
loggedInUser.Y -= 1;
|
||||
byte[] moveUpResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, PacketBuilder.DIRECTION_UP, PacketBuilder.DIRECTION_UP, true);
|
||||
sender.SendPacket(moveUpResponse);
|
||||
break;
|
||||
case PacketBuilder.MOVE_LEFT:
|
||||
if (Map.CheckPassable(loggedInUser.X - 1, loggedInUser.Y))
|
||||
loggedInUser.X -= 1;
|
||||
byte[] moveLeftResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, PacketBuilder.DIRECTION_LEFT, PacketBuilder.DIRECTION_LEFT, true);
|
||||
sender.SendPacket(moveLeftResponse);
|
||||
break;
|
||||
case PacketBuilder.MOVE_RIGHT:
|
||||
if (Map.CheckPassable(loggedInUser.X +1 , loggedInUser.Y))
|
||||
loggedInUser.X += 1;
|
||||
byte[] moveRightResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, PacketBuilder.DIRECTION_RIGHT, PacketBuilder.DIRECTION_RIGHT, true);
|
||||
sender.SendPacket(moveRightResponse);
|
||||
break;
|
||||
case PacketBuilder.MOVE_DOWN:
|
||||
if (Map.CheckPassable(loggedInUser.X, loggedInUser.Y + 1))
|
||||
loggedInUser.Y += 1;
|
||||
byte[] moveDownResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, PacketBuilder.DIRECTION_DOWN, PacketBuilder.DIRECTION_DOWN, true);
|
||||
sender.SendPacket(moveDownResponse);
|
||||
break;
|
||||
}
|
||||
|
||||
byte[] tileData = PacketBuilder.CreateAreaMessage(loggedInUser.X, loggedInUser.Y);
|
||||
sender.SendPacket(tileData);
|
||||
}
|
||||
public static void OnLoginRequest(Client sender, byte[] packet)
|
||||
{
|
||||
Logger.DebugPrint("Login request received from: " + sender.RemoteIp);
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace Horse_Isle_Server
|
|||
return time;
|
||||
}
|
||||
|
||||
|
||||
public static Isle GetIsle(int x, int y)
|
||||
{
|
||||
foreach(Isle isle in Isles)
|
||||
|
|
Loading…
Add table
Reference in a new issue