mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-21 12:19:15 +12:00
Add Isle Card Trading Game (?)
This commit is contained in:
parent
bea24a59a5
commit
13c049e3ff
8 changed files with 219 additions and 37 deletions
|
@ -0,0 +1,108 @@
|
|||
using HISP.Game.Items;
|
||||
using HISP.Server;
|
||||
using System.Threading;
|
||||
|
||||
namespace HISP.Game.Events
|
||||
{
|
||||
public class IsleCardTradingGame
|
||||
{
|
||||
public bool Active;
|
||||
private Timer tradingTimeout;
|
||||
private const int TRADING_TIMEOUT = 5;
|
||||
|
||||
|
||||
|
||||
public void StartEvent()
|
||||
{
|
||||
Active = true;
|
||||
tradingTimeout = new Timer(new TimerCallback(tradeTimedOut), null, TRADING_TIMEOUT * 60 * 1000, TRADING_TIMEOUT * 60 * 1000);
|
||||
byte[] msg = PacketBuilder.CreateChat(Messages.EventStartIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
|
||||
foreach (GameClient client in GameServer.ConnectedClients)
|
||||
if (client.LoggedIn)
|
||||
client.SendPacket(msg);
|
||||
|
||||
// Give Trading Cards
|
||||
|
||||
int[] allUsers = Database.GetUsers();
|
||||
foreach (int userid in allUsers)
|
||||
{
|
||||
int tradingCardId = Item.TradingCards[GameServer.RandomNumberGenerator.Next(0, Item.TradingCards.Length)];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ItemInstance itm = new ItemInstance(tradingCardId);
|
||||
|
||||
if (GameServer.IsUserOnline(userid))
|
||||
GameServer.GetUserById(userid).Inventory.AddWithoutDatabase(itm);
|
||||
|
||||
Database.AddItemToInventory(userid, itm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void EndEvent()
|
||||
{
|
||||
Active = false;
|
||||
|
||||
foreach(GameClient client in GameServer.ConnectedClients)
|
||||
{
|
||||
if(client.LoggedIn)
|
||||
{
|
||||
int totalCards = 0;
|
||||
|
||||
foreach (int itemId in Item.TradingCards)
|
||||
if (client.LoggedinUser.Inventory.HasItemId(itemId))
|
||||
totalCards += client.LoggedinUser.Inventory.GetItemByItemId(itemId).ItemInstances.Count;
|
||||
|
||||
bool win = (client.LoggedinUser.Inventory.HasItemId(Item.ColtTradingCard) &&
|
||||
client.LoggedinUser.Inventory.HasItemId(Item.FillyTradingCard) &&
|
||||
client.LoggedinUser.Inventory.HasItemId(Item.MareTradingCard) &&
|
||||
client.LoggedinUser.Inventory.HasItemId(Item.StallionTradingCard));
|
||||
|
||||
if(totalCards > 4)
|
||||
{
|
||||
byte[] disqualifiedTooManyCards = PacketBuilder.CreateChat(Messages.EventDisqualifiedIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
client.SendPacket(disqualifiedTooManyCards);
|
||||
}
|
||||
else if(!win && totalCards <= 0)
|
||||
{
|
||||
byte[] noCardsMessage = PacketBuilder.CreateChat(Messages.EventNoneIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
client.SendPacket(noCardsMessage);
|
||||
}
|
||||
else if(!win && totalCards >= 1)
|
||||
{
|
||||
byte[] onlyOneTypeOfCardMesage = PacketBuilder.CreateChat(Messages.EventOnlyOneTypeIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
client.SendPacket(onlyOneTypeOfCardMesage);
|
||||
}
|
||||
else if (win && totalCards >= 4) // it should be impossible to have this if you dont have one of each,
|
||||
{
|
||||
client.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.IsleCardsGameWin).Count++;
|
||||
|
||||
byte[] wonIsleCardGame = PacketBuilder.CreateChat(Messages.EventWonIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
client.SendPacket(wonIsleCardGame);
|
||||
|
||||
client.LoggedinUser.Money += 25000;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Remove all trading cards from the game
|
||||
foreach (int itemId in Item.TradingCards)
|
||||
GameServer.RemoveAllItemsOfIdInTheGame(itemId);
|
||||
|
||||
tradingTimeout.Dispose();
|
||||
tradingTimeout = null;
|
||||
}
|
||||
|
||||
private void tradeTimedOut(object state)
|
||||
{
|
||||
EndEvent();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -53,20 +53,8 @@ namespace HISP.Game.Events
|
|||
{
|
||||
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.ToArray())
|
||||
connectedClient.LoggedinUser.Inventory.Remove(itm);
|
||||
}
|
||||
}
|
||||
DroppedItems.DeleteAllItemsWithId(Item.WaterBalloon); // Delete all dropped items
|
||||
Database.DeleteAllItemsFromUsers(Item.WaterBalloon); // Delete from offline players
|
||||
|
||||
GameServer.RemoveAllItemsOfIdInTheGame(Item.WaterBalloon);
|
||||
|
||||
// Build event over message
|
||||
string winMsg = Messages.EventEndWaterBalloonGame;
|
||||
|
|
|
@ -75,6 +75,20 @@ namespace HISP.Game.Items
|
|||
public static int BirthdayToken;
|
||||
public static int MagicBean;
|
||||
public static int MagicDroplet;
|
||||
|
||||
public static int StallionTradingCard;
|
||||
public static int MareTradingCard;
|
||||
public static int ColtTradingCard;
|
||||
public static int FillyTradingCard;
|
||||
|
||||
public static int[] TradingCards
|
||||
{
|
||||
get
|
||||
{
|
||||
return new int[4] { StallionTradingCard, MareTradingCard, ColtTradingCard, FillyTradingCard };
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemInformation[] GetAllWishableItems()
|
||||
{
|
||||
List<ItemInformation> itemInfo = new List<ItemInformation>();
|
||||
|
|
|
@ -69,6 +69,13 @@ namespace HISP.Game
|
|||
public static string SocialTypeFormat;
|
||||
public static string SocialPlayerNoLongerNearby;
|
||||
|
||||
// Events : Isle Cards Trading Game
|
||||
public static string EventStartIsleTradingGame;
|
||||
public static string EventDisqualifiedIsleTradingGame;
|
||||
public static string EventOnlyOneTypeIsleTradingGame;
|
||||
public static string EventNoneIsleTradingGame;
|
||||
public static string EventWonIsleTradingGame;
|
||||
|
||||
// Events : Water Balloon Game
|
||||
public static string EventStartWaterBallonGame;
|
||||
public static string EventWonWaterBallonGame;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue