Add Feature pt1

This commit is contained in:
Silica 2022-03-07 07:08:47 -05:00
parent a184e4d735
commit 092534e331
131 changed files with 3113 additions and 1418 deletions

View file

@ -0,0 +1,123 @@
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 GameClient.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 GameClient.ConnectedClients)
{
if(client.LoggedIn)
{
int totalCards = 0;
int totalTypes = 0;
foreach (int itemId in Item.TradingCards)
if (client.LoggedinUser.Inventory.HasItemId(itemId))
totalCards += client.LoggedinUser.Inventory.GetItemByItemId(itemId).ItemInstances.Length;
if (client.LoggedinUser.Inventory.HasItemId(Item.ColtTradingCard))
totalTypes++;
if (client.LoggedinUser.Inventory.HasItemId(Item.FillyTradingCard))
totalTypes++;
if (client.LoggedinUser.Inventory.HasItemId(Item.MareTradingCard))
totalTypes++;
if (client.LoggedinUser.Inventory.HasItemId(Item.StallionTradingCard))
totalTypes++;
if(totalCards > 4)
{
byte[] disqualifiedTooManyCards = PacketBuilder.CreateChat(Messages.EventDisqualifiedIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(disqualifiedTooManyCards);
}
else if(totalTypes == 0)
{
byte[] noCardsMessage = PacketBuilder.CreateChat(Messages.EventNoneIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(noCardsMessage);
}
else if(totalTypes == 1)
{
byte[] onlyOneTypeOfCardMesage = PacketBuilder.CreateChat(Messages.EventOnlyOneTypeIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(onlyOneTypeOfCardMesage);
}
else if (totalTypes == 2)
{
byte[] onlyTwoTypeOfCardMesage = PacketBuilder.CreateChat(Messages.EventOnlyTwoTypeIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(onlyTwoTypeOfCardMesage);
}
else if (totalTypes == 3)
{
byte[] onlyThreeTypeOfCardMesage = PacketBuilder.CreateChat(Messages.EventOnlyThreeTypeIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(onlyThreeTypeOfCardMesage);
}
else if (totalTypes == 4)
{
client.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.IsleCardsGameWin).Count++;
byte[] wonIsleCardGame = PacketBuilder.CreateChat(Messages.EventWonIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(wonIsleCardGame);
client.LoggedinUser.AddMoney(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();
}
}
}

View file

@ -0,0 +1,159 @@
using HISP.Game.Items;
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Game.Events
{
public class ModsRevenge
{
public class ThrowTracker
{
public ThrowTracker(User thrower)
{
Thrower = thrower;
thrownAt = new List<User>();
}
public void AddThrownAt(User user)
{
thrownAt.Add(user);
}
public User Thrower;
private List<User> thrownAt;
public User[] ThrownAt
{
get
{
return thrownAt.ToArray();
}
}
}
public bool Active = false;
public const int REVENGE_TIMEOUT = 10;
private List<ThrowTracker> trackedThrows;
private Timer revengeTimeout;
public ThrowTracker[] TrackedThrows
{
get
{
return trackedThrows.ToArray();
}
}
public ModsRevenge()
{
trackedThrows = new List<ThrowTracker>();
Active = false;
}
public void StartEvent()
{
revengeTimeout = new Timer(new TimerCallback(revengeTimedOut), null, REVENGE_TIMEOUT * 60 * 1000, REVENGE_TIMEOUT * 60 * 1000);
int TOTAL_SPLATTERBALLS = 50; // Thanks MayDay!
// Give Splatterballs
int[] allUsers = Database.GetModeratorUsers();
foreach (int userid in allUsers)
{
for (int i = 0; i < TOTAL_SPLATTERBALLS; i++)
{
ItemInstance itm = new ItemInstance(Item.ModSplatterball);
if (GameServer.IsUserOnline(userid))
GameServer.GetUserById(userid).Inventory.AddWithoutDatabase(itm);
Database.AddItemToInventory(userid, itm);
}
}
byte[] annoucePacket = PacketBuilder.CreateChat(Messages.EventStartModsRevenge, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(annoucePacket);
}
public void EndEvent()
{
GameServer.RemoveAllItemsOfIdInTheGame(Item.ModSplatterball);
byte[] annoucePacket = PacketBuilder.CreateChat(Messages.EventEndModsRevenge, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(annoucePacket);
}
private void revengeTimedOut(object state)
{
resetEvent();
EndEvent();
}
private void resetEvent()
{
revengeTimeout.Dispose();
trackedThrows.Clear();
Active = false;
}
private ThrowTracker getUserThrowTracker(User thrower)
{
foreach (ThrowTracker throwTracker in TrackedThrows)
{
if (throwTracker.Thrower.Id == thrower.Id)
return throwTracker;
}
ThrowTracker tracker = new ThrowTracker(thrower);
trackedThrows.Add(tracker);
return tracker;
}
private bool checkUserThrownAtAlready(ThrowTracker tracker, User thrownAt)
{
foreach (User user in tracker.ThrownAt)
{
if (user.Id == thrownAt.Id)
return true;
}
return false;
}
public void LeaveEvent(User userToLeave)
{
foreach (ThrowTracker thrownMemory in TrackedThrows)
{
if (thrownMemory.Thrower.Id == userToLeave.Id)
trackedThrows.Remove(thrownMemory);
}
}
public void Payout(User thrower, User throwAt)
{
ThrowTracker throwCounter = getUserThrowTracker(thrower);
if(!checkUserThrownAtAlready(throwCounter, throwAt))
{
byte[] otherEarned = PacketBuilder.CreateChat(Messages.FormatModSplatterBallAwardedOther(thrower.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
byte[] youEarned = PacketBuilder.CreateChat(Messages.FormatModSplatterBallAwardedYou(throwAt.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
thrower.AddMoney(50);
throwAt.AddMoney(500);
thrower.LoggedinClient.SendPacket(youEarned);
throwAt.LoggedinClient.SendPacket(otherEarned);
throwCounter.AddThrownAt(throwAt);
}
}
}
}

View file

@ -0,0 +1,89 @@
using HISP.Game.Horse;
using HISP.Game.Items;
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.Events
{
public class RandomEvent
{
public static List<RandomEvent> RandomEvents = new List<RandomEvent>();
public static RandomEvent GetRandomEvent()
{
int randomEvent = GameServer.RandomNumberGenerator.Next(0, RandomEvents.Count);
return RandomEvents[randomEvent];
}
public static void ExecuteRandomEvent(User user)
{
while (true)
{
RandomEvent rngEvent = RandomEvent.GetRandomEvent();
if (rngEvent.HorseHealthDown != 0 && user.HorseInventory.HorseList.Length <= 0)
continue;
if (rngEvent.Text.Contains("%HORSENAME%") && user.HorseInventory.HorseList.Length <= 0)
continue;
int moneyEarned = 0;
if (rngEvent.MinMoney != 0 || rngEvent.MaxMoney != 0)
moneyEarned = GameServer.RandomNumberGenerator.Next(rngEvent.MinMoney, rngEvent.MaxMoney);
if (moneyEarned < 0)
if (user.Money + moneyEarned < 0)
continue;
if (rngEvent.GiveObject != 0)
user.Inventory.AddIgnoringFull(new ItemInstance(rngEvent.GiveObject));
if(moneyEarned != 0)
user.AddMoney(moneyEarned);
HorseInstance effectedHorse = null;
if(user.HorseInventory.HorseList.Length > 0)
{
int randomHorseIndex = GameServer.RandomNumberGenerator.Next(0, user.HorseInventory.HorseList.Length);
effectedHorse = user.HorseInventory.HorseList[randomHorseIndex];
}
if (rngEvent.HorseHealthDown != 0)
effectedHorse.BasicStats.Health -= rngEvent.HorseHealthDown;
string horseName = "[This Message Should Not Appear, if it does its a bug.]";
if (effectedHorse != null)
horseName = effectedHorse.Name;
string msg = Messages.FormatRandomEvent(rngEvent.Text, moneyEarned, horseName);
byte[] chatPacket = PacketBuilder.CreateChat(Messages.RandomEventPrefix + msg, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(chatPacket);
return;
}
}
public RandomEvent(int id, string text, int minMoney, int maxMoney, int horseHealth, int giveObject)
{
Id = id;
Text = text;
MinMoney = minMoney;
MaxMoney = maxMoney;
HorseHealthDown = horseHealth;
GiveObject = giveObject;
RandomEvents.Add(this);
}
public int Id;
public string Text;
public int MinMoney;
public int MaxMoney;
public int HorseHealthDown;
public int GiveObject;
}
}

View file

@ -0,0 +1,264 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Game.Events
{
public class RealTimeQuiz
{
public class QuizQuestion
{
public QuizQuestion(QuizCategory category)
{
BaseCategory = category;
}
public QuizCategory BaseCategory;
public string Question;
public string[] Answers;
}
public class QuizCategory
{
public string Name;
public QuizQuestion[] Questions;
}
public class Participent
{
public Participent(User user, RealTimeQuiz Quiz)
{
UserInstance = user;
Won = false;
Quit = false;
CorrectAnswers = 0;
MistakenAnswers = 0;
baseQuiz = Quiz;
NextQuestion();
}
public void NextQuestion()
{
OnQuestion = baseQuiz.Questions[CorrectAnswers++];
}
public void UpdateParticipent()
{
if (this.Quit)
return;
byte[] realTimeQuizQuestion = PacketBuilder.CreateMetaPacket(Meta.BuildRealTimeQuiz(this));
this.UserInstance.LoggedinClient.SendPacket(realTimeQuizQuestion);
}
public void CheckAnswer(string answer)
{
foreach (string correctAnswer in OnQuestion.Answers)
{
if(answer.ToLower().Trim() == correctAnswer.ToLower().Trim())
{
if(CorrectAnswers >= baseQuiz.Questions.Length)
{
baseQuiz.WinEvent(UserInstance);
return;
}
NextQuestion();
UpdateParticipent();
return;
}
if (answer.ToLower().Trim() == "quit")
{
baseQuiz.QuitEvent(UserInstance);
return;
}
}
MistakenAnswers++;
UpdateParticipent();
}
private RealTimeQuiz baseQuiz;
public User UserInstance;
public int CorrectAnswers;
public int MistakenAnswers;
public bool Quit;
public bool Won;
public QuizQuestion OnQuestion;
}
public static QuizCategory[] Categories;
public QuizQuestion[] Questions;
public bool Active;
public const int QUIZ_TIMEOUT = 5;
private Timer quizTimer;
public Participent[] Participents
{
get
{
return participents.ToArray();
}
}
private List<Participent> participents;
public RealTimeQuiz()
{
participents = new List<Participent>();
Questions = new QuizQuestion[8];
for(int i = 0; i < 8; i++)
{
QuizCategory chosenCategory = Categories[GameServer.RandomNumberGenerator.Next(0, Categories.Length)];
Questions[i] = chosenCategory.Questions[GameServer.RandomNumberGenerator.Next(0, chosenCategory.Questions.Length)];
}
Active = false;
}
private Participent getParticipent(int id)
{
foreach (Participent participent in Participents)
{
if (participent.UserInstance.Id == id)
{
return participent;
}
}
throw new KeyNotFoundException("No participent found.");
}
public Participent JoinEvent(User user)
{
try
{
return getParticipent(user.Id);
}
catch (KeyNotFoundException) { };
Participent newParticipent = new Participent(user, this);
user.InRealTimeQuiz = true;
participents.Add(newParticipent);
return newParticipent;
}
public void LeaveEvent(User user)
{
try
{
Participent partcipent = getParticipent(user.Id);
user.InRealTimeQuiz = false;
participents.Remove(partcipent);
partcipent = null;
}
catch (KeyNotFoundException) { };
}
public void QuitEvent(User user)
{
try
{
Participent partcipent = getParticipent(user.Id);
partcipent.Quit = true;
user.InRealTimeQuiz = false;
GameServer.UpdateArea(user.LoggedinClient);
}
catch (KeyNotFoundException) { };
}
public void StartEvent()
{
quizTimer = new Timer(new TimerCallback(quizTimesUp), null, QUIZ_TIMEOUT * 60 * 1000, QUIZ_TIMEOUT * 60 * 1000);
byte[] quizStartMessage = PacketBuilder.CreateChat(Messages.EventStartRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(quizStartMessage);
Active = true;
GameServer.QuizEvent = this;
}
public void WinEvent(User winner)
{
byte[] eventWinMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeQuizWin(winner.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(eventWinMessage);
getParticipent(winner.Id).Won = true;
winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.QuizWin).Count++;
if (winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.QuizWin).Count >= 15)
winner.Awards.AddAward(Award.GetAwardById(54)); // Quiz Genius
if (winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.QuizWin).Count >= 25)
winner.Awards.AddAward(Award.GetAwardById(33)); // Quick Wit
stopEvent();
}
public void EndEvent()
{
byte[] eventEndMessage = PacketBuilder.CreateChat(Messages.EventEndRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if(client.LoggedIn)
client.SendPacket(eventEndMessage);
stopEvent();
}
private void stopEvent()
{
foreach(Participent participent in Participents)
{
if (participent == null)
continue;
if (participent.Quit)
continue;
participent.UserInstance.InRealTimeQuiz = false;
GameServer.UpdateArea(participent.UserInstance.LoggedinClient);
int money = 0;
if (participent.Won)
money += 2500;
else
money += 250;
money += (participent.CorrectAnswers * 500);
money -= (participent.MistakenAnswers * 100);
if (money < 250)
money = 250;
if (participent.Won)
{
byte[] wonBonusMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeQuizWinBonus(money), PacketBuilder.CHAT_BOTTOM_RIGHT);
participent.UserInstance.LoggedinClient.SendPacket(wonBonusMessage);
}
else
{
byte[] bonusMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeQuizBonus(money), PacketBuilder.CHAT_BOTTOM_RIGHT);
participent.UserInstance.LoggedinClient.SendPacket(bonusMessage);
}
participent.UserInstance.AddMoney(money);
}
participents.Clear();
quizTimer.Dispose();
Active = false;
GameServer.QuizEvent = null;
}
private void quizTimesUp(object state)
{
EndEvent();
}
}
}

View file

@ -0,0 +1,125 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Game.Events
{
public class RealTimeRiddle
{
public static List<RealTimeRiddle> RealTimeRiddles = new List<RealTimeRiddle>();
public RealTimeRiddle(int riddleId, string riddleText, string[] answers, int reward)
{
RiddleId = riddleId;
RiddleText = riddleText;
Answers = answers;
Reward = reward;
Active = false;
RealTimeRiddles.Add(this);
}
public int RiddleId;
public string RiddleText;
public string[] Answers;
public bool Active;
public int Reward;
public static bool LastWon = false;
private Timer riddleTimeout;
private const int RIDDLE_TIMEOUT = 5;
public static RealTimeRiddle GetRandomRiddle()
{
int randomRiddleIndex = GameServer.RandomNumberGenerator.Next(0, RealTimeRiddles.Count);
return RealTimeRiddles[randomRiddleIndex];
}
public void StartEvent()
{
Active = true;
riddleTimeout = new Timer(new TimerCallback(riddleTimedOut), null, RIDDLE_TIMEOUT * 60 * 1000, RIDDLE_TIMEOUT * 60 * 1000);
// Send riddle message to all players
foreach(GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
ShowStartMessage(client);
}
}
public void ShowStartMessage(GameClient client)
{
if (!Active)
return;
byte[] riddleStartMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeRiddleStart(RiddleText), PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(riddleStartMessage);
}
public void Win(User winner)
{
if (!Active)
return;
if (Database.HasPlayerCompletedRealTimeRiddle(RiddleId, winner.Id))
{
byte[] alreadyWonRiddleMessage = PacketBuilder.CreateChat(Messages.EventAlreadySovledRealTimeRiddle, PacketBuilder.CHAT_BOTTOM_RIGHT);
winner.LoggedinClient.SendPacket(alreadyWonRiddleMessage);
return;
}
LastWon = true;
Database.CompleteRealTimeRiddle(RiddleId, winner.Id);
winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.RiddleWin).Count++;
if (winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.RiddleWin).Count >= 25)
winner.Awards.AddAward(Award.GetAwardById(33)); // Quick Wit
if (winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.RiddleWin).Count >= 250)
winner.Awards.AddAward(Award.GetAwardById(34)); // Riddle Genius
winner.AddMoney(Reward);
byte[] riddleWonMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeRiddleWonForOthers(winner.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
byte[] riddleYouWonMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeRiddleWonForYou(Reward), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Id != winner.Id)
client.SendPacket(riddleWonMessage);
else
client.SendPacket(riddleYouWonMessage);
}
EndEvent();
}
public void EndEvent()
{
if(Active)
{
Active = false;
riddleTimeout.Dispose();
riddleTimeout = null;
}
}
private void riddleTimedOut(object state)
{
byte[] riddleTimedOutMessage = PacketBuilder.CreateChat(Messages.EventEndRealTimeRiddle, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
client.SendPacket(riddleTimedOutMessage);
}
LastWon = false;
EndEvent();
}
public bool CheckRiddle(string message)
{
string msgCheck = message.ToLower();
foreach(string answer in Answers)
{
if (msgCheck.Contains(answer.ToLower()))
return true;
}
return false;
}
}
}

View file

@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using HISP.Game.Services;
using HISP.Server;
using HISP.Game.Horse;
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 GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(giveAwayMessage);
}
giveAwayTimer.Change(TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000);
}
public TackShopGiveaway()
{
List<World.SpecialTile> specialTiles = new List<World.SpecialTile>();
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)
{
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];
if (npcShops[0].ShortDescription.ToLower().Contains("tack"))
{
npcDesc = npcShops[0].ShortDescription.Substring(npcShops[0].ShortDescription.ToLower().IndexOf("tack"));
ShopName = npcName + "'s " + npcDesc;
}
else
{
ShopName = npcName + "'s Gear";
}
while(true)
{
int hrsIdx = GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Length);
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 GameClient.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, true, true);
winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.TackShopGiveaway).Count++;
byte[] horseWonMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayWon(winner.Username, HorseGiveaway.Breed.Name, ShopName, Town.Name, usersHere.Length), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.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 GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(eventEndedMessage);
}
}
}
}

View file

@ -0,0 +1,166 @@
using HISP.Game.Items;
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
using System.Threading;
namespace HISP.Game.Events
{
public class WaterBalloonGame
{
public WaterBalloonGame()
{
thrownWaterBalloonMemory = new List<ThrownCounter>();
Active = false;
}
private List<ThrownCounter> thrownWaterBalloonMemory;
public bool Active;
private Timer gameTimeout;
private const int WATER_BALLOON_GAME_TIMEOUT = 5;
public ThrownCounter[] ThrownWaterBalloonMemory
{
get
{
return thrownWaterBalloonMemory.ToArray();
}
}
public class ThrownCounter
{
public ThrownCounter(WaterBalloonGame game, User userHit, int numThrown)
{
UserHit = userHit;
NumThrown = numThrown;
baseGame = game;
game.thrownWaterBalloonMemory.Add(this);
}
private WaterBalloonGame baseGame;
public User UserHit;
public int NumThrown;
}
public void StartEvent()
{
Active = true;
gameTimeout = new Timer(new TimerCallback(gameTimedOut), null, WATER_BALLOON_GAME_TIMEOUT * 60 * 1000, WATER_BALLOON_GAME_TIMEOUT * 60 * 1000);
byte[] gameStartMessage = PacketBuilder.CreateChat(Messages.EventStartWaterBallonGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(gameStartMessage);
GameServer.AddItemToAllUsersEvenOffline(Item.WaterBalloon, 8);
}
public void EndEvent()
{
ThrownCounter[] winnerCounter = getWinners();
resetEvent();
GameServer.RemoveAllItemsOfIdInTheGame(Item.WaterBalloon);
// Build event over message
string winMsg = Messages.EventEndWaterBalloonGame;
foreach(ThrownCounter winner in winnerCounter)
{
winMsg += Messages.FormatWaterBalloonGameWinner(winner.UserHit.Username, winner.NumThrown);
}
// Send to all online users
byte[] gameWinnerAnnoucement = PacketBuilder.CreateChat(winMsg, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(gameWinnerAnnoucement);
// payout / tell ppl they won.
foreach (ThrownCounter winner in winnerCounter)
{
byte[] youWinMsg = PacketBuilder.CreateChat(Messages.EventWonWaterBallonGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
winner.UserHit.AddMoney(20000);
winner.UserHit.LoggedinClient.SendPacket(youWinMsg);
winner.UserHit.TrackedItems.GetTrackedItem(Tracking.TrackableItem.WaterbaloonGameWin).Count++;
}
}
private void gameTimedOut(object state)
{
EndEvent();
}
private void resetEvent()
{
gameTimeout.Dispose();
gameTimeout = null;
thrownWaterBalloonMemory.Clear();
Active = false;
}
private ThrownCounter[] getWinners()
{
int maxThrown = 0;
List<ThrownCounter> winningCounter = new List<ThrownCounter>();
// Find the highest throw count
foreach (ThrownCounter throwMemory in ThrownWaterBalloonMemory)
{
if (throwMemory == null)
continue;
if(throwMemory.NumThrown >= maxThrown)
{
maxThrown = throwMemory.NumThrown;
}
}
// Find all with that throw count and add to winner list
foreach (ThrownCounter throwMemory in ThrownWaterBalloonMemory)
{
if (throwMemory == null)
continue;
if (throwMemory.NumThrown == maxThrown)
{
winningCounter.Add(throwMemory);
}
}
return winningCounter.ToArray();
}
public void LeaveEvent(User userToLeave)
{
foreach (ThrownCounter thrownMemory in ThrownWaterBalloonMemory)
{
if (thrownMemory == null)
continue;
if (thrownMemory.UserHit.Id == userToLeave.Id)
thrownWaterBalloonMemory.Remove(thrownMemory);
}
}
private ThrownCounter getThrownCounter(User userToGet)
{
foreach(ThrownCounter thrownMemory in ThrownWaterBalloonMemory)
{
if (thrownMemory == null)
continue;
if (thrownMemory.UserHit.Id == userToGet.Id)
return thrownMemory;
}
return new ThrownCounter(this, userToGet, 0);
}
public void AddWaterBallon(User throwAt)
{
ThrownCounter throwCounter = getThrownCounter(throwAt);
throwCounter.NumThrown++;
}
}
}