1
Fork 0
mirror of https://github.com/RYGhub/royal-mifia.git synced 2024-11-24 22:54:19 +00:00

Completata la conversione anche nei ruoli

This commit is contained in:
Steffo 2017-07-18 01:06:30 +02:00
parent 4157ca3ace
commit c526c020f4
13 changed files with 61 additions and 64 deletions

10
main.py
View file

@ -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:

View file

@ -19,9 +19,9 @@ class Angelo(Role):
else:
return "<Role: Angelo, protecting {target}>".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

View file

@ -16,13 +16,13 @@ class Corrotto(Role):
def __repr__(self) -> str:
return "<Role: Corrotto, {uses} uses left>".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

View file

@ -17,7 +17,7 @@ class Derek(Role):
def __repr__(self) -> str:
return "<Role: Derek>"
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

View file

@ -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 "<Role: Investigatore, {uses} uses left>".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

View file

@ -16,13 +16,13 @@ class Investigatore(Role):
def __repr__(self) -> str:
return "<Role: Investigatore, {uses} uses left>".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

View file

@ -12,9 +12,9 @@ class Mamma(Role):
def __repr__(self) -> str:
return "<Role: Mamma>"
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,

View file

@ -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 "<Role: Mifioso, targeting {target}>".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

View file

@ -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

View file

@ -13,10 +13,10 @@ class Servitore(Role):
def __repr__(self) -> str:
return "<Role: Servitore del Caos>"
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)

View file

@ -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 "<Role: Signore del Caos>"
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)

View file

@ -18,21 +18,21 @@ class Stagista(Role):
def __repr__(self) -> str:
return "<Role: Stagista>"
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__)

View file

@ -12,14 +12,14 @@ class Terrorista(Role):
def __repr__(self) -> str:
return "<Role: Terrorista>"
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)