Files
EndlessHostRoles/Roles/Crewmate/Mathematician.cs
T
PEPPERcula 1077d83158 Shapeshifting & Petting for Trapster ability (#398)
* Update Trapster.cs

* Update CustomRolesHelper.cs

* Update CustomRolesHelper.cs

* Update Puppeteer.cs

* Update Vampire.cs

* Update ChatCommandPatch.cs

* Update IntroPatch.cs

* Update ChatCommandPatch.cs

* Update Trapster.cs

* Update Vampire.cs

* Update Puppeteer.cs

* Update Mathematician.cs

* Update CopyCat.cs

* Update en_US.json

* Update en_US.json

* Update AntiAdminer.cs

* Update Utils.cs

* Update en_US.json

* Update IntroPatch.cs

* Update CustomRolesHelper.cs

* Update CopyCat.cs

* Update CopyCat.cs

* Update CustomRolesHelper.cs
2025-11-12 11:03:17 +01:00

73 lines
2.7 KiB
C#

using System;
using EHR.Modules;
namespace EHR.Crewmate;
internal class Mathematician : RoleBase
{
public static (bool AskedQuestion, int Answer, byte ProtectedPlayerId, byte MathematicianPlayerId) State = (false, int.MaxValue, byte.MaxValue, byte.MaxValue);
public static bool On;
private static int Id => 643370;
public override bool IsEnable => On;
public override void SetupCustomOption()
{
Options.SetupSingleRoleOptions(Id, TabGroup.CrewmateRoles, CustomRoles.Mathematician);
}
public override void Init()
{
On = false;
State = (false, int.MaxValue, byte.MaxValue, byte.MaxValue);
}
public override void Add(byte playerId)
{
On = true;
State = (false, int.MaxValue, byte.MaxValue, byte.MaxValue);
}
public static void Ask(PlayerControl pc, string num1Str, string num2Str)
{
try
{
if (pc == null || !pc.IsAlive() || !GameStates.IsMeeting || State.AskedQuestion || State.ProtectedPlayerId != byte.MaxValue || !int.TryParse(num1Str, out int num1) || !int.TryParse(num2Str, out int num2)) return;
State.AskedQuestion = true;
State.Answer = num1 + num2;
State.MathematicianPlayerId = pc.PlayerId;
string question = string.Format(Translator.GetString("MathematicianQuestionString"), num1, num2);
ChatManager.SendPreviousMessagesToAll();
LateTask.New(() => Utils.SendMessage(question, title: Utils.ColorString(Utils.GetRoleColor(CustomRoles.Mathematician), Translator.GetString("Mathematician"))), 0.2f, log: false);
}
catch (Exception e) { Utils.ThrowException(e); }
}
public static void Reply(PlayerControl pc, string answerStr)
{
try
{
if (pc == null || !pc.IsAlive() || !GameStates.IsMeeting || !State.AskedQuestion || State.MathematicianPlayerId == pc.PlayerId || State.ProtectedPlayerId != byte.MaxValue || !int.TryParse(answerStr, out int answer)) return;
if (answer == State.Answer)
{
State.ProtectedPlayerId = pc.PlayerId;
pc.RpcIncreaseAbilityUseLimitBy(1f);
Utils.SendMessage(string.Format(Translator.GetString("MathematicianAnsweredString"), pc.GetRealName(), answer), title: Utils.ColorString(Utils.GetRoleColor(CustomRoles.Mathematician), Translator.GetString("Mathematician")));
State.AskedQuestion = false;
if (pc.AmOwner)
Achievements.Type.TheBestInSchool.Complete();
}
}
catch (Exception e) { Utils.ThrowException(e); }
}
public override void OnReportDeadBody()
{
State = (false, int.MaxValue, byte.MaxValue, byte.MaxValue);
}
}