Skip to content

Commit

Permalink
/concede when outside the minigame will vote to end it
Browse files Browse the repository at this point in the history
70% of the valid voters must vote
AFKers, CMs, hidden players, spectators, and people already in a minigame don't count
  • Loading branch information
Crystalwarrior committed Oct 4, 2024
1 parent 884a464 commit 88199d9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions server/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions server/commands/casing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88199d9

Please sign in to comment.