Implement score override

This commit is contained in:
Yohann D'ANELLO 2021-11-12 14:26:01 +01:00
parent 881b97218e
commit 94d8173f06
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 38 additions and 4 deletions

View File

@ -403,7 +403,7 @@ async def vote(ctx: commands.Context, player_name: str, vote: Vote | None):
await ctx.reply(f"Le vote de **{current_player.name}** a bien été falsifié (nouveau vote : *{vote}**).")
@bot.command(help="Préparation d'une salle")
@bot.command(help="Échange de vote")
@commands.has_any_role('IA', 'Dan')
async def swap(ctx: commands.Context, player_name: str):
"""
@ -432,6 +432,28 @@ async def swap(ctx: commands.Context, player_name: str):
"alors il est de retour à la normale.")
@bot.command(help="Modification du score d'un bracelet")
@commands.has_any_role('IA', 'Dan')
async def override(ctx: commands.Context, player_name: str, target_score: int):
"""
Override the score of a given player.
"""
game: Game = Game.INSTANCE
for player in game.players.values():
if player.name.lower() == player_name.lower():
current_player = player
break
else:
return await ctx.reply("Le joueur n'existe pas.")
game.score_overrides[current_player] = target_score
game.save('game.save')
await ctx.reply(f"Le score de **{current_player.name}** a bien été modifié. "
f"Il sera maintenant de **{target_score}**.")
@bot.command(help="Reboot")
@commands.has_permissions(administrator=True)
async def reboot(ctx: commands.Context):

View File

@ -35,7 +35,7 @@ class Player:
yield vote
@property
def score(self) -> int:
def calculated_score(self) -> int:
s = 3
for vote in self.round_votes:
@ -61,6 +61,12 @@ class Player:
return s
@property
def score(self) -> int:
if self in Game.INSTANCE.score_overrides:
return Game.INSTANCE.score_overrides[self]
return self.calculated_score
def __str__(self):
return self.name
@ -127,8 +133,9 @@ class Game:
state: GameState = GameState.PREPARING
rounds: list[Round] = field(default_factory=list)
players: dict[str, Player] = field(default_factory=dict)
score_overrides: dict[Player, int] = field(default_factory=dict, init=False)
def __post_init__(self):
def __post_init__(self: "Game") -> None:
Game.INSTANCE = self
def register_player(self, name: str, vote_channel_id: int) -> Player:

View File

@ -24,7 +24,12 @@
</tr>
<tr>
{% for player in game.players.values() %}
<td>{{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9⃣ {% endif %}</td>
<td>
{{ player.score }}{% if player.score <= 0 %} ☠️ {% elif player.score >= 9 %} 9⃣ {% endif %}
{% if admin and player in game.score_overrides %}
<span class="badge bg-danger">Triche</span>
{% endif %}
</td>
{% endfor %}
</tr>
</tbody>