Add the most important command and feature in the entire game,

This commit is contained in:
SilicaAndPina 2021-03-31 01:26:55 +13:00
parent b8242010ad
commit 5cac72f67a
4 changed files with 117 additions and 16 deletions

View file

@ -161,6 +161,8 @@ namespace HISP.Game.Chat
else if (message.ToUpper().StartsWith("!WARP")) else if (message.ToUpper().StartsWith("!WARP"))
return Command.Warp(message, args, user); return Command.Warp(message, args, user);
else if (message.ToUpper().StartsWith("!DANCE"))
return Command.Dance(message, args, user);
} }
return false; return false;
} }

View file

@ -307,17 +307,19 @@ namespace HISP.Game.Chat
doCommand:; doCommand:;
if (args.Length <= 0) if (args.Length <= 0)
{ {
goto cantUnderstandCommand; goto cantUnderstandCommand;
} }
else else
{ {
string areaName = string.Join(" ", args).ToLower();
foreach (GameClient client in GameServer.ConnectedClients) foreach (GameClient client in GameServer.ConnectedClients)
{ {
if (client.LoggedIn) if (client.LoggedIn)
{ {
if(client.LoggedinUser.Username.ToLower().Contains(args[0].ToLower())) if(client.LoggedinUser.Username.ToLower().Contains(areaName))
{ {
user.Teleport(client.LoggedinUser.X, client.LoggedinUser.Y); user.Teleport(client.LoggedinUser.X, client.LoggedinUser.Y);
formattedmessage += Messages.SuccessfullyWarpedToPlayer; formattedmessage += Messages.SuccessfullyWarpedToPlayer;
@ -328,7 +330,7 @@ namespace HISP.Game.Chat
foreach(World.Waypoint waypoint in World.Waypoints) foreach(World.Waypoint waypoint in World.Waypoints)
{ {
if(waypoint.Name.ToLower().Contains(args[0].ToLower())) if(waypoint.Name.ToLower().Contains(areaName))
{ {
user.Teleport(waypoint.PosX, waypoint.PosY); user.Teleport(waypoint.PosX, waypoint.PosY);
formattedmessage += Messages.SuccessfullyWarpedToLocation; formattedmessage += Messages.SuccessfullyWarpedToLocation;
@ -350,6 +352,18 @@ namespace HISP.Game.Chat
return true; return true;
} }
public static bool Dance(string message, string[] args, User user)
{
string moves = string.Join(" ", args).ToLower();
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
new Dance(user, moves);
byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Mute(string message, string[] args, User user) public static bool Mute(string message, string[] args, User user)
{ {
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1)); string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));

View file

@ -0,0 +1,89 @@
using HISP.Server;
using System;
using System.Threading;
namespace HISP.Player
{
public class Dance : IDisposable
{
public const int DanceSpeed = 1000;
private Timer danceTimer;
public string Moves;
public int MoveIndex;
private User baseUser;
public Dance(User BaseUser, string DanceMoves)
{
baseUser = BaseUser;
Moves = DanceMoves.ToLower();
MoveIndex = -1;
danceTimer = new Timer(new TimerCallback(onDanceTick), null, DanceSpeed, DanceSpeed);
}
private void onDanceTick(object state)
{
MoveIndex++;
if (MoveIndex >= Moves.Length)
goto done;
int onHorse = 0;
int facing = baseUser.Facing;
while (facing >= 5)
{
facing -= 5;
onHorse++;
}
char moveInDir = Moves[MoveIndex];
int direction;
switch(moveInDir)
{
case 'u':
direction = PacketBuilder.DIRECTION_UP;
break;
case 'd':
direction = PacketBuilder.DIRECTION_DOWN;
break;
case 'l':
direction = PacketBuilder.DIRECTION_LEFT;
break;
case 'r':
direction = PacketBuilder.DIRECTION_RIGHT;
break;
default:
goto done;
}
baseUser.Facing = direction + (onHorse * 5);
byte[] moveResponse = PacketBuilder.CreateMovementPacket(baseUser.X, baseUser.Y, baseUser.CharacterId, baseUser.Facing, PacketBuilder.DIRECTION_NONE, false);
baseUser.LoggedinClient.SendPacket(moveResponse);
GameServer.UpdateUserFacingAndLocation(baseUser);
done:;
if (MoveIndex < Moves.Length)
{
danceTimer.Change(DanceSpeed, DanceSpeed);
}
else
{
this.Dispose();
}
}
public void Dispose()
{
baseUser = null;
Moves = null;
danceTimer.Dispose();
danceTimer = null;
MoveIndex = -1;
}
}
}

View file

@ -4142,7 +4142,7 @@ namespace HISP.Server
sender.SendPacket(chatPacket); sender.SendPacket(chatPacket);
UpdateArea(sender); UpdateArea(sender);
UpdateUserInfo(sender.LoggedinUser); UpdateUserFacingAndLocation(sender.LoggedinUser);
} }
else if (method == PacketBuilder.SECCODE_AWARD) else if (method == PacketBuilder.SECCODE_AWARD)
{ {
@ -4659,7 +4659,7 @@ namespace HISP.Server
int facing = sender.LoggedinUser.Facing; int facing = sender.LoggedinUser.Facing;
while (facing >= 5) while (facing >= 5)
{ {
facing = facing - 5; facing -= 5;
onHorse++; onHorse++;
} }
byte direction = 0; byte direction = 0;
@ -5391,6 +5391,7 @@ namespace HISP.Server
if (message == "") if (message == "")
return; return;
if (Chat.ProcessCommand(sender.LoggedinUser, message)) if (Chat.ProcessCommand(sender.LoggedinUser, message))
{ {
Logger.DebugPrint(sender.LoggedinUser.Username + " Attempting to run command '" + message + "' in channel: " + channel.ToString()); Logger.DebugPrint(sender.LoggedinUser.Username + " Attempting to run command '" + message + "' in channel: " + channel.ToString());
@ -6768,7 +6769,7 @@ namespace HISP.Server
if (client.LoggedinUser.Id != userId) if (client.LoggedinUser.Id != userId)
client.SendPacket(loginMessageBytes); client.SendPacket(loginMessageBytes);
UpdateUserInfo(sender.LoggedinUser); UpdateUserFacingAndLocation(sender.LoggedinUser);
} }
else else
@ -7066,7 +7067,7 @@ namespace HISP.Server
if(!nearbyUser.MetaPriority) if(!nearbyUser.MetaPriority)
UpdateArea(nearbyUser.LoggedinClient); UpdateArea(nearbyUser.LoggedinClient);
UpdateUserInfo(client.LoggedinUser); UpdateUserFacingAndLocation(client.LoggedinUser);
} }
public static void UpdateDrawingForAll(string id, GameClient sender, string drawing, bool includingSender=false) public static void UpdateDrawingForAll(string id, GameClient sender, string drawing, bool includingSender=false)
@ -7150,21 +7151,16 @@ namespace HISP.Server
byte[] PlayerData = PacketBuilder.CreatePlayerData(forClient.LoggedinUser.Money, GameServer.GetNumberOfPlayers(), forClient.LoggedinUser.MailBox.MailCount); byte[] PlayerData = PacketBuilder.CreatePlayerData(forClient.LoggedinUser.Money, GameServer.GetNumberOfPlayers(), forClient.LoggedinUser.MailBox.MailCount);
forClient.SendPacket(PlayerData); forClient.SendPacket(PlayerData);
} }
public static void UpdateUserInfo(User user) public static void UpdateUserFacingAndLocation(User user)
{ {
byte[] playerInfoBytes = PacketBuilder.CreatePlayerInfoUpdateOrCreate(user.X, user.Y, user.Facing, user.CharacterId, user.Username); byte[] playerInfoBytes = PacketBuilder.CreatePlayerInfoUpdateOrCreate(user.X, user.Y, user.Facing, user.CharacterId, user.Username);
List<User> users = new List<User>();
foreach (GameClient client in ConnectedClients) foreach (GameClient client in ConnectedClients)
if (client.LoggedIn) if (client.LoggedIn)
{ {
if (client.LoggedinUser.Id != user.Id) if (client.LoggedinUser.Id != user.Id)
client.SendPacket(playerInfoBytes); client.SendPacket(playerInfoBytes);
} }
} }
public static void UpdateAreaForAll(int x, int y, bool ignoreMetaPrio=false, User exceptMe=null) public static void UpdateAreaForAll(int x, int y, bool ignoreMetaPrio=false, User exceptMe=null)
{ {
@ -7348,7 +7344,7 @@ namespace HISP.Server
byte[] rideHorsePacket = PacketBuilder.CreateHorseRidePacket(sender.LoggedinUser.X, sender.LoggedinUser.Y, sender.LoggedinUser.CharacterId, sender.LoggedinUser.Facing, 10, true); byte[] rideHorsePacket = PacketBuilder.CreateHorseRidePacket(sender.LoggedinUser.X, sender.LoggedinUser.Y, sender.LoggedinUser.CharacterId, sender.LoggedinUser.Facing, 10, true);
sender.SendPacket(rideHorsePacket); sender.SendPacket(rideHorsePacket);
UpdateUserInfo(sender.LoggedinUser); UpdateUserFacingAndLocation(sender.LoggedinUser);
} }
public static void StopRidingHorse(GameClient sender) public static void StopRidingHorse(GameClient sender)
{ {
@ -7363,7 +7359,7 @@ namespace HISP.Server
sender.SendPacket(rideHorsePacket); sender.SendPacket(rideHorsePacket);
sender.LoggedinUser.NoClip = false; sender.LoggedinUser.NoClip = false;
UpdateUserInfo(sender.LoggedinUser); UpdateUserFacingAndLocation(sender.LoggedinUser);
} }
public static bool ProcessMapCodeWithArg(GameClient forClient, World.SpecialTile tile) public static bool ProcessMapCodeWithArg(GameClient forClient, World.SpecialTile tile)
{ {