From a7ad6fc60c750c721109e0957c46c5317fc9b931 Mon Sep 17 00:00:00 2001
From: SilicaAndPina <earsyum@gmail.com>
Date: Fri, 12 Feb 2021 12:13:37 +1300
Subject: [PATCH] Add pot of gold.

---
 DataCollection/gamedata.json                    |  5 +++--
 .../HorseIsleServer/Game/Messages.cs            |  5 +++++
 Horse Isle Server/HorseIsleServer/Game/Quest.cs |  4 +++-
 .../HorseIsleServer/Game/Treasure.cs            |  3 +++
 .../HorseIsleServer/Server/GameDataJson.cs      |  1 +
 .../HorseIsleServer/Server/GameServer.cs        | 17 ++++++++++++++++-
 6 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json
index 1517ecd..8883f95 100755
--- a/DataCollection/gamedata.json
+++ b/DataCollection/gamedata.json
@@ -13,7 +13,8 @@
 	"random_movement":"You are sooo <B>%STAT%</B>.  You wander dizzily in a different direction.",
 	"incorrect_password":"Incorrect.  You will have to find the correct answer somewhere...",
 	"treasure":{
-		"pirate_treasure":"Wow!  You found buried treasure worth $%PRIZE%! Gotta love those pirates!"
+		"pirate_treasure":"Wow!  You found buried treasure worth $%PRIZE%! Gotta love those pirates!",
+		"pot_of_gold":"YEA!  You found the fabled pot of gold at the end of the rainbow! It was worth $%PRIZE%!"
 	},
 	"new_user":{
 	 "starting_message":"<B>Welcome Newest Rider of Horse Isle!</B><BR>Start by talking to Welcome Willy in the cabin. Click the TALK button by his name in the right hand window. He will know the location of a buried treasure on this island!  Move to the spot he describes using the arrow keys.  Then Click the WRENCH Icon at the lower right.",
@@ -567,7 +568,7 @@
 				{"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":"PotOfGold","value":"Pot Of Golds"},
 				{"id":"GameUpdates","value":"Game Updates / Resets"},
 				{"id":"UnipegTeamup","value":"UniPeg Team-up"}
 			],
diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs
index f621451..b66b149 100755
--- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs	
+++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs	
@@ -419,6 +419,7 @@ namespace HISP.Game
 
         // Treasure
         public static string PirateTreasureFormat;
+        public static string PotOfGoldFormat;
 
 
         // Groomer
@@ -778,6 +779,10 @@ namespace HISP.Game
         {
             return PirateTreasureFormat.Replace("%PRIZE%", prize.ToString("N0"));
         }
+        public static string FormatPotOfGold(int prize)
+        {
+            return PotOfGoldFormat.Replace("%PRIZE%", prize.ToString("N0"));
+        }
         public static string FormatWorkshopCraftEntry(int iconId, string itemName, int price, int itemId, int craftId)
         {
             return WorkshopCraftEntryFormat.Replace("%ICONID%", iconId.ToString()).Replace("%ITEMNAME%", itemName).Replace("%PRICE%", price.ToString("N0")).Replace("%ITEMID%", itemId.ToString()).Replace("%CRAFTID%", craftId.ToString());
diff --git a/Horse Isle Server/HorseIsleServer/Game/Quest.cs b/Horse Isle Server/HorseIsleServer/Game/Quest.cs
index c9906af..ea8d520 100755
--- a/Horse Isle Server/HorseIsleServer/Game/Quest.cs	
+++ b/Horse Isle Server/HorseIsleServer/Game/Quest.cs	
@@ -336,7 +336,9 @@ namespace HISP.Game
                 // check Treasures
                 if (Treasure.IsTileTreasure(x, y))
                 {
-                    Treasure.GetTreasureAt(x, y).CollectTreasure(user);
+                    Treasure treasure = Treasure.GetTreasureAt(x, y);
+                    if(treasure.Type == "BURIED")
+                        treasure.CollectTreasure(user);
                     return true;
                 }
             }
diff --git a/Horse Isle Server/HorseIsleServer/Game/Treasure.cs b/Horse Isle Server/HorseIsleServer/Game/Treasure.cs
index 97a49ba..ad1e477 100644
--- a/Horse Isle Server/HorseIsleServer/Game/Treasure.cs	
+++ b/Horse Isle Server/HorseIsleServer/Game/Treasure.cs	
@@ -157,6 +157,9 @@ namespace HISP.Game
             }
             else if(this.Type == "RAINBOW")
             {
+                byte[] treasureReceivedPacket = PacketBuilder.CreateChat(Messages.FormatPotOfGold(this.Value), PacketBuilder.CHAT_BOTTOM_RIGHT);
+                user.LoggedinClient.SendPacket(treasureReceivedPacket);
+                
                 user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PotOfGold).Count++;
 
                 if (user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PotOfGold).Count >= 3)
diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs
index d79d237..d027ee3 100755
--- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs	
+++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs	
@@ -729,6 +729,7 @@ namespace HISP.Server
 
             // Treasure
             Messages.PirateTreasureFormat = gameData.messages.treasure.pirate_treasure;
+            Messages.PotOfGoldFormat = gameData.messages.treasure.pot_of_gold;
 
             // Records
             Messages.ProfileSavedMessage = gameData.messages.profile_save;
diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs
index 249e05f..7f569f0 100755
--- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs	
+++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs	
@@ -2809,13 +2809,28 @@ namespace HISP.Server
                 return;
             }
 
-            if(loggedInUser.Y != newY || loggedInUser.X != newX)
+            
+            if (loggedInUser.Y != newY || loggedInUser.X != newX)
             {
                 loggedInUser.Facing = direction + (onHorse * 5);
                 if (moveTwo)
                     direction += 20;
                 loggedInUser.Y = newY;
                 loggedInUser.X = newX;
+
+
+                // check Treasures
+                if (Treasure.IsTileTreasure(loggedInUser.X, loggedInUser.Y))
+                {
+                    Treasure treasure = Treasure.GetTreasureAt(loggedInUser.X, loggedInUser.Y);
+                    if (treasure.Type == "RAINBOW")
+                    {
+                        treasure.CollectTreasure(loggedInUser);
+                        Update(sender);
+                        return;
+                    }
+                }
+
                 byte[] moveResponse = PacketBuilder.CreateMovementPacket(loggedInUser.X, loggedInUser.Y, loggedInUser.CharacterId, loggedInUser.Facing, direction, true);
                 sender.SendPacket(moveResponse);
             }