mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Implement water ballon game.
This commit is contained in:
parent
79b4b76c5d
commit
c8d6ec630a
4 changed files with 50 additions and 49 deletions
|
@ -21,7 +21,6 @@ namespace HISP.Game.Events
|
||||||
public bool Active;
|
public bool Active;
|
||||||
private Timer gameTimeout;
|
private Timer gameTimeout;
|
||||||
private const int WATER_BALLOON_GAME_TIMEOUT = 5;
|
private const int WATER_BALLOON_GAME_TIMEOUT = 5;
|
||||||
|
|
||||||
public class ThrownCounter
|
public class ThrownCounter
|
||||||
{
|
{
|
||||||
public ThrownCounter(WaterBalloonGame game, User userHit, int numThrown)
|
public ThrownCounter(WaterBalloonGame game, User userHit, int numThrown)
|
||||||
|
@ -47,41 +46,26 @@ namespace HISP.Game.Events
|
||||||
if (client.LoggedIn)
|
if (client.LoggedIn)
|
||||||
client.SendPacket(gameStartMessage);
|
client.SendPacket(gameStartMessage);
|
||||||
|
|
||||||
// Give ALL players water ballons
|
GameServer.AddItemToAllUsersEvenOffline(Item.WaterBalloon, 8);
|
||||||
|
|
||||||
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()
|
public void EndEvent()
|
||||||
{
|
{
|
||||||
ThrownCounter[] winnerCounter = getWinners();
|
ThrownCounter[] winnerCounter = getWinners();
|
||||||
resetEvent();
|
resetEvent();
|
||||||
|
// Remove from all online players
|
||||||
foreach(GameClient connectedClient in GameServer.ConnectedClients)
|
foreach(GameClient connectedClient in GameServer.ConnectedClients)
|
||||||
{
|
{
|
||||||
if(connectedClient.LoggedIn)
|
if(connectedClient.LoggedIn)
|
||||||
if(connectedClient.LoggedinUser.Inventory.HasItemId(Item.WaterBalloon))
|
if(connectedClient.LoggedinUser.Inventory.HasItemId(Item.WaterBalloon))
|
||||||
{
|
{
|
||||||
InventoryItem invItm = connectedClient.LoggedinUser.Inventory.GetItemByItemId(Item.WaterBalloon);
|
InventoryItem invItm = connectedClient.LoggedinUser.Inventory.GetItemByItemId(Item.WaterBalloon);
|
||||||
foreach (ItemInstance itm in invItm.ItemInstances)
|
foreach (ItemInstance itm in invItm.ItemInstances.ToArray())
|
||||||
connectedClient.LoggedinUser.Inventory.Remove(itm);
|
connectedClient.LoggedinUser.Inventory.Remove(itm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DroppedItems.DeleteAllItemOfType(Item.WaterBalloon); // Delete all dropped items
|
DroppedItems.DeleteAllItemsWithId(Item.WaterBalloon); // Delete all dropped items
|
||||||
Database.EradicateItemFromExistance(Item.WaterBalloon); // Delete from offline players
|
Database.DeleteAllItemsFromUsers(Item.WaterBalloon); // Delete from offline players
|
||||||
|
|
||||||
|
|
||||||
// Build event over message
|
// Build event over message
|
||||||
|
@ -100,9 +84,10 @@ namespace HISP.Game.Events
|
||||||
// payout / tell ppl they won.
|
// payout / tell ppl they won.
|
||||||
foreach (ThrownCounter winner in winnerCounter)
|
foreach (ThrownCounter winner in winnerCounter)
|
||||||
{
|
{
|
||||||
byte[] youWinMsg = PacketBuilder.CreateChat(winMsg, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
byte[] youWinMsg = PacketBuilder.CreateChat(Messages.EventWonWaterBallonGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
winner.UserHit.Money += 20000;
|
winner.UserHit.Money += 20000;
|
||||||
winner.UserHit.LoggedinClient.SendPacket(youWinMsg);
|
winner.UserHit.LoggedinClient.SendPacket(youWinMsg);
|
||||||
|
winner.UserHit.TrackedItems.GetTrackedItem(Tracking.TrackableItem.WaterbaloonGameWin).Count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,8 @@ namespace HISP.Game.Items
|
||||||
{
|
{
|
||||||
Database.DecrementDroppedItemDespawnTimer();
|
Database.DecrementDroppedItemDespawnTimer();
|
||||||
Database.RemoveDespawningItems(); // GO-GO-GO-GOGOGOGO GOTTA GO FAST!!!
|
Database.RemoveDespawningItems(); // GO-GO-GO-GOGOGOGO GOTTA GO FAST!!!
|
||||||
for (int i = 0; i < droppedItemsList.Count; i++)
|
int itmCount = droppedItemsList.Count;
|
||||||
|
for (int i = 0; i < itmCount; i++)
|
||||||
{
|
{
|
||||||
if (droppedItemsList[i] == null) // Item removed in another thread.
|
if (droppedItemsList[i] == null) // Item removed in another thread.
|
||||||
continue;
|
continue;
|
||||||
|
@ -120,7 +121,9 @@ namespace HISP.Game.Items
|
||||||
|
|
||||||
Logger.DebugPrint("Despawned Item at " + droppedItemsList[i].X + ", " + droppedItemsList[i].Y);
|
Logger.DebugPrint("Despawned Item at " + droppedItemsList[i].X + ", " + droppedItemsList[i].Y);
|
||||||
droppedItemsList.Remove(droppedItemsList[i]);
|
droppedItemsList.Remove(droppedItemsList[i]);
|
||||||
|
itmCount = droppedItemsList.Count;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -331,13 +334,12 @@ namespace HISP.Game.Items
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DeleteAllItemOfType(int itemId)
|
public static void DeleteAllItemsWithId(int itemId)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < droppedItemsList.Count; i++)
|
Database.DeleteAllDroppedItemsWithId(itemId);
|
||||||
{
|
foreach (DroppedItem itm in droppedItemsList.ToArray())
|
||||||
if (droppedItemsList[i].Instance.ItemId == itemId)
|
if (itm.Instance.ItemId == itemId)
|
||||||
droppedItemsList.Remove(droppedItemsList[i]);
|
droppedItemsList.Remove(itm);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Init()
|
public static void Init()
|
||||||
|
|
|
@ -1592,20 +1592,30 @@ namespace HISP.Server
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static void DeleteAllDroppedItemsWithId(int itemId)
|
||||||
public static void EradicateItemFromExistance(int itemId)
|
|
||||||
{
|
{
|
||||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
db.Open();
|
db.Open();
|
||||||
|
|
||||||
MySqlCommand sqlCommand = db.CreateCommand();
|
MySqlCommand sqlCommand = db.CreateCommand();
|
||||||
sqlCommand.CommandText = "DELETE FROM Inventory WHERE itemId=@itemId";
|
sqlCommand.CommandText = "DELETE FROM DroppedItems WHERE itemId=@itemId";
|
||||||
sqlCommand.Parameters.AddWithValue("@itemId", itemId);
|
sqlCommand.Parameters.AddWithValue("@itemId", itemId);
|
||||||
sqlCommand.Prepare();
|
sqlCommand.Prepare();
|
||||||
sqlCommand.ExecuteNonQuery();
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
sqlCommand = db.CreateCommand();
|
sqlCommand.Dispose();
|
||||||
sqlCommand.CommandText = "DELETE FROM DroppedItems WHERE itemId=@itemId";
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void DeleteAllItemsFromUsers(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.Parameters.AddWithValue("@itemId", itemId);
|
||||||
sqlCommand.Prepare();
|
sqlCommand.Prepare();
|
||||||
sqlCommand.ExecuteNonQuery();
|
sqlCommand.ExecuteNonQuery();
|
||||||
|
|
|
@ -93,21 +93,8 @@ namespace HISP.Server
|
||||||
Database.SetStartTime(-1);
|
Database.SetStartTime(-1);
|
||||||
World.StartDate = -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);
|
|
||||||
|
|
||||||
if(IsUserOnline(userid))
|
|
||||||
GetUserById(userid).Inventory.AddWithoutDatabase(itm);
|
|
||||||
|
|
||||||
Database.AddItemToInventory(userid, itm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AddItemToAllUsersEvenOffline(Item.BirthdayToken, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7517,6 +7504,23 @@ namespace HISP.Server
|
||||||
/*
|
/*
|
||||||
* Other...
|
* Other...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public static void AddItemToAllUsersEvenOffline(int itemId, int itemCount)
|
||||||
|
{
|
||||||
|
int[] allUsers = Database.GetUsers();
|
||||||
|
foreach (int userid in allUsers)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < itemCount; i++)
|
||||||
|
{
|
||||||
|
ItemInstance itm = new ItemInstance(itemId);
|
||||||
|
|
||||||
|
if (GameServer.IsUserOnline(userid))
|
||||||
|
GameServer.GetUserById(userid).Inventory.AddWithoutDatabase(itm);
|
||||||
|
|
||||||
|
Database.AddItemToInventory(userid, itm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void StartRidingHorse(GameClient sender, int horseRandomId)
|
public static void StartRidingHorse(GameClient sender, int horseRandomId)
|
||||||
{
|
{
|
||||||
HorseInstance horseMountInst = sender.LoggedinUser.HorseInventory.GetHorseById(horseRandomId);
|
HorseInstance horseMountInst = sender.LoggedinUser.HorseInventory.GetHorseById(horseRandomId);
|
||||||
|
|
Loading…
Add table
Reference in a new issue