diff --git a/main.py b/main.py index 8a4a783..6d679d0 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ class Player: def kill(self, bot): """Uccidi il giocatore.""" - self.role.ondeath(bot, self.game) + self.role.ondeath(bot) self.alive = False @@ -259,11 +259,11 @@ class Game: self.message(bot, s.mifia_target_protected.format(target=killed.tusername, icon=killed.protectedby.role.icon, protectedby=killed.protectedby.tusername)) - # Attiva gli onendday + # Attiva gli \ for currentrole in rolepriority: for player in self.playersinrole[currentrole.__name__]: if player.alive: - player.role.onendday(bot, self) + player.role.onendday(bot) # Cancella tutti i voti for player in self.players: player.votingfor = None @@ -380,7 +380,7 @@ class Game: self.assignroles(bot) self.message(bot, s.roles_assigned_successfully) for player in self.players: - player.role.onstartgame(bot, self) + player.role.onstartgame(bot) def revealallroles(self, bot): text = s.status_header.format(name=self.name, admin=self.admin.tusername, phase=self.phase) @@ -690,7 +690,7 @@ def power(bot, update): if player is not None: if player.alive: if len(cmd) > 2: - player.role.power(bot, game, cmd[2]) + player.role.power(bot, cmd[2]) else: player.message(bot, s.error_missing_parameters) else: diff --git a/roles/Angelo.py b/roles/Angelo.py index 058791c..ccc3822 100644 --- a/roles/Angelo.py +++ b/roles/Angelo.py @@ -19,9 +19,9 @@ class Angelo(Role): else: return "".format(target=self.protecting.tusername) - def power(self, bot, game, arg): + def power(self, bot, arg): # Imposta qualcuno come protetto - selected = game.findplayerbyusername(arg) + selected = self.player.game.findplayerbyusername(arg) if selected is None: self.player.message(bot, s.error_username) return @@ -38,7 +38,7 @@ class Angelo(Role): else: self.player.message(bot, s.error_angel_no_selfprotect) - def onendday(self, bot, game): + def onendday(self, bot): # Resetta la protezione if self.protecting is not None: self.protecting.protectedby = None diff --git a/roles/Corrotto.py b/roles/Corrotto.py index d0c15e1..7f519c4 100644 --- a/roles/Corrotto.py +++ b/roles/Corrotto.py @@ -16,13 +16,13 @@ class Corrotto(Role): def __repr__(self) -> str: return "".format(uses=self.poweruses) - def power(self, bot, game, arg): + def power(self, bot, arg): # Indaga sul vero ruolo di una persona, se sono ancora disponibili usi del potere. if self.poweruses <= 0: # Non hai abbastanza cariche! self.player.message(bot, s.error_no_uses) return - target = game.findplayerbyusername(arg) + target = self.player.game.findplayerbyusername(arg) if target is None: # Username non valido self.player.message(bot, s.error_username) @@ -34,6 +34,6 @@ class Corrotto(Role): role=target.role.name, left=self.poweruses)) - def onendday(self, bot, game): + def onendday(self, bot): # Ripristina il potere self.poweruses = self.refillpoweruses diff --git a/roles/Derek.py b/roles/Derek.py index 5a0ecf8..d9f368c 100644 --- a/roles/Derek.py +++ b/roles/Derek.py @@ -17,7 +17,7 @@ class Derek(Role): def __repr__(self) -> str: return "" - def power(self, bot, game, arg): + def power(self, bot, arg): # Attiva / disattiva la morte alla fine del round self.deathwish = not self.deathwish if self.deathwish: @@ -26,8 +26,8 @@ class Derek(Role): self.player.message(bot, s.derek_deathwish_set) - def onendday(self, bot, game): + def onendday(self, bot): if self.deathwish: - game.message(bot, s.derek_deathwish_successful.format(name=self.player.tusername)) - self.player.kill(bot, game) + self.player.game.message(bot, s.derek_deathwish_successful.format(name=self.player.tusername)) + self.player.kill(bot, self.player.game) self.chaos = True \ No newline at end of file diff --git a/roles/Disastro.py b/roles/Disastro.py index a9732c7..17c7f5e 100644 --- a/roles/Disastro.py +++ b/roles/Disastro.py @@ -1,6 +1,5 @@ from .Role import Role import strings as s -import random class Disastro(Role): """L'investigatore sbadato investiga, ma giunge a conclusioni sbagliate...""" @@ -17,16 +16,16 @@ class Disastro(Role): def __repr__(self) -> str: return "".format(uses=self.poweruses) - def power(self, bot, game, arg): + def power(self, bot, arg): # Indaga sul vero ruolo di una persona, se sono ancora disponibili usi del potere. if self.poweruses > 0: - target = game.findplayerbyusername(arg) + target = self.player.game.findplayerbyusername(arg) if target is not None: self.poweruses -= 1 - randomrole = game.getrandomrole() + randomrole = self.player.game.getrandomrole() while isinstance(target.role, randomrole): # TODO: se ci fossero solo disastri in una partita cosa succederebbe? - randomrole = game.getrandomrole() + randomrole = self.player.game.getrandomrole() self.player.message(bot, s.detective_discovery.format(target=target.tusername, icon=randomrole.icon, role=randomrole.name, @@ -36,10 +35,10 @@ class Disastro(Role): else: self.player.message(bot, s.error_no_uses) - def onendday(self, bot, game): + def onendday(self, bot): # Ripristina il potere self.poweruses = self.refillpoweruses - def ondeath(self, bot, game): + def ondeath(self, bot): self.icon = s.disaster_icon self.name = s.disaster_name diff --git a/roles/Investigatore.py b/roles/Investigatore.py index 7ec34fe..ff188a5 100644 --- a/roles/Investigatore.py +++ b/roles/Investigatore.py @@ -16,13 +16,13 @@ class Investigatore(Role): def __repr__(self) -> str: return "".format(uses=self.poweruses) - def power(self, bot, game, arg): + def power(self, bot, arg): # Indaga sul vero ruolo di una persona, se sono ancora disponibili usi del potere. if self.poweruses <= 0: # Non hai abbastanza cariche! self.player.message(bot, s.error_no_uses) return - target = game.findplayerbyusername(arg) + target = self.player.game.findplayerbyusername(arg) if target is None: # Username non valido self.player.message(bot, s.error_username) @@ -34,6 +34,6 @@ class Investigatore(Role): role=target.role.name, left=self.poweruses)) - def onendday(self, bot, game): + def onendday(self, bot): # Ripristina il potere self.poweruses = self.refillpoweruses diff --git a/roles/Mamma.py b/roles/Mamma.py index 457f96e..c7cd309 100644 --- a/roles/Mamma.py +++ b/roles/Mamma.py @@ -12,9 +12,9 @@ class Mamma(Role): def __repr__(self) -> str: return "" - def onstartgame(self, bot, game): + def onstartgame(self, bot): # Scegli un bersaglio casuale che non sia il giocatore stesso - possibletargets = game.players.copy() + possibletargets = self.player.game.players.copy() possibletargets.remove(self.player) target = random.sample(possibletargets, 1)[0] self.player.message(bot, s.mom_discovery.format(target=target.tusername, diff --git a/roles/Mifioso.py b/roles/Mifioso.py index 5cdf706..0f2c0a4 100644 --- a/roles/Mifioso.py +++ b/roles/Mifioso.py @@ -1,5 +1,4 @@ from .Role import Role -import random import strings as s class Mifioso(Role): @@ -19,9 +18,9 @@ class Mifioso(Role): else: return "".format(target=self.target.tusername) - def power(self, bot, game, arg): + def power(self, bot, arg): # Imposta una persona come bersaglio da uccidere. - selected = game.findplayerbyusername(arg) + selected = self.player.game.findplayerbyusername(arg) if selected is None: self.player.message(bot, s.error_username) return @@ -29,8 +28,8 @@ class Mifioso(Role): self.player.message(bot, s.mifia_target_selected.format(target=self.target.tusername)) - def onendday(self, bot, game): - if game.votingmifia: + def onendday(self, bot): + if self.player.game.votingmifia: # Se la partita è in modalità votingmifia l'uccisione della mifia viene gestita dalla classe Game self.target = None else: @@ -39,12 +38,12 @@ class Mifioso(Role): if self.target.protectedby is None: # Uccisione riuscita self.target.kill(bot, self) - game.message(bot, s.mifia_target_killed.format(target=self.target.tusername, + self.player.game.message(bot, s.mifia_target_killed.format(target=self.target.tusername, icon=self.target.role.icon, role=self.target.role.name)) else: # Bersaglio protetto da un angelo - game.message(bot, s.mifia_target_protected.format(target=self.target.tusername, + self.player.game.message(bot, s.mifia_target_protected.format(target=self.target.tusername, icon=self.target.protectedby.role.icon, protectedby=self.target.protectedby.tusername)) self.target = None diff --git a/roles/Role.py b/roles/Role.py index a462f73..285e053 100644 --- a/roles/Role.py +++ b/roles/Role.py @@ -15,18 +15,18 @@ class Role: def __str__(self) -> str: return "{} {}".format(self.icon, self.name) - def power(self, bot, game, arg): + def power(self, bot, arg): """Il potere del ruolo. Si attiva quando il bot riceve un /power in chat privata.""" pass - def onendday(self, bot, game): + def onendday(self, bot): """Metodo chiamato alla fine di ogni giorno.""" pass - def ondeath(self, bot, game): + def ondeath(self, bot): """Metodo chiamato alla morte del giocatore.""" pass - def onstartgame(self, bot, game): + def onstartgame(self, bot): """Metodo chiamato all'inizio della partita.""" pass \ No newline at end of file diff --git a/roles/Servitore.py b/roles/Servitore.py index 411f149..9d38939 100644 --- a/roles/Servitore.py +++ b/roles/Servitore.py @@ -13,10 +13,10 @@ class Servitore(Role): def __repr__(self) -> str: return "" - def onendday(self, bot, game): - for chaoslord in game.playersinrole["SignoreDelCaos"]: + def onendday(self, bot): + for chaoslord in self.player.game.playersinrole["SignoreDelCaos"]: if chaoslord.alive: break else: - game.changerole(bot, self.player, SignoreDelCaos) - game.message(bot, s.chaos_servant_inherited) + self.player.game.changerole(bot, self.player, SignoreDelCaos) + self.player.game.message(bot, s.chaos_servant_inherited) diff --git a/roles/SignoreDelCaos.py b/roles/SignoreDelCaos.py index 92a1caf..34302ec 100644 --- a/roles/SignoreDelCaos.py +++ b/roles/SignoreDelCaos.py @@ -1,6 +1,5 @@ from .Role import Role import strings as s -import random class SignoreDelCaos(Role): """Il Signore del Caos è un Derek negli ultimi secondi prima della morte. @@ -17,20 +16,20 @@ class SignoreDelCaos(Role): def __repr__(self) -> str: return "" - def power(self, bot, game, arg): - selected = game.findplayerbyusername(arg) + def power(self, bot, arg): + selected = self.player.game.findplayerbyusername(arg) if selected is not None and selected is not self.player and selected.alive: self.target = selected self.player.message(bot, s.chaos_lord_target_selected.format(target=self.target.tusername)) else: self.player.message(bot, s.error_no_username) - def onendday(self, bot, game): + def onendday(self, bot): if self.target is not None: if self.target.alive and self.player.alive: if not isinstance(self.target.role, SignoreDelCaos): - randomrole = game.getrandomrole() - game.changerole(bot, self.target, randomrole) - game.message(bot, s.chaos_lord_randomized) + randomrole = self.player.game.getrandomrole() + self.player.game.changerole(bot, self.target, randomrole) + self.player.game.message(bot, s.chaos_lord_randomized) else: - game.message(bot, s.chaos_lord_failed) + self.player.game.message(bot, s.chaos_lord_failed) diff --git a/roles/Stagista.py b/roles/Stagista.py index b2094cc..4767718 100644 --- a/roles/Stagista.py +++ b/roles/Stagista.py @@ -18,21 +18,21 @@ class Stagista(Role): def __repr__(self) -> str: return "" - def power(self, bot, game, arg): - target = game.findplayerbyusername(arg) + def power(self, bot, arg): + target = self.player.game.findplayerbyusername(arg) if target is not None and target is not self.player and target.alive: self.master = target self.player.message(bot, s.intern_started_internship.format(master=self.master.tusername)) else: self.player.message(bot, s.error_no_username) - def onendday(self, bot, game): + def onendday(self, bot): if self.master is not None: if isinstance(self.master.role, Derek) and self.master.role.chaos: - game.message(bot, s.intern_chaos_summoned) + self.player.game.message(bot, s.intern_chaos_summoned) self.master.alive = True - game.changerole(bot, self.master, SignoreDelCaos) - game.changerole(bot, self.player, Servitore) + self.player.game.changerole(bot, self.master, SignoreDelCaos) + self.player.game.changerole(bot, self.player, Servitore) else: - game.message(bot, s.intern_changed_role.format(icon=self.master.role.__class__.icon, role=self.master.role.__class__.name)) - game.changerole(bot, self.player, self.master.role.__class__) + self.player.game.message(bot, s.intern_changed_role.format(icon=self.master.role.__class__.icon, role=self.master.role.__class__.name)) + self.player.game.changerole(bot, self.player, self.master.role.__class__) diff --git a/roles/Terrorista.py b/roles/Terrorista.py index 1daad1a..17603f6 100644 --- a/roles/Terrorista.py +++ b/roles/Terrorista.py @@ -12,14 +12,14 @@ class Terrorista(Role): def __repr__(self) -> str: return "" - def ondeath(self, bot, game): + def ondeath(self, bot): # Se è stato ucciso da una votazione, attiva il suo potere - if self.player == game.lastlynch: - game.message(bot, s.terrorist_kaboom) - for selectedplayer in game.players: + if self.player == self.player.game.lastlynch: + self.player.game.message(bot, s.terrorist_kaboom) + for selectedplayer in self.player.game.players: # Elimina ogni giocatore che sta votando per sè stesso if selectedplayer.votingfor == self.player: - game.message(bot, s.terrorist_target_killed.format(target=selectedplayer.tusername, + self.player.game.message(bot, s.terrorist_target_killed.format(target=selectedplayer.tusername, icon=selectedplayer.role.icon, role=selectedplayer.role.name)) - selectedplayer.kill(bot, game) + selectedplayer.kill(bot, self.player.game)