add water balloon game functionality

This commit is contained in:
SilicaAndPina 2021-04-29 19:49:38 +12:00
parent e95140d708
commit 79b4b76c5d
7 changed files with 82 additions and 4 deletions

View file

@ -9515,6 +9515,7 @@
"mod_splatterball":713,
"fishing_poll":146,
"earthworm":83,
"water_balloon":334,
"birthday_token":1082,
"magic_droplet":1567,
"magic_bean":1566

View file

@ -1,11 +1,13 @@
using HISP.Player;
using HISP.Game.Inventory;
using HISP.Game.Items;
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Game.Events
{
public class WaterBalloonGame
{
public WaterBalloonGame()
@ -19,6 +21,7 @@ namespace HISP.Game.Events
public bool Active;
private Timer gameTimeout;
private const int WATER_BALLOON_GAME_TIMEOUT = 5;
public class ThrownCounter
{
public ThrownCounter(WaterBalloonGame game, User userHit, int numThrown)
@ -43,12 +46,44 @@ namespace HISP.Game.Events
foreach (GameClient client in GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(gameStartMessage);
// Give ALL players water ballons
int[] allUsers = Database.GetUsers();
foreach (int userid in allUsers)
{
Logger.DebugPrint("Adding Water Balloon to userid: " + userid.ToString());
for (int i = 0; i < 6; i++)
{
ItemInstance itm = new ItemInstance(Item.WaterBalloon);
if (GameServer.IsUserOnline(userid))
GameServer.GetUserById(userid).Inventory.AddWithoutDatabase(itm);
Database.AddItemToInventory(userid, itm);
}
}
}
public void EndEvent()
{
ThrownCounter[] winnerCounter = getWinners();
resetEvent();
foreach(GameClient connectedClient in GameServer.ConnectedClients)
{
if(connectedClient.LoggedIn)
if(connectedClient.LoggedinUser.Inventory.HasItemId(Item.WaterBalloon))
{
InventoryItem invItm = connectedClient.LoggedinUser.Inventory.GetItemByItemId(Item.WaterBalloon);
foreach (ItemInstance itm in invItm.ItemInstances)
connectedClient.LoggedinUser.Inventory.Remove(itm);
}
}
DroppedItems.DeleteAllItemOfType(Item.WaterBalloon); // Delete all dropped items
Database.EradicateItemFromExistance(Item.WaterBalloon); // Delete from offline players
// Build event over message
string winMsg = Messages.EventEndWaterBalloonGame;
foreach(ThrownCounter winner in winnerCounter)
@ -70,6 +105,7 @@ namespace HISP.Game.Events
winner.UserHit.LoggedinClient.SendPacket(youWinMsg);
}
}
private void gameTimedOut(object state)
{

View file

@ -331,6 +331,15 @@ namespace HISP.Game.Items
}
public static void DeleteAllItemOfType(int itemId)
{
for (int i = 0; i < droppedItemsList.Count; i++)
{
if (droppedItemsList[i].Instance.ItemId == itemId)
droppedItemsList.Remove(droppedItemsList[i]);
}
}
public static void Init()
{
ReadFromDatabase();

View file

@ -69,6 +69,7 @@ namespace HISP.Game.Items
public static int Pitchfork;
public static int WishingCoin;
public static int ModSplatterball;
public static int WaterBalloon;
public static int FishingPole;
public static int Earthworm;
public static int BirthdayToken;

View file

@ -1593,6 +1593,26 @@ namespace HISP.Server
}
}
public static void EradicateItemFromExistance(int itemId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "DELETE FROM Inventory WHERE itemId=@itemId";
sqlCommand.Parameters.AddWithValue("@itemId", itemId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "DELETE FROM DroppedItems WHERE itemId=@itemId";
sqlCommand.Parameters.AddWithValue("@itemId", itemId);
sqlCommand.Prepare();
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
}
public static void SetTrackedItemCount(int playerId, Tracking.TrackableItem what, int count)

View file

@ -871,6 +871,7 @@ namespace HISP.Server
Item.FishingPole = gameData.item.special.fishing_poll;
Item.Earthworm = gameData.item.special.earthworm;
Item.BirthdayToken = gameData.item.special.birthday_token;
Item.WaterBalloon = gameData.item.special.water_balloon;
Item.ModSplatterball = gameData.item.special.mod_splatterball;
Item.MagicBean = gameData.item.special.magic_bean;
Item.MagicDroplet = gameData.item.special.magic_droplet;

View file

@ -5984,7 +5984,12 @@ namespace HISP.Server
sender.SendPacket(thrownHitYourself);
break;
}
if(itemId == Item.WaterBalloon)
{
if (WaterBalloonEvent != null)
if (WaterBalloonEvent.Active)
WaterBalloonEvent.AddWaterBallon(userAt[userIndx]);
}
if(itemId == Item.ModSplatterball)
{
byte[] otherEarned = PacketBuilder.CreateChat(Messages.FormatModSplatterBallAwardedOther(sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
@ -7046,7 +7051,12 @@ namespace HISP.Server
// Remove Trade Reference
sender.LoggedinUser.TradingWith = null;
sender.LoggedinUser.PendingTradeTo = 0;
// Leave open water balloon game
if (WaterBalloonEvent != null)
if(WaterBalloonEvent.Active)
WaterBalloonEvent.LeaveEvent(sender.LoggedinUser);
// Leave open quiz.
if (QuizEvent != null)
QuizEvent.LeaveEvent(sender.LoggedinUser);