From 0682ae8ccdc446e77b9ddc5fcbe758bb274366d9 Mon Sep 17 00:00:00 2001 From: Laplace <405420687@qq.com> Date: Wed, 19 Jun 2024 03:51:53 +0800 Subject: [PATCH] Update cs2rtv.cs --- cs2rtv/cs2rtv.cs | 83 +++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/cs2rtv/cs2rtv.cs b/cs2rtv/cs2rtv.cs index 6a6c947..abfc963 100644 --- a/cs2rtv/cs2rtv.cs +++ b/cs2rtv/cs2rtv.cs @@ -628,54 +628,57 @@ public void StartRtv() foreach (var player in IsPlayer()) MenuManager.OpenChatMenu(player, votemenu); - _rtvtimer = AddTimer(30f, () => + Server.NextFrame(()=> { - if (!isrtving) return; - if (totalvotes == 0) - { - nextmap = mapnominatelist[random.Next(0, mapnominatelist.Count - 1)]; - Server.PrintToChatAll("地图投票已结束"); - rtvwin = true; - } - else if (votes.Select(x => x.Value).Max() > (totalvotes * 0.5f)) + _rtvtimer = AddTimer(30f, () => { - votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); - nextmap = votes.First().Key; - Server.PrintToChatAll("地图投票已结束"); - rtvwin = true; - } - else if (votes.Select(x => x.Value).Max() <= (totalvotes * 0.5f) && votemaplist.Count >= 4 && totalvotes > 2) - { - Server.PrintToChatAll("本轮投票未有地图投票比例超过50%,将进行下一轮投票"); - votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); - var y = votemaplist.Count(); - votemaplist.Clear(); - var x = 0; - while (x < (y * 0.5f)) + if (!isrtving) return; + if (totalvotes == 0) + { + nextmap = mapnominatelist[random.Next(0, mapnominatelist.Count - 1)]; + Server.PrintToChatAll("地图投票已结束"); + rtvwin = true; + } + else if (votes.Select(x => x.Value).Max() > (totalvotes * 0.5f)) + { + votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); + nextmap = votes.First().Key; + Server.PrintToChatAll("地图投票已结束"); + rtvwin = true; + } + else if (votes.Select(x => x.Value).Max() <= (totalvotes * 0.5f) && votemaplist.Count >= 4 && totalvotes > 2) { - if (votes.ElementAt(x).Key != null) + Server.PrintToChatAll("本轮投票未有地图投票比例超过50%,将进行下一轮投票"); + votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); + var y = votemaplist.Count(); + votemaplist.Clear(); + var x = 0; + while (x < (y * 0.5f)) { - if(votes.ElementAt(x).Value != 0) + if (votes.ElementAt(x).Key != null) { - votemaplist!.Add(votes.ElementAt(x).Key); - x++; - }else + if(votes.ElementAt(x).Value != 0) + { + votemaplist!.Add(votes.ElementAt(x).Key); + x++; + }else + break; + } + else break; } - else - break; } - } - else if (votes.Select(x => x.Value).Max() <= (totalvotes * 0.5f) && (votemaplist.Count < 4 || totalvotes <= 2)) - { - votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); - nextmap = votes.First().Key; - if(votes.ContainsKey(Server.MapName) && votes.First().Value <= (votes.GetValueOrDefault(Server.MapName)+1)) - nextmap = Server.MapName; - Server.PrintToChatAll("地图投票已结束"); - rtvwin = true; - } - VoteEnd(nextmap); + else if (votes.Select(x => x.Value).Max() <= (totalvotes * 0.5f) && (votemaplist.Count < 4 || totalvotes <= 2)) + { + votes = votes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value); + nextmap = votes.First().Key; + if(votes.ContainsKey(Server.MapName) && votes.First().Value <= (votes.GetValueOrDefault(Server.MapName)+1)) + nextmap = Server.MapName; + Server.PrintToChatAll("地图投票已结束"); + rtvwin = true; + } + VoteEnd(nextmap); + }); }); }