mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
Add missing RPC for Bed Wars (#346)
* Update BedWars.cs * Update Inhibitor.cs * Update Utils.cs * Update HudSpritePatch.cs * Update RPC.cs * Update OutroPatch.cs
This commit is contained in:
1 parent
61fa9207d9
commit
1b0c7c441c
6 files changed
+58
-12
No files matched your search
+41
-4
@@ -67,7 +67,7 @@ public static class BedWars
|
||||
private static OptionItem IronSwordDamageMultiplierOption;
|
||||
private static OptionItem DiamondSwordDamageMultiplierOption;
|
||||
|
||||
public static (Color Color, string Team) Winner = (Color.white, "No one wins");
|
||||
public static (Color Color, string Team) WinnerData = (Color.white, "No one wins");
|
||||
|
||||
public static void SetupCustomOption()
|
||||
{
|
||||
@@ -268,15 +268,52 @@ public static class BedWars
|
||||
|
||||
if (Enum.GetValues<BedWarsTeam>().FindFirst(x => Main.AllAlivePlayerControls.Select(p => p.PlayerId).Concat(Reviving).All(p => !Data.TryGetValue(p, out PlayerData data) || data.Team == x), out BedWarsTeam team))
|
||||
{
|
||||
Winner = (team.GetColor(), team.GetName() + Translator.GetString("Win"));
|
||||
WinnerData = (team.GetColor(), team.GetName() + Translator.GetString("Win"));
|
||||
CustomWinnerHolder.WinnerIds = Data.Where(x => x.Value.Team == team).Select(x => x.Key).ToHashSet();
|
||||
Logger.Info($"Winners: {team.GetName()} - {string.Join(", ", CustomWinnerHolder.WinnerIds.Select(id => Main.AllPlayerNames.GetValueOrDefault(id, string.Empty)))}", "BedWars");
|
||||
SendRPC();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void SendRPC()
|
||||
{
|
||||
var w = Utils.CreateRPC(CustomRPC.BedWarsSync);
|
||||
|
||||
w.Write(WinnerData.Color);
|
||||
w.Write(WinnerData.Team);
|
||||
|
||||
w.Write(Data.Count);
|
||||
|
||||
foreach ((byte id, PlayerData data) in Data)
|
||||
{
|
||||
w.Write(id);
|
||||
w.Write((byte)data.Team);
|
||||
}
|
||||
|
||||
Utils.EndRPC(w);
|
||||
}
|
||||
|
||||
public static void ReceiveRPC(MessageReader reader)
|
||||
{
|
||||
WinnerData.Color = reader.ReadColor();
|
||||
WinnerData.Team = reader.ReadString();
|
||||
|
||||
int count = reader.ReadInt32();
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
byte id = reader.ReadByte();
|
||||
|
||||
if (!Data.TryGetValue(id, out PlayerData data))
|
||||
Data[id] = data = new PlayerData();
|
||||
|
||||
data.Team = (BedWarsTeam)reader.ReadInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnCheckMurder(PlayerControl killer, PlayerControl target)
|
||||
{
|
||||
if (IsGracePeriod || !Data.TryGetValue(killer.PlayerId, out PlayerData killerData) || !Data.TryGetValue(target.PlayerId, out PlayerData targetData) || killerData.Team == targetData.Team) return;
|
||||
@@ -322,7 +359,7 @@ public static class BedWars
|
||||
Trapped = [];
|
||||
Reviving = [];
|
||||
|
||||
Winner = (Color.white, "No one wins");
|
||||
WinnerData = (Color.white, "No one wins");
|
||||
FixedUpdatePatch.LastUpdate = [];
|
||||
|
||||
InventorySlots = InventorySlotsOption.GetInt();
|
||||
@@ -358,7 +395,7 @@ public static class BedWars
|
||||
{
|
||||
if (Options.CurrentGameMode != CustomGameMode.BedWars) yield break;
|
||||
|
||||
Winner = (Color.white, "No one wins");
|
||||
WinnerData = (Color.white, "No one wins");
|
||||
|
||||
yield return new WaitForSecondsRealtime(3f);
|
||||
|
||||
|
||||
+8
-1
@@ -176,7 +176,8 @@ public enum CustomRPC
|
||||
KOTZSync,
|
||||
SpeedrunSync,
|
||||
NaturalDisastersSync,
|
||||
TMGSync
|
||||
TMGSync,
|
||||
BedWarsSync
|
||||
}
|
||||
|
||||
public enum Sounds
|
||||
@@ -1302,6 +1303,11 @@ internal static class RPCHandlerPatch
|
||||
TheMindGame.ReceiveRPC(reader);
|
||||
break;
|
||||
}
|
||||
case CustomRPC.BedWarsSync:
|
||||
{
|
||||
BedWars.ReceiveRPC(reader);
|
||||
break;
|
||||
}
|
||||
case CustomRPC.ParityCopCommand:
|
||||
{
|
||||
ParityCop.ReceiveRPC(reader);
|
||||
@@ -1676,3 +1682,4 @@ internal static class PlayerPhysicsRPCHandlerPatch
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -246,7 +246,7 @@ public static class Utils
|
||||
|
||||
public static bool IsAnySabotageActive()
|
||||
{
|
||||
return CustomSabotage.Instances.Count > 0 || new[] { SystemTypes.Electrical, SystemTypes.Reactor, SystemTypes.Laboratory, SystemTypes.LifeSupp, SystemTypes.Comms, SystemTypes.HeliSabotage, SystemTypes.MushroomMixupSabotage }.Any(IsActive);
|
||||
return CustomSabotage.Instances.Count > 0 || new[] { SystemTypes.Electrical, SystemTypes.Reactor, SystemTypes.Laboratory, SystemTypes.LifeSupp, SystemTypes.Comms, SystemTypes.HeliSabotage, SystemTypes.MushroomMixupSabotage, (SystemTypes)SubmergedCompatibility.SubmergedSystemTypes.Ballast }.Any(IsActive);
|
||||
}
|
||||
|
||||
public static bool IsActive(SystemTypes type)
|
||||
@@ -4180,3 +4180,4 @@ public class Message(string text, byte sendTo = byte.MaxValue, string title = ""
|
||||
public byte SendTo { get; } = sendTo;
|
||||
public string Title { get; } = title;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public static class HudSpritePatch
|
||||
if (player == null) return;
|
||||
|
||||
if (!Main.EnableCustomButton.Value || !Main.ProcessShapeshifts || Mastermind.ManipulatedPlayers.ContainsKey(player.PlayerId) || ExileController.Instance || GameStates.IsMeeting) return;
|
||||
if ((!SetHudActivePatch.IsActive && !MeetingStates.FirstMeeting) || !player.IsAlive() || Options.CurrentGameMode is not CustomGameMode.Standard and not CustomGameMode.CaptureTheFlag) return;
|
||||
if ((!SetHudActivePatch.IsActive && !MeetingStates.FirstMeeting) || !player.IsAlive()) return;
|
||||
|
||||
if (ResetButtonIcons || !AmongUsClient.Instance.IsGameStarted || !Main.IntroDestroyed || GameStates.IsLobby || GameStates.IsNotJoined || !GameStates.InGame)
|
||||
{
|
||||
@@ -516,3 +516,4 @@ public static class HudSpritePatch
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using static EHR.Translator;
|
||||
|
||||
|
||||
namespace EHR;
|
||||
|
||||
[HarmonyPatch(typeof(AmongUsClient), nameof(AmongUsClient.OnGameEnd))]
|
||||
@@ -281,7 +280,7 @@ internal static class SetEverythingUpPatch
|
||||
}
|
||||
case CustomGameMode.BedWars:
|
||||
{
|
||||
(Color Color, string Team) winnerData = AmongUsClient.Instance.AmHost ? BedWars.Winner : (Color.black, string.Empty);
|
||||
(Color Color, string Team) winnerData = BedWars.WinnerData;
|
||||
__instance.BackgroundBar.material.color = winnerData.Color;
|
||||
winnerText.text = winnerData.Team;
|
||||
winnerText.color = winnerData.Color;
|
||||
@@ -717,4 +716,5 @@ internal static class SetEverythingUpPatch
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ internal class Inhibitor : RoleBase
|
||||
|
||||
public override bool CanUseKillButton(PlayerControl pc)
|
||||
{
|
||||
return base.CanUseKillButton(pc) && !Utils.IsActive(SystemTypes.Electrical) && !Utils.IsActive(SystemTypes.Comms) && !Utils.IsActive(SystemTypes.MushroomMixupSabotage) && !Utils.IsActive(SystemTypes.Laboratory) && !Utils.IsActive(SystemTypes.LifeSupp) && !Utils.IsActive(SystemTypes.Reactor) && !Utils.IsActive(SystemTypes.HeliSabotage);
|
||||
return base.CanUseKillButton(pc) && !Utils.IsAnySabotageActive();
|
||||
}
|
||||
|
||||
public override void SetKillCooldown(byte id)
|
||||
@@ -73,4 +73,4 @@ internal class Inhibitor : RoleBase
|
||||
{
|
||||
Main.AllPlayerKillCooldown[InhibitorId] = InhibitorCDAfterMeetings.GetFloat();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user