Add Tracked Items (statistics)

This commit is contained in:
SilicaAndPina 2021-01-15 21:11:08 +13:00
parent 6012ccff8e
commit 83c75fe418
9 changed files with 283 additions and 21 deletions

View file

@ -351,29 +351,32 @@
"icon_mod":420
},
"misc_stats":{
"header":"^ATYour Miscellaneous Stats^H",
"no_stats_recorded":"<BR>None Yet.",
"stat_format":"%STAT% (%COUNT%)<BR>",
"pirate_treasures":"Pirate Treasures",
"travels":"Travels",
"horse_captures":"Horse Captures",
"crafts":"Crafts",
"wishes":"Wishes",
"trainer":"Trainer",
"arena_loss":"Arena Loss",
"trades":"Trades",
"horse_leases":"Horse Leases",
"auto_sell":"Auto Sell",
"pegasus_team_up":"Pegasus Team up",
"horse_giveaway_win":"Horse Giveaway Wins",
"real_time_quiz_win":"Real Time Quiz Wins",
"real_time_riddle":"Real Time Riddles",
"real_time_isle_cards_win":"Real Time Isle Cards Win",
"sold_horse_to_pawneer":"Sold Horse To Pawneer",
"water_balloon_win":"Water Balloon Wins",
"unicorn_team_up":"Unicorn Team up",
"pot_of_gold":"Pot Of Gold",
"game_update_reset":"Game Updates / Resets",
"unipeg_team_up":"UniPeg Team up"
"tracked_items":[
{"id":"PirateTreasure","value":"Pirate Treasures"},
{"id":"Transport","value":"Travels"},
{"id":"HorseCapture","value":"Horse Captures"},
{"id":"Crafting","value":"Crafts"},
{"id":"WishingWell","value":"Wishes"},
{"id":"Training","value":"Trainers"},
{"id":"ArenaLoss","value":"Arena Loss"},
{"id":"Trading","value":"Trades"},
{"id":"HorseLease","value":"Horse Leases"},
{"id":"AutoSells","value":"Auto-Sell"},
{"id":"PegasusTeamup","value":"Pegasus Team-up"},
{"id":"TackShopGiveaway","value":"Horse Giveaway Wins"},
{"id":"QuizWin","value":"Real Time Quiz Wins"},
{"id":"RiddleWin","value":"Real Time Riddles"},
{"id":"IsleCardsGameWin","value":"Real Time Isle Cards Win"},
{"id":"HorsePawn","value":"Sold Horse To Pawneer"},
{"id":"WaterbaloonGameWin","value":"Water Balloon Wins"},
{"id":"UnicornTeamup","value":"Unicorn Team-up"},
{"id":"PotOfGold","value":"Pot Of Gold"},
{"id":"GameUpdates","value":"Game Updates / Resets"},
{"id":"UnipegTeamup","value":"UniPeg Team-up"}
],
},
"stats_page":{
"stats_bar_format":"^ATPlayer %USERNAME%'s Details^H",

View file

@ -57,6 +57,12 @@ namespace HISP.Game
public static string[] StatPlayerFormats;
// Misc Stats
public static string StatMiscHeader;
public static string StatMiscNoneRecorded;
public static string StatMiscEntryFormat;
// Quests Completed Page
public static string QuestLogHeader;
public static string QuestFormat;
@ -465,6 +471,10 @@ namespace HISP.Game
public static string NothingInterestingHere;
public static string FormatMiscStatsEntry(string statName, int value)
{
return StatMiscEntryFormat.Replace("%STAT%", statName).Replace("%COUNT%", value.ToString());
}
public static string FormatCompactedAdvancedStats(int speed, int strength, int conformation, int agility, int endurance, int inteligence, int personality)
{
return HorseAdvancedStatsCompactedFormat.Replace("%SPEED%", speed.ToString()).Replace("%STRENGTH%", strength.ToString()).Replace("%CONFORMATION%",conformation.ToString()).Replace("%AGILITY%", agility.ToString()).Replace("%ENDURANCE%", endurance.ToString()).Replace("%INTELIGENCE%", inteligence.ToString()).Replace("%PERSONALITY%", personality.ToString());

View file

@ -1184,6 +1184,28 @@ namespace HISP.Game
return message;
}
public static string BuildMiscStats(User user)
{
string message = Messages.StatMiscHeader;
if (user.TrackedItems.TrackingItems.Length <= 0)
message += Messages.StatMiscNoneRecorded;
foreach(Tracking.TrackedItem trackedItem in user.TrackedItems.TrackingItems)
{
try
{
message += Messages.FormatMiscStatsEntry(Tracking.GetTrackedItemsStatsMenuName(trackedItem.What), trackedItem.Count);
}
catch(KeyNotFoundException)
{
Logger.ErrorPrint(user.Username + " Has tracked items in db that dont have a value associated.");
continue;
}
}
message += Messages.BackToMap;
message += Messages.MetaTerminator;
return message;
}
public static string BuildTackMenu(HorseInstance horse, User user)
{
string message = Messages.FormatTackedAsFollowedMessage(horse.Name);

View file

@ -0,0 +1,117 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game
{
class Tracking
{
public enum TrackableItem
{
PirateTreasure,
Transport,
HorseCapture,
Crafting,
WishingWell,
Training,
ArenaLoss,
Trading,
HorseLease,
AutoSells,
PegasusTeamup,
TackShopGiveaway,
QuizWin,
RiddleWin,
IsleCardsGameWin,
HorsePawn,
WaterbaloonGameWin,
UnicornTeamup,
PotOfGold,
GameUpdates,
UnipegTeamup
}
public class TrackedItem
{
public TrackedItem(User sbaseUser, TrackableItem what, int itmcount)
{
What = what;
count = itmcount;
baseUser = sbaseUser;
}
public TrackableItem What;
public int Count
{
get
{
return count;
}
set
{
Database.SetTrackedItemCount(baseUser.Id, What, value);
count = value;
}
}
private int count;
private User baseUser;
}
private List<TrackedItem> trackingItems = new List<TrackedItem>();
private User baseUser;
public TrackedItem[] TrackingItems
{
get
{
return trackingItems.ToArray();
}
}
public Tracking(User user)
{
baseUser = user;
for(int i = 0; i < 20; i++)
{
TrackableItem item = (TrackableItem)i;
if(Database.HasTrackedItem(user.Id, item))
{
TrackedItem trackedItem = new TrackedItem(baseUser, item, Database.GetTrackedCount(user.Id, item));
trackingItems.Add(trackedItem);
}
}
}
public TrackedItem GetTrackedItem(TrackableItem what)
{
foreach(TrackedItem trackedItem in TrackingItems)
{
if (trackedItem.What == what)
return trackedItem;
}
// if it doesnt exist- create it
TrackedItem item = new TrackedItem(baseUser, what, 0);
Database.AddTrackedItem(baseUser.Id, what, 0);
trackingItems.Add(item);
return item;
}
public struct TrackedItemStatsMenu
{
public string What;
public string Value;
}
public static List<TrackedItemStatsMenu> TrackedItemsStatsMenu = new List<TrackedItemStatsMenu>();
public static string GetTrackedItemsStatsMenuName(TrackableItem item)
{
foreach(TrackedItemStatsMenu trackedItem in TrackedItemsStatsMenu)
{
if (trackedItem.What == item.ToString())
return trackedItem.Value;
}
throw new KeyNotFoundException("no such tracked item found.");
}
}
}

View file

@ -88,6 +88,7 @@
<Compile Include="Game\Services\Shop.cs" />
<Compile Include="Game\Inventory\ShopInventory.cs" />
<Compile Include="Game\SwfModules\Brickpoet.cs" />
<Compile Include="Game\Tracking.cs" />
<Compile Include="Player\Award.cs" />
<Compile Include="Player\Equips\Jewelry.cs" />
<Compile Include="Player\Equips\CompetitionGear.cs" />

View file

@ -46,6 +46,7 @@ namespace HISP.Player
public HorseInventory HorseInventory;
public HorseInstance LastViewedHorse;
public HorseInstance CurrentlyRidingHorse;
public Tracking TrackedItems;
public PlayerQuests Quests;
public Highscore Highscores;
public Award Awards;
@ -431,6 +432,7 @@ namespace HISP.Player
MailBox = new Mailbox(this);
Highscores = new Highscore(this);
Awards = new Award(this);
TrackedItems = new Tracking(this);
HorseInventory = new HorseInventory(this);
// Generate SecCodes

View file

@ -38,8 +38,23 @@ namespace HISP.Server
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 TrackingStats = "CREATE TABLE Tracking(playerId INT, what TEXT(128), count INT)";
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = TrackingStats;
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
catch (Exception e)
{
Logger.WarnPrint(e.Message);
};
try
{
@ -325,6 +340,74 @@ namespace HISP.Server
}
public static void AddTrackedItem(int playerId, Tracking.TrackableItem what, int count)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO Tracking VALUES(@playerId, @what, @count)";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@what", what.ToString());
sqlCommand.Parameters.AddWithValue("@count", count);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static bool HasTrackedItem(int playerId, Tracking.TrackableItem what)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT COUNT(*) FROM Tracking WHERE playerId=@playerId AND what=@what";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@what", what.ToString());
sqlCommand.Prepare();
int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return count > 0;
}
}
public static int GetTrackedCount(int playerId, Tracking.TrackableItem what)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT count FROM Tracking WHERE playerId=@playerId AND what=@what";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@what", what.ToString());
sqlCommand.Prepare();
int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return count;
}
}
public static void SetTrackedItemCount(int playerId, Tracking.TrackableItem what, int count)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE Tracking SET count=@count WHERE playerId=@playerId AND what=@what";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Parameters.AddWithValue("@what", what.ToString());
sqlCommand.Parameters.AddWithValue("@count", count);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void AddLastPlayer(string roomId, int playerId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))

View file

@ -493,6 +493,15 @@ namespace HISP.Server
HorseInfo.HorseCategories.Add(category);
Logger.DebugPrint("Registered horse category type: " + category.Name);
}
int totalTrackedItems = gameData.messages.meta.misc_stats.tracked_items.Count;
for(int i = 0; i < totalTrackedItems; i++)
{
Tracking.TrackedItemStatsMenu trackedItem = new Tracking.TrackedItemStatsMenu();
trackedItem.What = gameData.messages.meta.misc_stats.tracked_items[i].id;
trackedItem.Value = gameData.messages.meta.misc_stats.tracked_items[i].value;
Tracking.TrackedItemsStatsMenu.Add(trackedItem);
Logger.DebugPrint("Registered Tracked Item: " + trackedItem.What + " value: " + trackedItem.Value);
}
HorseInfo.HorseNames = gameData.horses.names.ToObject<string[]>();
@ -563,6 +572,13 @@ namespace HISP.Server
Messages.StatTired = gameData.messages.meta.stats_page.tired_stat_name;
Messages.StatPlayerFormats = gameData.messages.meta.stats_page.player_stats.ToObject<string[]>();
// Misc Stats
Messages.StatMiscHeader = gameData.messages.meta.misc_stats.header;
Messages.StatMiscNoneRecorded = gameData.messages.meta.misc_stats.no_stats_recorded;
Messages.StatMiscEntryFormat = gameData.messages.meta.misc_stats.stat_format;
// Movement
Messages.RandomMovement = gameData.messages.random_movement;
// Quests Log

View file

@ -748,6 +748,7 @@ namespace HISP.Server
break;
}
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.HorseCapture).Count++;
Logger.InfoPrint(sender.LoggedinUser.Username + " Captured a: " + capturing.Instance.Breed.Name + " new location: " + capturing.X + ", " + capturing.Y);
sender.LoggedinUser.MetaPriority = true;
@ -1190,6 +1191,11 @@ namespace HISP.Server
break;
case "38": // Read Books
break;
case "53": // Misc Stats / Tracked Items
sender.LoggedinUser.MetaPriority = true;
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildMiscStats(sender.LoggedinUser));
sender.SendPacket(metaPacket);
break;
case "28c1": // Abuse Report
sender.LoggedinUser.MetaPriority = true;
metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildAbuseReportPage());
@ -1513,6 +1519,7 @@ namespace HISP.Server
Logger.ErrorPrint("Unknnown Wish type: " + wishType.ToString("X"));
break;
}
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.WishingWell).Count++;
byte[] msg = PacketBuilder.CreateChat(message, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(msg);
@ -2219,6 +2226,7 @@ namespace HISP.Server
}
sender.LoggedinUser.Teleport(transportLocation.GotoX, transportLocation.GotoY);
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Transport).Count++;
byte[] welcomeToIslePacket = PacketBuilder.CreateChat(Messages.FormatWelcomeToAreaMessage(transportLocation.LocationTitle), PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(welcomeToIslePacket);