Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telekinesis update (telepathy + Messenger) #1154

Draft
wants to merge 46 commits into
base: Drakos_TelekinesisRoles
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0c7cf44
wow I already broke the game, how fun.....
Ultradragon005 Aug 11, 2024
956aebc
Merge branch 'DevBuild_2.1.0' into telekinesis-update
Ultradragon005 Aug 11, 2024
aa06b23
fix bugs
Ultradragon005 Aug 12, 2024
ceb415e
now finally time to begin on Messenger
Ultradragon005 Aug 12, 2024
9f06169
.
Ultradragon005 Aug 12, 2024
b149e43
nvm I guess I'm just autistic
Ultradragon005 Aug 12, 2024
131a816
revert
Ultradragon005 Aug 12, 2024
19f85eb
skibidi toilet
Ultradragon005 Aug 12, 2024
696c711
Almsot done, jsut need some fixes left
Ultradragon005 Aug 12, 2024
4054446
finishing touches
Ultradragon005 Aug 12, 2024
c536c28
Updates
Ultradragon005 Aug 12, 2024
467e3c5
done
Ultradragon005 Aug 12, 2024
c7ab50d
update
Ultradragon005 Aug 12, 2024
486278c
bruh
Ultradragon005 Aug 12, 2024
7781c25
bruh 2.0
Ultradragon005 Aug 12, 2024
b70c262
larger delay
Ultradragon005 Aug 12, 2024
bc67cb7
move
Ultradragon005 Aug 12, 2024
23002ff
change id
Ultradragon005 Aug 12, 2024
87801c2
move
Ultradragon005 Aug 12, 2024
a5d2fdc
how the hell did I forget that
Ultradragon005 Aug 12, 2024
789881d
oh also not supposed to be experimental anymore
Ultradragon005 Aug 12, 2024
36dcdd2
eh, this can break too
Ultradragon005 Aug 12, 2024
f6b47fd
cleanup logic
Ultradragon005 Aug 12, 2024
ef501d3
change
Ultradragon005 Aug 12, 2024
ab8b8da
forget revert
Ultradragon005 Aug 12, 2024
b47aafb
more cleanup
Ultradragon005 Aug 12, 2024
3bfe675
nah, it will be funny af 🤣
Ultradragon005 Aug 12, 2024
eef3efd
OH THIS MF
Ultradragon005 Aug 13, 2024
35344cf
fix
Ultradragon005 Aug 13, 2024
fe63d08
I already checked for null
Ultradragon005 Aug 13, 2024
8f7477c
use strinbuilder && 0 => 1
Ultradragon005 Aug 13, 2024
5470ce0
fix
Ultradragon005 Aug 13, 2024
579ac56
fix again..
Ultradragon005 Aug 13, 2024
a844c52
rename
Ultradragon005 Aug 13, 2024
a68a2e2
simplify
Ultradragon005 Aug 16, 2024
ea1cf2f
fix
Ultradragon005 Aug 16, 2024
70d2a6f
fix again...
Ultradragon005 Aug 16, 2024
a185904
change
Ultradragon005 Aug 16, 2024
c7be738
fix again..
Ultradragon005 Aug 16, 2024
35445b1
fix id
Ultradragon005 Aug 17, 2024
57c3b3e
CustomRoles.NotAssigned => CustomRoles.Telepathy
Ultradragon005 Aug 17, 2024
f49691f
I forgot .outofgame exists...
Ultradragon005 Aug 19, 2024
b42dff1
merge latest
Ultradragon005 Aug 19, 2024
d95bb17
.
Ultradragon005 Aug 19, 2024
a21a3c2
merge latest
Ultradragon005 Aug 29, 2024
89ffd8e
fix error
Ultradragon005 Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Modules/ExtendedPlayerControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,6 @@ public static void RpcMurderPlayer(this PlayerControl killer, PlayerControl targ
DollMaster.CheckMurderAsPossessed(killer, target);
return;
}

killer.RpcMurderPlayer(target, true);
}

Expand Down
7 changes: 7 additions & 0 deletions Modules/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,13 @@ public bool IsEqual(PlayerVersion pv)
return pv.version == version && pv.tag == tag;
}
}
public enum KilledType
{
Directly,
Indirectly,
Remotely,
Suicide_
}
public static class GameStates
{
public static bool InGame = false;
Expand Down
106 changes: 104 additions & 2 deletions Modules/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using TOHE.Roles.Core;
using static TOHE.Translator;
using TOHE.Patches;
using MS.Internal.Xml.XPath;


namespace TOHE;
Expand Down Expand Up @@ -1663,8 +1664,108 @@ public static List<PlayerControl> GetPlayerListByIds(this IEnumerable<byte> Play
}
public static List<PlayerControl> GetPlayerListByRole(this CustomRoles role)
=> GetPlayerListByIds(Main.PlayerStates.Values.Where(x => x.MainRole == role).Select(r => r.PlayerId));

public static IEnumerable<t> GetRoleBasesByType <t>() where t : RoleBase

public static bool IsSameTeammate(this PlayerControl player, PlayerControl target, out Custom_Team team)
{
team = default;
if (player.IsAnySubRole(x => x.IsConverted()))
{
var Compare = player.GetCustomSubRoles().First(x => x.IsConverted());

team = player.Is(CustomRoles.Madmate) ? Custom_Team.Impostor : Custom_Team.Neutral;
return target.Is(Compare);
}
else if (!target.IsAnySubRole(x => x.IsConverted()))
{
team = player.GetCustomRole().GetCustomRoleTeam();
return target.Is(team);
}


return false;
}
public static string DetermineSetMessage(PlayerControl Player, PlayerControl killer, out Dictionary<int, string> DeterminedMessage)
{
string[] Translatables = { "Messenger.KillerLastKillIn",
"Messenger.KillerExistIn", "Messenger.KillersRoleIs",
"Messenger.KilledType", "Messenger.MyTypeIs", "Messenger.TheLastKillers",
"Messenger.PlayerOnSameTeam", "Messenger.LazyFuck", "Messenger.KillersFaction", "Messenger.ThisRoleExists"};

static t CreateAndInvoke<t>(Func<t> func)
{
return func.Invoke();
}

List<string> TakeMsg = [..Translatables];
var Msg = new StringBuilder();
DeterminedMessage = [];
for (int i = 1; i <= 3; i++)
{
var ran = TakeMsg.RandomElement();
TakeMsg.Remove(ran);
var CurrentMessage = "";
try
{
CurrentMessage = ran switch
{
"Messenger.KillerLastKillIn" when killer != null && killer.IsAlive() && Main.LastKillerRoom.TryGetValue(Player.PlayerId, out var pokoj) => string.Format(GetString("Messenger.KillerLastKillIn"), GetString($"{pokoj.RoomId}")),
"Messenger.KillerExistIn" when Main.AllAlivePlayerControls.Where(x => x.GetCustomRole().IsImpostor() || x.IsNeutralKiller() || x.IsNeutralApocalypse() || x.IsTransformedNeutralApocalypse()).Shuffle(IRandom.Instance).FirstOrDefault() is not null and PlayerControl killar => CreateAndInvoke(() =>
{ // yes using Apoc/TApoc may not be 100% accurate but they may or may not keep the game keep going and I'm too lazy to make a specific check
SystemTypes room = killar.GetPlainShipRoom().RoomId;
return string.Format(GetString("Messenger.KillerExistIn"), GetString($"{room}"));
}),
"Messenger.KillersRoleIs" when Main.RememberKillerRole != "" => string.Format(GetString("Messenger.KillersRoleIs"), Main.RememberKillerRole),
"Messenger.KilledType" when Main.PlayerKilledBy.TryGetValue(Player.PlayerId, out var KilledType) => string.Format(GetString("Messenger.KilledType"), GetString($"{KilledType}")),
"Messenger.MyTypeIs" => string.Format(GetString("Messenger.MyTypeIs"), (!Player.IsAnySubRole(x => x.IsConverted() && !Player.Is(CustomRoles.Madmate)) ? Player.GetCustomRole().GetCustomRoleTeam() : Custom_Team.Neutral)),
"Messenger.TheLastKillers" when Main.AllAlivePlayerControls.Where(x => x.GetCustomRole().IsImpostor() || x.IsNeutralKiller() || x.IsNeutralApocalypse()).Any() => CreateAndInvoke(() =>
{
var Killers = Main.AllAlivePlayerControls.Where(x => x.GetCustomRole().IsImpostor() || x.IsNeutralKiller() || x.IsNeutralApocalypse());
var msg = new StringBuilder();
Killers.Do(x => msg.Append($"{GetString($"{x.GetCustomRole()}")}, "));
return string.Format(GetString("Messenger.TheLastKillers"), msg.ToString());
}),
"Messenger.PlayerOnSameTeam" when Main.AllAlivePlayerControls.Shuffle(IRandom.Instance).FirstOrDefault(x => Player.IsSameTeammate(x, out _)) is not null and PlayerControl friend => string.Format(GetString("Messenger.PlayerOnSameTeam"), friend.GetRealName(clientData: true)),
"Messenger.LazyFuck" => CreateAndInvoke(() =>
{
var mintask = Main.AllAlivePlayerControls.Where(x => !x.HasImpKillButton()).Min(x => x.GetPlayerTaskState().CompletedTasksCount);
var lazyfuck = Main.AllAlivePlayerControls.First(x => x.GetPlayerTaskState().CompletedTasksCount == mintask);

var suspects = Main.AllAlivePlayerControls.Where(x => x.HasImpKillButton()).AddItem(lazyfuck);

var ScapeGoat = suspects.Shuffle(IRandom.Instance).First();

return string.Format(GetString("Messenger.LazyFuck"), ScapeGoat.GetRealName(clientData: true));
}),

"Messenger.KillersFaction" when Main.RememberedFaction != null => string.Format(GetString("Messenger.KillersFaction"), GetString($"Team{Main.RememberedFaction.Value}")),

_ => CreateAndInvoke(() =>
{
var rndPC = Main.AllAlivePlayerControls.ToArray().RandomElement();
return string.Format(GetString("Messenger.ThisRoleExists"), GetString($"{rndPC.GetCustomRole()}"));
}),
};
}
catch(Exception exx)
{
CurrentMessage = CreateAndInvoke(() =>
{
var rndPC = Main.AllAlivePlayerControls.ToArray().RandomElement();
return string.Format(GetString("Messenger.ThisRoleExists"), GetString($"{rndPC.GetCustomRole()}"));
});
Logger.Warn($" The case ( {ran} ) Returned an error", "Utils.DetermineSetMessag");
Utils.ThrowException(exx);
}
DeterminedMessage[i] = CurrentMessage;
Msg.Append($"{i}) " + CurrentMessage + "\n");
}


return Msg.ToString();

}

public static IEnumerable<t> GetRoleBasesByType <t>() where t : RoleBase
{
try
{
Expand Down Expand Up @@ -2082,6 +2183,7 @@ static int GetInfoSize(string RoleInfo)

TargetSuffix.Append(seerRoleClass?.GetSuffix(seer, target, isForMeeting: isForMeeting));
TargetSuffix.Append(CustomRoleManager.GetSuffixOthers(seer, target, isForMeeting: isForMeeting));
TargetSuffix.Append(Messenger.GetSuffix(target, isForMeeting));

if (TargetSuffix.Length > 0)
{
Expand Down
9 changes: 8 additions & 1 deletion Patches/ChatCommandPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text.RegularExpressions;
using TOHE.Modules;
using TOHE.Modules.ChatManager;
using TOHE.Roles._Ghosts_.Crewmate;
using TOHE.Roles.AddOns.Common;
using TOHE.Roles.Core;
using TOHE.Roles.Core.AssignManager;
using TOHE.Roles.Crewmate;
Expand Down Expand Up @@ -67,7 +69,10 @@ public static bool Prefix(ChatController __instance)
if (Nemesis.NemesisMsgCheck(PlayerControl.LocalPlayer, text)) goto Canceled;
if (Retributionist.RetributionistMsgCheck(PlayerControl.LocalPlayer, text)) goto Canceled;
if (Medium.MsMsg(PlayerControl.LocalPlayer, text)) goto Canceled;
if (PlayerControl.LocalPlayer.GetRoleClass() is Swapper sw && sw.SwapMsg(PlayerControl.LocalPlayer, text)) goto Canceled;
if (PlayerControl.LocalPlayer.GetRoleClass() is Swapper sw && sw.SwapMsg(PlayerControl.LocalPlayer, text)) goto Canceled;
if (Telepathy.TelepathyMessage(PlayerControl.LocalPlayer, args)) goto Canceled;
if (Messenger.CheckMessage(PlayerControl.LocalPlayer, args)) goto Canceled;

Directory.CreateDirectory(modTagsFiles);
Directory.CreateDirectory(vipTagsFiles);
Directory.CreateDirectory(sponsorTagsFiles);
Expand Down Expand Up @@ -1888,6 +1893,8 @@ public static void OnReceiveChat(PlayerControl player, string text, out bool can
if (Medium.MsMsg(player, text)) { Logger.Info($"Is Medium command", "OnReceiveChat"); return; }
if (Nemesis.NemesisMsgCheck(player, text)) { Logger.Info($"Is Nemesis Revenge command", "OnReceiveChat"); return; }
if (Retributionist.RetributionistMsgCheck(player, text)) { Logger.Info($"Is Retributionist Revenge command", "OnReceiveChat"); return; }
if (Telepathy.TelepathyMessage(player, args)) { Logger.Info("Is Telepathy MSG command", "OnRecieveChat"); return; }
if (Messenger.CheckMessage(player, args)) { Logger.Info("Is Messenger MSG command", "OnRecieveChat"); return; }

Directory.CreateDirectory(modTagsFiles);
Directory.CreateDirectory(vipTagsFiles);
Expand Down
1 change: 1 addition & 0 deletions Patches/MeetingHudPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ public static void NotifyRoleSkillOnMeetingStart()
{
pc?.GetRoleClass()?.OnMeetingHudStart(pc);
Main.PlayerStates.Do(plr => plr.Value.RoleClass.OnOthersMeetingHudStart(pc));
Messenger.NotifyAddonOnMeeting(pc);

foreach (var csId in Cyber.CyberDead)
{
Expand Down
38 changes: 37 additions & 1 deletion Patches/PlayerControlPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerC

Logger.Info($"End: CustomRoleManager.OnCheckMurder", "CheckMurder");

Main.PlayerKilledBy[target.PlayerId] = KilledType.Directly;

//== Kill target ==
__instance.RpcMurderPlayer(target);
//============
Expand Down Expand Up @@ -392,7 +394,7 @@ public static bool Prefix(PlayerControl __instance, [HarmonyArgument(0)] PlayerC
target.RpcShapeshift(target, false);
}
}

if (!target.IsProtected() && !Doppelganger.CheckDoppelVictim(target.PlayerId) && !Camouflage.ResetSkinAfterDeathPlayers.Contains(target.PlayerId))
{
Camouflage.ResetSkinAfterDeathPlayers.Add(target.PlayerId);
Expand Down Expand Up @@ -487,6 +489,21 @@ public static void Postfix(PlayerControl __instance, [HarmonyArgument(0)] Player

Utils.NotifyRoles(SpecifySeer: killer);
Utils.NotifyRoles(SpecifySeer: target);

_ = new LateTask(() => {

if (!Main.PlayerKilledBy.ContainsKey(target.PlayerId))
{

if (Vector2.Distance(target.GetRealKiller().GetCustomPosition(), target.transform.position) > 2f)
Main.PlayerKilledBy[target.PlayerId] = KilledType.Remotely;
else if (target.GetRealKiller() == target)
Main.PlayerKilledBy[target.PlayerId] = KilledType.Suicide_;
else
Main.PlayerKilledBy[target.PlayerId] = KilledType.Indirectly;
}

}, 1f, "Set Main.Playerkilled by in MurderPlayer Patch");
}
public static void AfterPlayerDeathTasks(PlayerControl killer, PlayerControl target, bool inMeeting)
{
Expand Down Expand Up @@ -930,6 +947,7 @@ public static void AfterReportTasks(PlayerControl player, NetworkedPlayerInfo ta
Main.AllKillers.Clear();
GuessManager.GuesserGuessed.Clear();


Logger.Info($"target is null? - {target == null}", "AfterReportTasks");
Logger.Info($"target.Object is null? - {target?.Object == null}", "AfterReportTasks");
Logger.Info($"target.PlayerId is - {target?.PlayerId}", "AfterReportTasks");
Expand All @@ -939,6 +957,11 @@ public static void AfterReportTasks(PlayerControl player, NetworkedPlayerInfo ta
try
{
playerStates.RoleClass?.OnReportDeadBody(player, target);

if (!Utils.GetPlayerById(playerStates.PlayerId).IsAlive() && target?.Object?.GetRealKiller() != null)
{
Main.LastKillerRoom[target.PlayerId] = target.Object.GetRealKiller().GetPlainShipRoom();
}
}
catch (Exception error)
{
Expand All @@ -948,6 +971,17 @@ public static void AfterReportTasks(PlayerControl player, NetworkedPlayerInfo ta
}
}

Main.RememberedFaction = null;
Main.RememberKillerRole = "";
Ultradragon005 marked this conversation as resolved.
Show resolved Hide resolved
if (target?.Object?.GetRealKiller() != null)
{
Main.RememberKillerRole = GetString($"{target.Object.GetRealKiller().GetCustomRole()}");
if (!target.Object.GetRealKiller().IsAnySubRole(x => x.IsConverted() && !target.Object.Is(CustomRoles.Madmate)))
Main.RememberedFaction = target.Object.GetRealKiller().GetCustomRole().GetCustomRoleTeam();
else
Main.RememberedFaction = Custom_Team.Neutral;
}

// Alchemist & Bloodlust
Alchemist.OnReportDeadBodyGlobal();

Expand Down Expand Up @@ -1853,6 +1887,8 @@ public static void Postfix(PlayerControl __instance)
Utils.LateExileTask.Add(SelfExile);
}
}
if (!Main.PlayerKilledBy.ContainsKey(__instance.PlayerId))
Main.PlayerKilledBy[__instance.PlayerId] = KilledType.Indirectly;
}
catch (Exception exx)
{
Expand Down
26 changes: 5 additions & 21 deletions Patches/onGameStartedPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static void Postfix(AmongUsClient __instance)
Main.clientIdList.Clear();

PlayerControlSetRolePatch.DidSetGhost.Clear();
Main.LastKillerRoom.Clear();
Main.RememberedFaction = null;
Main.PlayerKilledBy.Clear();

Main.CheckShapeshift.Clear();
Main.ShapeshiftTarget.Clear();
Expand Down Expand Up @@ -195,31 +198,12 @@ public static void Postfix(AmongUsClient __instance)
RoleClass?.OnInit();
}

CustomRoleManager.AddonClasses.Values.Where(x => x != null).Do(x => x.Init());

LastImpostor.Init();
TargetArrow.Init();
LocateArrow.Init();
DoubleTrigger.Init();
Workhorse.Init();
Diseased.Init();
Clumsy.Init();
Aware.Init();
Radar.Init();
Glow.Init();
Sleuth.Init();
Bait.Init();
Antidote.Init();
Fool.Init();
Burst.Init();
DoubleShot.Init();
Lucky.Init();
Bewilder.Init();
//ChiefOfPolice.Init();
Cyber.Init();
Oiiai.Init();
Tired.Init();
Statue.Init();
Ghoul.Init();
Rainbow.Init();

//FFA
FFAManager.Init();
Expand Down
Loading