Add mods revenge

This commit is contained in:
SilicaAndPina 2021-05-11 22:14:35 +12:00
parent 291b6e5292
commit 5fedb7841d
7 changed files with 233 additions and 17 deletions

View file

@ -79,6 +79,10 @@
"awarded_you":"Mod Revenge taken upon %USERNAME%! $50 earned."
},
"events":{
"mods_revenge":{
"event_start":"<B>MODS' REVENGE:</B> Mods' revenge has begun! For the next 10 minutes, any mod that hits you with a Splatterball will earn you $500. Go find Mods and make yourself a target! Only one payout per Mod.",
"event_end":"<B>MODS REVENGE:</B> Mods Revenge is now over. All Splatterballs removed."
},
"water_balloon_game":{
"event_start":"<B>WATER BALLOON FIGHT:</B> You have just been given 8 Water Balloons. Whoever gets hit the MOST in 5 minutes (60 game minutes) will win a prize (hits on yourself are not counted).",
"event_won":"<B>You are a Water Balloon winner!</B> Prize: $20,000",
@ -89,6 +93,8 @@
"event_start":"<B>ISLE CARD TRADING GAME:</B> You have just been given FOUR Isle Trading Cards. They are identical. To win at this game, you will need exactly one of each stallion, mare, colt and filly card in 5 minutes (60 game minutes).",
"event_disqualified":"<B>ISLE CARDS TIME IS UP:</B> You are disqualified for having over 4 cards!",
"event_one_type":"<B>ISLE CARDS TIME IS UP:</B> You only have one type of card. Removing cards.",
"event_two_type":"<B>ISLE CARDS TIME IS UP:</B> You only have two types of cards. Removing cards.",
"event_three_type":"<B>ISLE CARDS TIME IS UP:</B> You have three types of cards! Better luck next time. Removing cards.",
"event_no_cards":"<B>ISLE CARDS TIME IS UP:</B> You don't have any isle cards!",
"event_win":"<B>ISLE CARDS TIME IS UP:</B> You have all four cards! Great work! Prize=$25,000"
},

View file

@ -51,32 +51,47 @@ namespace HISP.Game.Events
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.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 (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(!win && totalCards <= 0)
else if(totalTypes == 0)
{
byte[] noCardsMessage = PacketBuilder.CreateChat(Messages.EventNoneIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
client.SendPacket(noCardsMessage);
}
else if(!win && totalCards >= 1)
else if(totalTypes == 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,
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++;

View file

@ -0,0 +1,144 @@
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 User Thrower;
public List<User> ThrownAt;
}
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 = 8; // I dont know the actural amount t-t
// Give Splatterballs
int[] allUsers = Database.GetUsers();
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 GameServer.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 GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(annoucePacket);
}
private void revengeTimedOut(object state)
{
resetEvent();
}
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;
}
return new ThrowTracker(thrower);
}
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.Money += 50;
throwAt.Money += 500;
thrower.LoggedinClient.SendPacket(youEarned);
throwAt.LoggedinClient.SendPacket(otherEarned);
throwCounter.ThrownAt.Add(throwAt);
}
}
}
}

View file

@ -69,10 +69,16 @@ namespace HISP.Game
public static string SocialTypeFormat;
public static string SocialPlayerNoLongerNearby;
// Events : Mods Revenge
public static string EventStartModsRevenge;
public static string EventEndModsRevenge;
// Events : Isle Cards Trading Game
public static string EventStartIsleTradingGame;
public static string EventDisqualifiedIsleTradingGame;
public static string EventOnlyOneTypeIsleTradingGame;
public static string EventOnlyTwoTypeIsleTradingGame;
public static string EventOnlyThreeTypeIsleTradingGame;
public static string EventNoneIsleTradingGame;
public static string EventWonIsleTradingGame;

View file

@ -4042,6 +4042,25 @@ namespace HISP.Server
return instances;
}
}
public static int[] GetModsAndAdmins()
{
List<int> userList = new List<int>();
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT id FROM Users WHERE Moderator=\"YES\" AND Admin=\"YES\"";
MySqlDataReader reader = sqlCommand.ExecuteReader();
while (reader.Read())
{
userList.Add(reader.GetInt32(0));
}
sqlCommand.Dispose();
}
return userList.ToArray();
}
public static int[] GetUsers()
{
List<int> userList = new List<int>();

View file

@ -964,10 +964,16 @@ namespace HISP.Server
// Message Queue
Messages.MessageQueueHeader = gameData.messages.message_queue;
// Events : Mods Revenge
Messages.EventStartModsRevenge = gameData.messages.events.mods_revenge.event_start;
Messages.EventEndModsRevenge = gameData.messages.events.mods_revenge.event_end;
// 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.EventOnlyTwoTypeIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_two_type;
Messages.EventOnlyThreeTypeIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_three_type;
Messages.EventNoneIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_no_cards;
Messages.EventWonIsleTradingGame = gameData.messages.events.isle_card_trading_game.event_win;

View file

@ -44,6 +44,7 @@ namespace HISP.Server
public static RealTimeQuiz QuizEvent = null;
public static WaterBalloonGame WaterBalloonEvent = new WaterBalloonGame();
public static IsleCardTradingGame IsleCardTrading;
public static ModsRevenge ModsRevengeEvent = new ModsRevenge();
/*
* Private stuff
@ -134,6 +135,11 @@ namespace HISP.Server
}
}
}
// Mods Revenge
if(totalMinutesElapsed % (((60*8)+5)+10) == 0)
{
ModsRevengeEvent.StartEvent();
}
// Isle Card Trading Game
if(totalMinutesElapsed % ((60 + 50)+5) == 0)
{
@ -152,7 +158,7 @@ namespace HISP.Server
TackShopGiveawayEvent.StartEvent();
}
// Real Time Riddle
if(totalMinutesElapsed % (30+5) == 0)
if(totalMinutesElapsed % (30) == 0)
{
RiddleEvent = RealTimeRiddle.GetRandomRiddle();
RiddleEvent.StartEvent();
@ -5957,7 +5963,7 @@ namespace HISP.Server
}
ItemInstance curItem = sender.LoggedinUser.Inventory.GetItemByItemId(itemId).ItemInstances[0];
User[] userAt = GetUsersAt(sender.LoggedinUser.X, sender.LoggedinUser.Y, false, true);
User[] userAt = GetReallyNearbyUsers(sender.LoggedinUser.X, sender.LoggedinUser.Y);
while (true)
{
@ -5983,14 +5989,7 @@ namespace HISP.Server
}
if(itemId == Item.ModSplatterball)
{
byte[] otherEarned = PacketBuilder.CreateChat(Messages.FormatModSplatterBallAwardedOther(sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
byte[] youEarned = PacketBuilder.CreateChat(Messages.FormatModSplatterBallAwardedYou(userAt[userIndx].Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.LoggedinUser.Money += 50;
userAt[userIndx].Money += 500;
sender.SendPacket(youEarned);
userAt[userIndx].LoggedinClient.SendPacket(otherEarned);
ModsRevengeEvent.Payout(sender.LoggedinUser, userAt[userIndx]);
}
byte[] thrownForYou = PacketBuilder.CreateChat(Messages.FormatThrownItemMessage(throwableItem.ThrowMessage, userAt[userIndx].Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
@ -7052,6 +7051,8 @@ namespace HISP.Server
if (QuizEvent != null)
QuizEvent.LeaveEvent(sender.LoggedinUser);
ModsRevengeEvent.LeaveEvent(sender.LoggedinUser);
// Delete Arena Entries
if (Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))
{
@ -7195,6 +7196,25 @@ namespace HISP.Server
throw new KeyNotFoundException("User not found (not online?)");
}
public static User[] GetReallyNearbyUsers(int x, int y)
{
int startX = x - 3;
int endX = x + 3;
int startY = y - 3;
int endY = y + 3;
List<User> usersNearby = new List<User>();
foreach (GameClient client in ConnectedClients)
if (client.LoggedIn)
{
if (startX <= client.LoggedinUser.X && endX >= client.LoggedinUser.X && startY <= client.LoggedinUser.Y && endY >= client.LoggedinUser.Y)
usersNearby.Add(client.LoggedinUser);
}
return usersNearby.ToArray();
}
public static User[] GetNearbyUsers(int x, int y, bool includeStealth=false, bool includeMuted=false)
{
int startX = x - 15;