mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-06 13:15: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;
|
||||
private Timer gameTimeout;
|
||||
private const int WATER_BALLOON_GAME_TIMEOUT = 5;
|
||||
|
||||
public class ThrownCounter
|
||||
{
|
||||
public ThrownCounter(WaterBalloonGame game, User userHit, int numThrown)
|
||||
|
@ -47,41 +46,26 @@ namespace HISP.Game.Events
|
|||
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);
|
||||
}
|
||||
}
|
||||
GameServer.AddItemToAllUsersEvenOffline(Item.WaterBalloon, 8);
|
||||
}
|
||||
|
||||
public void EndEvent()
|
||||
{
|
||||
ThrownCounter[] winnerCounter = getWinners();
|
||||
resetEvent();
|
||||
|
||||
// Remove from all online players
|
||||
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)
|
||||
foreach (ItemInstance itm in invItm.ItemInstances.ToArray())
|
||||
connectedClient.LoggedinUser.Inventory.Remove(itm);
|
||||
}
|
||||
}
|
||||
DroppedItems.DeleteAllItemOfType(Item.WaterBalloon); // Delete all dropped items
|
||||
Database.EradicateItemFromExistance(Item.WaterBalloon); // Delete from offline players
|
||||
DroppedItems.DeleteAllItemsWithId(Item.WaterBalloon); // Delete all dropped items
|
||||
Database.DeleteAllItemsFromUsers(Item.WaterBalloon); // Delete from offline players
|
||||
|
||||
|
||||
// Build event over message
|
||||
|
@ -100,9 +84,10 @@ namespace HISP.Game.Events
|
|||
// payout / tell ppl they won.
|
||||
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.LoggedinClient.SendPacket(youWinMsg);
|
||||
winner.UserHit.TrackedItems.GetTrackedItem(Tracking.TrackableItem.WaterbaloonGameWin).Count++;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -106,7 +106,8 @@ namespace HISP.Game.Items
|
|||
{
|
||||
Database.DecrementDroppedItemDespawnTimer();
|
||||
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.
|
||||
continue;
|
||||
|
@ -120,7 +121,9 @@ namespace HISP.Game.Items
|
|||
|
||||
Logger.DebugPrint("Despawned Item at " + droppedItemsList[i].X + ", " + droppedItemsList[i].Y);
|
||||
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++)
|
||||
{
|
||||
if (droppedItemsList[i].Instance.ItemId == itemId)
|
||||
droppedItemsList.Remove(droppedItemsList[i]);
|
||||
}
|
||||
Database.DeleteAllDroppedItemsWithId(itemId);
|
||||
foreach (DroppedItem itm in droppedItemsList.ToArray())
|
||||
if (itm.Instance.ItemId == itemId)
|
||||
droppedItemsList.Remove(itm);
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
|
|
|
@ -1592,20 +1592,30 @@ namespace HISP.Server
|
|||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
public static void EradicateItemFromExistance(int itemId)
|
||||
public static void DeleteAllDroppedItemsWithId(int itemId)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
|
||||
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.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
|
||||
sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "DELETE FROM DroppedItems WHERE itemId=@itemId";
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
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.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
|
|
|
@ -93,21 +93,8 @@ namespace HISP.Server
|
|||
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);
|
||||
|
||||
if(IsUserOnline(userid))
|
||||
GetUserById(userid).Inventory.AddWithoutDatabase(itm);
|
||||
|
||||
Database.AddItemToInventory(userid, itm);
|
||||
}
|
||||
}
|
||||
|
||||
AddItemToAllUsersEvenOffline(Item.BirthdayToken, 10);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7517,6 +7504,23 @@ namespace HISP.Server
|
|||
/*
|
||||
* 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)
|
||||
{
|
||||
HorseInstance horseMountInst = sender.LoggedinUser.HorseInventory.GetHorseById(horseRandomId);
|
||||
|
|
Loading…
Add table
Reference in a new issue