mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-20 11:49:14 +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;
|
||||
|
|
|
@ -12,29 +12,49 @@ namespace HISP
|
|||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.Title = "HISP - Horse Isle Server Emulator";
|
||||
ConfigReader.OpenConfig();
|
||||
CrossDomainPolicy.GetPolicy();
|
||||
Database.OpenDatabase();
|
||||
GameDataJson.ReadGamedata();
|
||||
#if (!DEBUG)
|
||||
try
|
||||
{
|
||||
#endif
|
||||
Console.Title = "HISP - Horse Isle Server Emulator";
|
||||
ConfigReader.OpenConfig();
|
||||
CrossDomainPolicy.GetPolicy();
|
||||
Database.OpenDatabase();
|
||||
GameDataJson.ReadGamedata();
|
||||
|
||||
Map.OpenMap();
|
||||
World.ReadWorldData();
|
||||
Treasure.Init();
|
||||
Map.OpenMap();
|
||||
World.ReadWorldData();
|
||||
Treasure.Init();
|
||||
|
||||
DroppedItems.Init();
|
||||
WildHorse.Init();
|
||||
DroppedItems.Init();
|
||||
WildHorse.Init();
|
||||
|
||||
Drawingroom.LoadAllDrawingRooms();
|
||||
Brickpoet.LoadPoetryRooms();
|
||||
Multiroom.CreateMultirooms();
|
||||
Drawingroom.LoadAllDrawingRooms();
|
||||
Brickpoet.LoadPoetryRooms();
|
||||
Multiroom.CreateMultirooms();
|
||||
|
||||
Auction.LoadAllAuctionRooms();
|
||||
Auction.LoadAllAuctionRooms();
|
||||
|
||||
Item.DoSpecialCases();
|
||||
Item.DoSpecialCases();
|
||||
|
||||
|
||||
GameServer.StartServer();
|
||||
GameServer.StartServer();
|
||||
#if (!DEBUG)
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.ErrorPrint("Server has crashed! :(");
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint("UNCAUGHT EXCEPTION!");
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint(e.Message);
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint(e.StackTrace);
|
||||
while(true){};
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -876,6 +876,11 @@ namespace HISP.Server
|
|||
Item.MagicBean = gameData.item.special.magic_bean;
|
||||
Item.MagicDroplet = gameData.item.special.magic_droplet;
|
||||
|
||||
Item.StallionTradingCard = gameData.item.special.stallion_trading_card;
|
||||
Item.MareTradingCard = gameData.item.special.mare_trading_card;
|
||||
Item.ColtTradingCard = gameData.item.special.colt_trading_card;
|
||||
Item.FillyTradingCard = gameData.item.special.filly_trading_card;
|
||||
|
||||
GameServer.IdleWarning = Convert.ToInt32(gameData.messages.disconnect.client_timeout.warn_after);
|
||||
GameServer.IdleTimeout = Convert.ToInt32(gameData.messages.disconnect.client_timeout.kick_after);
|
||||
|
||||
|
@ -888,6 +893,7 @@ namespace HISP.Server
|
|||
Map.NewUserStartY = gameData.messages.new_user.starting_y;
|
||||
|
||||
// Timed Messages
|
||||
|
||||
Messages.PlaytimeMessageFormat = gameData.messages.timed_messages.playtime_message;
|
||||
Messages.RngMessages = gameData.messages.timed_messages.rng_message.ToObject<string[]>();
|
||||
|
||||
|
@ -903,7 +909,6 @@ namespace HISP.Server
|
|||
Messages.NowMutingPlayerFormat = gameData.messages.meta.mute_command.now_ignoring_player;
|
||||
Messages.StoppedMutingPlayerFormat = gameData.messages.meta.mute_command.stop_ignoring_player;
|
||||
|
||||
|
||||
Messages.PlayerIgnoringYourPrivateMessagesFormat = gameData.messages.meta.mute_command.player_ignoring_your_pm;
|
||||
Messages.PlayerIgnoringYourBuddyRequests = gameData.messages.meta.mute_command.player_ignoring_your_br;
|
||||
Messages.PlayerIgnoringYourSocials = gameData.messages.meta.mute_command.player_ignoring_your_socials;
|
||||
|
@ -959,6 +964,13 @@ namespace HISP.Server
|
|||
// Message Queue
|
||||
Messages.MessageQueueHeader = gameData.messages.message_queue;
|
||||
|
||||
// Events : Isle Trading Game
|
||||
Messages.EventStartIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_start;
|
||||
Messages.EventDisqualifiedIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_disqualified;
|
||||
Messages.EventOnlyOneTypeIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_one_type;
|
||||
Messages.EventNoneIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_no_cards;
|
||||
Messages.EventWonIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_win;
|
||||
|
||||
// Events : Water Ballon Game
|
||||
Messages.EventStartWaterBallonGame = gameData.messages.events.water_balloon_game.event_start;
|
||||
Messages.EventWonWaterBallonGame = gameData.messages.events.water_balloon_game.event_won;
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace HISP.Server
|
|||
public static TackShopGiveaway TackShopGiveawayEvent = null;
|
||||
public static RealTimeQuiz QuizEvent = null;
|
||||
public static WaterBalloonGame WaterBalloonEvent = new WaterBalloonGame();
|
||||
public static IsleCardTradingGame IsleCardTrading;
|
||||
|
||||
/*
|
||||
* Private stuff
|
||||
|
@ -134,29 +135,30 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
// Isle Card Trading Game
|
||||
if(totalMinutesElapsed % (60 + 50) == 0)
|
||||
if(totalMinutesElapsed % ((60 + 50)+5) == 0)
|
||||
{
|
||||
|
||||
IsleCardTrading = new IsleCardTradingGame();
|
||||
IsleCardTrading.StartEvent();
|
||||
}
|
||||
// Water Balloon Game
|
||||
if(totalMinutesElapsed % (60 * 2) == 0)
|
||||
if(totalMinutesElapsed % ((60 * 2)+5) == 0)
|
||||
{
|
||||
WaterBalloonEvent.StartEvent();
|
||||
}
|
||||
// Tack Shop Giveaway
|
||||
if(totalMinutesElapsed % (60 * 3) == 0)
|
||||
if(totalMinutesElapsed % ((60 * 3)+2) == 0)
|
||||
{
|
||||
TackShopGiveawayEvent = new TackShopGiveaway();
|
||||
TackShopGiveawayEvent.StartEvent();
|
||||
}
|
||||
// Real Time Riddle
|
||||
if(totalMinutesElapsed % 30 == 0)
|
||||
if(totalMinutesElapsed % (30+5) == 0)
|
||||
{
|
||||
RiddleEvent = RealTimeRiddle.GetRandomRiddle();
|
||||
RiddleEvent.StartEvent();
|
||||
}
|
||||
// Real Time Quiz
|
||||
if(totalMinutesElapsed % (60 + 15) == 0)
|
||||
if(totalMinutesElapsed % ((60 + 15)+5) == 0)
|
||||
{
|
||||
QuizEvent = new RealTimeQuiz();
|
||||
QuizEvent.StartEvent();
|
||||
|
@ -7523,6 +7525,24 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveAllItemsOfIdInTheGame(int id)
|
||||
{
|
||||
// Remove from all online players
|
||||
foreach (GameClient connectedClient in GameServer.ConnectedClients)
|
||||
{
|
||||
if (connectedClient.LoggedIn)
|
||||
if (connectedClient.LoggedinUser.Inventory.HasItemId(id))
|
||||
{
|
||||
InventoryItem invItm = connectedClient.LoggedinUser.Inventory.GetItemByItemId(id);
|
||||
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
|
||||
}
|
||||
|
||||
public static void StartRidingHorse(GameClient sender, int horseRandomId)
|
||||
{
|
||||
HorseInstance horseMountInst = sender.LoggedinUser.HorseInventory.GetHorseById(horseRandomId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue