mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
139 lines
4.5 KiB
C#
139 lines
4.5 KiB
C#
using EHR.Modules;
|
|
using EHR.Patches;
|
|
using Hazel;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace EHR.Roles;
|
|
|
|
public class Collector : RoleBase
|
|
{
|
|
private const int Id = 11100;
|
|
public static OptionItem CollectorCollectAmount;
|
|
private static List<byte> PlayerIdList = [];
|
|
public static Dictionary<byte, byte> CollectorVoteFor = [];
|
|
public static Dictionary<byte, int> CollectVote = [];
|
|
|
|
private static Color32 ShadeColor;
|
|
public override bool IsEnable => PlayerIdList.Count > 0;
|
|
|
|
public override void SetupCustomOption()
|
|
{
|
|
Options.SetupRoleOptions(Id, TabGroup.NeutralRoles, CustomRoles.Collector);
|
|
|
|
CollectorCollectAmount = new IntegerOptionItem(Id + 13, "CollectorCollectAmount", new(1, 60, 1), 30, TabGroup.NeutralRoles)
|
|
.SetParent(Options.CustomRoleSpawnChances[CustomRoles.Collector])
|
|
.SetValueFormat(OptionFormat.Votes);
|
|
}
|
|
|
|
public override void Init()
|
|
{
|
|
PlayerIdList = [];
|
|
CollectorVoteFor = [];
|
|
CollectVote = [];
|
|
ShadeColor = Utils.GetRoleColor(CustomRoles.Collector).ShadeColor(0.25f);
|
|
}
|
|
|
|
public override void Add(byte playerId)
|
|
{
|
|
PlayerIdList.Add(playerId);
|
|
CollectVote.TryAdd(playerId, 0);
|
|
}
|
|
|
|
public override void Remove(byte playerId)
|
|
{
|
|
PlayerIdList.Remove(playerId);
|
|
}
|
|
|
|
private static void SendRPC(byte playerId)
|
|
{
|
|
if (!Utils.DoRPC) return;
|
|
|
|
MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.SetCollectorVotes, SendOption.Reliable);
|
|
writer.Write(playerId);
|
|
writer.Write(CollectVote[playerId]);
|
|
AmongUsClient.Instance.FinishRpcImmediately(writer);
|
|
}
|
|
|
|
public static void ReceiveRPC(MessageReader reader)
|
|
{
|
|
byte PlayerId = reader.ReadByte();
|
|
int Num = reader.ReadInt32();
|
|
CollectVote.TryAdd(PlayerId, 0);
|
|
CollectVote[PlayerId] = Num;
|
|
}
|
|
|
|
public override void GetProgressText(byte playerId, bool comms, StringBuilder resultText)
|
|
{
|
|
if (!CollectVote.TryGetValue(playerId, out int VoteAmount)) return;
|
|
|
|
int CollectNum = CollectorCollectAmount.GetInt();
|
|
Color32 color = ShadeColor;
|
|
|
|
resultText.Append(Utils.ColorPrefix(color))
|
|
.Append('(')
|
|
.Append(VoteAmount)
|
|
.Append('/')
|
|
.Append(CollectNum)
|
|
.Append(")</color>");
|
|
}
|
|
|
|
|
|
|
|
public static bool CollectorWin(bool check = true)
|
|
{
|
|
PlayerControl[] pc = Main.EnumeratePlayerControls().Where(x => x.Is(CustomRoles.Collector) && x.IsAlive() && CollectDone(x)).ToArray();
|
|
|
|
if (pc.Length > 0)
|
|
{
|
|
if (check) return true;
|
|
|
|
CustomWinnerHolder.SetWinnerOrAdditonalWinner(CustomWinner.Collector);
|
|
foreach (PlayerControl winner in pc) CustomWinnerHolder.WinnerIds.Add(winner.PlayerId);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static bool CollectDone(PlayerControl player)
|
|
{
|
|
if (player.Is(CustomRoles.Collector))
|
|
{
|
|
byte pcid = player.PlayerId;
|
|
int VoteAmount = CollectVote[pcid];
|
|
int CollectNum = CollectorCollectAmount.GetInt();
|
|
if (VoteAmount >= CollectNum) return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static void CollectorVotes(PlayerControl target, PlayerVoteArea ps) //集票者投票给谁
|
|
{
|
|
if (CheckForEndVotingPatch.CheckRole(ps.TargetPlayerId, CustomRoles.Collector)) CollectorVoteFor.TryAdd(target.PlayerId, ps.TargetPlayerId);
|
|
}
|
|
|
|
public static void CollectAmount(Dictionary<byte, int> VotingData, MeetingHud __instance) //得到集票者收集到的票
|
|
{
|
|
foreach (PlayerVoteArea pva in __instance.playerStates)
|
|
{
|
|
if (pva == null) continue;
|
|
|
|
PlayerControl pc = Utils.GetPlayerById(pva.TargetPlayerId);
|
|
if (pc == null) continue;
|
|
|
|
foreach ((byte key, int value) in VotingData)
|
|
{
|
|
if (CollectorVoteFor.ContainsKey(key) && pc.PlayerId == CollectorVoteFor[key] && pc.Is(CustomRoles.Collector))
|
|
{
|
|
CollectVote.TryAdd(pc.PlayerId, 0);
|
|
CollectVote[pc.PlayerId] += value;
|
|
SendRPC(pc.PlayerId);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |