mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
add more for real time quiz.
This commit is contained in:
parent
753abb5231
commit
4e8ad17d1c
8 changed files with 227 additions and 17 deletions
|
@ -62,7 +62,12 @@
|
||||||
"starved_horse":"You have been sent to Prison Isle for starving one of your horses! They have been fed for you.",
|
"starved_horse":"You have been sent to Prison Isle for starving one of your horses! They have been fed for you.",
|
||||||
"message_queue":"<B>OFFLINE MESSAGE:</B>",
|
"message_queue":"<B>OFFLINE MESSAGE:</B>",
|
||||||
"timed_messages":{
|
"timed_messages":{
|
||||||
{"hours":2, "messages":["You have been playing for 2 hours. Aren't you sleepy? It's okay to go to bed. We'll all be here tomorrow."]},
|
"rng_message":["Don't forget to pet your kitty/dog/fish/stuffed animal.",
|
||||||
|
"Don't forget to stretch once in a while.", "Are you running late for school/work?!?!",
|
||||||
|
"Aren't you sleepy? It's okay to go to bed. We'll all be here tomorrow.",
|
||||||
|
"Please take a break and check on your family/pets/world. :)",
|
||||||
|
"Please take breaks once in a while."]
|
||||||
|
"playtime_message": "You have been playing for %TOTALHOURS% hours. "
|
||||||
},
|
},
|
||||||
"chat_errors":{
|
"chat_errors":{
|
||||||
"cant_find_player":"Could not find player to Private chat!",
|
"cant_find_player":"Could not find player to Private chat!",
|
||||||
|
@ -94,7 +99,8 @@
|
||||||
"event_win_bonus":"<B>QUIZ WINNER BONUS:</B> $%MONEY% Earned. ($2500 win + $500/correct - $100/mistake)",
|
"event_win_bonus":"<B>QUIZ WINNER BONUS:</B> $%MONEY% Earned. ($2500 win + $500/correct - $100/mistake)",
|
||||||
"event_win":"<B>QUIZ COMPLETED:</B> %USERNAME% answered all questions first!",
|
"event_win":"<B>QUIZ COMPLETED:</B> %USERNAME% answered all questions first!",
|
||||||
"event_unavailable":"Realtime quiz is currently unavailable",
|
"event_unavailable":"Realtime quiz is currently unavailable",
|
||||||
"event_entered":"You have entered the Realtime Quiz. Good luck!"
|
"event_entered":"You have entered the Realtime Quiz. Good luck!",
|
||||||
|
"event_quit":"Realtime quiz was quit already. Only one try per Quiz.",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"horse_leaser":{
|
"horse_leaser":{
|
||||||
|
|
|
@ -3,6 +3,7 @@ using HISP.Server;
|
||||||
using HISP.Game.Items;
|
using HISP.Game.Items;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using HISP.Game.Events;
|
||||||
|
|
||||||
namespace HISP.Game.Chat
|
namespace HISP.Game.Chat
|
||||||
{
|
{
|
||||||
|
@ -371,12 +372,22 @@ namespace HISP.Game.Chat
|
||||||
|
|
||||||
public static bool Quiz(string message, string[] args, User user)
|
public static bool Quiz(string message, string[] args, User user)
|
||||||
{
|
{
|
||||||
bool quizActive = false;
|
bool quizActive = (GameServer.QuizEvent != null);
|
||||||
// TODO: Check quiz event is running.
|
|
||||||
if (quizActive)
|
if (quizActive)
|
||||||
{
|
{
|
||||||
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
|
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
|
||||||
|
|
||||||
|
RealTimeQuiz.Participent participent = GameServer.QuizEvent.JoinEvent(user);
|
||||||
|
|
||||||
|
if(participent.Quit)
|
||||||
|
{
|
||||||
|
byte[] quizQuit = PacketBuilder.CreateChat(Messages.EventQuitRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
user.LoggedinClient.SendPacket(quizQuit);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
participent.UpdateParticipent();
|
||||||
byte[] enteredRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
byte[] enteredRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
user.LoggedinClient.SendPacket(enteredRealTimeQuiz);
|
user.LoggedinClient.SendPacket(enteredRealTimeQuiz);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
using System;
|
using HISP.Player;
|
||||||
|
using HISP.Server;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Threading;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace HISP.Game.Events
|
namespace HISP.Game.Events
|
||||||
{
|
{
|
||||||
class RealTimeQuiz
|
public class RealTimeQuiz
|
||||||
{
|
{
|
||||||
public class QuizQuestion
|
public class QuizQuestion
|
||||||
{
|
{
|
||||||
|
@ -24,7 +23,185 @@ namespace HISP.Game.Events
|
||||||
public QuizQuestion[] Questions;
|
public QuizQuestion[] Questions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QuizCategory[] Categories;
|
public class Participent
|
||||||
|
{
|
||||||
|
public Participent(User user)
|
||||||
|
{
|
||||||
|
UserInstance = user;
|
||||||
|
Won = false;
|
||||||
|
Quit = false;
|
||||||
|
CorrectAnswers = 0;
|
||||||
|
MistakenAnswers = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void NextQuestion()
|
||||||
|
{
|
||||||
|
QuizCategory chosenCategory = Categories[GameServer.RandomNumberGenerator.Next(0, Categories.Length)];
|
||||||
|
OnQuestion = chosenCategory.Questions[GameServer.RandomNumberGenerator.Next(0, chosenCategory.Questions.Length)];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateParticipent()
|
||||||
|
{
|
||||||
|
if (this.Quit)
|
||||||
|
return;
|
||||||
|
|
||||||
|
byte[] realTimeQuizQuestion = PacketBuilder.CreateMetaPacket(Meta.BuildRealTimeQuiz(this));
|
||||||
|
this.UserInstance.LoggedinClient.SendPacket(realTimeQuizQuestion);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User UserInstance;
|
||||||
|
public int CorrectAnswers;
|
||||||
|
public int MistakenAnswers;
|
||||||
|
public bool Quit;
|
||||||
|
public bool Won;
|
||||||
|
|
||||||
|
public QuizQuestion OnQuestion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static QuizCategory[] Categories;
|
||||||
|
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>();
|
||||||
|
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);
|
||||||
|
user.InRealTimeQuiz = true;
|
||||||
|
participents.Add(newParticipent);
|
||||||
|
|
||||||
|
|
||||||
|
return newParticipent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LeaveEvent(User user, bool sendData=true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Participent partcipent = getParticipent(user.Id);
|
||||||
|
partcipent.Quit = true;
|
||||||
|
user.InRealTimeQuiz = false;
|
||||||
|
|
||||||
|
if(sendData)
|
||||||
|
if (user.LoggedinClient != null)
|
||||||
|
if(GameServer.IsUserOnline(user.Id))
|
||||||
|
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 GameServer.ConnectedClients)
|
||||||
|
if (client.LoggedIn)
|
||||||
|
client.SendPacket(quizStartMessage);
|
||||||
|
|
||||||
|
Active = true;
|
||||||
|
|
||||||
|
GameServer.QuizEvent = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EndEvent()
|
||||||
|
{
|
||||||
|
byte[] eventEndMessage = PacketBuilder.CreateChat(Messages.EventEndRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||||
|
foreach (GameClient client in GameServer.ConnectedClients)
|
||||||
|
if(client.LoggedIn)
|
||||||
|
client.SendPacket(eventEndMessage);
|
||||||
|
|
||||||
|
stopEvent();
|
||||||
|
}
|
||||||
|
private void stopEvent()
|
||||||
|
{
|
||||||
|
foreach(Participent participent in Participents)
|
||||||
|
{
|
||||||
|
if (participent.UserInstance.LoggedinClient != null)
|
||||||
|
{
|
||||||
|
if (GameServer.IsUserOnline(participent.UserInstance.Id))
|
||||||
|
{
|
||||||
|
if (participent.Quit)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (participent.UserInstance.InRealTimeQuiz)
|
||||||
|
GameServer.UpdateArea(participent.UserInstance.LoggedinClient);
|
||||||
|
|
||||||
|
participent.UserInstance.InRealTimeQuiz = false;
|
||||||
|
|
||||||
|
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.Money += money;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
participents.Clear();
|
||||||
|
participents = null;
|
||||||
|
quizTimer.Dispose();
|
||||||
|
|
||||||
|
Active = false;
|
||||||
|
GameServer.TackShopGiveawayEvent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void quizTimesUp(object state)
|
||||||
|
{
|
||||||
|
EndEvent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace HISP.Game
|
||||||
public static string EventWinRealTimeQuizFormat;
|
public static string EventWinRealTimeQuizFormat;
|
||||||
public static string EventUnavailableRealTimeQuiz;
|
public static string EventUnavailableRealTimeQuiz;
|
||||||
public static string EventEnteredRealTimeQuiz;
|
public static string EventEnteredRealTimeQuiz;
|
||||||
|
public static string EventQuitRealTimeQuiz;
|
||||||
|
|
||||||
// Events : Real Time Riddles
|
// Events : Real Time Riddles
|
||||||
public static string EventStartRealTimeRiddleFormat;
|
public static string EventStartRealTimeRiddleFormat;
|
||||||
|
|
|
@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using HISP.Game.Chat;
|
using HISP.Game.Chat;
|
||||||
|
using HISP.Game.Events;
|
||||||
|
|
||||||
namespace HISP.Game
|
namespace HISP.Game
|
||||||
{
|
{
|
||||||
|
@ -733,6 +734,10 @@ namespace HISP.Game
|
||||||
message += Messages.MetaTerminator;
|
message += Messages.MetaTerminator;
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
public static string BuildRealTimeQuiz(RealTimeQuiz.Participent participent)
|
||||||
|
{
|
||||||
|
return Messages.FormatEventRealTimeQuizMeta(participent.CorrectAnswers, participent.MistakenAnswers, participent.OnQuestion.BaseCategory.Name, participent.OnQuestion.Question);
|
||||||
|
}
|
||||||
public static string BuildCompanionLibary()
|
public static string BuildCompanionLibary()
|
||||||
{
|
{
|
||||||
string message = "";
|
string message = "";
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace HISP.Player
|
||||||
public HorseInfo.Breed PawneerOrderBreed = null;
|
public HorseInfo.Breed PawneerOrderBreed = null;
|
||||||
public string PawneerOrderColor = "";
|
public string PawneerOrderColor = "";
|
||||||
public string PawneerOrderGender = "";
|
public string PawneerOrderGender = "";
|
||||||
|
public bool InRealTimeQuiz = false;
|
||||||
public int PendingTradeTo;
|
public int PendingTradeTo;
|
||||||
public Mailbox MailBox;
|
public Mailbox MailBox;
|
||||||
public Friends Friends;
|
public Friends Friends;
|
||||||
|
@ -439,7 +439,6 @@ namespace HISP.Player
|
||||||
public int SecCodeInc = 0;
|
public int SecCodeInc = 0;
|
||||||
public int SecCodeCount = 0;
|
public int SecCodeCount = 0;
|
||||||
|
|
||||||
|
|
||||||
public int GetPlayerListIcon()
|
public int GetPlayerListIcon()
|
||||||
{
|
{
|
||||||
int icon = -1;
|
int icon = -1;
|
||||||
|
|
|
@ -962,6 +962,7 @@ namespace HISP.Server
|
||||||
Messages.EventWinRealTimeQuizFormat = gameData.messages.events.real_time_quiz.event_win;
|
Messages.EventWinRealTimeQuizFormat = gameData.messages.events.real_time_quiz.event_win;
|
||||||
Messages.EventUnavailableRealTimeQuiz = gameData.messages.events.real_time_quiz.event_unavailable;
|
Messages.EventUnavailableRealTimeQuiz = gameData.messages.events.real_time_quiz.event_unavailable;
|
||||||
Messages.EventEnteredRealTimeQuiz = gameData.messages.events.real_time_quiz.event_entered;
|
Messages.EventEnteredRealTimeQuiz = gameData.messages.events.real_time_quiz.event_entered;
|
||||||
|
Messages.EventQuitRealTimeQuiz = gameData.messages.events.real_time_quiz.event_quit;
|
||||||
|
|
||||||
// Events : Real Time Riddle
|
// Events : Real Time Riddle
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ namespace HISP.Server
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
public static RealTimeRiddle RiddleEvent = RealTimeRiddle.GetRandomRiddle();
|
public static RealTimeRiddle RiddleEvent = RealTimeRiddle.GetRandomRiddle();
|
||||||
public static TackShopGiveaway TackShopGiveawayEvent;
|
public static TackShopGiveaway TackShopGiveawayEvent = null;
|
||||||
|
public static RealTimeQuiz QuizEvent = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private stuff
|
* Private stuff
|
||||||
|
@ -164,7 +165,8 @@ namespace HISP.Server
|
||||||
// Real Time Quiz
|
// Real Time Quiz
|
||||||
if(totalMinutesElapsed % 75 == 0)
|
if(totalMinutesElapsed % 75 == 0)
|
||||||
{
|
{
|
||||||
|
QuizEvent = new RealTimeQuiz();
|
||||||
|
QuizEvent.StartEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalMinutesElapsed % 60 == 0)
|
if (totalMinutesElapsed % 60 == 0)
|
||||||
|
@ -6951,7 +6953,6 @@ namespace HISP.Server
|
||||||
if (sender.LoggedIn)
|
if (sender.LoggedIn)
|
||||||
{
|
{
|
||||||
Database.SetPlayerLastLogin(Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()), sender.LoggedinUser.Id); // Set last login date
|
Database.SetPlayerLastLogin(Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()), sender.LoggedinUser.Id); // Set last login date
|
||||||
|
|
||||||
Database.RemoveOnlineUser(sender.LoggedinUser.Id);
|
Database.RemoveOnlineUser(sender.LoggedinUser.Id);
|
||||||
|
|
||||||
// Leave multirooms
|
// Leave multirooms
|
||||||
|
@ -6961,9 +6962,13 @@ namespace HISP.Server
|
||||||
// Remove Trade Reference
|
// Remove Trade Reference
|
||||||
sender.LoggedinUser.TradingWith = null;
|
sender.LoggedinUser.TradingWith = null;
|
||||||
sender.LoggedinUser.PendingTradeTo = 0;
|
sender.LoggedinUser.PendingTradeTo = 0;
|
||||||
|
|
||||||
|
// Quit open quiz.
|
||||||
|
if (QuizEvent != null)
|
||||||
|
QuizEvent.LeaveEvent(sender.LoggedinUser, false);
|
||||||
|
|
||||||
// Delete Arena Entries
|
// Delete Arena Entries
|
||||||
if(Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))
|
if (Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))
|
||||||
{
|
{
|
||||||
Arena arena = Arena.GetArenaUserEnteredIn(sender.LoggedinUser);
|
Arena arena = Arena.GetArenaUserEnteredIn(sender.LoggedinUser);
|
||||||
arena.DeleteEntry(sender.LoggedinUser);
|
arena.DeleteEntry(sender.LoggedinUser);
|
||||||
|
@ -7371,7 +7376,7 @@ namespace HISP.Server
|
||||||
forClient.LoggedinUser.ListingAuction = false;
|
forClient.LoggedinUser.ListingAuction = false;
|
||||||
|
|
||||||
string LocationStr = "";
|
string LocationStr = "";
|
||||||
if (!World.InSpecialTile(forClient.LoggedinUser.X, forClient.LoggedinUser.Y))
|
if (!World.InSpecialTile(forClient.LoggedinUser.X, forClient.LoggedinUser.Y) && !forClient.LoggedinUser.InRealTimeQuiz)
|
||||||
{
|
{
|
||||||
LocationStr = Meta.BuildMetaInfo(forClient.LoggedinUser, forClient.LoggedinUser.X, forClient.LoggedinUser.Y);
|
LocationStr = Meta.BuildMetaInfo(forClient.LoggedinUser, forClient.LoggedinUser.X, forClient.LoggedinUser.Y);
|
||||||
}
|
}
|
||||||
|
@ -7383,12 +7388,17 @@ namespace HISP.Server
|
||||||
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket(specialTile.AutoplaySwf,PacketBuilder.PACKET_SWF_MODULE_GENTLE);
|
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket(specialTile.AutoplaySwf,PacketBuilder.PACKET_SWF_MODULE_GENTLE);
|
||||||
forClient.SendPacket(swfModulePacket);
|
forClient.SendPacket(swfModulePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forClient.LoggedinUser.InRealTimeQuiz)
|
||||||
|
return;
|
||||||
|
|
||||||
if (specialTile.Code != null)
|
if (specialTile.Code != null)
|
||||||
if (!ProcessMapCodeWithArg(forClient, specialTile))
|
if (!ProcessMapCodeWithArg(forClient, specialTile))
|
||||||
return;
|
return;
|
||||||
LocationStr = Meta.BuildSpecialTileInfo(forClient.LoggedinUser, specialTile);
|
LocationStr = Meta.BuildSpecialTileInfo(forClient.LoggedinUser, specialTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
byte[] AreaMessage = PacketBuilder.CreateMetaPacket(LocationStr);
|
byte[] AreaMessage = PacketBuilder.CreateMetaPacket(LocationStr);
|
||||||
forClient.SendPacket(AreaMessage);
|
forClient.SendPacket(AreaMessage);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue