mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Add pirate treasures, and pot of gold (Though, text is missing for Pot of Gold- i have to find one in public server first.)
This commit is contained in:
parent
e326dd2bf7
commit
cfdea72b6c
9 changed files with 346 additions and 2 deletions
|
@ -32,6 +32,11 @@ namespace HISP.Game
|
|||
|
||||
int pos = ((x * Height) + y);
|
||||
|
||||
if (overlay && Treasure.IsTileBuiredTreasure(x, y))
|
||||
return 193; // Burried Treasure tile.
|
||||
else if (overlay && Treasure.IsTilePotOfGold(x, y))
|
||||
return 186; // Pot of Gold tile.
|
||||
|
||||
if (overlay)
|
||||
return oMapData[pos];
|
||||
else
|
||||
|
|
|
@ -344,8 +344,12 @@ namespace HISP.Game
|
|||
public static string HorseEquipFormat;
|
||||
public static string BackToHorse;
|
||||
|
||||
// Treasure
|
||||
public static string PirateTreasureFormat;
|
||||
|
||||
|
||||
// Groomer
|
||||
|
||||
public static string GroomerBestToHisAbilitiesFormat;
|
||||
public static string GroomerCannotAffordMessage;
|
||||
public static string GroomerHorseCurrentlyAtFormat;
|
||||
|
@ -587,6 +591,10 @@ namespace HISP.Game
|
|||
// Click
|
||||
public static string NothingInterestingHere;
|
||||
|
||||
public static string FormatPirateTreasure(int prize)
|
||||
{
|
||||
return PirateTreasureFormat.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());
|
||||
|
|
|
@ -330,6 +330,15 @@ namespace HISP.Game
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(tool == Quest.Shovel)
|
||||
{
|
||||
// Also check Treasures
|
||||
if (Treasure.IsTileTreasure(x, y))
|
||||
Treasure.GetTreasureAt(x, y).CollectTreasure(user);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
239
Horse Isle Server/HorseIsleServer/Game/Treasure.cs
Normal file
239
Horse Isle Server/HorseIsleServer/Game/Treasure.cs
Normal file
|
@ -0,0 +1,239 @@
|
|||
using HISP.Player;
|
||||
using HISP.Server;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
public class Treasure
|
||||
{
|
||||
private static List<Treasure> treasures = new List<Treasure>();
|
||||
public static Treasure[] Treasures
|
||||
{
|
||||
get
|
||||
{
|
||||
return treasures.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private int value;
|
||||
|
||||
public int RandomId;
|
||||
public int X;
|
||||
public int Y;
|
||||
public int Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return value;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.value = value;
|
||||
Database.SetTreasureValue(RandomId, value);
|
||||
}
|
||||
}
|
||||
|
||||
public string Type;
|
||||
public Treasure(int x, int y, string type, int randomId = -1, int moneyValue=-1)
|
||||
{
|
||||
RandomId = Security.RandomID.NextRandomId(randomId);
|
||||
|
||||
if(type == "BURIED")
|
||||
{
|
||||
if(moneyValue == -1)
|
||||
value = GameServer.RandomNumberGenerator.Next(100,5000);
|
||||
}
|
||||
else if(type == "RAINBOW")
|
||||
{
|
||||
if (moneyValue == -1)
|
||||
value = GameServer.RandomNumberGenerator.Next(10000, 50000);
|
||||
}
|
||||
|
||||
if (moneyValue != -1)
|
||||
value = moneyValue;
|
||||
|
||||
X = x;
|
||||
Y = y;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public static int NumberOfPirates()
|
||||
{
|
||||
int count = 0;
|
||||
foreach (Treasure treasure in Treasures)
|
||||
{
|
||||
if (treasure.Type == "BURIED")
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int NumberOfRainbows()
|
||||
{
|
||||
int count = 0;
|
||||
foreach(Treasure treasure in Treasures)
|
||||
{
|
||||
if (treasure.Type == "RAINBOW")
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static bool IsTileTreasure(int x, int y)
|
||||
{
|
||||
foreach (Treasure treasure in Treasures)
|
||||
{
|
||||
if (treasure.X == x && treasure.Y == y)
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool IsTileBuiredTreasure(int x, int y)
|
||||
{
|
||||
foreach (Treasure treasure in Treasures)
|
||||
{
|
||||
if (treasure.Type == "BURIED")
|
||||
{
|
||||
if (treasure.X == x && treasure.Y == y)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsTilePotOfGold(int x, int y)
|
||||
{
|
||||
foreach(Treasure treasure in Treasures)
|
||||
{
|
||||
if(treasure.Type == "RAINBOW")
|
||||
{
|
||||
if (treasure.X == x && treasure.Y == y)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Treasure GetTreasureAt(int x, int y)
|
||||
{
|
||||
foreach (Treasure treasure in Treasures)
|
||||
{
|
||||
if (treasure.X == x && treasure.Y == y)
|
||||
return treasure;
|
||||
}
|
||||
throw new KeyNotFoundException("NO Treasure at " + x + "," + y);
|
||||
}
|
||||
|
||||
public static void AddValue()
|
||||
{
|
||||
foreach(Treasure treasure in treasures)
|
||||
{
|
||||
treasure.Value += 1;
|
||||
}
|
||||
}
|
||||
public void CollectTreasure(User user)
|
||||
{
|
||||
|
||||
treasures.Remove(this);
|
||||
GenerateTreasure();
|
||||
|
||||
byte[] MovementPacket = PacketBuilder.CreateMovementPacket(user.X, user.Y, user.CharacterId, user.Facing, PacketBuilder.DIRECTION_TELEPORT, true);
|
||||
user.LoggedinClient.SendPacket(MovementPacket);
|
||||
|
||||
user.Money += Value;
|
||||
|
||||
if(this.Type == "BURIED")
|
||||
{
|
||||
byte[] treasureReceivedPacket = PacketBuilder.CreateChat(Messages.FormatPirateTreasure(this.Value), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
user.LoggedinClient.SendPacket(treasureReceivedPacket);
|
||||
user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PirateTreasure).Count++;
|
||||
|
||||
if(user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PirateTreasure).Count >= 10)
|
||||
user.Awards.AddAward(Award.GetAwardById(18)); // Pirate Tracker
|
||||
|
||||
if (user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PirateTreasure).Count >= 100)
|
||||
user.Awards.AddAward(Award.GetAwardById(19)); // Pirate Stalker
|
||||
}
|
||||
else if(this.Type == "RAINBOW")
|
||||
{
|
||||
user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PotOfGold).Count++;
|
||||
|
||||
if (user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PotOfGold).Count >= 3)
|
||||
user.Awards.AddAward(Award.GetAwardById(20)); // Leprechaun
|
||||
|
||||
if (user.TrackedItems.GetTrackedItem(Tracking.TrackableItem.PirateTreasure).Count >= 20)
|
||||
user.Awards.AddAward(Award.GetAwardById(21)); // Lucky Leprechaun
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void GenerateTreasure()
|
||||
{
|
||||
while(NumberOfPirates() < 5)
|
||||
{
|
||||
// Pick x/y
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
|
||||
|
||||
if (!Map.CheckPassable(tryX, tryY)) // can the player walk here?
|
||||
continue;
|
||||
|
||||
if (World.InTown(tryX, tryY)) // in a town?
|
||||
continue;
|
||||
|
||||
if (Map.GetTileId(tryX, tryY, true) != 1) // is there allready an overlay here?
|
||||
continue;
|
||||
|
||||
if (Map.TerrainTiles[Map.GetTileId(tryX, tryY, false) - 1].Type != "BEACH")
|
||||
continue;
|
||||
|
||||
// Create Treasure
|
||||
Treasure treasure = new Treasure(tryX, tryY, "BURIED");
|
||||
treasures.Add(treasure);
|
||||
Database.AddTreasure(treasure.RandomId, treasure.X, treasure.Y, treasure.Value, treasure.Type);
|
||||
|
||||
Logger.DebugPrint("Created Pirate Treasure at " + treasure.X + "," + treasure.Y + " with value: " + treasure.Value);
|
||||
|
||||
}
|
||||
|
||||
while (NumberOfRainbows() < 1)
|
||||
{
|
||||
// Pick x/y
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
|
||||
|
||||
if (!Map.CheckPassable(tryX, tryY)) // can the player walk here?
|
||||
continue;
|
||||
|
||||
if (World.InTown(tryX, tryY)) // in a town?
|
||||
continue;
|
||||
|
||||
if (Map.GetTileId(tryX, tryY, true) != 1) // is there allready an overlay here?
|
||||
continue;
|
||||
|
||||
if (Map.TerrainTiles[Map.GetTileId(tryX, tryY, false) - 1].Type != "GRASS" && Map.TerrainTiles[Map.GetTileId(tryX, tryY, false) - 1].Type != "BEACH") // Grass and BEACH tiles only.
|
||||
continue;
|
||||
|
||||
// Create Treasure
|
||||
Treasure treasure = new Treasure(tryX, tryY, "RAINBOW");
|
||||
treasures.Add(treasure);
|
||||
Database.AddTreasure(treasure.RandomId, treasure.X, treasure.Y, treasure.Value, treasure.Type);
|
||||
|
||||
Logger.DebugPrint("Created Pot of Gold at " + treasure.X + "," + treasure.Y + " with value: " + treasure.Value);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
Treasure[] treasuresLst = Database.GetTreasures();
|
||||
foreach (Treasure treasure in treasuresLst)
|
||||
{
|
||||
treasures.Add(treasure);
|
||||
}
|
||||
|
||||
GenerateTreasure();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -242,6 +242,9 @@ namespace HISP.Player
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value > Map.Width)
|
||||
value = Map.Width;
|
||||
|
||||
Database.SetPlayerX(value, Id);
|
||||
x = value;
|
||||
}
|
||||
|
@ -255,6 +258,8 @@ namespace HISP.Player
|
|||
}
|
||||
set
|
||||
{
|
||||
if (value > Map.Height)
|
||||
value = Map.Height;
|
||||
Database.SetPlayerY(value, Id);
|
||||
y = value;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,11 @@ namespace HISP
|
|||
CrossDomainPolicy.GetPolicy();
|
||||
Database.OpenDatabase();
|
||||
GameDataJson.ReadGamedata();
|
||||
|
||||
Map.OpenMap();
|
||||
World.ReadWorldData();
|
||||
Treasure.Init();
|
||||
|
||||
DroppedItems.Init();
|
||||
WildHorse.Init();
|
||||
Brickpoet.LoadPoetryRooms();
|
||||
|
|
|
@ -412,6 +412,62 @@ namespace HISP.Server
|
|||
|
||||
}
|
||||
|
||||
public static void SetTreasureValue(int randomId, int value)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "UPDATE Treasure SET value=@value";
|
||||
sqlCommand.Parameters.AddWithValue("@value", value);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTreasure(int randomId, int x, int y, int value, string type)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "INSERT INTO Treasure VALUES(@randomId, @x, @y, @value, @type)";
|
||||
sqlCommand.Parameters.AddWithValue("@randomId", randomId);
|
||||
sqlCommand.Parameters.AddWithValue("@x", x);
|
||||
sqlCommand.Parameters.AddWithValue("@y", y);
|
||||
sqlCommand.Parameters.AddWithValue("@value", value);
|
||||
sqlCommand.Parameters.AddWithValue("@type", type);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
public static Treasure[] GetTreasures()
|
||||
{
|
||||
List<Treasure> treasures = new List<Treasure>();
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT * FROM Treasure";
|
||||
MySqlDataReader reader = sqlCommand.ExecuteReader();
|
||||
while(reader.Read())
|
||||
{
|
||||
int randomId = reader.GetInt32(0);
|
||||
int x = reader.GetInt32(1);
|
||||
int y = reader.GetInt32(2);
|
||||
int value = reader.GetInt32(3);
|
||||
string type = reader.GetString(4);
|
||||
Treasure treasure = new Treasure(x, y, type, randomId, value);
|
||||
treasures.Add(treasure);
|
||||
}
|
||||
sqlCommand.Dispose();
|
||||
return treasures.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTrackedItem(int playerId, Tracking.TrackableItem what, int count)
|
||||
{
|
||||
|
|
|
@ -592,6 +592,9 @@ namespace HISP.Server
|
|||
Map.NewUserStartX = gameData.messages.new_user.starting_x;
|
||||
Map.NewUserStartY = gameData.messages.new_user.starting_y;
|
||||
|
||||
// Treasure
|
||||
Messages.PirateTreasureFormat = gameData.messages.treasure.pirate_treasure;
|
||||
|
||||
// Records
|
||||
Messages.ProfileSavedMessage = gameData.messages.profile_save;
|
||||
Messages.PrivateNotesSavedMessage = gameData.messages.private_notes_save;
|
||||
|
|
|
@ -84,8 +84,7 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Treasure.AddValue();
|
||||
Database.IncPlayerTirednessForOfflineUsers();
|
||||
DroppedItems.Update();
|
||||
WildHorse.Update();
|
||||
|
@ -951,6 +950,12 @@ namespace HISP.Server
|
|||
}
|
||||
|
||||
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.HorseCapture).Count++;
|
||||
|
||||
if(sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.HorseCapture).Count >= 100)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(24)); // Wrangler
|
||||
if (sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.HorseCapture).Count >= 1000)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(25)); // Pro Wrangler
|
||||
|
||||
Logger.InfoPrint(sender.LoggedinUser.Username + " Captured a: " + capturing.Instance.Breed.Name + " new location: " + capturing.X + ", " + capturing.Y);
|
||||
|
||||
sender.LoggedinUser.MetaPriority = true;
|
||||
|
@ -2819,6 +2824,12 @@ namespace HISP.Server
|
|||
sender.LoggedinUser.Teleport(transportLocation.GotoX, transportLocation.GotoY);
|
||||
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Transport).Count++;
|
||||
|
||||
|
||||
if (sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Transport).Count >= 500)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(27)); // Traveller
|
||||
if (sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Transport).Count >= 5000)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(28)); // Globetrotter
|
||||
|
||||
byte[] welcomeToIslePacket = PacketBuilder.CreateChat(Messages.FormatWelcomeToAreaMessage(transportLocation.LocationTitle), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
sender.SendPacket(welcomeToIslePacket);
|
||||
|
||||
|
@ -3469,6 +3480,11 @@ namespace HISP.Server
|
|||
|
||||
sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Crafting).Count++;
|
||||
|
||||
if (sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Crafting).Count >= 100)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(22)); // Craftiness
|
||||
if (sender.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.Crafting).Count >= 1000)
|
||||
sender.LoggedinUser.Awards.AddAward(Award.GetAwardById(23)); // Workmanship
|
||||
|
||||
byte[] itemCraftSuccess = PacketBuilder.CreateChat(Messages.WorkshopCraftingSuccess, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
sender.SendPacket(itemCraftSuccess);
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue