From 88199d917c73cc6a1540729a88c8d97f653da8d9 Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Fri, 4 Oct 2024 15:15:46 +0300 Subject: [PATCH] /concede when outside the minigame will vote to end it 70% of the valid voters must vote AFKers, CMs, hidden players, spectators, and people already in a minigame don't count --- server/area.py | 34 ++++++++++++++++++++++++++++++++++ server/commands/casing.py | 3 +++ 2 files changed, 37 insertions(+) diff --git a/server/area.py b/server/area.py index 40052a78..8cbb91f6 100644 --- a/server/area.py +++ b/server/area.py @@ -200,6 +200,10 @@ def __init__(self, area_manager, name): # Who's debating who self.red_team = set() self.blue_team = set() + # Clients who cast votes + self.votes_cast = set() + # What percentage of valid voters needs to vote to force-end the minigame, rounded + self.votes_percentage = 0.7 # Minigame name self.minigame = "" # Minigame schedule @@ -1981,6 +1985,36 @@ def end_minigame(self, reason=""): ) self.minigame = "" + def vote_end_minigame(self, client): + if client.area.minigame == "": + client.send_ooc("There is no minigame running right now.") + return + + valid_voters = [ + c for c in self.clients if + not c.hidden and + not c in self.afkers and + not c in self.owners and + c.char_id not in client.area.blue_team and + c.char_id not in client.area.red_team + ] + if client not in valid_voters: + client.send_ooc("You're not qualified to vote-end this minigame! (You're a Spectator, Hidden or the area owner)") + return + self.votes_cast.add(client) + votes_casted = len(self.votes_cast) + votes_needed = round(len(valid_voters) * self.votes_percentage) + + info = f'[{client.id}] {client.showname} is voting to end the minigame!' + + if votes_casted >= votes_needed: + client.area.end_minigame("Voted to end.") + info += f'\nSuccessfully voted to end with ({votes_casted}/{votes_needed}) votes.' + else: + info += f'({votes_casted}/{votes_needed}) votes left.' + + self.broadcast_ooc(info) + def start_debate(self, client, target, pta=False): if (client.char_id in self.red_team and target.char_id in self.blue_team) or ( client.char_id in self.blue_team and target.char_id in self.red_team diff --git a/server/commands/casing.py b/server/commands/casing.py index 542de75f..2bb35a95 100644 --- a/server/commands/casing.py +++ b/server/commands/casing.py @@ -985,6 +985,9 @@ def ooc_cmd_concede(client, arg): client.area.broadcast_ooc( "The minigame has been forcibly ended.") return + if client.char_id not in client.area.blue_team and client.char_id not in client.area.red_team: + client.area.vote_end_minigame(client) + return client.area.start_debate( client, client ) # starting a debate against yourself is a concede