Add birthday tokens lol

This commit is contained in:
SilicaAndPina 2021-02-28 01:53:46 +13:00
parent efdd02214e
commit 37c4c679a3
6 changed files with 79 additions and 6 deletions

View file

@ -8853,7 +8853,8 @@
"pitchfork":152,
"wishing_coin":50,
"fishing_poll":146,
"earthworm":83
"earthworm":83,
"birthday_token":1082
},
"throwable":[
{"id":144,"message":"blanketing wet snow on "},

View file

@ -68,6 +68,7 @@ namespace HISP.Game.Items
public static int WishingCoin;
public static int FishingPole;
public static int Earthworm;
public static int BirthdayToken;
public static ItemInformation[] GetAllWishableItems()
{

View file

@ -186,6 +186,7 @@ namespace HISP.Game
public string TypeFlag;
}
public static Time ServerTime = new Time();
public static int StartDate;
public static List<Waypoint> Waypoints = new List<Waypoint>();
public static List<Isle> Isles = new List<Isle>();
@ -221,7 +222,9 @@ namespace HISP.Game
ServerTime.PreciseMinutes = Database.GetServerTime();
ServerTime.Days = Database.GetServerDay();
ServerTime.Years = Database.GetServerYear();
StartDate = Database.GetServerStartTime();
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
}
public static bool InZone(int x, int y)

View file

@ -25,7 +25,7 @@ namespace HISP.Server
string ExtTable = "CREATE TABLE IF NOT EXISTS 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 IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(128), Message Text(1028), TimeSent INT, BeenRead TEXT(3))";
string BuddyTable = "CREATE TABLE IF NOT EXISTS BuddyList(Id INT, IdFriend INT, Pending TEXT(3))";
string WorldTable = "CREATE TABLE IF NOT EXISTS World(Time INT, Day INT, Year INT)";
string WorldTable = "CREATE TABLE World(Time INT, Day INT, Year INT, StartTime INT)";
string WeatherTable = "CREATE TABLE IF NOT EXISTS Weather(Area TEXT(1028), Weather TEXT(64))";
string InventoryTable = "CREATE TABLE IF NOT EXISTS Inventory(PlayerID INT, RandomID INT, ItemID INT, Data INT)";
string ShopInventory = "CREATE TABLE IF NOT EXISTS ShopInventory(ShopID INT, RandomID INT, ItemID INT)";
@ -429,10 +429,9 @@ namespace HISP.Server
sqlCommand.CommandText = WorldTable;
sqlCommand.ExecuteNonQuery();
sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0)";
sqlCommand.CommandText = "INSERT INTO World VALUES(0,0,0,@startDate)";
sqlCommand.Parameters.AddWithValue("@startDate", (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
@ -2188,6 +2187,20 @@ namespace HISP.Server
}
}
public static void SetStartTime(int startTime)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "UPDATE World SET StartTime=@startTimer";
sqlCommand.Parameters.AddWithValue("@startTimer", startTime);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void SetServerTime(int time, int day, int year)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -2217,6 +2230,19 @@ namespace HISP.Server
}
}
public static int GetServerStartTime()
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT StartTime FROM World";
int startTime = Convert.ToInt32(sqlCommand.ExecuteScalar());
sqlCommand.Dispose();
return startTime;
}
}
public static int GetServerDay()
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
@ -3698,7 +3724,24 @@ namespace HISP.Server
return instances;
}
}
public static int[] GetUsers()
{
List<int> userList = new List<int>();
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT id FROM Users";
MySqlDataReader reader = sqlCommand.ExecuteReader();
while(reader.Read())
{
userList.Add(reader.GetInt32(0));
}
sqlCommand.Dispose();
}
return userList.ToArray();
}
public static void AddItemToInventory(int playerId, ItemInstance instance)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))

View file

@ -804,9 +804,10 @@ namespace HISP.Server
Item.WishingCoin = gameData.item.special.wishing_coin;
Item.FishingPole = gameData.item.special.fishing_poll;
Item.Earthworm = gameData.item.special.earthworm;
Item.BirthdayToken = gameData.item.special.birthday_token;
// New Users
Messages.NewUserMessage = gameData.messages.new_user.starting_message;
Map.NewUserStartX = gameData.messages.new_user.starting_x;
Map.NewUserStartY = gameData.messages.new_user.starting_y;

View file

@ -80,6 +80,30 @@ namespace HISP.Server
}
}
}
if((World.StartDate != -1)) // Birthday tokens
{
int curTime = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
if (curTime >= World.StartDate + 378691200)
{
Logger.InfoPrint("Your server has been running for 12 years! Adding birthday tokens");
Database.SetStartTime(-1);
World.StartDate = -1;
int[] allUsers = Database.GetUsers(); // This is slow af, but we only have to do it once ..
foreach (int userid in allUsers)
{
Logger.DebugPrint("Adding Birthday Token to userid: " + userid.ToString());
for (int i = 0; i < 10; i++)
{
ItemInstance itm = new ItemInstance(Item.BirthdayToken);
Database.AddItemToInventory(userid, itm);
}
}
}
}
gameTimer.Change(gameTickSpeed, gameTickSpeed);
lastServerTime = World.ServerTime.Minutes;
}