Mercurial > libervia-backend
diff src/plugins/plugin_misc_tarot.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | beaf6bec2fcd |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_tarot.py Fri Jan 18 17:55:27 2013 +0100 +++ b/src/plugins/plugin_misc_tarot.py Fri Jan 18 17:55:34 2013 +0100 @@ -98,7 +98,7 @@ card_elt = domish.Element((None,'card')) card_elt['suit'] = card.suit card_elt['value'] = card.value - cards_list_elt.addChild(card_elt) + cards_list_elt.addChild(card_elt) return cards_list_elt def __xml_to_list(self, cards_list_elt): @@ -107,7 +107,7 @@ for card in cards_list_elt.elements(): cards_list.append((card['suit'], card['value'])) return cards_list - + def __create_started_elt(self, players): """Create a game_started domish element""" @@ -164,7 +164,7 @@ error_elt.addChild(played_elt) error_elt.addChild(invalid_elt) return error_elt - + def __next_player(self, game_data, next_pl = None): """Increment player number & return player name @param next_pl: if given, then next_player is forced to this one @@ -180,7 +180,7 @@ """give the nick of the player who win this trick""" players_data = game_data['players_data'] first = game_data['first_player'] - first_idx = game_data['players'].index(first) + first_idx = game_data['players'].index(first) suit_asked = None strongest = None winner = None @@ -225,19 +225,19 @@ if not excuse in played: #the Excuse is not on the table, nothing to do return - + excuse_player = None #Who has played the Excuse ? for player in game_data['players']: if players_data[player]['played'] == excuse: excuse_player = player break - + if excuse_player == winner: return #the excuse player win the trick, nothing to do - + #first we remove the excuse from played cards played.remove(excuse) - #then we give it back to the original owner + #then we give it back to the original owner owner_levees = players_data[excuse_player]['levees'] owner_levees.append(excuse) #finally we give a low card to the trick winner @@ -267,10 +267,10 @@ for player in game_data['players']: scores_str+=_("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player':player, 'score_game':0, 'total_score': players_data[player]['score']} debug(scores_str) - + return (scores_str, [], []) - + def __calculate_scores(self, game_data): """The game is finished, time to know who won :) @param game_data: data of the game @@ -285,7 +285,7 @@ nb_bouts +=1 bouts.append(card.value) score += card.points - + #We we do a basic check on score calculation check_score = 0 defenseurs = game_data['players'][:] @@ -297,7 +297,7 @@ for card in game_data['chien']: check_score+=card.points assert (score + check_score == 91) - + point_limit = None if nb_bouts == 3: point_limit = 36 @@ -340,7 +340,7 @@ for player in game_data['players']: scores_str+=_("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player':player, 'score_game':player_score[player], 'total_score': players_data[player]['score']} debug(scores_str) - + return (scores_str, winners, loosers) def __invalid_cards(self, game_data, cards): @@ -437,7 +437,7 @@ for player in players: self.host.plugins["XEP-0249"].invite(jid.JID(player), room.occupantJID.userhostJID(), {"game":"Tarot"}, profile) self.waiting_inv[_room] = (time(), players) #TODO: remove invitation waiting for too long, using the time data - + def after_init(ignore): room_name = "sat_tarot_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key) print "\n\n===> room_name:", room_name @@ -445,7 +445,7 @@ muc_service = None for service in self.host.memory.getServerServiceEntities("conference", "text", profile): if not ".irc." in service.userhost(): - #FIXME: + #FIXME: #This awfull ugly hack is here to avoid an issue with openfire: the irc gateway #use "conference/text" identity (instead of "conference/irc"), there is certainly a better way #to manage this, but this hack fill do it for test purpose @@ -454,7 +454,7 @@ if not muc_service: error(_("Can't find a MUC service")) return - + _jid, xmlstream = self.host.getJidNStream(profile) d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile).addCallback(tarotRoomJoined) @@ -580,23 +580,23 @@ mess = self.createGameElt(to_jid) mess.firstChildElement().addChild(self.__ask_contrat()) self.host.profiles[profile].xmlstream.send(mess) - + def card_game_cmd(self, mess_elt, profile): - from_jid = jid.JID(mess_elt['from']) + from_jid = jid.JID(mess_elt['from']) room_jid = jid.JID(from_jid.userhost()) game_elt = mess_elt.firstChildElement() game_data = self.games[room_jid.userhost()] players_data = game_data['players_data'] - + for elt in game_elt.elements(): - + if elt.name == 'started': #new game created players = [] for player in elt.elements(): players.append(unicode(player)) self.host.bridge.tarotGameStarted(room_jid.userhost(), from_jid.full(), players, profile) - + elif elt.name == 'player_ready': #ready to play player = elt['player'] status = self.games[room_jid.userhost()]['status'] @@ -605,7 +605,7 @@ debug (_('Player %(player)s is ready to start [status: %(status)s]') % {'player':player, 'status':status}) if status.values().count('ready') == nb_players: #everybody is ready, we can start the game self.newGame(room_jid, profile) - + elif elt.name == 'hand': #a new hand has been received self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile) @@ -613,7 +613,7 @@ form = data_form.Form.fromElement(elt.firstChildElement()) xml_data = dataForm2xml(form) self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile) - + elif elt.name == 'contrat_choosed': #TODO: check we receive the contrat from the right person #TODO: use proper XEP-0004 way for answering form @@ -648,7 +648,7 @@ return debug (_("%(player)s win the bid with %(contrat)s") % {'player':best_contrat[0],'contrat':best_contrat[1]}) game_data['contrat'] = best_contrat[1] - + if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre": self.__start_play(room_jid, game_data, profile) game_data['attaquant'] = best_contrat[0] @@ -662,7 +662,7 @@ #the attacker (attaquant) get the chien game_data['hand'][best_contrat[0]].extend(game_data['chien']) del game_data['chien'][:] - + if game_data['contrat'] == "Garde Sans": #The chien go into attaquant's (attacker) levees players_data[best_contrat[0]]['levees'].extend(game_data['chien']) @@ -693,13 +693,13 @@ players_data[elt['player']]['levees'].extend(list_cards) #we add the chien to attaquant's levées for card in list_cards: game_data['hand'][elt['player']].remove(card) - + self.__start_play(room_jid, game_data, profile) - + elif game_data['stage'] == "play": current_player = game_data['players'][game_data['current_player']] cards = TarotCard.from_tuples(self.__xml_to_list(elt)) - + if mess_elt['type'] == 'groupchat': self.host.bridge.tarotGameCardsPlayed(room_jid.userhost(), elt['player'], self.__xml_to_list(elt), profile) else: @@ -719,7 +719,7 @@ mess = self.createGameElt(room_jid) playcard_elt = mess.firstChildElement().addChild(elt) self.host.profiles[profile].xmlstream.send(mess) - + #Did everybody played ? played = [players_data[player]['played'] for player in game_data['players']] if all(played): @@ -776,13 +776,13 @@ error (_('Unmanaged error type: %s') % elt['type']) else: error (_('Unmanaged card game element: %s') % elt.name) - + def getHandler(self, profile): return CardGameHandler(self) class CardGameHandler (XMPPHandler): implements(iwokkel.IDisco) - + def __init__(self, plugin_parent): self.plugin_parent = plugin_parent self.host = plugin_parent.host