Mercurial > libervia-backend
annotate src/plugins/plugin_misc_tarot.py @ 717:358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
- "MUC user joined", "MUC user left" and class XMPPHandler are managed directly in RoomGame
- renamed __init__ parameters 'player_init_data' to 'player_init' and 'options' to 'game_init'
- pass the players list in radiocol method 'createGame' and signal 'radiocolStarted' (needed for invitation system and for UI players identification)
- added some parameters to manage who can invite, who can join, who to wait for... managed with check***Auth methods
- joining a game that is already launched may be possible, regarding these parameters and the invitation list
- leave and join a game again is partly managed: new tarot round is launched, we should keep playing the same round instead
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 21 Nov 2013 15:49:53 +0100 |
parents | ecc5a5b34ee1 |
children | 074970227bc0 |
rev | line source |
---|---|
88 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing French Tarot game |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
88 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
88 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
88 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
88 | 19 |
20 from logging import debug, info, warning, error | |
21 from twisted.words.xish import domish | |
563 | 22 from twisted.words.protocols.jabber import jid |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
23 from wokkel import data_form |
88 | 24 |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
25 from sat.tools.xml_tools import dataForm2XML |
682
2805fa3f4bdf
tools: moved src/tools/games.py to src/tools/frontends/
souliane <souliane@mailoo.org>
parents:
630
diff
changeset
|
26 from sat.tools.frontends.games import TarotCard |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
27 from sat.tools.plugins.games import RoomGame |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
28 from time import time |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
29 import random |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
30 |
88 | 31 |
90 | 32 NS_CG = 'http://www.goffi.org/protocol/card_game' |
33 CG_TAG = 'card_game' | |
88 | 34 |
35 PLUGIN_INFO = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
36 "name": "Tarot cards plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 "import_name": "Tarot", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
38 "type": "Misc", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
39 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
40 "dependencies": ["XEP-0045", "XEP-0249"], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
41 "main": "Tarot", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 "handler": "yes", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 "description": _("""Implementation of Tarot card game""") |
88 | 44 } |
45 | |
94 | 46 |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
47 class Tarot(RoomGame): |
88 | 48 |
49 def __init__(self, host): | |
50 info(_("Plugin Tarot initialization")) | |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
51 RoomGame.__init__(self, host, PLUGIN_INFO, (NS_CG, CG_TAG), |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
52 game_init={'hand_size': 18, 'init_player': 0, 'current_player': None, 'contrat': None, 'stage': None}, |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
53 player_init={'score': 0}) |
91 | 54 self.contrats = [_('Passe'), _('Petite'), _('Garde'), _('Garde Sans'), _('Garde Contre')] |
712
f610864eb7a5
plugins (MUC, tools, games): generalize the generation of a unique room name when joining a MUC and no room is specified:
souliane <souliane@mailoo.org>
parents:
683
diff
changeset
|
55 host.bridge.addMethod("tarotGameLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom) # args: players, room_jid, profile |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
56 host.bridge.addMethod("tarotGameCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame) # args: room_jid, players, profile |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
57 host.bridge.addMethod("tarotGameReady", ".plugin", in_sign='sss', out_sign='', method=self.playerReady) # args: player, referee, profile |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
58 host.bridge.addMethod("tarotGameContratChoosed", ".plugin", in_sign='ssss', out_sign='', method=self.contratChoosed) # args: player, referee, contrat, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
59 host.bridge.addMethod("tarotGamePlayCards", ".plugin", in_sign='ssa(ss)s', out_sign='', method=self.play_cards) # args: player, referee, cards, profile |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
60 host.bridge.addSignal("tarotGamePlayers", ".plugin", signature='ssass') # args: room_jid, referee, players, profile |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
61 host.bridge.addSignal("tarotGameStarted", ".plugin", signature='ssass') # args: room_jid, referee, players, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
62 host.bridge.addSignal("tarotGameNew", ".plugin", signature='sa(ss)s') # args: room_jid, hand, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
63 host.bridge.addSignal("tarotGameChooseContrat", ".plugin", signature='sss') # args: room_jid, xml_data, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
64 host.bridge.addSignal("tarotGameShowCards", ".plugin", signature='ssa(ss)a{ss}s') # args: room_jid, type ["chien", "poignée",...], cards, data[dict], profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
65 host.bridge.addSignal("tarotGameCardsPlayed", ".plugin", signature='ssa(ss)s') # args: room_jid, player, type ["chien", "poignée",...], cards, data[dict], profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
66 host.bridge.addSignal("tarotGameYourTurn", ".plugin", signature='ss') # args: room_jid, profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
67 host.bridge.addSignal("tarotGameScore", ".plugin", signature='ssasass') # args: room_jid, xml_data, winners (list of nicks), loosers (list of nicks), profile |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
68 host.bridge.addSignal("tarotGameInvalidCards", ".plugin", signature='ssa(ss)a(ss)s') # args: room_jid, game phase, played_cards, invalid_cards, profile |
88 | 69 self.deck_ordered = [] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
70 for value in ['excuse'] + map(str, range(1, 22)): |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
71 self.deck_ordered.append(TarotCard(("atout", value))) |
92 | 72 for suit in ["pique", "coeur", "carreau", "trefle"]: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
73 for value in map(str, range(1, 11)) + ["valet", "cavalier", "dame", "roi"]: |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
74 self.deck_ordered.append(TarotCard((suit, value))) |
88 | 75 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
76 def __card_list_to_xml(self, cards_list, elt_name): |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
77 """Convert a card list to domish element""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
78 cards_list_elt = domish.Element((None, elt_name)) |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
79 for card in cards_list: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
80 card_elt = domish.Element((None, 'card')) |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
81 card_elt['suit'] = card.suit |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
82 card_elt['value'] = card.value |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
83 cards_list_elt.addChild(card_elt) |
92 | 84 return cards_list_elt |
90 | 85 |
92 | 86 def __xml_to_list(self, cards_list_elt): |
87 """Convert a domish element with cards to a list of tuples""" | |
88 cards_list = [] | |
89 for card in cards_list_elt.elements(): | |
90 cards_list.append((card['suit'], card['value'])) | |
91 return cards_list | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
92 |
91 | 93 def __ask_contrat(self): |
94 """Create a element for asking contrat""" | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
95 contrat_elt = domish.Element((None, 'contrat')) |
91 | 96 form = data_form.Form('form', title=_('contrat selection')) |
97 field = data_form.Field('list-single', 'contrat', options=map(data_form.Option, self.contrats), required=True) | |
98 form.addField(field) | |
99 contrat_elt.addChild(form.toElement()) | |
100 return contrat_elt | |
101 | |
95 | 102 def __give_scores(self, scores, winners, loosers): |
103 """Create an element to give scores | |
104 @param scores: unicode (can contain line feed) | |
105 @param winners: list of unicode nicks of winners | |
106 @param loosers: list of unicode nicks of loosers""" | |
107 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
108 score_elt = domish.Element((None, 'score')) |
95 | 109 form = data_form.Form('form', title=_('scores')) |
110 for line in scores.split('\n'): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
111 field = data_form.Field('fixed', value=line) |
95 | 112 form.addField(field) |
113 score_elt.addChild(form.toElement()) | |
114 for winner in winners: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
115 winner_elt = domish.Element((None, 'winner')) |
95 | 116 winner_elt.addContent(winner) |
117 score_elt.addChild(winner_elt) | |
118 for looser in loosers: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
119 looser_elt = domish.Element((None, 'looser')) |
95 | 120 looser_elt.addContent(looser) |
121 score_elt.addChild(looser_elt) | |
122 return score_elt | |
123 | |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
124 def __invalid_cards_elt(self, played_cards, invalid_cards, game_phase): |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
125 """Create a element for invalid_cards error |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
126 @param list_cards: list of Card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
127 @param game_phase: phase of the game ['ecart', 'play']""" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
128 error_elt = domish.Element((None, 'error')) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
129 played_elt = self.__card_list_to_xml(played_cards, 'played') |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
130 invalid_elt = self.__card_list_to_xml(invalid_cards, 'invalid') |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
131 error_elt['type'] = 'invalid_cards' |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
132 error_elt['phase'] = game_phase |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
133 error_elt.addChild(played_elt) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
134 error_elt.addChild(invalid_elt) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
135 return error_elt |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
136 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
137 def __next_player(self, game_data, next_pl=None): |
94 | 138 """Increment player number & return player name |
139 @param next_pl: if given, then next_player is forced to this one | |
140 """ | |
141 if next_pl: | |
142 game_data['current_player'] = game_data['players'].index(next_pl) | |
143 return next_pl | |
144 else: | |
145 pl_idx = game_data['current_player'] = (game_data['current_player'] + 1) % len(game_data['players']) | |
146 return game_data['players'][pl_idx] | |
147 | |
148 def __winner(self, game_data): | |
149 """give the nick of the player who win this trick""" | |
150 players_data = game_data['players_data'] | |
151 first = game_data['first_player'] | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
152 first_idx = game_data['players'].index(first) |
94 | 153 suit_asked = None |
154 strongest = None | |
155 winner = None | |
156 for idx in [(first_idx + i) % 4 for i in range(4)]: | |
157 player = game_data['players'][idx] | |
158 card = players_data[player]['played'] | |
159 if card.value == "excuse": | |
160 continue | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
161 if suit_asked is None: |
94 | 162 suit_asked = card.suit |
163 if (card.suit == suit_asked or card.suit == "atout") and card > strongest: | |
164 strongest = card | |
165 winner = player | |
95 | 166 assert winner |
94 | 167 return winner |
168 | |
169 def __excuse_hack(self, game_data, played, winner): | |
95 | 170 """give a low card to other team and keep excuse if trick is lost |
171 @param game_data: data of the game | |
172 @param played: cards currently on the table | |
173 @param winner: nick of the trick winner""" | |
94 | 174 #TODO: manage the case where excuse is played on the last trick (and lost) |
175 players_data = game_data['players_data'] | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
176 excuse = TarotCard(("atout", "excuse")) |
95 | 177 |
320
5fc5e6a7e5c3
plugin Tarot: added a launch method to automatically create a new room, invite players and create the game
Goffi <goffi@goffi.org>
parents:
291
diff
changeset
|
178 #we first check if the Excuse was already played |
95 | 179 #and if somebody is waiting for a card |
94 | 180 for player in game_data['players']: |
181 if players_data[player]['wait_for_low']: | |
182 #the excuse owner has to give a card to somebody | |
183 if winner == player: | |
184 #the excuse owner win the trick, we check if we have something to give | |
185 for card in played: | |
186 if card.points == 0.5: | |
187 pl_waiting = players_data[player]['wait_for_low'] | |
188 played.remove(card) | |
189 players_data[pl_waiting]['levees'].append(card) | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
190 debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": player, "card_waited": card, "player_waiting": pl_waiting}) |
95 | 191 return |
94 | 192 return |
193 | |
194 if not excuse in played: | |
95 | 195 #the Excuse is not on the table, nothing to do |
94 | 196 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
197 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
198 excuse_player = None # Who has played the Excuse ? |
94 | 199 for player in game_data['players']: |
200 if players_data[player]['played'] == excuse: | |
201 excuse_player = player | |
202 break | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
203 |
94 | 204 if excuse_player == winner: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
205 return # the excuse player win the trick, nothing to do |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
206 |
94 | 207 #first we remove the excuse from played cards |
208 played.remove(excuse) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
209 #then we give it back to the original owner |
94 | 210 owner_levees = players_data[excuse_player]['levees'] |
211 owner_levees.append(excuse) | |
212 #finally we give a low card to the trick winner | |
213 low_card = None | |
95 | 214 #We look backward in cards won by the Excuse owner to |
215 #find a low value card | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
216 for card_idx in range(len(owner_levees) - 1, -1, -1): |
94 | 217 if owner_levees[card_idx].points == 0.5: |
218 low_card = owner_levees[card_idx] | |
219 del owner_levees[card_idx] | |
220 players_data[winner]['levees'].append(low_card) | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
221 debug(_('Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation') % {"excuse_owner": excuse_player, "card_waited": low_card, "player_waiting": winner}) |
94 | 222 break |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
223 if not low_card: # The player has no low card yet |
94 | 224 #TODO: manage case when player never win a trick with low card |
225 players_data[excuse_player]['wait_for_low'] = winner | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
226 debug(_("%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one") % {'excuse_owner': excuse_player, 'winner': winner}) |
94 | 227 |
328 | 228 def __draw_game(self, game_data): |
229 """The game is draw, no score change | |
230 @param game_data: data of the game | |
231 @return: tuple with (string victory message, list of winners, list of loosers)""" | |
232 players_data = game_data['players_data'] | |
233 scores_str = _('Draw game') | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
234 scores_str += '\n' |
328 | 235 for player in game_data['players']: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
236 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']} |
328 | 237 debug(scores_str) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
238 |
328 | 239 return (scores_str, [], []) |
240 | |
94 | 241 def __calculate_scores(self, game_data): |
95 | 242 """The game is finished, time to know who won :) |
243 @param game_data: data of the game | |
244 @return: tuple with (string victory message, list of winners, list of loosers)""" | |
94 | 245 players_data = game_data['players_data'] |
246 levees = players_data[game_data['attaquant']]['levees'] | |
247 score = 0 | |
248 nb_bouts = 0 | |
95 | 249 bouts = [] |
94 | 250 for card in levees: |
251 if card.bout: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
252 nb_bouts += 1 |
95 | 253 bouts.append(card.value) |
94 | 254 score += card.points |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
255 |
161
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
256 #We we do a basic check on score calculation |
95 | 257 check_score = 0 |
258 defenseurs = game_data['players'][:] | |
259 defenseurs.remove(game_data['attaquant']) | |
260 for defenseur in defenseurs: | |
261 for card in players_data[defenseur]['levees']: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
262 check_score += card.points |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
263 if game_data['contrat'] == "Garde Contre": |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
264 for card in game_data['chien']: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
265 check_score += card.points |
95 | 266 assert (score + check_score == 91) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
267 |
94 | 268 point_limit = None |
269 if nb_bouts == 3: | |
270 point_limit = 36 | |
271 elif nb_bouts == 2: | |
272 point_limit = 41 | |
273 elif nb_bouts == 1: | |
274 point_limit = 51 | |
275 else: | |
276 point_limit = 56 | |
95 | 277 if game_data['contrat'] == 'Petite': |
278 contrat_mult = 1 | |
279 elif game_data['contrat'] == 'Garde': | |
280 contrat_mult = 2 | |
281 elif game_data['contrat'] == 'Garde Sans': | |
282 contrat_mult = 4 | |
283 elif game_data['contrat'] == 'Garde Contre': | |
284 contrat_mult = 6 | |
285 else: | |
161
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
286 error(_('INTERNAL ERROR: contrat not managed (mispelled ?)')) |
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
287 assert(False) |
95 | 288 |
94 | 289 victory = (score >= point_limit) |
161
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
290 margin = abs(score - point_limit) |
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
291 points_defenseur = (margin + 25) * contrat_mult * (-1 if victory else 1) |
95 | 292 winners = [] |
293 loosers = [] | |
294 player_score = {} | |
295 for player in game_data['players']: | |
296 #TODO: adjust this for 3 and 5 players variants | |
297 #TODO: manage bonuses (petit au bout, poignée, chelem) | |
298 player_score[player] = points_defenseur if player != game_data['attaquant'] else points_defenseur * -3 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
299 players_data[player]['score'] += player_score[player] # we add score of this game to the global score |
95 | 300 if player_score[player] > 0: |
301 winners.append(player) | |
302 else: | |
303 loosers.append(player) | |
94 | 304 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
305 scores_str = _('The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): he %(victory)s') % {'attaquant': game_data['attaquant'], 'points': score, 'point_limit': point_limit, 'nb_bouts': nb_bouts, 'plural': 's' if nb_bouts > 1 else '', 'separator': ': ' if nb_bouts != 0 else '', 'bouts': ','.join(map(str, bouts)), 'victory': 'win' if victory else 'loose'} |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
306 scores_str += '\n' |
95 | 307 for player in game_data['players']: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
308 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']} |
95 | 309 debug(scores_str) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
310 |
95 | 311 return (scores_str, winners, loosers) |
94 | 312 |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
313 def __invalid_cards(self, game_data, cards): |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
314 """Checks that the player has the right to play what he wants to |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
315 @param game_data: Game data |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
316 @param cards: cards the player want to play |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
317 @return forbidden_cards cards or empty list if cards are ok""" |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
318 forbidden_cards = [] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
319 if game_data['stage'] == 'ecart': |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
320 for card in cards: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
321 if card.bout or card.value == "roi": |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
322 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
323 #TODO: manage case where atouts (trumps) are in the dog |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
324 elif game_data['stage'] == 'play': |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
325 biggest_atout = None |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
326 suit_asked = None |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
327 players = game_data['players'] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
328 players_data = game_data['players_data'] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
329 idx = players.index(game_data['first_player']) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
330 current_idx = game_data['current_player'] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
331 current_player = players[current_idx] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
332 if idx == current_idx: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
333 #the player is the first to play, he can play what he wants |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
334 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
335 while (idx != current_idx): |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
336 player = players[idx] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
337 played_card = players_data[player]['played'] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
338 if not suit_asked and played_card.value != "excuse": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
339 suit_asked = played_card.suit |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
340 if played_card.suit == "atout" and played_card > biggest_atout: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
341 biggest_atout = played_card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
342 idx = (idx + 1) % len(players) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
343 has_suit = False # True if there is one card of the asked suit in the hand of the player |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
344 has_atout = False |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
345 biggest_hand_atout = None |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
346 |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
347 for hand_card in game_data['hand'][current_player]: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
348 if hand_card.suit == suit_asked: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
349 has_suit = True |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
350 if hand_card.suit == "atout": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
351 has_atout = True |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
352 if hand_card.suit == "atout" and hand_card > biggest_hand_atout: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
353 biggest_hand_atout = hand_card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
354 |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
355 assert len(cards) == 1 |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
356 card = cards[0] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
357 if card.suit != suit_asked and has_suit and card.value != "excuse": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
358 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
359 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
360 if card.suit != suit_asked and card.suit != "atout" and has_atout: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
361 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
362 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
363 if card.suit == "atout" and card < biggest_atout and biggest_hand_atout > biggest_atout and card.value != "excuse": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
364 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
365 else: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
366 error(_('Internal error: unmanaged game stage')) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
367 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
368 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
369 def __start_play(self, room_jid, game_data, profile): |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
370 """Start the game (tell to the first player after dealer to play""" |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
371 game_data['stage'] = "play" |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
372 next_player_idx = game_data['current_player'] = (game_data['init_player'] + 1) % len(game_data['players']) # the player after the dealer start |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
373 game_data['first_player'] = next_player = game_data['players'][next_player_idx] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
374 to_jid = jid.JID(room_jid.userhost() + "/" + next_player) # FIXME: gof: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
375 self.send(to_jid, 'your_turn', profile=profile) |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
376 |
563 | 377 def contratChoosed(self, player, referee, contrat, profile_key='@NONE@'): |
91 | 378 """Must be call by player when the contrat is selected |
92 | 379 @param player: player's name |
91 | 380 @param referee: arbiter jid |
381 @contrat: contrat choosed (must be the exact same string than in the give list options) | |
382 @profile_key: profile | |
383 """ | |
384 profile = self.host.memory.getProfileName(profile_key) | |
385 if not profile: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
386 error(_("profile %s is unknown") % profile_key) |
91 | 387 return |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
388 debug(_('contrat [%(contrat)s] choosed by %(profile)s') % {'contrat': contrat, 'profile': profile}) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
389 self.send(jid.JID(referee), ('', 'contrat_choosed'), {'player': player}, content=contrat, profile=profile) |
88 | 390 |
563 | 391 def play_cards(self, player, referee, cards, profile_key='@NONE@'): |
92 | 392 """Must be call by player when the contrat is selected |
393 @param player: player's name | |
394 @param referee: arbiter jid | |
395 @cards: cards played (list of tuples) | |
396 @profile_key: profile | |
397 """ | |
398 profile = self.host.memory.getProfileName(profile_key) | |
399 if not profile: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
400 error(_("profile %s is unknown") % profile_key) |
92 | 401 return |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
402 debug(_('Cards played by %(profile)s: [%(cards)s]') % {'profile': profile, 'cards': cards}) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
403 elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), 'cards_played') |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
404 self.send(jid.JID(referee), elem, {'player': player}, profile=profile) |
88 | 405 |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
406 def newRound(self, room_jid, profile): |
91 | 407 game_data = self.games[room_jid.userhost()] |
408 players = game_data['players'] | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
409 game_data['first_player'] = None # first player for the current trick |
95 | 410 game_data['contrat'] = None |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
411 common_data = {'contrat': None, |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
412 'levees': [], # cards won |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
413 'played': None, # card on the table |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
414 'wait_for_low': None # Used when a player wait for a low card because of excuse |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
415 } |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
416 |
91 | 417 hand = game_data['hand'] = {} |
418 hand_size = game_data['hand_size'] | |
419 chien = game_data['chien'] = [] | |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
420 deck = self.deck_ordered[:] |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
421 random.shuffle(deck) |
328 | 422 for i in range(4): |
88 | 423 hand[players[i]] = deck[0:hand_size] |
424 del deck[0:hand_size] | |
92 | 425 chien.extend(deck) |
88 | 426 del(deck[:]) |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
427 msg_elts = {} |
88 | 428 for player in players: |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
429 msg_elts[player] = self.__card_list_to_xml(hand[player], 'hand') |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
430 |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
431 RoomGame.newRound(self, room_jid, (common_data, msg_elts), profile) |
91 | 432 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
433 pl_idx = game_data['current_player'] = (game_data['init_player'] + 1) % len(players) # the player after the dealer start |
91 | 434 player = players[pl_idx] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
435 to_jid = jid.JID(room_jid.userhost() + "/" + player) # FIXME: gof: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
436 self.send(to_jid, self.__ask_contrat(), profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
437 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
438 def room_game_cmd(self, mess_elt, profile): |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
439 """ |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
440 @param mess_elt: instance of twisted.words.xish.domish.Element |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
441 """ |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
442 from_jid = jid.JID(mess_elt['from']) |
93 | 443 room_jid = jid.JID(from_jid.userhost()) |
90 | 444 game_elt = mess_elt.firstChildElement() |
92 | 445 game_data = self.games[room_jid.userhost()] |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
446 if 'players_data' in game_data: |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
447 players_data = game_data['players_data'] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
448 |
92 | 449 for elt in game_elt.elements(): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
450 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
451 if elt.name == 'started' or elt.name == 'players': # new game created |
90 | 452 players = [] |
453 for player in elt.elements(): | |
454 players.append(unicode(player)) | |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
455 signal = self.host.bridge.tarotGameStarted if elt.name == 'started' else self.host.bridge.tarotGamePlayers |
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
456 signal(room_jid.userhost(), from_jid.full(), players, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
457 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
458 elif elt.name == 'player_ready': # ready to play |
92 | 459 player = elt['player'] |
90 | 460 status = self.games[room_jid.userhost()]['status'] |
461 nb_players = len(self.games[room_jid.userhost()]['players']) | |
462 status[player] = 'ready' | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
463 debug(_('Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status}) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
464 if status.values().count('ready') == nb_players: # everybody is ready, we can start the game |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
465 self.newRound(room_jid, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
466 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
467 elif elt.name == 'hand': # a new hand has been received |
92 | 468 self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile) |
91 | 469 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
470 elif elt.name == 'contrat': # it's time to choose contrat |
91 | 471 form = data_form.Form.fromElement(elt.firstChildElement()) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
472 xml_data = dataForm2XML(form) |
92 | 473 self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
474 |
92 | 475 elif elt.name == 'contrat_choosed': |
91 | 476 #TODO: check we receive the contrat from the right person |
92 | 477 #TODO: use proper XEP-0004 way for answering form |
478 player = elt['player'] | |
479 players_data[player]['contrat'] = unicode(elt) | |
91 | 480 contrats = [players_data[player]['contrat'] for player in game_data['players']] |
481 if contrats.count(None): | |
482 #not everybody has choosed his contrat, it's next one turn | |
483 player = self.__next_player(game_data) | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
484 to_jid = jid.JID(room_jid.userhost() + "/" + player) # FIXME: gof: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
485 self.send(to_jid, self.__ask_contrat(), profile=profile) |
91 | 486 else: |
487 best_contrat = [None, "Passe"] | |
488 for player in game_data['players']: | |
489 contrat = players_data[player]['contrat'] | |
490 idx_best = self.contrats.index(best_contrat[1]) | |
491 idx_pl = self.contrats.index(contrat) | |
492 if idx_pl > idx_best: | |
493 best_contrat[0] = player | |
494 best_contrat[1] = contrat | |
328 | 495 if best_contrat[1] == "Passe": |
496 debug(_("Everybody is passing, round ended")) | |
497 to_jid = jid.JID(room_jid.userhost()) | |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
498 self.send(to_jid, self.__give_scores(*self.__draw_game(game_data)), profile=profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
499 game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) # we change the dealer |
328 | 500 for player in game_data['players']: |
501 game_data['status'][player] = "init" | |
502 return | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
503 debug(_("%(player)s win the bid with %(contrat)s") % {'player': best_contrat[0], 'contrat': best_contrat[1]}) |
95 | 504 game_data['contrat'] = best_contrat[1] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
505 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
506 if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre": |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
507 self.__start_play(room_jid, game_data, profile) |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
508 game_data['attaquant'] = best_contrat[0] |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
509 else: |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
510 #Time to show the chien to everybody |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
511 to_jid = jid.JID(room_jid.userhost()) # FIXME: gof: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
512 elem = self.__card_list_to_xml(game_data['chien'], 'chien') |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
513 self.send(to_jid, elem, {'attaquant': best_contrat[0]}, profile=profile) |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
514 #the attacker (attaquant) get the chien |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
515 game_data['hand'][best_contrat[0]].extend(game_data['chien']) |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
516 del game_data['chien'][:] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
517 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
518 if game_data['contrat'] == "Garde Sans": |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
519 #The chien go into attaquant's (attacker) levees |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
520 players_data[best_contrat[0]]['levees'].extend(game_data['chien']) |
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
521 del game_data['chien'][:] |
91 | 522 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
523 elif elt.name == 'chien': # we have received the chien |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
524 debug(_("tarot: chien received")) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
525 data = {"attaquant": elt['attaquant']} |
92 | 526 game_data['stage'] = "ecart" |
527 game_data['attaquant'] = elt['attaquant'] | |
528 self.host.bridge.tarotGameShowCards(room_jid.userhost(), "chien", self.__xml_to_list(elt), data, profile) | |
529 | |
530 elif elt.name == 'cards_played': | |
531 if game_data['stage'] == "ecart": | |
532 #TODO: show atouts (trumps) if player put some in écart | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
533 assert (game_data['attaquant'] == elt['player']) # TODO: throw an xml error here |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
534 list_cards = TarotCard.from_tuples(self.__xml_to_list(elt)) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
535 #we now check validity of card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
536 invalid_cards = self.__invalid_cards(game_data, list_cards) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
537 if invalid_cards: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
538 elem = self.__invalid_cards_elt(list_cards, invalid_cards, game_data['stage']) |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
539 self.send(jid.JID(room_jid.userhost() + '/' + elt['player']), elem, profile=profile) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
540 return |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
541 |
95 | 542 #FIXME: gof: manage Garde Sans & Garde Contre cases |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
543 players_data[elt['player']]['levees'].extend(list_cards) # we add the chien to attaquant's levées |
95 | 544 for card in list_cards: |
545 game_data['hand'][elt['player']].remove(card) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
546 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
547 self.__start_play(room_jid, game_data, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
548 |
93 | 549 elif game_data['stage'] == "play": |
550 current_player = game_data['players'][game_data['current_player']] | |
141
8c80d4dec7a8
mover Card class to tools/games and renamed it in TarotCard
Goffi <goffi@goffi.org>
parents:
134
diff
changeset
|
551 cards = TarotCard.from_tuples(self.__xml_to_list(elt)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
552 |
94 | 553 if mess_elt['type'] == 'groupchat': |
554 self.host.bridge.tarotGameCardsPlayed(room_jid.userhost(), elt['player'], self.__xml_to_list(elt), profile) | |
555 else: | |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
556 #we first check validity of card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
557 invalid_cards = self.__invalid_cards(game_data, cards) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
558 if invalid_cards: |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
559 elem = self.__invalid_cards_elt(cards, invalid_cards, game_data['stage']) |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
560 self.send(jid.JID(room_jid.userhost() + '/' + current_player), elem, profile=profile) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
561 return |
93 | 562 #the card played is ok, we forward it to everybody |
94 | 563 #first we remove it from the hand and put in on the table |
93 | 564 game_data['hand'][current_player].remove(cards[0]) |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
565 players_data[current_player]['played'] = cards[0] |
93 | 566 |
567 #then we forward the message | |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
568 self.send(room_jid, elt, profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
569 |
94 | 570 #Did everybody played ? |
571 played = [players_data[player]['played'] for player in game_data['players']] | |
95 | 572 if all(played): |
573 #everybody has played | |
94 | 574 winner = self.__winner(game_data) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
575 debug(_('The winner of this trick is %s') % winner) |
94 | 576 #the winner win the trick |
577 self.__excuse_hack(game_data, played, winner) | |
578 players_data[elt['player']]['levees'].extend(played) | |
579 #nothing left on the table | |
580 for player in game_data['players']: | |
581 players_data[player]['played'] = None | |
582 if len(game_data['hand'][current_player]) == 0: | |
583 #no card lef: the game is finished | |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
584 elem = self.__give_scores(*self.__calculate_scores(game_data)) |
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
585 self.send(room_jid, elem, profile=profile) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
586 game_data['init_player'] = (game_data['init_player'] + 1) % len(game_data['players']) # we change the dealer |
328 | 587 for player in game_data['players']: |
588 game_data['status'][player] = "init" | |
94 | 589 return |
590 #next player is the winner | |
591 next_player = game_data['first_player'] = self.__next_player(game_data, winner) | |
592 else: | |
593 next_player = self.__next_player(game_data) | |
594 | |
93 | 595 #finally, we tell to the next player to play |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
596 to_jid = jid.JID(room_jid.userhost() + "/" + next_player) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
597 self.send(to_jid, 'your_turn', profile=profile) |
93 | 598 |
92 | 599 elif elt.name == 'your_turn': |
600 self.host.bridge.tarotGameYourTurn(room_jid.userhost(), profile) | |
91 | 601 |
95 | 602 elif elt.name == 'score': |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
603 form_elt = elt.elements(name='x', uri='jabber:x:data').next() |
95 | 604 winners = [] |
605 loosers = [] | |
563 | 606 for winner in elt.elements(name='winner', uri=NS_CG): |
95 | 607 winners.append(unicode(winner)) |
563 | 608 for looser in elt.elements(name='looser', uri=NS_CG): |
95 | 609 loosers.append(unicode(looser)) |
610 form = data_form.Form.fromElement(form_elt) | |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
611 xml_data = dataForm2XML(form) |
95 | 612 self.host.bridge.tarotGameScore(room_jid.userhost(), xml_data, winners, loosers, profile) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
613 elif elt.name == 'error': |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
614 if elt['type'] == 'invalid_cards': |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
615 played_cards = self.__xml_to_list(elt.elements(name='played', uri=NS_CG).next()) |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
616 invalid_cards = self.__xml_to_list(elt.elements(name='invalid', uri=NS_CG).next()) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
617 self.host.bridge.tarotGameInvalidCards(room_jid.userhost(), elt['phase'], played_cards, invalid_cards, profile) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
618 else: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
619 error(_('Unmanaged error type: %s') % elt['type']) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
620 else: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
621 error(_('Unmanaged card game element: %s') % elt.name) |