Make Quiz Questions The Same for Each User

This commit is contained in:
SilicaAndPina 2021-04-16 11:30:52 +12:00
parent ccb3e4420a
commit 7a85eaac5d
6 changed files with 41 additions and 18 deletions

View file

@ -100,6 +100,7 @@
"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_entered_already":"Realtime quiz was already entered.",
"event_quit":"Realtime quiz was quit already. Only one try per Quiz.", "event_quit":"Realtime quiz was quit already. Only one try per Quiz.",
}, },
}, },

View file

@ -373,6 +373,12 @@ 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 = (GameServer.QuizEvent != null); bool quizActive = (GameServer.QuizEvent != null);
if(user.InRealTimeQuiz)
{
byte[] cantEnterRealTimeQuiz = PacketBuilder.CreateChat(Messages.EventAlreadyEnteredRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(cantEnterRealTimeQuiz);
return false;
}
if (quizActive) if (quizActive)
{ {
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1)); string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));

View file

@ -25,21 +25,20 @@ namespace HISP.Game.Events
public class Participent public class Participent
{ {
public Participent(User user) public Participent(User user, RealTimeQuiz Quiz)
{ {
UserInstance = user; UserInstance = user;
Won = false; Won = false;
Quit = false; Quit = false;
CorrectAnswers = 0; CorrectAnswers = 0;
MistakenAnswers = 0; MistakenAnswers = 0;
baseQuiz = Quiz;
NextQuestion(); NextQuestion();
} }
public void NextQuestion() public void NextQuestion()
{ {
CorrectAnswers++; OnQuestion = baseQuiz.Questions[CorrectAnswers++];
QuizCategory chosenCategory = Categories[GameServer.RandomNumberGenerator.Next(0, Categories.Length)];
OnQuestion = chosenCategory.Questions[GameServer.RandomNumberGenerator.Next(0, chosenCategory.Questions.Length)];
} }
public void UpdateParticipent() public void UpdateParticipent()
@ -57,9 +56,9 @@ namespace HISP.Game.Events
{ {
if(answer.ToLower().Trim() == correctAnswer.ToLower().Trim()) if(answer.ToLower().Trim() == correctAnswer.ToLower().Trim())
{ {
if(CorrectAnswers == 8) if(CorrectAnswers >= baseQuiz.Questions.Length)
{ {
GameServer.QuizEvent.WinEvent(UserInstance); baseQuiz.WinEvent(UserInstance);
return; return;
} }
@ -69,7 +68,7 @@ namespace HISP.Game.Events
} }
if (answer.ToLower().Trim() == "quit") if (answer.ToLower().Trim() == "quit")
{ {
GameServer.QuizEvent.LeaveEvent(UserInstance); baseQuiz.QuitEvent(UserInstance);
return; return;
} }
} }
@ -77,16 +76,17 @@ namespace HISP.Game.Events
UpdateParticipent(); UpdateParticipent();
} }
private RealTimeQuiz baseQuiz;
public User UserInstance; public User UserInstance;
public int CorrectAnswers; public int CorrectAnswers;
public int MistakenAnswers; public int MistakenAnswers;
public bool Quit; public bool Quit;
public bool Won; public bool Won;
public QuizQuestion OnQuestion; public QuizQuestion OnQuestion;
} }
public static QuizCategory[] Categories; public static QuizCategory[] Categories;
public QuizQuestion[] Questions;
public bool Active; public bool Active;
public const int QUIZ_TIMEOUT = 5; public const int QUIZ_TIMEOUT = 5;
private Timer quizTimer; private Timer quizTimer;
@ -102,7 +102,14 @@ namespace HISP.Game.Events
public RealTimeQuiz() public RealTimeQuiz()
{ {
participents = new List<Participent>(); 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; Active = false;
} }
@ -125,7 +132,7 @@ namespace HISP.Game.Events
} }
catch (KeyNotFoundException) { }; catch (KeyNotFoundException) { };
Participent newParticipent = new Participent(user); Participent newParticipent = new Participent(user, this);
user.InRealTimeQuiz = true; user.InRealTimeQuiz = true;
participents.Add(newParticipent); participents.Add(newParticipent);
@ -133,18 +140,26 @@ namespace HISP.Game.Events
return newParticipent; return newParticipent;
} }
public void LeaveEvent(User user, bool sendData=true) 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 try
{ {
Participent partcipent = getParticipent(user.Id); Participent partcipent = getParticipent(user.Id);
partcipent.Quit = true; partcipent.Quit = true;
user.InRealTimeQuiz = false; user.InRealTimeQuiz = false;
GameServer.UpdateArea(user.LoggedinClient);
if(sendData)
if (user.LoggedinClient != null)
if(GameServer.IsUserOnline(user.Id))
GameServer.UpdateArea(user.LoggedinClient);
} }
catch (KeyNotFoundException) { }; catch (KeyNotFoundException) { };
} }

View file

@ -78,6 +78,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 EventAlreadyEnteredRealTimeQuiz;
public static string EventQuitRealTimeQuiz; public static string EventQuitRealTimeQuiz;
// Events : Real Time Riddles // Events : Real Time Riddles
@ -2020,7 +2021,6 @@ namespace HISP.Game
{ {
return HorseCompanionEquipMessageFormat.Replace("%HORSENAME%", horseName).Replace("%ITEM%", itemName); return HorseCompanionEquipMessageFormat.Replace("%HORSENAME%", horseName).Replace("%ITEM%", itemName);
} }
public static string FormatPlaytimeMessage(int hours) public static string FormatPlaytimeMessage(int hours)
{ {
return PlaytimeMessageFormat.Replace("%TOTALHOURS%", hours.ToString()); return PlaytimeMessageFormat.Replace("%TOTALHOURS%", hours.ToString());

View file

@ -966,6 +966,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.EventAlreadyEnteredRealTimeQuiz = gameData.messages.events.real_time_quiz.event_entered_already;
Messages.EventQuitRealTimeQuiz = gameData.messages.events.real_time_quiz.event_quit; Messages.EventQuitRealTimeQuiz = gameData.messages.events.real_time_quiz.event_quit;
// Events : Real Time Riddle // Events : Real Time Riddle

View file

@ -7003,9 +7003,9 @@ namespace HISP.Server
sender.LoggedinUser.TradingWith = null; sender.LoggedinUser.TradingWith = null;
sender.LoggedinUser.PendingTradeTo = 0; sender.LoggedinUser.PendingTradeTo = 0;
// Quit open quiz. // Leave open quiz.
if (QuizEvent != null) if (QuizEvent != null)
QuizEvent.LeaveEvent(sender.LoggedinUser, false); QuizEvent.LeaveEvent(sender.LoggedinUser);
// Delete Arena Entries // Delete Arena Entries
if (Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser)) if (Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))