diff --git a/DataCollection/gamedata.json b/DataCollection/gamedata.json index e06236f..a2dcfdf 100755 --- a/DataCollection/gamedata.json +++ b/DataCollection/gamedata.json @@ -67,7 +67,13 @@ "event_end":"TIME IS UP: No one answered the Chat Riddle in time.", "event_won_others":"RIDDLE SOLVED! By player %PLAYERNAME%!", "event_won_you":"YOU SOLVED THE RIDDLE! You earned: $%PRIZE%!" - } + }, + "tack_shop_giveaway":{ + "event_start":"TACK SHOP HORSE GIVEAWAY: A %COLOR% %BREED% %GENDER% will be given away to one random person at %SHOPNAME% in %TOWN% in 2 minutes!!!", + "event_1min":"TACK SHOP HORSE GIVEAWAY: A %COLOR% %BREED% %GENDER% will be given away to one random person at %SHOPNAME% in %TOWN% in 1 minute!!!", + "event_won":"TACK SHOP HORSE GIVEAWAY: %PLAYERNAME% has won the %BREED% horse Giveaway at %SHOPNAME% in %TOWN%! Thanks to all %PLAYERCOUNT% players that attended the event.", + "event_end":"TACK SHOP HORSE GIVEAWAY: No one was at %SHOPNAME% in %TOWN% to win the horse. Oh well, event is over.", + }, }, "horse_leaser":{ "cant_afford":"You cannot afford the lease fee.", diff --git a/Horse Isle Server/HorseIsleServer/Game/Events/TackShopGiveaway.cs b/Horse Isle Server/HorseIsleServer/Game/Events/TackShopGiveaway.cs new file mode 100644 index 0000000..7220dd3 --- /dev/null +++ b/Horse Isle Server/HorseIsleServer/Game/Events/TackShopGiveaway.cs @@ -0,0 +1,149 @@ +using HISP.Game.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using HISP.Server; +using HISP.Game.Horse; +using System.Threading; +using HISP.Player; + +namespace HISP.Game.Events +{ + public class TackShopGiveaway + { + public string ShopName; + public World.SpecialTile Location; + public HorseInstance HorseGiveaway; + public World.Town Town; + public bool Active = false; + public const int TACKSHOP_TIMEOUT = 1; + private Timer giveAwayTimer; + private int timesTicked = 0; + + private void giveawayTick(object state) + { + timesTicked++; + if (timesTicked >= 2) + { + EndEvent(); + return; + } + if (timesTicked >= 1) + { + byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveaway1Min(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT); + foreach (GameClient client in GameServer.ConnectedClients) + if (client.LoggedIn) + client.SendPacket(giveAwayMessage); + } + giveAwayTimer.Change(TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000); + } + + public TackShopGiveaway() + { + List specialTiles = new List(); + + foreach(World.SpecialTile sTile in World.SpecialTiles) + { + if(sTile.Code != null) + { + if(sTile.Code.StartsWith("STORE-")) + { + + int storeId = int.Parse(sTile.Code.Split("-")[1]); + Shop shopData = Shop.GetShopById(storeId); + + if(shopData.BuysItemTypes.Contains("TACK")) + { + Npc.NpcEntry[] npcShop = Npc.GetNpcByXAndY(sTile.X, sTile.Y); + if(npcShop.Length > 0) + { + if(npcShop[0].ShortDescription.ToLower().Contains("tack")) + { + specialTiles.Add(sTile); + } + } + } + } + } + } + + string npcName = "ERROR"; + string npcDesc = "OBTAINING NAME"; + + int shpIdx = GameServer.RandomNumberGenerator.Next(0, specialTiles.Count); + Location = specialTiles[shpIdx]; + Npc.NpcEntry[] npcShops = Npc.GetNpcByXAndY(Location.X, Location.Y); + + npcName = npcShops[0].Name.Split(" ")[0]; + npcDesc = npcShops[0].ShortDescription.Substring(npcShops[0].ShortDescription.ToLower().IndexOf("tack")); + + ShopName = npcName + "'s " + npcDesc; + + while(true) + { + int hrsIdx = GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Count); + HorseInfo.Breed breed = HorseInfo.Breeds[hrsIdx]; + if (breed.SpawnInArea == "none") + continue; + + HorseGiveaway = new HorseInstance(breed); + HorseGiveaway.Name = "Tack Shop Giveaway"; + break; + } + + if (World.InTown(Location.X, Location.Y)) + Town = World.GetTown(Location.X, Location.Y); + } + + public void StartEvent() + { + giveAwayTimer = new Timer(new TimerCallback(giveawayTick), null, TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000); + + byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayStart(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT); + foreach (GameClient client in GameServer.ConnectedClients) + if (client.LoggedIn) + client.SendPacket(giveAwayMessage); + + Active = true; + + GameServer.TackShopGiveawayEvent = this; + } + + public void EndEvent() + { + giveAwayTimer.Dispose(); + + Active = false; + GameServer.TackShopGiveawayEvent = null; + + User[] usersHere = GameServer.GetUsersAt(Location.X, Location.Y, false, true); + + if(usersHere.Length > 0) + { + int winIndx = GameServer.RandomNumberGenerator.Next(0, usersHere.Length); + User winner = usersHere[winIndx]; + + winner.HorseInventory.AddHorse(HorseGiveaway); + + byte[] horseWonMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayWon(winner.Username, HorseGiveaway.Breed.Name, ShopName, Town.Name, usersHere.Length), PacketBuilder.CHAT_BOTTOM_RIGHT); + foreach (GameClient client in GameServer.ConnectedClients) + if (client.LoggedIn) + client.SendPacket(horseWonMessage); + + } + else + { + byte[] eventEndedMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayEnd(ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT); + foreach (GameClient client in GameServer.ConnectedClients) + if (client.LoggedIn) + client.SendPacket(eventEndedMessage); + } + } + + + + + + + } +} diff --git a/Horse Isle Server/HorseIsleServer/Game/Messages.cs b/Horse Isle Server/HorseIsleServer/Game/Messages.cs index ba35b8a..5a87f42 100755 --- a/Horse Isle Server/HorseIsleServer/Game/Messages.cs +++ b/Horse Isle Server/HorseIsleServer/Game/Messages.cs @@ -64,6 +64,12 @@ namespace HISP.Game public static string EventWonRealTimeRiddleForOthersFormat; public static string EventWonRealTimeRiddleForYouFormat; + // Events : Tack Shop Giveaway + public static string EventStartTackShopGiveawayFormat; + public static string Event1MinTackShopGiveawayFormat; + public static string EventWonTackShopGiveawayFormat; + public static string EventEndTackShopGiveawayFormat; + // MultiHorses public static string OtherPlayersHere; public static string MultiHorseSelectOneToJoinWith; @@ -1101,6 +1107,25 @@ namespace HISP.Game // Click public static string NothingInterestingHere; + // Event : Tack Shop Giveaway + + public static string FormatEventTackShopGiveawayEnd(string shopName, string townName) + { + return EventEndTackShopGiveawayFormat.Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName); + } + public static string FormatEventTackShopGiveawayWon(string playerName, string breed, string shopName, string townName, int totalPlayersAt) + { + return EventWonTackShopGiveawayFormat.Replace("%PLAYERNAME%", playerName).Replace("%BREED%", breed).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName).Replace("%PLAYERCOUNT%", totalPlayersAt.ToString("N0", CultureInfo.InvariantCulture)); + } + public static string FormatEventTackShopGiveaway1Min(string color, string breed, string gender, string shopName, string townName) + { + return Event1MinTackShopGiveawayFormat.Replace("%COLOR%", color).Replace("%BREED%", breed).Replace("%GENDER%", gender).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName); + } + public static string FormatEventTackShopGiveawayStart(string color, string breed, string gender, string shopName, string townName) + { + return EventStartTackShopGiveawayFormat.Replace("%COLOR%", color).Replace("%BREED%", breed).Replace("%GENDER%", gender).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName); + } + // Event : Real Time Riddle public static string FormatEventRealTimeRiddleStart(string riddleText) { diff --git a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs index a77b118..3bda7f3 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameDataJson.cs @@ -924,6 +924,14 @@ namespace HISP.Server Messages.EventWonRealTimeRiddleForOthersFormat = gameData.messages.events.real_time_riddle.event_won_others; Messages.EventWonRealTimeRiddleForYouFormat = gameData.messages.events.real_time_riddle.event_won_you; + // Events : Tack Shop Giveaway + + Messages.EventStartTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_start; + Messages.Event1MinTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_1min; + Messages.EventWonTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_won; + Messages.EventEndTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_end; + + // MultiHorses Messages.OtherPlayersHere = gameData.messages.meta.multihorses.other_players_here; Messages.MultiHorseSelectOneToJoinWith = gameData.messages.meta.multihorses.select_a_horse; diff --git a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs index d98dd29..848f3e4 100755 --- a/Horse Isle Server/HorseIsleServer/Server/GameServer.cs +++ b/Horse Isle Server/HorseIsleServer/Server/GameServer.cs @@ -40,6 +40,7 @@ namespace HISP.Server // Events public static RealTimeRiddle RiddleEvent = RealTimeRiddle.GetRandomRiddle(); + public static TackShopGiveaway TackShopGiveawayEvent; /* * Private stuff @@ -143,7 +144,11 @@ namespace HISP.Server } } } - + if(totalMinutesElapsed % (60 * 3) == 0) + { + TackShopGiveawayEvent = new TackShopGiveaway(); + TackShopGiveawayEvent.StartEvent(); + } if(totalMinutesElapsed % 30 == 0) { RiddleEvent = RealTimeRiddle.GetRandomRiddle(); @@ -195,10 +200,6 @@ namespace HISP.Server } } - if (RandomNumberGenerator.Next(0, 100) == 59) // Real Time Riddle - { - - } Database.IncPlayerTirednessForOfflineUsers();