implement view horse window

This commit is contained in:
SilicaAndPina 2021-01-09 21:40:14 +13:00
parent 1229f3d44e
commit 444a13f349
7 changed files with 308 additions and 28 deletions

View file

@ -89,6 +89,7 @@ namespace HISP.Game.Horse
Category = "KEEPER";
Spoiled = 0;
MagicUsed = 0;
TrainTimer = 0;
RanchId = 0;
Leaser = 0;
}
@ -100,6 +101,7 @@ namespace HISP.Game.Horse
public string Description;
public string Sex;
public string Color;
public int TrainTimer;
public HorseInfo.Breed Breed;
public HorseInfo.BasicStats BasicStats;
public HorseInfo.AdvancedStats AdvancedStats;
@ -109,6 +111,5 @@ namespace HISP.Game.Horse
public int MagicUsed;
public string Category;
}
}

View file

@ -211,6 +211,16 @@ namespace HISP.Game
public static string HorseReleaseButton;
public static string HorseOthers;
// Tack horse menu
public static string HorseTackedAsFollows;
public static string HorseUnEquipSaddleFormat;
public static string HorseUnEquipSadlePadFormat;
public static string HorseUnEquipBridleFormat;
public static string HorseTackInInventory;
public static string HorseEquipFormat;
public static string HorseBackTo;
// Consume
public static string ConsumeItemFormat;
@ -410,9 +420,9 @@ namespace HISP.Game
{
return HorseReleasedByFormat.Replace("%USERNAME%", name);
}
public static string FormatHorseHandsHigh(string color, string sex, int handsHigh)
public static string FormatHorseHandsHigh(string color, string breed,string sex, int handsHigh)
{
return HorseHandsHeightFormat.Replace("%COLOR%", color).Replace("%SEX%", sex).Replace("%HANDS%", handsHigh.ToString());
return HorseHandsHeightFormat.Replace("%COLOR%", color).Replace("%SEX%", sex).Replace("%HANDS%", handsHigh.ToString()).Replace("%BREED%", breed);
}
public static string FormatHorseExperience(int experience)
{

View file

@ -708,6 +708,7 @@ namespace HISP.Game
return message;
}
public static string BuildFindNpcMenu()
{
string message = Messages.LibaryFindNpc;
@ -875,26 +876,32 @@ namespace HISP.Game
}
return Messages.FormatAbuseReportMetaPage(reportReasons);
}
public static string BuildHorseInventory(User user)
private static string buildHorseList(User user)
{
// TODO: calculate max number based on ranch barns owned.
string message = Messages.FormatHorseHeader(user.HorseInventory.MaxHorses, user.HorseInventory.HorseList.Length);
string message = "";
int i = 1;
foreach(HorseInfo.Category category in HorseInfo.HorseCategories)
foreach (HorseInfo.Category category in HorseInfo.HorseCategories)
{
HorseInstance[] horsesInCategory = user.HorseInventory.GetHorsesInCategory(category);
if(horsesInCategory.Length > 0)
if (horsesInCategory.Length > 0)
{
message += category.Meta;
foreach(HorseInstance instance in horsesInCategory)
foreach (HorseInstance instance in horsesInCategory)
{
message += Messages.FormatHorseEntry(i, instance.Name, instance.Breed.Name, instance.RandomId);
i++;
}
}
}
return message;
}
public static string BuildHorseInventory(User user)
{
// TODO: calculate max number based on ranch barns owned.
string message = Messages.FormatHorseHeader(user.HorseInventory.MaxHorses, user.HorseInventory.HorseList.Length);
message += buildHorseList(user);
message += Messages.ViewBaiscStats;
message += Messages.ViewAdvancedStats;
message += Messages.BackToMap;
@ -962,6 +969,226 @@ namespace HISP.Game
message += Messages.MetaTerminator;
return message;
}
public static string BuildHorseInformation(HorseInstance horse, User user)
{
string message = "";
message += Messages.FormatHorseName(horse.Name);
message += Messages.FormatHorseReleasedBy(Database.GetUsername(horse.Owner));
message += Messages.FormatHorseHandsHigh(horse.Color, horse.Breed.Name, horse.Sex, Convert.ToInt32(Math.Floor(HorseInfo.CalculateHands(horse.AdvancedStats.Height))));
message += Messages.FormatHorseExperience(horse.BasicStats.Experience);
if (horse.TrainTimer > 0)
message += Messages.FormatTrainableIn(horse.TrainTimer);
else
message += Messages.HorseIsTrainable;
message += Messages.FormatMountButton(horse.RandomId);
message += Messages.FormatFeedButton(horse.RandomId);
message += Messages.FormatTackButton(horse.RandomId);
message += Messages.FormatPetButton(horse.RandomId);
message += Messages.FormatProfileButton(horse.RandomId);
string autoSellMessage = Messages.HorseNoAutoSell;
if (horse.AutoSell > 0)
autoSellMessage = Messages.FormatAutoSellPrice(horse.AutoSell);
message += Messages.FormatAutoSell(autoSellMessage);
message += Messages.FormatHorseCategory(horse.Category);
message += Messages.HorseStats;
// What is energy?
message += Messages.FormatHorseBasicStat(horse.BasicStats.Health, horse.BasicStats.Hunger, horse.BasicStats.Thirst, horse.BasicStats.Mood, 1000, horse.BasicStats.Groom, horse.BasicStats.Groom);
message += Messages.HorseTacked;
if (horse.Equipment.Saddle != null)
message += Messages.FormatHorseTackEntry(horse.Equipment.Saddle.IconId, horse.Equipment.Saddle.Name, horse.Equipment.Saddle.Id);
if (horse.Equipment.SaddlePad != null)
message += Messages.FormatHorseTackEntry(horse.Equipment.SaddlePad.IconId, horse.Equipment.SaddlePad.Name, horse.Equipment.SaddlePad.Id);
if (horse.Equipment.Bridle != null)
message += Messages.FormatHorseTackEntry(horse.Equipment.Bridle.IconId, horse.Equipment.Bridle.Name, horse.Equipment.Bridle.Id);
message += Messages.HorseCompanion;
if (horse.Equipment.Companion != null)
message += Messages.FormatHorseCompanionEntry(horse.Equipment.Companion.IconId, horse.Equipment.Companion.Name, horse.Equipment.Companion.Id);
else
message += Messages.HorseNoCompanion;
message += Messages.FormatHorseAdvancedStats(horse.Spoiled, horse.MagicUsed);
int CompanionBoostAgility = 0;
int CompanionBoostConformation = 0;
int CompanionBoostEndurance = 0;
int CompanionBoostPersonality = 0;
int CompanionBoostSpeed = 0;
int CompanionBoostStrength = 0;
int CompanionBoostInteligence = 0;
int TackBoostAgility = 0;
int TackBoostConformation = 0;
int TackBoostEndurance = 0;
int TackBoostPersonality = 0;
int TackBoostSpeed = 0;
int TackBoostStrength = 0;
int TackBoostInteligence = 0;
if(horse.Equipment.Saddle != null)
{
foreach (Item.Effects effect in horse.Equipment.Saddle.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITY":
TackBoostAgility += effect.EffectAmount;
break;
case "CONFORMATION":
TackBoostConformation += effect.EffectAmount;
break;
case "ENDURANCE":
TackBoostEndurance += effect.EffectAmount;
break;
case "PERSONALITY":
TackBoostPersonality += effect.EffectAmount;
break;
case "SPEED":
TackBoostSpeed += effect.EffectAmount;
break;
case "STRENGTH":
TackBoostStrength += effect.EffectAmount;
break;
case "INTELLIGENCEOFFSET":
TackBoostInteligence += effect.EffectAmount;
break;
}
}
}
if (horse.Equipment.SaddlePad != null)
{
foreach (Item.Effects effect in horse.Equipment.SaddlePad.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITY":
TackBoostAgility += effect.EffectAmount;
break;
case "CONFORMATION":
TackBoostConformation += effect.EffectAmount;
break;
case "ENDURANCE":
TackBoostEndurance += effect.EffectAmount;
break;
case "PERSONALITY":
TackBoostPersonality += effect.EffectAmount;
break;
case "SPEED":
TackBoostSpeed += effect.EffectAmount;
break;
case "STRENGTH":
TackBoostStrength += effect.EffectAmount;
break;
case "INTELLIGENCEOFFSET":
TackBoostInteligence += effect.EffectAmount;
break;
}
}
}
if (horse.Equipment.Bridle != null)
{
foreach (Item.Effects effect in horse.Equipment.Bridle.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITY":
TackBoostAgility += effect.EffectAmount;
break;
case "CONFORMATION":
TackBoostConformation += effect.EffectAmount;
break;
case "ENDURANCE":
TackBoostEndurance += effect.EffectAmount;
break;
case "PERSONALITY":
TackBoostPersonality += effect.EffectAmount;
break;
case "SPEED":
TackBoostSpeed += effect.EffectAmount;
break;
case "STRENGTH":
TackBoostStrength += effect.EffectAmount;
break;
case "INTELLIGENCE":
TackBoostInteligence += effect.EffectAmount;
break;
}
}
}
if (horse.Equipment.Companion != null)
{
foreach (Item.Effects effect in horse.Equipment.Companion.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITY":
CompanionBoostAgility += effect.EffectAmount;
break;
case "CONFORMATION":
CompanionBoostConformation += effect.EffectAmount;
break;
case "ENDURANCE":
CompanionBoostEndurance += effect.EffectAmount;
break;
case "PERSONALITY":
CompanionBoostPersonality += effect.EffectAmount;
break;
case "SPEED":
CompanionBoostSpeed += effect.EffectAmount;
break;
case "STRENGTH":
CompanionBoostStrength += effect.EffectAmount;
break;
case "INTELLIGENCE":
CompanionBoostInteligence += effect.EffectAmount;
break;
}
}
}
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Speed + horse.AdvancedStats.Speed, CompanionBoostSpeed, TackBoostSpeed, horse.Breed.BaseStats.Speed * 2);
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Strength + horse.AdvancedStats.Strength, CompanionBoostStrength, TackBoostStrength, horse.Breed.BaseStats.Strength * 2);
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Conformation + horse.AdvancedStats.Conformation, CompanionBoostConformation, TackBoostConformation, horse.Breed.BaseStats.Conformation * 2);
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Agility + horse.AdvancedStats.Agility, CompanionBoostAgility, TackBoostAgility, horse.Breed.BaseStats.Agility * 2);
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Inteligence + horse.AdvancedStats.Inteligence, CompanionBoostInteligence, TackBoostInteligence, horse.Breed.BaseStats.Inteligence * 2);
message += Messages.FormatHorseAdvancedStat(horse.Breed.BaseStats.Personality + horse.AdvancedStats.Personality, CompanionBoostPersonality, TackBoostPersonality, horse.Breed.BaseStats.Personality * 2);
message += Messages.FormatHorseBreedDetails(horse.Breed.Name, horse.Breed.Description);
message += Messages.FormatHorseHeight(Convert.ToInt32(Math.Floor(HorseInfo.CalculateHands(horse.Breed.BaseStats.MinHeight))), Convert.ToInt32(Math.Floor(HorseInfo.CalculateHands(horse.Breed.BaseStats.MaxHeight))));
message += Messages.FormatPossibleColors(horse.Breed.Colors);
if(!World.InTown(user.X, user.Y))
{
message += Messages.HorseReleaseButton;
}
message += Messages.HorseOthers;
message += buildHorseList(user);
message += Messages.BackToMap;
message += Messages.MetaTerminator;
return message;
}
public static string BuildChatpoint(User user, Npc.NpcEntry npc, Npc.NpcChat chatpoint)
{
bool hideReplys = false;

View file

@ -35,8 +35,8 @@ namespace HISP.Server
string Leaderboards = "CREATE TABLE Leaderboards(playerId INT, minigame TEXT(128), wins INT, looses INT, timesplayed INT, score INT, type TEXT(128))";
string NpcStartPoint = "CREATE TABLE NpcStartPoint(playerId INT, npcId INT, chatpointId INT)";
string PoetryRooms = "CREATE TABLE PoetryRooms(poetId INT, X INT, Y INT, roomId INT)";
string Horses = "CREATE TABLE Horses(randomId INT, ownerId INT, ranchId INT, leaser INT, breed INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, autoSell INT, category TEXT(128), spoiled INT, magicUsed INT)";
string WildHorse = "CREATE TABLE WildHorse(randomId INT, originalOwner INT, breed INT, x INT, y INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, timeout INT, autoSell INT, category TEXT(128), spoiled INT, magicUsed INT)";
string Horses = "CREATE TABLE Horses(randomId INT, ownerId INT, ranchId INT, leaser INT, breed INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, autoSell INT, trainTimer INT, category TEXT(128), spoiled INT, magicUsed INT)";
string WildHorse = "CREATE TABLE WildHorse(randomId INT, originalOwner INT, breed INT, x INT, y INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, timeout INT, autoSell INT, trainTimer INT, category TEXT(128), spoiled INT, magicUsed INT)";
string LastPlayer = "CREATE TABLE LastPlayer(roomId TEXT(1028), playerId INT)";
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
@ -401,7 +401,7 @@ namespace HISP.Server
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO Horses VALUES(@randomId,@originalOwner,@ranch,@leaser,@breed,@name,@description,@sex,@color,@health,@shoes,@hunger,@thirst,@mood,@groom,@tiredness,@experience,@speed,@strength,@conformation,@agility,@endurance,@inteligence,@personality,@height,@saddle,@saddlepad,@bridle,@companion,@autosell,@category,@spoiled,@magicused)";
sqlCommand.CommandText = "INSERT INTO Horses VALUES(@randomId,@originalOwner,@ranch,@leaser,@breed,@name,@description,@sex,@color,@health,@shoes,@hunger,@thirst,@mood,@groom,@tiredness,@experience,@speed,@strength,@conformation,@agility,@endurance,@inteligence,@personality,@height,@saddle,@saddlepad,@bridle,@companion,@autosell,@training,@category,@spoiled,@magicused)";
sqlCommand.Parameters.AddWithValue("@randomId", horse.RandomId);
sqlCommand.Parameters.AddWithValue("@originalOwner", horse.Owner);
@ -456,6 +456,7 @@ namespace HISP.Server
sqlCommand.Parameters.AddWithValue("@autosell", horse.AutoSell);
sqlCommand.Parameters.AddWithValue("@training", horse.TrainTimer);
sqlCommand.Parameters.AddWithValue("@category", horse.Category);
sqlCommand.Parameters.AddWithValue("@spoiled", horse.Spoiled);
sqlCommand.Parameters.AddWithValue("@magicused", horse.MagicUsed);
@ -521,9 +522,10 @@ namespace HISP.Server
inst.Equipment.Companion = Item.GetItemById(reader.GetInt32(28));
inst.AutoSell = reader.GetInt32(29);
inst.Category = reader.GetString(30);
inst.Spoiled = reader.GetInt32(31);
inst.MagicUsed = reader.GetInt32(32);
inst.TrainTimer = reader.GetInt32(30);
inst.Category = reader.GetString(31);
inst.Spoiled = reader.GetInt32(32);
inst.MagicUsed = reader.GetInt32(33);
inv.AddHorse(inst, false);
}
@ -538,7 +540,7 @@ namespace HISP.Server
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO WildHorse VALUES(@randomId,@originalOwner,@breed,@x,@y,@name,@description,@sex,@color,@health,@shoes,@hunger,@thirst,@mood,@groom,@tiredness,@experience,@speed,@strength,@conformation,@agility,@endurance,@inteligence,@personality,@height,@saddle,@saddlepad,@bridle,@companion,@timeout,@autosell,@category,@spoiled,@magicused)";
sqlCommand.CommandText = "INSERT INTO WildHorse VALUES(@randomId,@originalOwner,@breed,@x,@y,@name,@description,@sex,@color,@health,@shoes,@hunger,@thirst,@mood,@groom,@tiredness,@experience,@speed,@strength,@conformation,@agility,@endurance,@inteligence,@personality,@height,@saddle,@saddlepad,@bridle,@companion,@timeout,@autosell,@training,@category,@spoiled,@magicused)";
sqlCommand.Parameters.AddWithValue("@randomId", horse.Instance.RandomId);
sqlCommand.Parameters.AddWithValue("@originalOwner", horse.Instance.Owner);
@ -594,6 +596,7 @@ namespace HISP.Server
sqlCommand.Parameters.AddWithValue("@timeout", horse.Timeout);
sqlCommand.Parameters.AddWithValue("@autosell", horse.Instance.AutoSell);
sqlCommand.Parameters.AddWithValue("@training", horse.Instance.TrainTimer);
sqlCommand.Parameters.AddWithValue("@category", horse.Instance.Category);
sqlCommand.Parameters.AddWithValue("@spoiled", horse.Instance.Spoiled);
sqlCommand.Parameters.AddWithValue("@magicused", horse.Instance.MagicUsed);
@ -658,9 +661,10 @@ namespace HISP.Server
inst.Equipment.Companion = Item.GetItemById(reader.GetInt32(28));
inst.AutoSell = reader.GetInt32(30);
inst.Category = reader.GetString(31);
inst.Spoiled = reader.GetInt32(32);
inst.MagicUsed = reader.GetInt32(33);
inst.TrainTimer = reader.GetInt32(31);
inst.Category = reader.GetString(32);
inst.Spoiled = reader.GetInt32(33);
inst.MagicUsed = reader.GetInt32(34);
int x = reader.GetInt32(3);
int y = reader.GetInt32(4);

View file

@ -104,7 +104,7 @@ namespace HISP.Server
byte[] metaTags = PacketBuilder.CreateMetaPacket(Meta.BuildHorseInventory(sender.LoggedinUser));
sender.SendPacket(metaTags);
break;
case PacketBuilder.HORSE_LOOK:
case PacketBuilder.HORSE_MOUNT:
int randomId = 0;
string packetStr = Encoding.UTF8.GetString(packet);
string randomIdStr = packetStr.Substring(2, packetStr.Length - 4);
@ -112,6 +112,33 @@ namespace HISP.Server
{
randomId = int.Parse(randomIdStr);
}
catch (Exception)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid randomid to horse interaction packet ");
break;
}
if (sender.LoggedinUser.HorseInventory.HorseIdExist(randomId))
{
HorseInstance horseInst = sender.LoggedinUser.HorseInventory.GetHorseById(randomId);
break;
}
else
{
Logger.HackerPrint(sender.LoggedinUser.Username + " Tried to mont at a non existant horse.");
break;
}
break;
case PacketBuilder.HORSE_LOOK:
randomId = 0;
packetStr = Encoding.UTF8.GetString(packet);
randomIdStr = packetStr.Substring(2, packetStr.Length - 4);
try
{
randomId = int.Parse(randomIdStr);
}
catch (Exception)
{
@ -122,10 +149,11 @@ namespace HISP.Server
{
int TileID = Map.GetTileId(sender.LoggedinUser.X, sender.LoggedinUser.Y, false);
string type = Map.TerrainTiles[TileID - 1].Type;
HorseInstance horse = sender.LoggedinUser.HorseInventory.GetHorseById(randomId);
string loadSwf = HorseInfo.BreedViewerSwf(horse, type);
HorseInstance horseInst = sender.LoggedinUser.HorseInventory.GetHorseById(randomId);
byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildHorseInformation(horseInst, sender.LoggedinUser));
sender.SendPacket(metaPacket);
string loadSwf = HorseInfo.BreedViewerSwf(horseInst, type);
byte[] swfPacket = PacketBuilder.CreateSwfModulePacket(loadSwf, PacketBuilder.PACKET_SWF_MODULE_FORCE);
sender.SendPacket(swfPacket);

View file

@ -48,6 +48,7 @@ namespace HISP.Server
public const byte HORSE_LIST = 0x0A;
public const byte HORSE_LOOK = 0x14;
public const byte HORSE_TRY_CAPTURE = 0x1C;
public const byte HORSE_MOUNT = 0x46;
public const byte HORSE_ESCAPE = 0x1E;
public const byte HORSE_CAUGHT = 0x1D;