Add changing weather.

This commit is contained in:
SilicaAndPina 2021-02-03 18:41:38 +13:00
parent 6c42c57bfe
commit b4920205c8
7 changed files with 245 additions and 16 deletions

View file

@ -133,6 +133,10 @@
"venus_flytrap_format":"The Giant Venus Flytrap chomped at you!<BR><B>OUCH!!</B><BR>It chomped your pocket, taking $%MONEY% with it!!",
"password_input":"<BR>^PLReply:|^PS14|ANSWER^R1",
"last_poet":"^R1^LLast Player Poet:%USERNAME% ^R1",
"farrier":{
"shoes_total":"^LYour horse %HORSENAME%: shoes currently %TOTAL%/%MAX%^R1",
"put_on_steel_shoes":"Your horse has had new Steel Horseshoes put on. Now shoes=%TOTAL%/%MAX%.",
},
"vet":{
"service_horse":"^LYour horse %HORSENAME%: health currently %CURHEALTH%/%MAXHEALTH%^R1",
"not_needed":"^I257^T8Vet services are not needed for this horse.^R1",

View file

@ -231,7 +231,7 @@ namespace HISP.Game.Chat
List<GameClient> recipiants = new List<GameClient>();
if(World.InIsle(user.X,user.Y))
{
User[] usersInSile = GameServer.GetUsersUsersInIsle(World.GetIsle(user.X, user.Y), true, false);
User[] usersInSile = GameServer.GetUsersInIsle(World.GetIsle(user.X, user.Y), true, false);
foreach (User userInIsle in usersInSile)
{
if (user.Id != userInIsle.Id)
@ -416,7 +416,7 @@ namespace HISP.Game.Chat
case ChatChannel.Isle:
int inIsle = 0;
if (World.InIsle(user.X, user.Y))
inIsle = GameServer.GetUsersUsersInIsle(World.GetIsle(user.X, user.Y), false, false).Length -1;
inIsle = GameServer.GetUsersInIsle(World.GetIsle(user.X, user.Y), false, false).Length -1;
return Messages.FormatIsleChatMessageForSender(inIsle, user.Username, message);
case ChatChannel.Here:
int usersHere = GameServer.GetUsersAt(user.X, user.Y, false, false).Length -1;

View file

@ -1,4 +1,5 @@
using System.Collections.Generic;
using HISP.Player;
using HISP.Server;
namespace HISP.Game
@ -29,12 +30,53 @@ namespace HISP.Game
}
public class Isle
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public int Tileset;
public string Name;
public string SelectRandomWeather()
{
Waypoint point;
try
{
point = GetWaypoint();
}
catch (KeyNotFoundException)
{
return "SUNNY";
}
int intWeatherType = GameServer.RandomNumberGenerator.Next(0, point.WeatherTypesAvalible.Length);
string weather = point.WeatherTypesAvalible[intWeatherType];
return weather;
}
public string Weather
{
get
{
if (!Database.WeatherExists(Name))
{
string weather = SelectRandomWeather();
Database.InsertWeather(Name, weather);
return weather;
}
else
{
return Database.GetWeather(Name);
}
}
set
{
Database.SetWeather(Name, value);
foreach(User user in GameServer.GetUsersInIsle(this,true,true))
{
GameServer.UpdateArea(user.LoggedinClient);
}
}
}
public Waypoint GetWaypoint()
{
@ -49,7 +91,46 @@ namespace HISP.Game
public int StartY;
public int EndY;
public string Name;
public string SelectRandomWeather()
{
Waypoint point;
try
{
point = GetWaypoint();
}
catch (KeyNotFoundException)
{
return "SUNNY";
}
int intWeatherType = GameServer.RandomNumberGenerator.Next(0, point.WeatherTypesAvalible.Length);
string weather = point.WeatherTypesAvalible[intWeatherType];
return weather;
}
public string Weather
{
get
{
if (!Database.WeatherExists(Name))
{
string weather = SelectRandomWeather();
Database.InsertWeather(Name, weather);
return weather;
}
else
{
return Database.GetWeather(Name);
}
}
set
{
Database.SetWeather(Name, value);
foreach (User user in GameServer.GetUsersInTown(this, true, true))
{
GameServer.UpdateArea(user.LoggedinClient);
}
}
}
public Waypoint GetWaypoint()
{
return getWaypoint(this.Name);
@ -295,9 +376,5 @@ namespace HISP.Game
return true;
}
public static string GetWeather()
{
return Database.GetWorldWeather();
}
}
}

View file

@ -53,7 +53,18 @@ namespace HISP.Player
public Award Awards;
public int CapturingHorseId;
public DateTime LoginTime;
public string LastSeenWeather;
public string GetWeatherSeen()
{
string weather = "SUNNY";
if (World.InTown(this.X, this.Y))
weather = World.GetTown(this.X, this.Y).Weather;
if (World.InIsle(this.X, this.Y))
weather = World.GetIsle(this.X, this.Y).Weather;
LastSeenWeather = weather;
return weather;
}
public DateTime SubscribedUntil
{
get

View file

@ -23,7 +23,8 @@ namespace HISP.Server
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(1028),IpAddress TEXT(1028),PrivateNotes Text(1028), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT)";
string MailTable = "CREATE TABLE Mailbox(IdTo INT, PlayerFrom TEXT(16),Subject TEXT(128), Message Text(1028), TimeSent INT)";
string BuddyTable = "CREATE TABLE BuddyList(Id INT, IdFriend INT, Pending BOOL)";
string WorldTable = "CREATE TABLE World(Time INT,Day INT, Year INT, Weather TEXT(64))";
string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT)";
string WeatherTable = "CREATE TABLE Weather(Area TEXT(1028), Weather TEXT(64))";
string InventoryTable = "CREATE TABLE Inventory(PlayerID INT, RandomID INT, ItemID INT)";
string ShopInventory = "CREATE TABLE ShopInventory(ShopID INT, RandomID INT, ItemID INT)";
string DroppedItems = "CREATE TABLE DroppedItems(X INT, Y INT, RandomID INT, ItemID INT, DespawnTimer INT)";
@ -149,6 +150,19 @@ namespace HISP.Server
Logger.WarnPrint(e.Message);
};
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = WeatherTable;
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
catch (Exception e)
{
Logger.WarnPrint(e.Message);
};
try
{
@ -303,7 +317,7 @@ namespace HISP.Server
sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,'SUNNY')";
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0)";
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
@ -405,6 +419,8 @@ namespace HISP.Server
}
}
public static void SetTrackedItemCount(int playerId, Tracking.TrackableItem what, int count)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -1044,15 +1060,56 @@ namespace HISP.Server
}
public static string GetWorldWeather()
public static bool WeatherExists(string Area)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT Weather FROM World";
sqlCommand.CommandText = "SELECT COUNT(*) FROM Weather WHERE Area=@area";
sqlCommand.Parameters.AddWithValue("@area", Area);
int count = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return count > 0;
}
}
public static void InsertWeather(string Area, string Weather)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO Weather VALUES(@area,@weather)";
sqlCommand.Parameters.AddWithValue("@weather", Weather);
sqlCommand.Parameters.AddWithValue("@area", Area);
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void SetWeather(string Area, string Weather)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE Weather SET Weather=@weather WHERE Area=@area";
sqlCommand.Parameters.AddWithValue("@weather", Weather);
sqlCommand.Parameters.AddWithValue("@area", Area);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static string GetWeather(string Area)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT Weather FROM Weather WHERE Area=@area";
sqlCommand.Parameters.AddWithValue("@area", Area);
string Weather = sqlCommand.ExecuteScalar().ToString();
sqlCommand.Dispose();
return Weather;

View file

@ -64,6 +64,25 @@ namespace HISP.Server
if(totalMinutesElapsed % 24 == 0)
Database.DoIntrestPayments(ConfigReader.IntrestRate);
foreach (World.Town town in World.Towns)
{
if (RandomNumberGenerator.Next(0, 10) > 5)
{
town.Weather = town.SelectRandomWeather();
Logger.DebugPrint("Changing the weather in " + town.Name + " to " + town.Weather);
}
}
foreach (World.Isle isle in World.Isles)
{
if(RandomNumberGenerator.Next(0,10) > 5)
{
isle.Weather = isle.SelectRandomWeather();
Logger.DebugPrint("Changing the weather in " + isle.Name + " to " + isle.Weather);
}
}
Database.IncPlayerTirednessForOfflineUsers();
DroppedItems.Update();
WildHorse.Update();
@ -1540,7 +1559,8 @@ namespace HISP.Server
byte[] WelcomeMessage = PacketBuilder.CreateWelcomeMessage(user.Username);
sender.SendPacket(WelcomeMessage);
byte[] WorldData = PacketBuilder.CreateWorldData(World.ServerTime.Minutes, World.ServerTime.Days, World.ServerTime.Years, World.GetWeather());
byte[] WorldData = PacketBuilder.CreateWorldData(World.ServerTime.Minutes, World.ServerTime.Days, World.ServerTime.Years, sender.LoggedinUser.GetWeatherSeen());
sender.SendPacket(WorldData);
// Send first time message;
@ -3634,7 +3654,25 @@ namespace HISP.Server
return false;
}
}
public static User[] GetUsersUsersInIsle(World.Isle isle, bool includeStealth = false, bool includeMuted = false)
public static User[] GetUsersInTown(World.Town town, bool includeStealth = false, bool includeMuted = false)
{
List<User> usersInTown = new List<User>();
foreach (GameClient client in ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
continue;
if (!includeMuted && client.LoggedinUser.MuteIsland)
continue;
if (World.InTown(client.LoggedinUser.X, client.LoggedinUser.Y))
if (World.GetIsle(client.LoggedinUser.X, client.LoggedinUser.Y).Name == town.Name)
usersInTown.Add(client.LoggedinUser);
}
return usersInTown.ToArray();
}
public static User[] GetUsersInIsle(World.Isle isle, bool includeStealth = false, bool includeMuted = false)
{
List<User> usersInIsle = new List<User>();
foreach (GameClient client in ConnectedClients)
@ -3866,6 +3904,18 @@ namespace HISP.Server
byte[] metaPacket = PacketBuilder.CreateMetaPacket(Meta.BuildInventoryInfo(forClient.LoggedinUser.Inventory));
forClient.SendPacket(metaPacket);
}
public static void UpdateWeather(GameClient forClient)
{
if (!forClient.LoggedIn)
{
Logger.ErrorPrint(forClient.RemoteIp + "tried to update weather information when not logged in.");
return;
}
byte[] WeatherUpdate = PacketBuilder.CreateWeatherUpdatePacket(forClient.LoggedinUser.GetWeatherSeen());
forClient.SendPacket(WeatherUpdate);
}
public static void UpdateWorld(GameClient forClient)
{
if (!forClient.LoggedIn)
@ -3874,7 +3924,7 @@ namespace HISP.Server
return;
}
byte[] WorldData = PacketBuilder.CreateWorldData(World.ServerTime.Minutes, World.ServerTime.Days, World.ServerTime.Years, World.GetWeather());
byte[] WorldData = PacketBuilder.CreateWorldData(World.ServerTime.Minutes, World.ServerTime.Days, World.ServerTime.Years, forClient.LoggedinUser.GetWeatherSeen());
forClient.SendPacket(WorldData);
}
public static void UpdatePlayer(GameClient forClient)
@ -3939,6 +3989,15 @@ namespace HISP.Server
return;
LocationStr = Meta.BuildSpecialTileInfo(forClient.LoggedinUser, specialTile);
}
string lastWeather = forClient.LoggedinUser.LastSeenWeather;
string weather = forClient.LoggedinUser.GetWeatherSeen();
if(lastWeather != weather)
{
byte[] WeatherUpdate = PacketBuilder.CreateWeatherUpdatePacket(weather);
forClient.SendPacket(WeatherUpdate);
}
byte[] AreaMessage = PacketBuilder.CreateMetaPacket(LocationStr);
forClient.SendPacket(AreaMessage);
forClient.LoggedinUser.MetaPriority = false;

View file

@ -139,6 +139,8 @@ namespace HISP.Server
public const byte LOGIN_CUSTOM_MESSAGE = 0x16;
public const byte LOGIN_SUCCESS = 0x14;
public const byte WEATHER_UPDATE = 0x13;
public const byte DIRECTION_UP = 0;
public const byte DIRECTION_RIGHT = 1;
public const byte DIRECTION_DOWN = 2;
@ -146,6 +148,8 @@ namespace HISP.Server
public const byte DIRECTION_TELEPORT = 4;
public const byte DIRECTION_NONE = 10;
public static byte[] CreateBrickPoetMovePacket(Brickpoet.PoetryPeice peice)
{
@ -590,6 +594,23 @@ namespace HISP.Server
return Packet;
}
public static byte[] CreateWeatherUpdatePacket(string newWeather)
{
byte[] strBytes = Encoding.UTF8.GetBytes(newWeather);
MemoryStream ms = new MemoryStream();
ms.WriteByte(PACKET_WORLD);
ms.WriteByte(WEATHER_UPDATE);
ms.Write(strBytes, 0x00, strBytes.Length);
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();
return Packet;
}
public static byte[] CreateWorldData(int gameTime, int gameDay, int gameYear, string weather)
{
byte[] strBytes = Encoding.UTF8.GetBytes(weather);