a lot of fixes

This commit is contained in:
Gurge44 committed 2025-04-12 10:46:21 +02:00
1 parent 496df16c86
commit c3982d0dc2
7 files changed
+81 -38

No files matched your search

+54 -25
View File
@@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using AmongUs.GameOptions;
using HarmonyLib;
using Hazel;
using UnityEngine;
@@ -147,13 +146,13 @@ public static class Quiz
public static bool CanKill()
{
return FFAEndTS != 0 && AllowKills;
return AllowKills;
}
public static string GetSuffix(PlayerControl seer)
{
if (NoSuffix) return string.Empty;
bool wasWrong = DyingPlayers.Contains(seer.PlayerId);
if (FFAEndTS == 0)
@@ -179,7 +178,7 @@ public static class Quiz
}
string question = CurrentQuestion.Question;
for (var i = 50; i < question.Length; i += 50)
{
int index = question.LastIndexOf(' ', i);
@@ -197,8 +196,8 @@ public static class Quiz
if (CurrentDifficulty > Difficulty.Test && Settings[CurrentDifficulty].QuestionsAsked.GetInt() <= QuestionsAsked)
{
int correctRequirement = Settings[CurrentDifficulty].CorrectRequirement.GetInt();
var dyingPlayers = HistoricDyingPlayers.Flatten().GroupBy(x => x).Where(x => x.Count() < correctRequirement).Flatten().ToList();
int maxIncorrect = Settings[CurrentDifficulty].QuestionsAsked.GetInt() - Settings[CurrentDifficulty].CorrectRequirement.GetInt();
var dyingPlayers = HistoricDyingPlayers.Flatten().GroupBy(x => x).Where(x => x.Count() > maxIncorrect).Flatten().Distinct().ToList();
str += "\n" + dyingPlayers.Count switch
{
0 => GetString("Quiz.Notify.AllCorrect"),
@@ -211,6 +210,8 @@ public static class Quiz
return str;
}
if (!AllowKills) return string.Empty;
var ffaTimeLeft = FFAEndTS - Utils.TimeStamp;
var rndRoom = Main.AllAlivePlayerControls.Without(seer).Select(x => x.GetPlainShipRoom()).Where(x => x != null).Select(x => x.RoomId).Distinct().Without(SystemTypes.Hallway).RandomElement();
return string.Format(GetString(wasWrong ? "Quiz.Notify.FFAOngoing" : "Quiz.Notify.FFASpectating"), GetString(rndRoom.ToString()), ffaTimeLeft);
@@ -261,13 +262,14 @@ public static class Quiz
NameNotifyManager.Reset();
NoSuffix = false;
TestRound();
CurrentDifficulty = Difficulty.Test;
QuestionTimeLimitEndTS = Utils.TimeStamp + 30;
CurrentQuestion = GetQuestion(0);
while (QuestionTimeLimitEndTS != 0)
{
yield return new WaitForSeconds(1f);
if (GameStates.IsMeeting || ExileController.Instance || !GameStates.InGame || GameStates.IsLobby) yield break;
Logger.Info("Waiting for test round to end", "debug");
}
yield return new WaitForSeconds(3f);
@@ -284,17 +286,7 @@ public static class Quiz
NameNotifyManager.Reset();
}
yield return NewQuestion(increaseDifficulty: showTutorial);
}
private static void TestRound()
{
CurrentDifficulty = Difficulty.Test;
QuestionTimeLimitEndTS = Utils.TimeStamp + 30;
CurrentQuestion = GetQuestion(0);
Logger.Warn("Test round started", "debug");
Logger.Warn("Question: " + CurrentQuestion.Question + " - Answers: " + string.Join(", ", CurrentQuestion.Answers) + " - Correct Answer: " + CurrentQuestion.CorrectAnswerIndex, "debug");
yield return NewQuestion(increaseDifficulty: showTutorial, newRound: true);
}
private static IEnumerator NewQuestion(bool increaseDifficulty = true, bool newRound = false)
@@ -328,6 +320,9 @@ public static class Quiz
time += CurrentQuestion.Answers.Sum(x => x.Length / 15);
if (Main.CurrentMap is MapNames.Skeld or MapNames.Dleks) time -= 3;
QuestionTimeLimitEndTS = Utils.TimeStamp + time;
Logger.Info($"New question: {CurrentQuestion.Question} | {string.Join(", ", CurrentQuestion.Answers)} | {CurrentQuestion.CorrectAnswerIndex}", "Quiz");
Logger.Info($"Time limit: {time}", "Quiz");
}
private static int GetRandomQuestionIndex()
@@ -384,10 +379,44 @@ public static class Quiz
yield break;
}
var correctRequirement = settings.CorrectRequirement.GetInt();
Dictionary<byte, (int Num, bool Enough)> correctCounts = [];
foreach ((byte id, Dictionary<Difficulty, int> dictionary) in NumCorrectAnswers)
{
int correctAnswers = dictionary[CurrentDifficulty];
bool enough = correctAnswers >= correctRequirement;
correctCounts[id] = (correctAnswers, enough);
}
var sender = CustomRpcSender.Create("Quiz.NumCorrectAnswerNotify", SendOption.Reliable);
var hasValue = false;
foreach ((byte id, (int num, bool enough)) in correctCounts)
{
var pc = id.GetPlayer();
if (pc == null) continue;
var color = enough ? Color.green : Color.red;
sender.Notify(pc, string.Format(Utils.ColorString(color, GetString("Quiz.Notify.CorrectAnswerNum")), num, QuestionsAsked, correctRequirement));
hasValue = true;
if (sender.stream.Length > 800)
{
sender.SendMessage();
sender = CustomRpcSender.Create("Quiz.NumCorrectAnswerNotify", SendOption.Reliable);
hasValue = false;
}
}
sender.SendMessage(dispose: !hasValue);
yield return new WaitForSeconds(3f);
List<byte> dyingPlayers = correctCounts.Where(x => !x.Value.Enough).Select(x => x.Key).ToList();
Logger.Info($"Round {Rounds + 1} of {CurrentDifficulty} difficulty ended. Dying players: {dyingPlayers.Count} | {string.Join(", ", dyingPlayers.Select(x => Main.AllPlayerNames[x]))}", "Quiz");
Rounds++;
QuestionsAsked = 0;
var correctRequirement = settings.CorrectRequirement.GetInt();
var dyingPlayers = HistoricDyingPlayers.Flatten().GroupBy(x => x).Where(x => x.Count() < correctRequirement).Flatten().ToList();
HistoricDyingPlayers = [];
switch (dyingPlayers.Count)
@@ -406,7 +435,7 @@ public static class Quiz
AllowKills = true;
FFAEndTS = Utils.TimeStamp + FFAEventLength.GetInt();
var spectators = aapc.ExceptBy(dyingPlayers, x => x.PlayerId).ToArray();
var sender = CustomRpcSender.Create("Quiz.FFA-Event-RpcExileV2", SendOption.Reliable);
sender = CustomRpcSender.Create("Quiz.FFA-Event-RpcExileV2", SendOption.Reliable);
spectators.Do(sender.RpcExileV2);
sender.SendMessage();
Main.PlayerStates.Values.IntersectBy(spectators.Select(x => x.PlayerId), x => x.Player.PlayerId).Do(x => x.SetDead());
@@ -418,7 +447,7 @@ public static class Quiz
yield return new WaitForSeconds(1f);
if (GameStates.IsMeeting || ExileController.Instance || !GameStates.InGame || GameStates.IsLobby) yield break;
Utils.NotifyRoles();
stillLiving = dyingPlayers.ToValidPlayers().FindAll(x => x.IsAlive());
stillLiving.RemoveAll(x => x == null || !x.IsAlive());
if (stillLiving.Count <= 1) break;
}
@@ -470,15 +499,15 @@ public static class Quiz
if (QuestionTimeLimitEndTS != 0)
{
Logger.Info("Ongoing question", "debug");
if (QuestionTimeLimitEndTS <= now)
{
Logger.Info("Question timer ended", "Quiz");
if (CurrentDifficulty == Difficulty.Test)
{
SystemTypes correctRoom = UsedRooms[Main.CurrentMap][(char)('A' + CurrentQuestion.CorrectAnswerIndex)];
DyingPlayers = Main.AllAlivePlayerControls.Select(x => (ID: x.PlayerId, Room: x.GetPlainShipRoom())).Where(x => correctRoom == SystemTypes.Outside ? x.Room != null : x.Room == null || x.Room.RoomId != correctRoom).Select(x => x.ID).ToList();
QuestionTimeLimitEndTS = 0;
Logger.Warn("End of test round", "debug");
}
else
Main.Instance.StartCoroutine(EndQuestion());
+1 -1
View File
@@ -46,7 +46,7 @@ public class CustomRpcSender
this.name = name;
this.isUnsafe = isUnsafe;
currentRpcTarget = -2;
onSendDelegate = () => Logger.Info($"{this.name}'s onSendDelegate =>", "CustomRpcSender");
onSendDelegate = () => { };
currentState = State.Ready;
Logger.Info($"\"{name}\" is ready", "CustomRpcSender");
+3 -1
View File
@@ -1250,6 +1250,8 @@ internal static class ExtendedPlayerControl
CustomRoles.Potato => false,
// Speedrun
CustomRoles.Runner => Speedrun.CanKill.Contains(pc.PlayerId),
// Quiz
CustomRoles.QuizPlayer => Quiz.CanKill(),
// Hide And Seek
CustomRoles.Seeker => true,
CustomRoles.Hider => false,
@@ -1297,7 +1299,7 @@ internal static class ExtendedPlayerControl
public static bool CanUseSabotage(this PlayerControl pc)
{
if (!pc.IsAlive() || pc.inVent || pc.Data.Role.Role == RoleTypes.GuardianAngel) return false;
if (!pc.IsAlive() || pc.Data.Role.Role == RoleTypes.GuardianAngel) return false;
return Main.PlayerStates.TryGetValue(pc.PlayerId, out PlayerState state) && state.Role.CanUseSabotage(pc);
}
+4 -2
View File
@@ -1940,7 +1940,7 @@ public static class Utils
};
}
}
return name != player.name && player.CurrentOutfitType == PlayerOutfitType.Default;
}
@@ -2151,7 +2151,7 @@ public static class Utils
string seers = seerList.Length == apc.Length ? "Everyone" : string.Join(", ", seerList.Select(x => x.GetRealName()));
string targets = targetList.Length == apc.Length ? "Everyone" : string.Join(", ", targetList.Select(x => x.GetRealName()));
if (seers.Length == 0) seers = "\u2205";
if (targets.Length == 0) targets = "\u2205";
@@ -2408,6 +2408,8 @@ public static class Utils
if (!GameStates.IsLobby)
{
if (Options.CurrentGameMode == CustomGameMode.Quiz) SelfName = string.Empty;
if (NameNotifyManager.GetNameNotify(seer, out string name) && name.Length > 0) SelfName = name;
switch (Options.CurrentGameMode)
+3 -1
View File
@@ -447,7 +447,7 @@ internal static class SetHudActivePatch
public static void Postfix(HudManager __instance, [HarmonyArgument(2)] bool isActive)
{
__instance?.ReportButton?.ToggleVisible(!GameStates.IsLobby && isActive);
if (GameStates.IsLobby || !isActive) __instance?.ReportButton?.ToggleVisible(false);
if (__instance == null)
{
@@ -461,6 +461,8 @@ internal static class SetHudActivePatch
switch (Options.CurrentGameMode)
{
case CustomGameMode.Quiz:
__instance.KillButton.ToggleVisible(Quiz.CanKill());
goto case CustomGameMode.MoveAndStop;
case CustomGameMode.MoveAndStop:
case CustomGameMode.HotPotato:
case CustomGameMode.Speedrun:
+7 -2
View File
@@ -238,10 +238,12 @@ internal static class CheckMurderPatch
case CustomGameMode.RoomRush:
case CustomGameMode.NaturalDisasters:
case CustomGameMode.Speedrun when !Speedrun.OnCheckMurder(killer, target):
case CustomGameMode.Quiz when !Quiz.CanKill():
case CustomGameMode.Quiz:
if (Quiz.CanKill()) killer.Kill(target);
return false;
case CustomGameMode.AllInOne:
if (killer.Is(CustomRoles.Killer)) killer.Kill(target);
if (killer.Is(CustomRoles.Killer) || (CustomGameMode.Quiz.IsActiveOrIntegrated() && Quiz.CanKill()))
killer.Kill(target);
if (CustomGameMode.KingOfTheZones.IsActiveOrIntegrated())
KingOfTheZones.OnCheckMurder(killer, target);
@@ -1637,6 +1639,9 @@ internal static class FixedUpdatePatch
case CustomGameMode.SoloKombat:
SoloPVP.GetNameNotify(target, ref realName);
break;
case CustomGameMode.Quiz when self:
realName = string.Empty;
break;
}
if (Deathpact.IsInActiveDeathpact(seer)) realName = Deathpact.GetDeathpactString(seer);
+9 -6
View File
@@ -4926,15 +4926,17 @@
"Quiz.Tutorial.OnWrongAnswer": "<size=90%>If you answer <#ff0000>incorrectly</color>, you will most likely die.</size>",
"Quiz.Tutorial.OnCorrectAnswer": "<size=90%>If you answer <#00ff00>correctly</color>, you get to survive\\n(and potentially spectate others during the FFA).</size>",
"Quiz.Notify.NextStage": "--------------------\\nStage {0}\\n--------------------\\n<size=90%>{1} Rounds\\n{2} Questions\\n{3}/{4} Answers Must Be Correct\\n{5}s To Answer Each Question</size>",
"Quiz.Notify.NextRound": "<size=150%><#ffff00>Round {0}</color></size>\\n<size=90%>Answer <#ffff00>{1}</color> questions correctly to survive</size>",
"Quiz.Notify.CorrectAnswer": "<{0}>The correct answer was:\\n{1} - {2} ({3})",
"Quiz.Notify.AllCorrect": "<#00ffa5>Everyone found the correct answer!</color>",
"Quiz.Notify.AllWrong": "<#ffff00><u>Everyone</u> got this question wrong, so no one will die!</color>",
"Quiz.Notify.OnlyYouWrong": "<#ff0000>Only you got this question wrong. You will die now.</color>",
"Quiz.Notify.OneWrong": "<#00a5ff>1 player got this question wrong. They will simply die.</color>",
"Quiz.Notify.IncorrectFFA": "<#ff4444>Luckily, you're not alone to get this question wrong!\\nYou will participate in a Free For All (FFA) event against the others who failed.\\nKill everyone else and be the last one alive to get a second chance!\\nBe sure to do this within the time limit, or all of you will die!</color>",
"Quiz.Notify.CorrectFFA": "<#00ffff>More than 1 player failed this question!\\nYou get to spectate them fighting in a Free For All (FFA) match to survive!",
"Quiz.Notify.AllCorrect": "<#00ffa5>Everyone found all correct answers!</color>",
"Quiz.Notify.AllWrong": "<#ffff00><u>Everyone</u> would die, so no one will die!</color>",
"Quiz.Notify.OnlyYouWrong": "<#ff0000>Only you failed this round. You will die now.</color>",
"Quiz.Notify.OneWrong": "<#00a5ff>1 player failed this round. They will simply die.</color>",
"Quiz.Notify.IncorrectFFA": "<#ff4444>Luckily, you're not alone to failed this round!\\nYou will participate in a Free For All (FFA) event against the others who failed.\\nKill everyone else and be the last one alive to get a second chance!\\nBe sure to do this within the time limit, or all of you will die!</color>",
"Quiz.Notify.CorrectFFA": "<#00ffff>More than 1 player failed this round!\\nYou get to spectate them fighting in a Free For All (FFA) match to survive!",
"Quiz.Notify.FFAOngoing": "<size=80%><#ffff00><u>Kill everyone</u> and survive</color>\\nHint: Someone is in {0}\\n<#ffa500>{1}</color></size>",
"Quiz.Notify.FFASpectating": "<size=80%><#00ffff>Spectate the chaos!</color>\\n<#00a5ff>{1}</color></size>",
"Quiz.Notify.CorrectAnswerNum": "<size=80%>You got {0}/{1} questions correct! The required amount was {2}.</size>",
"Quiz.EndResults.CorrectAnswerNum": "Correct Answers: ",
"Quiz.Questions.Test.0": "Which map are we on?",
"Quiz.Questions.Test.0.Answer.A": "The Skeld / dlekS ehT",
@@ -8313,6 +8315,7 @@
"AllInOne.SoloKombat.Integration": "Integrate <#f55252>Solo PVP</color>",
"AllInOne.Speedrun.Integration": "Integrate <#800080>Speedrun</color>",
"AllInOne.KingOfTheZones.Integration": "Integrate <#ff0000>King Of The Zones</color>",
"AllInOne.Quiz.Integration": "Integrate <#CF2472>Quiz</color>",
"AllInOne.HotPotato.TimerMultiplier": "Hot Potato - Timer Multiplier",
"AllInOne.MoveAndStop.MinGreenTimeBonus": "Stop And Go - Minimum Green Time Bonus",
"AllInOne.MoveAndStop.MaxGreenTimeBonus": "Stop And Go - Maximum Green Time Bonus",