Add socials to the game.

This commit is contained in:
SilicaAndPina 2021-03-01 13:36:22 +13:00
parent 4e333d1387
commit ba64c364f4
11 changed files with 699 additions and 122 deletions

View file

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Chat
{
public class SocialType
{
public SocialType(string type)
{
Socials = new List<Social>();
Type = type;
SocialTypes.Add(this);
}
public static List<SocialType> SocialTypes = new List<SocialType>();
public string Type;
public List<Social> Socials;
public class Social
{
public SocialType BaseSocialType;
public int Id;
public string ButtonName;
public string ForSender;
public string ForTarget;
public string ForEveryone;
public string SoundEffect;
}
public static Social GetSocial(int socialId)
{
foreach (SocialType sType in SocialTypes)
foreach (Social social in sType.Socials)
if (social.Id == socialId)
return social;
throw new KeyNotFoundException("Social " + socialId.ToString() + " not found!");
}
public static SocialType GetSocialType(string type)
{
foreach (SocialType stype in SocialTypes)
if (stype.Type == type)
return stype;
throw new KeyNotFoundException("SocialType " + type + " NOT FOUND!");
}
public static void AddNewSocial(string type, Social social)
{
foreach(SocialType stype in SocialTypes)
{
if(stype.Type == type)
{
social.BaseSocialType = stype;
stype.Socials.Add(social);
return;
}
}
SocialType sType = new SocialType(type);
social.BaseSocialType = sType;
sType.Socials.Add(social);
return;
}
}
}

View file

@ -13,6 +13,11 @@ namespace HISP.Game
// Mod isle
public static string ModIsleMessage;
// Socials
public static string SocialButton;
public static string SocialMessageFormat;
public static string SocialTypeFormat;
// Trading
public static string TradeWithPlayerFormat;
@ -85,7 +90,6 @@ namespace HISP.Game
// Player Interaction
public static string PlayerHereMenuFormat;
public static string PlayerHereMulitpleMenuFormat;
public static string PlayerHereProfileButton;
public static string PlayerHereSocialButton;
@ -577,6 +581,8 @@ namespace HISP.Game
public static string ViewBaiscStats;
public static string ViewAdvancedStats;
public static string HorseBuckedYou;
public static string HorseLlamaBuckedYou;
public static string HorseCamelBuckedYou;
public static string HorseRidingMessageFormat;
public static string HorseNameYoursFormat;
@ -905,6 +911,7 @@ namespace HISP.Game
public static string BackToMapHorse;
public static string LongFullLine;
public static string MetaTerminator;
public static string R1;
// Pawneer
public static string PawneerUntackedHorsesICanBuy;
@ -985,7 +992,23 @@ namespace HISP.Game
// Click
public static string NothingInterestingHere;
// Socials
public static string FormatSocialButton(int socialId, string buttonName)
{
string id = "" + Convert.ToChar(0x21 + socialId);
return SocialButton.Replace("%ID%", id).Replace("%SOCIALNAME%", buttonName);
}
public static string FormatSocialMessage(string socialMsg, string targetName, string senderName)
{
return SocialMessageFormat.Replace("%SOCIALMSG%", socialMsg.Replace("%TARGETNAME%", targetName).Replace("%SENDERNAME%", senderName));
}
public static string FormatSocialMenuType(string type)
{
return SocialTypeFormat.Replace("%TYPE%", Converters.CapitalizeFirstLetter(type.ToLower()));
}
// Trading
public static string FormatTradeYouReceived(int money)
{
return TradeYouReceivedMoneyMessageFormat.Replace("%MONEY%", money.ToString("N0", CultureInfo.InvariantCulture));

View file

@ -8,6 +8,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using HISP.Game.Chat;
namespace HISP.Game
{
@ -62,7 +63,14 @@ namespace HISP.Game
}
if(count >= 2)
playersHere += Messages.PlayerHereMulitpleMenuFormat;
{
SocialType stype = SocialType.GetSocialType("GROUP");
foreach(SocialType.Social social in stype.Socials)
{
playersHere += Messages.FormatSocialButton(social.Id, social.ButtonName);
}
playersHere += Messages.R1;
}
if (count <= 0)
return "";
@ -141,7 +149,7 @@ namespace HISP.Game
message += Messages.ThingsIAmSelling;
foreach (InventoryItem item in itemList)
{
message += "^R1";
message += Messages.R1;
Item.ItemInformation itemInfo = Item.GetItemById(item.ItemId);
int count = item.ItemInstances.Count;
@ -163,7 +171,7 @@ namespace HISP.Game
}
// Check whats avalilble to be sold
message += "^R1" + Messages.ThingsYouSellMe;
message += Messages.R1 + Messages.ThingsYouSellMe;
InventoryItem[] shopperItemList = shopperInventory.GetItemList();
foreach (InventoryItem shopperitem in shopperItemList)
@ -179,14 +187,14 @@ namespace HISP.Game
string countStr = count.ToString();
message += "^R1";
message += Messages.R1;
message += Messages.FormatShopEntry(itemInfo.IconId, countStr, itemInfo.Name, shop.CalculateSellCost(itemInfo));
message += Messages.FormatSellButton(shopperitem.ItemInstances[0].RandomId);
message += Messages.FormatSellAllButton(itemInfo.Id);
message += Messages.FormatItemInformationButton(shopperitem.ItemInstances[0].RandomId);
}
message += "^R1" + Messages.ExitThisPlace;
message += Messages.R1 + Messages.ExitThisPlace;
return message;
}
@ -363,7 +371,7 @@ namespace HISP.Game
{
message += Messages.NpcNoChatpoints;
}
message += "^R1";
message += Messages.R1;
}
return message;
}
@ -445,6 +453,28 @@ namespace HISP.Game
return message;
}
public static string BuildSocialMenu(bool onHorse)
{
string message = "";
foreach(SocialType sType in SocialType.SocialTypes)
{
if (sType.Type == "GROUP")
continue;
if (sType.Type == "HORSE")
if (!onHorse)
continue;
message += Messages.FormatSocialMenuType(sType.Type);
foreach(SocialType.Social social in sType.Socials)
{
message += Messages.FormatSocialButton(social.Id, social.ButtonName);
}
message += Messages.R1;
}
message += Messages.BackToMap;
message += Messages.MetaTerminator;
return message;
}
public static string BuildTradeAddItem(int totalItems)
{
@ -1957,7 +1987,7 @@ namespace HISP.Game
message += Messages.FormatItemThrowButton(randomId);
message += Messages.FormatItemInformationButton(randomId);
message += "^R1";
message += Messages.R1;
}
message += Messages.BackToMap;
@ -2101,7 +2131,7 @@ namespace HISP.Game
}
else
{
message += "^R1";
message += Messages.R1;
}
}

View file

@ -96,6 +96,7 @@ namespace HISP.Player
public Highscore Highscores;
public Riddler LastRiddle;
public Award Awards;
public User SocializingWith;
public int CapturingHorseId;
public DateTime LoginTime;
public string LastSeenWeather;

View file

@ -6,7 +6,6 @@ using HISP.Game.SwfModules;
using HISP.Security;
using HISP.Server;
using HISP.Game.Services;
namespace HISP
{
public class Program

View file

@ -1154,7 +1154,7 @@ namespace HISP.Server
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO RiddlesComplete VALUES(@riddleId, @playerId, \"YES\")";
sqlCommand.CommandText = "INSERT INTO RiddlesComplete VALUES(@playerId, @riddleId, \"YES\")";
sqlCommand.Parameters.AddWithValue("@riddleId", riddleId);
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();

View file

@ -408,6 +408,9 @@ namespace HISP.Server
case PacketBuilder.PACKET_PLAYER_INTERACTION:
GameServer.OnPlayerInteration(this, Packet);
break;
case PacketBuilder.PACKET_SOCIALS:
GameServer.OnSocialPacket(this, Packet);
break;
default:
Logger.ErrorPrint("Unimplemented Packet: " + BitConverter.ToString(Packet).Replace('-', ' '));
break;

View file

@ -793,6 +793,28 @@ namespace HISP.Server
Logger.DebugPrint("Registered Leaser: " + leaser.LeaseId.ToString() + " For a " + leaser.HorseName);
}
// Register Socials
int totalSocials = gameData.social_types.Count;
for (int i = 0; i < totalSocials; i++)
{
string socialType = gameData.social_types[i].type;
int totalSocialsOfType = gameData.social_types[i].socials.Count;
for (int ii = 0; ii < totalSocialsOfType; ii++)
{
SocialType.Social social = new SocialType.Social();
social.Id = gameData.social_types[i].socials[ii].social_id;
social.ButtonName = gameData.social_types[i].socials[ii].button_name;
social.ForSender = gameData.social_types[i].socials[ii].for_sender;
social.ForTarget = gameData.social_types[i].socials[ii].for_target;
social.ForEveryone = gameData.social_types[i].socials[ii].for_everyone;
social.SoundEffect = gameData.social_types[i].socials[ii].sound_effect;
SocialType.AddNewSocial(socialType, social);
Logger.DebugPrint("Registered Social: " + social.ButtonName);
}
}
HorseInfo.HorseNames = gameData.horses.names.ToObject<string[]>();
Item.Present = gameData.item.special.present;
@ -825,6 +847,11 @@ namespace HISP.Server
Map.ModIsleX = gameData.messages.commands.mod_isle.x;
Map.ModIsleY = gameData.messages.commands.mod_isle.y;
// Socials
Messages.SocialButton = gameData.messages.meta.player_interaction.socials.socials_button;
Messages.SocialMessageFormat = gameData.messages.meta.player_interaction.socials.socials_message;
Messages.SocialTypeFormat = gameData.messages.meta.player_interaction.socials.socials_menu_type;
// Trade
Messages.TradeWithPlayerFormat = gameData.messages.meta.player_interaction.trade.trading_with;
@ -898,7 +925,6 @@ namespace HISP.Server
// Player Interation
Messages.PlayerHereMenuFormat = gameData.messages.meta.player_interaction.menu;
Messages.PlayerHereMulitpleMenuFormat = gameData.messages.meta.player_interaction.multiple_players_menu;
Messages.PlayerHereProfileButton = gameData.messages.meta.player_interaction.profiile_button;
Messages.PlayerHereSocialButton = gameData.messages.meta.player_interaction.social_button;
@ -1382,6 +1408,8 @@ namespace HISP.Server
Messages.ViewBaiscStats = gameData.messages.meta.horse.view_basic_stats;
Messages.ViewAdvancedStats = gameData.messages.meta.horse.view_advanced_stats;
Messages.HorseBuckedYou = gameData.messages.meta.horse.horse_bucked;
Messages.HorseLlamaBuckedYou = gameData.messages.meta.horse.llama_bucked;
Messages.HorseCamelBuckedYou = gameData.messages.meta.horse.camel_bucked;
Messages.HorseRidingMessageFormat = gameData.messages.meta.horse.riding_message;
Messages.HorseNameYoursFormat = gameData.messages.meta.horse.horse_inventory.your_horse_format;
@ -1663,8 +1691,11 @@ namespace HISP.Server
Messages.NoPitchforkMeta = gameData.messages.meta.hay_pile.no_pitchfork;
Messages.HasPitchforkMeta = gameData.messages.meta.hay_pile.pitchfork;
Messages.R1 = gameData.messages.meta.r1;
Messages.PasswordEntry = gameData.messages.meta.password_input;
// Venus Fly Trap
Messages.VenusFlyTrapFormat = gameData.messages.meta.venus_flytrap_format;
// Shortcut

View file

@ -321,7 +321,8 @@ namespace HISP.Server
}
catch(FormatException)
{
Logger.InfoPrint(sender.LoggedinUser.Username + " tried to trade with User ID NaN.");
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to trade with User ID NaN.");
break;
}
if(IsUserOnline(playerId))
{
@ -354,6 +355,105 @@ namespace HISP.Server
}
return;
}
public static void OnSocialPacket(GameClient sender, byte[] packet)
{
if (!sender.LoggedIn)
{
Logger.ErrorPrint(sender.RemoteIp + " Tried to be socialable, but has no account and therefor no friends.");
return;
}
byte method = packet[1];
switch (method)
{
case PacketBuilder.SOCIALS_MENU:
string packetStr = Encoding.UTF8.GetString(packet);
string playerIdStr = packetStr.Substring(2, packetStr.Length - 4);
int playerId = -1;
try
{
playerId = int.Parse(playerIdStr);
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to socialize with User ID NaN.");
break;
}
if(IsUserOnline(playerId))
{
sender.LoggedinUser.SocializingWith = GetUserById(playerId);
sender.LoggedinUser.MetaPriority = true;
byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildSocialMenu(sender.LoggedinUser.CurrentlyRidingHorse != null));
sender.SendPacket(metaPacket);
}
else
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to socialize with User #"+playerId.ToString()+" but there not online.");
}
break;
case PacketBuilder.SOCIALS_USE:
int socialId = Convert.ToInt32(packet[2] - (byte)0x21);
SocialType.Social social = SocialType.GetSocial(socialId);
foreach(User user in GetUsersAt(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, true))
{
if (social.BaseSocialType.Type != "GROUP")
if (user.Id == sender.LoggedinUser.SocializingWith.Id)
continue;
if (user.Id == sender.LoggedinUser.Id)
continue;
if (user.MuteAll || user.MuteSocials)
continue;
byte[] msgEveryone = PacketBuilder.CreateChat(Messages.FormatSocialMessage(social.ForEveryone, sender.LoggedinUser.SocializingWith.Username, sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(msgEveryone);
}
if(social.ForTarget != null)
{
if(sender.LoggedinUser.SocializingWith != null)
{
if (social.BaseSocialType.Type != "GROUP")
{
if (!sender.LoggedinUser.SocializingWith.MuteAll || !sender.LoggedinUser.SocializingWith.MuteSocials)
{
byte[] msgTarget = PacketBuilder.CreateChat(Messages.FormatSocialMessage(social.ForTarget, sender.LoggedinUser.SocializingWith.Username, sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.LoggedinUser.SocializingWith.LoggedinClient.SendPacket(msgTarget);
}
}
}
}
if(social.ForSender != null)
{
if (sender.LoggedinUser.SocializingWith != null)
{
byte[] msgSender = PacketBuilder.CreateChat(Messages.FormatSocialMessage(social.ForSender, sender.LoggedinUser.SocializingWith.Username, sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(msgSender);
}
}
foreach(User user in GetUsersAt(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, true))
{
if (social.SoundEffect != null)
{
if (user.MuteAll || user.MuteSocials)
continue;
byte[] soundEffect = PacketBuilder.CreatePlaysoundPacket(social.SoundEffect);
user.LoggedinClient.SendPacket(soundEffect);
}
}
break;
default:
Logger.ErrorPrint(sender.LoggedinUser.Username + " unknown social: " + method.ToString("X") + " packet dump: " + BitConverter.ToString(packet).Replace("-", " "));
break;
}
}
public static void OnBirdMapRequested(GameClient sender, byte[] packet)
{
if (!sender.LoggedIn)
@ -3960,9 +4060,16 @@ namespace HISP.Server
if(GameServer.RandomNumberGenerator.Next(0, 100) >= 97 || sender.LoggedinUser.Username.ToLower() == "dream")
{
loggedInUser.CurrentlyRidingHorse.BasicStats.Experience++;
byte[] horseBuckedMessage;
if(loggedInUser.CurrentlyRidingHorse.Breed.Type == "llama")
horseBuckedMessage = PacketBuilder.CreateChat(Messages.HorseLlamaBuckedYou, PacketBuilder.CHAT_BOTTOM_RIGHT);
else if (loggedInUser.CurrentlyRidingHorse.Breed.Type == "camel")
horseBuckedMessage = PacketBuilder.CreateChat(Messages.HorseCamelBuckedYou, PacketBuilder.CHAT_BOTTOM_RIGHT);
else
horseBuckedMessage = PacketBuilder.CreateChat(Messages.HorseBuckedYou, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.LoggedinUser.CurrentlyRidingHorse = null;
sender.LoggedinUser.Facing %= 5;
byte[] horseBuckedMessage = PacketBuilder.CreateChat(Messages.HorseBuckedYou, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(horseBuckedMessage);
}
}

View file

@ -51,6 +51,10 @@ namespace HISP.Server
public const byte PACKET_SWFMODULE = 0x50;
public const byte PACKET_AUCTION = 0x24;
public const byte PACKET_PLAYER_INTERACTION = 0x2A;
public const byte PACKET_SOCIALS = 0x5A;
public const byte SOCIALS_MENU = 0x14;
public const byte SOCIALS_USE = 0x15;
public const byte PLAYER_INTERACTION_TRADE = 0x28;
public const byte PLAYER_INTERACTION_ADD_ITEM = 0x29;