From d49c0b70401e4346da8934e5ff65aee21b52e397 Mon Sep 17 00:00:00 2001
From: Loris TICHADOU <loris.tichadou@ensiie.fr>
Date: Fri, 22 Jul 2016 16:10:30 +0200
Subject: [PATCH] Fonctionnel a 95% jusqu'a 12 joueurs

---
 putsch.py | 116 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 93 insertions(+), 23 deletions(-)

diff --git a/putsch.py b/putsch.py
index 50e2e14..32cbeb4 100644
--- a/putsch.py
+++ b/putsch.py
@@ -28,6 +28,26 @@ def Paquet(nbrJoueurs) :
 		return res
 	if nbrJoueurs == 7 :
 		res = Paquet(6)
+		res.append("idiot")
+		return res
+	if nbrJoueurs == 8 :
+		res = Paquet(7)
+		res.append("loups")
+		return res
+	if nbrJoueurs == 9 :
+		res = Paquet(8)
+		res.append("villageois")
+		return res
+	if nbrJoueurs == 10 :
+		res = Paquet(9)
+		res.append("villageois")
+		return res
+	if nbrJoueurs == 11 :
+		res = Paquet(10)
+		res.append("loups")
+		return res
+	if nbrJoueurs == 12 :
+		res = Paquet(11)
 		res.append("villageois")
 		return res
 
@@ -87,6 +107,9 @@ class Boooob(ircbot.SingleServerIRCBot):
 		self.ancien = ""
 		self.canlive = 1
 
+		self.idiot = ""
+		self.canvote = 1
+
 		self.victime = []
 	
 	
@@ -155,11 +178,11 @@ class Boooob(ircbot.SingleServerIRCBot):
 				for f in self.joueurs :
 					if f in message and "!who" in message:
 						for g in dir(self) :
-							if f in str(getattr(self, g)) and g != "joueurs" and g != "lovers" and g != "avote" and g != "votes" :
+							if f in str(getattr(self, g)) and g != "joueurs" and g != "lovers" and g != "avote" and g != "votes" and self.cansee == 1  :
 								serv.privmsg(personne, "La classe de "+f+" est :"+g)
 								self.voyanteok = 1
+								self.cansee = 0
 								break
-						self.cansee = 0
 			#sorciere
 			if self.sorciere == personne  and self.sorciereok != 1 :
 				if "!nope" in message :
@@ -228,6 +251,7 @@ class Boooob(ircbot.SingleServerIRCBot):
                        
         def on_pubmsg(self, serv, ev): #quand qq ecrit dans le chat
 		canal = ev.target()
+		canal2 = self.channels[canal]  #Sert a recup la liste des users
 
                 personne = ev.source()
                 personne = couper(personne)
@@ -245,16 +269,16 @@ class Boooob(ircbot.SingleServerIRCBot):
 			if self.topic == 0 :
 				#serv.topic(canal,"Tapez !newgame pour demarrer une partie ! ")
 				self.topic = 1
+			if "!gratuit" in message :
+				serv.privmsg(canal, "Et hop, on hl tout le monde !")
+				for f in canal2.users() :
+					serv.privmsg(canal, f)
 			if "!thanks" in message :
 				serv.privmsg(canal, "Mon createur tient particulierement à remercier : Boobiies, Jara, Nami, Twibby, koohbra, Groot, Jeanne, Senseo, Ampleur, Inco, Missan et Sisi pour leur assiduité pendant les tests, et pour pas avoir ralé à cause des hl gratuits")
 			if "!newgame" in message :
 				serv.privmsg(canal, "Ok, "+personne+" a lancé une partie, tapez !join pour rejoindre (si vous retapez !join, vous quittez !)")
 				serv.privmsg(canal, personne+" a rejoint la partie !")
-				if len(self.joueurs) < 7 :
-
-					self.joueurs.append(personne)
-				else :
-					serv.privmsg(canal, "Desolé "+personne+", c'est complet pour l'instant...")
+				self.joueurs.append(personne)
 				self.ingame = 1
 				self.phase = 1
 		if self.ingame == 1 :
@@ -334,6 +358,9 @@ class Boooob(ircbot.SingleServerIRCBot):
 				self.ancien = ""
 				self.canlive = 1
 
+				self.idiot = ""
+				self.canvote = 1
+
 				self.victime = []
 
 				serv.privmsg("#lg_putsch", " Ouf, reinitialisation reussie !")
@@ -347,7 +374,7 @@ class Boooob(ircbot.SingleServerIRCBot):
 			if self.phase == 1 : #phase où les joueurs rejoignent la partie
 				if "!join" in message :
 					if personne not in self.joueurs :
-						if len(self.joueurs) < 7 :
+						if len(self.joueurs) < 13 :
 							serv.privmsg(canal, personne+" a rejoint la partie !")
 							self.joueurs.append(personne)
 						else :
@@ -504,7 +531,7 @@ class Boooob(ircbot.SingleServerIRCBot):
 							for g in dir(self) :
 								if f in str(getattr(self,g)) and g == "lovers" :
 									serv.privmsg("#lg_putsch", "Les amoureux sont morts ! (coucou "+f+" ! )" )
-								if f in str(getattr(self, g)) and g != "joueurs" and g != "victime" and g != "avote" and g != "lovers" and g != "sorcierevictime" :
+								if f in str(getattr(self, g)) and g != "joueurs" and g != "victime" and g != "avote" and g != "lovers" and g != "sorcierevictime" and g != "voleur" :
 									if f != self.chasseurvictime :
 										serv.privmsg("#lg_putsch" , f+" est decedé cette nuit.. son role : "+g+".")
 										serv.mode("#lg_putsch", "-v "+f)
@@ -523,11 +550,23 @@ class Boooob(ircbot.SingleServerIRCBot):
 										
 
 						if self.chasseurvictime != "" :
+							if self.lovers != [] :
+
+								if self.lovers[0] in self.victime or self.lovers[1] in self.victime :
+									for f in self.lovers :
+										if f not in self.victime :
+											self.victime.append(f)
 							for g in dir(self) :
-								if self.chasseurvictime in str(getattr(self, g)) and g!="joueurs" and g!="victime" and g != "avote" and g != "lovers" and g != "sorcierevictime" and g != "chasseurvictime" :
+								if f in str(getattr(self,g)) and g == "lovers" :
+									serv.privmsg("#lg_putsch", "Les amoureux sont morts ! (coucou "+f+" ! )" )
+
+								if self.chasseurvictime in str(getattr(self, g)) and g!="joueurs" and g!="victime" and g != "avote" and g != "lovers" and g != "sorcierevictime" and g != "chasseurvictime" and g != "voleur" and g != "votes" :
 									serv.privmsg("#lg_putsch", self.chasseur+" Decide donc de se venger sur "+self.chasseurvictime+", dont le role etait : "+g+" ! HEADSHOT !")
 									serv.mode("#lg_putsch" , "-v "+self.chasseurvictime)
-									self.joueurs.remove(self.chasseurvictime)
+									try :
+										self.joueurs.remove(self.chasseurvictime)
+									except :
+										print "erreur"
 									self.chasseur = ""
 									if g == "loups" or g == "villageois" :
 										if g == "loups" :
@@ -538,7 +577,8 @@ class Boooob(ircbot.SingleServerIRCBot):
 									else :
 										setattr(self,g,"")
 
-						self.chasseurvictime = ""		
+						self.chasseurvictime = ""
+						self.sorcierevictime = ""
 						self.chasseurok = 0
 						self.voyanteok = 0
 						self.loupsok = 0
@@ -556,6 +596,10 @@ class Boooob(ircbot.SingleServerIRCBot):
 
 			
 			if self.phase == 4 :
+				if "!list" in message :
+					serv.privmsg("#lg_putsch", "La liste des joueurs est :"+list_to_str(self.joueurs))
+
+
 				if self.phase4trig == 1 :
 
 					serv.privmsg("#lg_putsch", "Ce crime ( ou pas...) ne peut rester impuni !")
@@ -563,6 +607,7 @@ class Boooob(ircbot.SingleServerIRCBot):
 					serv.privmsg("#lg_putsch", "Le village se reunit et decide de lyncher quelqu'un...")
 					self.phase4trig = 0
 					serv.privmsg("#lg_putsch", "Vous avez 1 minute pour debattre avant le debut du vote")
+				
 				if time.time() - self.temps > 60 and self.phase4trig == 0 :
 					self.phase4 = 1
 					self.phase4trig = 2
@@ -574,7 +619,8 @@ class Boooob(ircbot.SingleServerIRCBot):
 						serv.privmsg("#lg_putsch", "fin du vote...")
 						bid = []
 						for f in self.joueurs :
-							serv.privmsg("#lg_putsch", "Le nombre de voix pour "+f+" est :"+str(self.votes.count(f)))
+							if self.votes.count(f) > 0 :
+								serv.privmsg("#lg_putsch", "Le nombre de voix pour "+f+" est :"+str(self.votes.count(f)))
 							bid.append(str(self.votes.count(f)))
 						a = max(bid) 
 						c = 0
@@ -582,7 +628,16 @@ class Boooob(ircbot.SingleServerIRCBot):
 							if f == a :
 								c=c+1
 						if c == 1 :
+
 							self.victime.append(self.joueurs[bid.index(a)])
+						  	
+							if self.idiot in self.victime :
+								serv.privmsg("#lg_putsch", "Le village a decidé de lyncher l'idiot : "+self.idiot)
+								serv.privmsg("#lg_putsch", self.idiot+" n'est donc pas lynché, mais ne peut plus voter desormais...")
+								self.canvote = 0
+								self.victime.remove(self.idiot)
+								self.chasseurok = 1
+
 							if self.lovers != [] :
 
 								if self.lovers[0] in self.victime or self.lovers[1] in self.victime :
@@ -592,6 +647,8 @@ class Boooob(ircbot.SingleServerIRCBot):
 							for f in self.victime :
 								if f in self.loups :
 									serv.kick("#lg_putsch_loups", f)
+
+
 								for g in dir(self) :
 									if f in str(getattr(self, g)) and g == "lovers" :
 										serv.privmsg("#lg_putsch", "Les amoureux sont morts ! (coucou "+f+" ! )" )
@@ -608,7 +665,7 @@ class Boooob(ircbot.SingleServerIRCBot):
 												self.loups.remove(f)
 												serv.kick("#lg_putsch_loups", f)
 											if g == "villageois" :
-												serv.villageois.remove(f)
+												self.villageois.remove(f)
 										else :
 											setattr(self,g, "")
 										if g == "ancien" :
@@ -679,18 +736,31 @@ class Boooob(ircbot.SingleServerIRCBot):
 						self.phase4 = 0
 
 					
-					if "!list" in message :
-						serv.privmsg("#lg_putsch", "La liste des joueurs est : "+", ".join(self.joueurs))
-
 					if "!recap" in message :
 						for f in self.joueurs :
-							serv.privmsg("#lg_putsch", "Le nombre de voix pour "+f+" est :"+str(self.votes.count(f)))
-
-					if "!vote" in message and personne not in self.avote and message.split(" ")[1] in self.joueurs and personne in self.joueurs :
-						self.votes.append(message.split(" ")[1])
-						self.avote.append(personne)
-						serv.privmsg("#lg_putsch", personne+" a voté pour "+message.split(" ")[1]+" !")
+							if self.votes.count(f) > 0 :
+								serv.privmsg("#lg_putsch", "Le nombre de voix pour "+f+" est :"+str(self.votes.count(f)))
 
+					if "!vote" in message and personne not in self.avote and (message.split(" ")[1] in self.joueurs or message.split(" ")[1] == "random") and personne in self.joueurs :
+						w = 1
+						if self.canvote == 0 :
+							
+							if personne == self.idiot :
+								w = 0
+								serv.privmsg("#lg_putsch", "l'idiot essaie de voter... le village l'ignore")
+							if message.split(" ")[1] == self.idiot :
+								w = 0
+								serv.privmsg("#lg_putsch", personne+" essaie de voter pour l'idiot... le village l'ignore...")
+						if w == 1 :
+							if message.split(" ")[1] == "random" :
+								bi = self.joueurs[rand.randint(0, len(self.joueurs) - 1)]
+								self.votes.append(bi)
+								serv.privmsg("#lg_putsch", "LE POUVOIR DU RANDOM ! ")
+								serv.ptivmsg("#lg_putsch", personne+" a voté pour "+bi+" !")
+							else :
+								self.votes.append(message.split(" ")[1])
+								serv.privmsg("#lg_putsch", personne+" a voté pour "+message.split(" ")[1]+" !")
+							self.avote.append(personne)
 
 					
 				
-- 
GitLab