Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_tarot.py @ 3317:83f25da66bec
core (memory): files are now public by default except for those in root directory:
using public permissions by default makes permissions change more easy as we don't have to
recursively change all permissions of sub files when changing directory. Root directories
are private by default.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:02:41 +0200 |
parents | 559a625a236b |
children | be6d91572633 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
88 | 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 |
3136 | 5 # Copyright (C) 2009-2020 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 |
771 | 20 from sat.core.i18n import _ |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
878
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
24 log = getLogger(__name__) |
88 | 25 from twisted.words.xish import domish |
563 | 26 from twisted.words.protocols.jabber import jid |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
27 from twisted.internet import defer |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
28 from wokkel import data_form |
88 | 29 |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
30 from sat.memory import memory |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
31 from sat.tools import xml_tools |
719
56aa0e98c92e
frontends tools: moved src/tools/frontends to frontends/src/tools
souliane <souliane@mailoo.org>
parents:
718
diff
changeset
|
32 from sat_frontends.tools.games import TarotCard |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
33 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
|
34 |
88 | 35 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 NS_CG = "http://www.goffi.org/protocol/card_game" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 CG_TAG = "card_game" |
88 | 38 |
39 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
40 C.PI_NAME: "Tarot cards plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
41 C.PI_IMPORT_NAME: "Tarot", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
42 C.PI_TYPE: "Misc", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
43 C.PI_PROTOCOLS: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
44 C.PI_DEPENDENCIES: ["XEP-0045", "XEP-0249", "ROOM-GAME"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
45 C.PI_MAIN: "Tarot", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1970
diff
changeset
|
46 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 C.PI_DESCRIPTION: _("""Implementation of Tarot card game"""), |
88 | 48 } |
49 | |
94 | 50 |
718
074970227bc0
plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
51 class Tarot(object): |
074970227bc0
plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
52 def inheritFromRoomGame(self, host): |
074970227bc0
plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
53 global RoomGame |
074970227bc0
plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
54 RoomGame = host.plugins["ROOM-GAME"].__class__ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 self.__class__ = type( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 self.__class__.__name__, (self.__class__, RoomGame, object), {} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 ) |
88 | 58 |
59 def __init__(self, host): | |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
60 log.info(_("Plugin Tarot initialization")) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
61 self._sessions = memory.Sessions() |
718
074970227bc0
plugin tools: turn src/plugin/games.py into a plugin and move it to src/plugins/plugin_misc_room_game.py
souliane <souliane@mailoo.org>
parents:
717
diff
changeset
|
62 self.inheritFromRoomGame(host) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 RoomGame._init_( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 PLUGIN_INFO, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 (NS_CG, CG_TAG), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 game_init={ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 "hand_size": 18, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 "init_player": 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 "current_player": None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 "contrat": None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 "stage": None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 }, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 player_init={"score": 0}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 self.contrats = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 _("Passe"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 _("Petite"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 _("Garde"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 _("Garde Sans"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 _("Garde Contre"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 "tarotGameLaunch", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 in_sign="asss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
88 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 method=self._prepareRoom, |
3028 | 90 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
91 ) # args: players, room_jid, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 "tarotGameCreate", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 in_sign="sass", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 method=self._createGame, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 ) # args: room_jid, players, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 "tarotGameReady", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 in_sign="sss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 method=self._playerReady, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 ) # args: player, referee, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 "tarotGamePlayCards", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 in_sign="ssa(ss)s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 method=self.play_cards, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 ) # args: player, referee, cards, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 "tarotGamePlayers", ".plugin", signature="ssass" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 ) # args: room_jid, referee, players, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 "tarotGameStarted", ".plugin", signature="ssass" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 ) # args: room_jid, referee, players, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 "tarotGameNew", ".plugin", signature="sa(ss)s" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 ) # args: room_jid, hand, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 "tarotGameChooseContrat", ".plugin", signature="sss" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 ) # args: room_jid, xml_data, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 "tarotGameShowCards", ".plugin", signature="ssa(ss)a{ss}s" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 ) # args: room_jid, type ["chien", "poignée",...], cards, data[dict], profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 "tarotGameCardsPlayed", ".plugin", signature="ssa(ss)s" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 ) # args: room_jid, player, type ["chien", "poignée",...], cards, data[dict], profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 "tarotGameYourTurn", ".plugin", signature="ss" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 ) # args: room_jid, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 "tarotGameScore", ".plugin", signature="ssasass" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ) # args: room_jid, xml_data, winners (list of nicks), loosers (list of nicks), profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 host.bridge.addSignal( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 "tarotGameInvalidCards", ".plugin", signature="ssa(ss)a(ss)s" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 ) # args: room_jid, game phase, played_cards, invalid_cards, profile |
88 | 140 self.deck_ordered = [] |
3028 | 141 for value in ["excuse"] + list(map(str, list(range(1, 22)))): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
142 self.deck_ordered.append(TarotCard(("atout", value))) |
92 | 143 for suit in ["pique", "coeur", "carreau", "trefle"]: |
3028 | 144 for value in list(map(str, list(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
|
145 self.deck_ordered.append(TarotCard((suit, value))) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 self.__choose_contrat_id = host.registerCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 self._contratChoosed, with_data=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 ) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
149 self.__score_id = host.registerCallback(self._scoreShowed, with_data=True) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
150 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
151 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
|
152 """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
|
153 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
|
154 for card in cards_list: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 card_elt = domish.Element((None, "card")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 card_elt["suit"] = card.suit |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
157 card_elt["value"] = card.value |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
158 cards_list_elt.addChild(card_elt) |
92 | 159 return cards_list_elt |
90 | 160 |
92 | 161 def __xml_to_list(self, cards_list_elt): |
162 """Convert a domish element with cards to a list of tuples""" | |
163 cards_list = [] | |
164 for card in cards_list_elt.elements(): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 cards_list.append((card["suit"], card["value"])) |
92 | 166 return cards_list |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
167 |
91 | 168 def __ask_contrat(self): |
169 """Create a element for asking contrat""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
170 contrat_elt = domish.Element((None, "contrat")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 form = data_form.Form("form", title=_("contrat selection")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
172 field = data_form.Field( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
173 "list-single", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 "contrat", |
3028 | 175 options=list(map(data_form.Option, self.contrats)), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
176 required=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 ) |
91 | 178 form.addField(field) |
179 contrat_elt.addChild(form.toElement()) | |
180 return contrat_elt | |
181 | |
95 | 182 def __give_scores(self, scores, winners, loosers): |
183 """Create an element to give scores | |
184 @param scores: unicode (can contain line feed) | |
185 @param winners: list of unicode nicks of winners | |
186 @param loosers: list of unicode nicks of loosers""" | |
187 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 score_elt = domish.Element((None, "score")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 form = data_form.Form("form", title=_("scores")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 for line in scores.split("\n"): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 field = data_form.Field("fixed", value=line) |
95 | 192 form.addField(field) |
193 score_elt.addChild(form.toElement()) | |
194 for winner in winners: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 winner_elt = domish.Element((None, "winner")) |
95 | 196 winner_elt.addContent(winner) |
197 score_elt.addChild(winner_elt) | |
198 for looser in loosers: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 looser_elt = domish.Element((None, "looser")) |
95 | 200 looser_elt.addContent(looser) |
201 score_elt.addChild(looser_elt) | |
202 return score_elt | |
203 | |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
204 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
|
205 """Create a element for invalid_cards error |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
206 @param list_cards: list of Card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
207 @param game_phase: phase of the game ['ecart', 'play']""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 error_elt = domish.Element((None, "error")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 played_elt = self.__card_list_to_xml(played_cards, "played") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 invalid_elt = self.__card_list_to_xml(invalid_cards, "invalid") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
211 error_elt["type"] = "invalid_cards" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 error_elt["phase"] = game_phase |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
213 error_elt.addChild(played_elt) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
214 error_elt.addChild(invalid_elt) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
215 return error_elt |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
216 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
217 def __next_player(self, game_data, next_pl=None): |
94 | 218 """Increment player number & return player name |
219 @param next_pl: if given, then next_player is forced to this one | |
220 """ | |
221 if next_pl: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 game_data["current_player"] = game_data["players"].index(next_pl) |
94 | 223 return next_pl |
224 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 pl_idx = game_data["current_player"] = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 game_data["current_player"] + 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 ) % len(game_data["players"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 return game_data["players"][pl_idx] |
94 | 229 |
230 def __winner(self, game_data): | |
231 """give the nick of the player who win this trick""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 players_data = game_data["players_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 first = game_data["first_player"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 first_idx = game_data["players"].index(first) |
94 | 235 suit_asked = None |
236 strongest = None | |
237 winner = None | |
238 for idx in [(first_idx + i) % 4 for i in range(4)]: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 player = game_data["players"][idx] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 card = players_data[player]["played"] |
94 | 241 if card.value == "excuse": |
242 continue | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
243 if suit_asked is None: |
94 | 244 suit_asked = card.suit |
245 if (card.suit == suit_asked or card.suit == "atout") and card > strongest: | |
246 strongest = card | |
247 winner = player | |
95 | 248 assert winner |
94 | 249 return winner |
250 | |
251 def __excuse_hack(self, game_data, played, winner): | |
95 | 252 """give a low card to other team and keep excuse if trick is lost |
253 @param game_data: data of the game | |
254 @param played: cards currently on the table | |
255 @param winner: nick of the trick winner""" | |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
256 # TODO: manage the case where excuse is played on the last trick (and lost) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 players_data = game_data["players_data"] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
258 excuse = TarotCard(("atout", "excuse")) |
95 | 259 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
260 # we first check if the Excuse was already played |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
261 # and if somebody is waiting for a card |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 if players_data[player]["wait_for_low"]: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
264 # the excuse owner has to give a card to somebody |
94 | 265 if winner == player: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
266 # the excuse owner win the trick, we check if we have something to give |
94 | 267 for card in played: |
268 if card.points == 0.5: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 pl_waiting = players_data[player]["wait_for_low"] |
94 | 270 played.remove(card) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 players_data[pl_waiting]["levees"].append(card) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 _( |
3028 | 274 "Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 "excuse_owner": player, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 "card_waited": card, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 "player_waiting": pl_waiting, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 ) |
95 | 282 return |
94 | 283 return |
284 | |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
285 if excuse not in played: |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
286 # the Excuse is not on the table, nothing to do |
94 | 287 return |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
288 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
289 excuse_player = None # Who has played the Excuse ? |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
290 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 if players_data[player]["played"] == excuse: |
94 | 292 excuse_player = player |
293 break | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
294 |
94 | 295 if excuse_player == winner: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
296 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
|
297 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
298 # first we remove the excuse from played cards |
94 | 299 played.remove(excuse) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
300 # then we give it back to the original owner |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
301 owner_levees = players_data[excuse_player]["levees"] |
94 | 302 owner_levees.append(excuse) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
303 # finally we give a low card to the trick winner |
94 | 304 low_card = None |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
305 # We look backward in cards won by the Excuse owner to |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
306 # find a low value card |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
307 for card_idx in range(len(owner_levees) - 1, -1, -1): |
94 | 308 if owner_levees[card_idx].points == 0.5: |
309 low_card = owner_levees[card_idx] | |
310 del owner_levees[card_idx] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
311 players_data[winner]["levees"].append(low_card) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
312 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
313 _( |
3028 | 314 "Player %(excuse_owner)s give %(card_waited)s to %(player_waiting)s for Excuse compensation" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
315 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
316 % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
317 "excuse_owner": excuse_player, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
318 "card_waited": low_card, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
319 "player_waiting": winner, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
320 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
321 ) |
94 | 322 break |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
323 if not low_card: # The player has no low card yet |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
324 # TODO: manage case when player never win a trick with low card |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
325 players_data[excuse_player]["wait_for_low"] = winner |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
326 log.debug( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
327 _( |
3028 | 328 "%(excuse_owner)s keep the Excuse but has not card to give, %(winner)s is waiting for one" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
329 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
330 % {"excuse_owner": excuse_player, "winner": winner} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
331 ) |
94 | 332 |
328 | 333 def __draw_game(self, game_data): |
334 """The game is draw, no score change | |
335 @param game_data: data of the game | |
336 @return: tuple with (string victory message, list of winners, list of loosers)""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
337 players_data = game_data["players_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
338 scores_str = _("Draw game") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
339 scores_str += "\n" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
340 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
341 scores_str += _( |
3028 | 342 "\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
343 ) % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
344 "player": player, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
345 "score_game": 0, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
346 "total_score": players_data[player]["score"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
347 } |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
348 log.debug(scores_str) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
349 |
328 | 350 return (scores_str, [], []) |
351 | |
94 | 352 def __calculate_scores(self, game_data): |
95 | 353 """The game is finished, time to know who won :) |
354 @param game_data: data of the game | |
355 @return: tuple with (string victory message, list of winners, list of loosers)""" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
356 players_data = game_data["players_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
357 levees = players_data[game_data["attaquant"]]["levees"] |
94 | 358 score = 0 |
359 nb_bouts = 0 | |
95 | 360 bouts = [] |
94 | 361 for card in levees: |
362 if card.bout: | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
363 nb_bouts += 1 |
95 | 364 bouts.append(card.value) |
94 | 365 score += card.points |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
366 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
367 # We do a basic check on score calculation |
95 | 368 check_score = 0 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
369 defenseurs = game_data["players"][:] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
370 defenseurs.remove(game_data["attaquant"]) |
95 | 371 for defenseur in defenseurs: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
372 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
|
373 check_score += card.points |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
374 if game_data["contrat"] == "Garde Contre": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
375 for card in game_data["chien"]: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
376 check_score += card.points |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
377 assert score + check_score == 91 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
378 |
94 | 379 point_limit = None |
380 if nb_bouts == 3: | |
381 point_limit = 36 | |
382 elif nb_bouts == 2: | |
383 point_limit = 41 | |
384 elif nb_bouts == 1: | |
385 point_limit = 51 | |
386 else: | |
387 point_limit = 56 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 if game_data["contrat"] == "Petite": |
95 | 389 contrat_mult = 1 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 elif game_data["contrat"] == "Garde": |
95 | 391 contrat_mult = 2 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
392 elif game_data["contrat"] == "Garde Sans": |
95 | 393 contrat_mult = 4 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
394 elif game_data["contrat"] == "Garde Contre": |
95 | 395 contrat_mult = 6 |
396 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
397 log.error(_("INTERNAL ERROR: contrat not managed (mispelled ?)")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
398 assert False |
95 | 399 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
400 victory = score >= point_limit |
161
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
401 margin = abs(score - point_limit) |
c37826d80f2a
plugin tarot: fixed bad score calculation
Goffi <goffi@goffi.org>
parents:
147
diff
changeset
|
402 points_defenseur = (margin + 25) * contrat_mult * (-1 if victory else 1) |
95 | 403 winners = [] |
404 loosers = [] | |
405 player_score = {} | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
406 for player in game_data["players"]: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
407 # TODO: adjust this for 3 and 5 players variants |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
408 # TODO: manage bonuses (petit au bout, poignée, chelem) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 player_score[player] = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
410 points_defenseur |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
411 if player != game_data["attaquant"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 else points_defenseur * -3 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
413 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
414 players_data[player]["score"] += player_score[ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
415 player |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
416 ] # we add score of this game to the global score |
95 | 417 if player_score[player] > 0: |
418 winners.append(player) | |
419 else: | |
420 loosers.append(player) | |
94 | 421 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
422 scores_str = _( |
3028 | 423 "The attacker (%(attaquant)s) makes %(points)i and needs to make %(point_limit)i (%(nb_bouts)s oulder%(plural)s%(separator)s%(bouts)s): (s)he %(victory)s" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
424 ) % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 "attaquant": game_data["attaquant"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
426 "points": score, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
427 "point_limit": point_limit, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
428 "nb_bouts": nb_bouts, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
429 "plural": "s" if nb_bouts > 1 else "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 "separator": ": " if nb_bouts != 0 else "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
431 "bouts": ",".join(map(str, bouts)), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 "victory": "wins" if victory else "looses", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
433 } |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 scores_str += "\n" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 scores_str += _( |
3028 | 437 "\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 ) % { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 "player": player, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 "score_game": player_score[player], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
441 "total_score": players_data[player]["score"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 } |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
443 log.debug(scores_str) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
444 |
95 | 445 return (scores_str, winners, loosers) |
94 | 446 |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
447 def __invalid_cards(self, game_data, cards): |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
448 """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
|
449 @param game_data: Game data |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
450 @param cards: cards the player want to play |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
451 @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
|
452 forbidden_cards = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
453 if game_data["stage"] == "ecart": |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
454 for card in cards: |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
455 if card.bout or card.value == "roi": |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
456 forbidden_cards.append(card) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
457 # TODO: manage case where atouts (trumps) are in the dog |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
458 elif game_data["stage"] == "play": |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
459 biggest_atout = None |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
460 suit_asked = None |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
461 players = game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
462 players_data = game_data["players_data"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 idx = players.index(game_data["first_player"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
464 current_idx = game_data["current_player"] |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
465 current_player = players[current_idx] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
466 if idx == current_idx: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
467 # the player is the first to play, he can play what he wants |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
468 return forbidden_cards |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
469 while idx != current_idx: |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
470 player = players[idx] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
471 played_card = players_data[player]["played"] |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
472 if not suit_asked and played_card.value != "excuse": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
473 suit_asked = played_card.suit |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
474 if played_card.suit == "atout" and played_card > biggest_atout: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
475 biggest_atout = played_card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
476 idx = (idx + 1) % len(players) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
477 has_suit = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
478 False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
479 ) # 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
|
480 has_atout = False |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
481 biggest_hand_atout = None |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
482 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
483 for hand_card in game_data["hand"][current_player]: |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
484 if hand_card.suit == suit_asked: |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
485 has_suit = True |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
486 if hand_card.suit == "atout": |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
487 has_atout = True |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
488 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
|
489 biggest_hand_atout = hand_card |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
490 |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
491 assert len(cards) == 1 |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
492 card = cards[0] |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
493 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
|
494 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
495 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
496 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
|
497 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
498 return forbidden_cards |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
499 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
500 card.suit == "atout" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
501 and card < biggest_atout |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
502 and biggest_hand_atout > biggest_atout |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
503 and card.value != "excuse" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
504 ): |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
505 forbidden_cards.append(card) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
506 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
507 log.error(_("Internal error: unmanaged game stage")) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
508 return forbidden_cards |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
509 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
510 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
|
511 """Start the game (tell to the first player after dealer to play""" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
512 game_data["stage"] = "play" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
513 next_player_idx = game_data["current_player"] = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
514 game_data["init_player"] + 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
515 ) % len( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
516 game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
517 ) # the player after the dealer start |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
518 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
|
519 to_jid = jid.JID(room_jid.userhost() + "/" + next_player) # FIXME: gof: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
520 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
|
521 |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
522 def _contratChoosed(self, raw_data, profile): |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
523 """Will be called when the contrat is selected |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
524 @param raw_data: contains the choosed session id and the chosen contrat |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
525 @param profile_key: profile |
91 | 526 """ |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
527 try: |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
528 session_data = self._sessions.profileGet(raw_data["session_id"], profile) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
529 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
530 log.warning(_("session id doesn't exist, session has probably expired")) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
531 # TODO: send error dialog |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
532 return defer.succeed({}) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
533 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
534 room_jid = session_data["room_jid"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
535 referee_jid = self.games[room_jid]["referee"] |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
536 player = self.host.plugins["XEP-0045"].getRoomNick(room_jid, profile) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
537 data = xml_tools.XMLUIResult2DataFormResult(raw_data) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
538 contrat = data["contrat"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
539 log.debug( |
3028 | 540 _("contrat [%(contrat)s] choosed by %(profile)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
541 % {"contrat": contrat, "profile": profile} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
542 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
543 d = self.send( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
544 referee_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
545 ("", "contrat_choosed"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
546 {"player": player}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
547 content=contrat, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
548 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
549 ) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
550 d.addCallback(lambda ignore: {}) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
551 del self._sessions[raw_data["session_id"]] |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
552 return d |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
553 |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
554 def _scoreShowed(self, raw_data, profile): |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
555 """Will be called when the player closes the score dialog |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
556 @param raw_data: nothing to retrieve from here but the session id |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
557 @param profile_key: profile |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
558 """ |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
559 try: |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
560 session_data = self._sessions.profileGet(raw_data["session_id"], profile) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
561 except KeyError: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
562 log.warning(_("session id doesn't exist, session has probably expired")) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
563 # TODO: send error dialog |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
564 return defer.succeed({}) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
565 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
566 room_jid_s = session_data["room_jid"].userhost() |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
567 # XXX: empty hand means to the frontend "reset the display"... |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
568 self.host.bridge.tarotGameNew(room_jid_s, [], profile) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
569 del self._sessions[raw_data["session_id"]] |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
570 return defer.succeed({}) |
88 | 571 |
916
1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents:
878
diff
changeset
|
572 def play_cards(self, player, referee, cards, profile_key=C.PROF_KEY_NONE): |
92 | 573 """Must be call by player when the contrat is selected |
574 @param player: player's name | |
575 @param referee: arbiter jid | |
576 @cards: cards played (list of tuples) | |
577 @profile_key: profile | |
578 """ | |
579 profile = self.host.memory.getProfileName(profile_key) | |
580 if not profile: | |
3028 | 581 log.error(_("profile %s is unknown") % profile_key) |
92 | 582 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
583 log.debug( |
3028 | 584 _("Cards played by %(profile)s: [%(cards)s]") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
585 % {"profile": profile, "cards": cards} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
586 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
587 elem = self.__card_list_to_xml(TarotCard.from_tuples(cards), "cards_played") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
588 self.send(jid.JID(referee), elem, {"player": player}, profile=profile) |
88 | 589 |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
590 def newRound(self, room_jid, profile): |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
591 game_data = self.games[room_jid] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
592 players = game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
593 game_data["first_player"] = None # first player for the current trick |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
594 game_data["contrat"] = None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
595 common_data = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
596 "contrat": None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
597 "levees": [], # cards won |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
598 "played": None, # card on the table |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
599 "wait_for_low": None, # Used when a player wait for a low card because of excuse |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
600 } |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
601 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
602 hand = game_data["hand"] = {} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
603 hand_size = game_data["hand_size"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
604 chien = game_data["chien"] = [] |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
605 deck = self.deck_ordered[:] |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
606 random.shuffle(deck) |
328 | 607 for i in range(4): |
88 | 608 hand[players[i]] = deck[0:hand_size] |
609 del deck[0:hand_size] | |
92 | 610 chien.extend(deck) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
611 del (deck[:]) |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
612 msg_elts = {} |
88 | 613 for player in players: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
614 msg_elts[player] = self.__card_list_to_xml(hand[player], "hand") |
683
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
615 |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
616 RoomGame.newRound(self, room_jid, (common_data, msg_elts), profile) |
91 | 617 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
618 pl_idx = game_data["current_player"] = (game_data["init_player"] + 1) % len( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
619 players |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
620 ) # the player after the dealer start |
91 | 621 player = players[pl_idx] |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
622 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
|
623 self.send(to_jid, self.__ask_contrat(), profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
624 |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
625 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
|
626 """ |
75e4f5e2cc65
plugins radiocol, card_game, quiz: code factorization
souliane <souliane@mailoo.org>
parents:
682
diff
changeset
|
627 @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
|
628 """ |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
629 client = self.host.getClient(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
630 from_jid = jid.JID(mess_elt["from"]) |
93 | 631 room_jid = jid.JID(from_jid.userhost()) |
1970
200cd707a46d
plugin XEP-0045, quick_frontend + primitivus (chat): cleaning of XEP-0045 (first pass):
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
632 nick = self.host.plugins["XEP-0045"].getRoomNick(client, room_jid) |
826
71f8e996f765
plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents:
825
diff
changeset
|
633 |
90 | 634 game_elt = mess_elt.firstChildElement() |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
635 game_data = self.games[room_jid] |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
636 is_player = self.isPlayer(room_jid, nick) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
637 if "players_data" in game_data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
638 players_data = game_data["players_data"] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
639 |
92 | 640 for elt in game_elt.elements(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
641 if not is_player and (elt.name not in ("started", "players")): |
826
71f8e996f765
plugins radiocol_tarot: do not process received messages for MUC users that are actually not playing the game + fix for testing purpose
souliane <souliane@mailoo.org>
parents:
825
diff
changeset
|
642 continue # user is in the room but not playing |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
643 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 if elt.name in ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
645 "started", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
646 "players", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
647 ): # new game created and/or players list updated |
90 | 648 players = [] |
649 for player in elt.elements(): | |
3028 | 650 players.append(str(player)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 signal = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
652 self.host.bridge.tarotGameStarted |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
653 if elt.name == "started" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
654 else self.host.bridge.tarotGamePlayers |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
655 ) |
717
358018c5c398
plugins (games): more factorization and flexibility for launching and joining games:
souliane <souliane@mailoo.org>
parents:
714
diff
changeset
|
656 signal(room_jid.userhost(), from_jid.full(), players, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
657 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
658 elif elt.name == "player_ready": # ready to play |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
659 player = elt["player"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
660 status = self.games[room_jid]["status"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
661 nb_players = len(self.games[room_jid]["players"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
662 status[player] = "ready" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
663 log.debug( |
3028 | 664 _("Player %(player)s is ready to start [status: %(status)s]") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
665 % {"player": player, "status": status} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
666 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
667 if ( |
3028 | 668 list(status.values()).count("ready") == nb_players |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
669 ): # 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
|
670 self.newRound(room_jid, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
671 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
672 elif elt.name == "hand": # a new hand has been received |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
673 self.host.bridge.tarotGameNew( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
674 room_jid.userhost(), self.__xml_to_list(elt), profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
675 ) |
91 | 676 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
677 elif elt.name == "contrat": # it's time to choose contrat |
91 | 678 form = data_form.Form.fromElement(elt.firstChildElement()) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
679 session_id, session_data = self._sessions.newSession(profile=profile) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
680 session_data["room_jid"] = room_jid |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
681 xml_data = xml_tools.dataForm2XMLUI( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
682 form, self.__choose_contrat_id, session_id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
683 ).toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
684 self.host.bridge.tarotGameChooseContrat( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
685 room_jid.userhost(), xml_data, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
686 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
687 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
688 elif elt.name == "contrat_choosed": |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
689 # TODO: check we receive the contrat from the right person |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
690 # TODO: use proper XEP-0004 way for answering form |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
691 player = elt["player"] |
3028 | 692 players_data[player]["contrat"] = str(elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
693 contrats = [players_data[p]["contrat"] for p in game_data["players"]] |
91 | 694 if contrats.count(None): |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
695 # not everybody has choosed his contrat, it's next one turn |
91 | 696 player = self.__next_player(game_data) |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
697 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
|
698 self.send(to_jid, self.__ask_contrat(), profile=profile) |
91 | 699 else: |
700 best_contrat = [None, "Passe"] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
701 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
702 contrat = players_data[player]["contrat"] |
91 | 703 idx_best = self.contrats.index(best_contrat[1]) |
704 idx_pl = self.contrats.index(contrat) | |
705 if idx_pl > idx_best: | |
706 best_contrat[0] = player | |
707 best_contrat[1] = contrat | |
328 | 708 if best_contrat[1] == "Passe": |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
709 log.debug(_("Everybody is passing, round ended")) |
328 | 710 to_jid = jid.JID(room_jid.userhost()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
711 self.send( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
712 to_jid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
713 self.__give_scores(*self.__draw_game(game_data)), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
714 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
715 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
716 game_data["init_player"] = (game_data["init_player"] + 1) % len( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
717 game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
718 ) # we change the dealer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
719 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
720 game_data["status"][player] = "init" |
328 | 721 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
722 log.debug( |
3028 | 723 _("%(player)s win the bid with %(contrat)s") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
724 % {"player": best_contrat[0], "contrat": best_contrat[1]} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
725 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
726 game_data["contrat"] = best_contrat[1] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
727 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
728 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
729 game_data["contrat"] == "Garde Sans" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
730 or game_data["contrat"] == "Garde Contre" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
731 ): |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
732 self.__start_play(room_jid, game_data, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 game_data["attaquant"] = best_contrat[0] |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
734 else: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
735 # 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
|
736 to_jid = jid.JID(room_jid.userhost()) # FIXME: gof: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
737 elem = self.__card_list_to_xml(game_data["chien"], "chien") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
738 self.send( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
739 to_jid, elem, {"attaquant": best_contrat[0]}, profile=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
740 ) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
741 # the attacker (attaquant) get the chien |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
742 game_data["hand"][best_contrat[0]].extend(game_data["chien"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
743 del game_data["chien"][:] |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
744 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
745 if game_data["contrat"] == "Garde Sans": |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
746 # The chien go into attaquant's (attacker) levees |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
747 players_data[best_contrat[0]]["levees"].extend(game_data["chien"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
748 del game_data["chien"][:] |
91 | 749 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
750 elif elt.name == "chien": # we have received the chien |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
916
diff
changeset
|
751 log.debug(_("tarot: chien received")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
752 data = {"attaquant": elt["attaquant"]} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
753 game_data["stage"] = "ecart" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
754 game_data["attaquant"] = elt["attaquant"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
755 self.host.bridge.tarotGameShowCards( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
756 room_jid.userhost(), "chien", self.__xml_to_list(elt), data, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
757 ) |
92 | 758 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
759 elif elt.name == "cards_played": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
760 if game_data["stage"] == "ecart": |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
761 # TODO: show atouts (trumps) if player put some in écart |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
762 assert ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
763 game_data["attaquant"] == elt["player"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
764 ) # 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
|
765 list_cards = TarotCard.from_tuples(self.__xml_to_list(elt)) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
766 # we now check validity of card |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
767 invalid_cards = self.__invalid_cards(game_data, list_cards) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
768 if invalid_cards: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
769 elem = self.__invalid_cards_elt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
770 list_cards, invalid_cards, game_data["stage"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
771 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
772 self.send( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
773 jid.JID(room_jid.userhost() + "/" + elt["player"]), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
774 elem, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
775 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
776 ) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
777 return |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
778 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
779 # FIXME: gof: manage Garde Sans & Garde Contre cases |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
780 players_data[elt["player"]]["levees"].extend( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
781 list_cards |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
782 ) # we add the chien to attaquant's levées |
95 | 783 for card in list_cards: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
784 game_data["hand"][elt["player"]].remove(card) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
785 |
98
dd556233a1b1
Tarot Plugin: Garde Sans and Garde Contre are now managed
Goffi <goffi@goffi.org>
parents:
96
diff
changeset
|
786 self.__start_play(room_jid, game_data, profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
787 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
788 elif game_data["stage"] == "play": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
789 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
|
790 cards = TarotCard.from_tuples(self.__xml_to_list(elt)) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
791 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
792 if mess_elt["type"] == "groupchat": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
793 self.host.bridge.tarotGameCardsPlayed( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
794 room_jid.userhost(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
795 elt["player"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
796 self.__xml_to_list(elt), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
797 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
798 ) |
94 | 799 else: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
800 # we first check validity of card |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
801 invalid_cards = self.__invalid_cards(game_data, cards) |
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
802 if invalid_cards: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
803 elem = self.__invalid_cards_elt( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
804 cards, invalid_cards, game_data["stage"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
805 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
806 self.send( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
807 jid.JID(room_jid.userhost() + "/" + current_player), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
808 elem, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
809 profile=profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
810 ) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
811 return |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
812 # the card played is ok, we forward it to everybody |
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
813 # first we remove it from the hand and put in on the table |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
814 game_data["hand"][current_player].remove(cards[0]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
815 players_data[current_player]["played"] = cards[0] |
93 | 816 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
817 # 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
|
818 self.send(room_jid, elt, profile=profile) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
819 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
820 # Did everybody played ? |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
821 played = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
822 players_data[player]["played"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
823 for player in game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
824 ] |
95 | 825 if all(played): |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
826 # everybody has played |
94 | 827 winner = self.__winner(game_data) |
3028 | 828 log.debug(_("The winner of this trick is %s") % winner) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
829 # the winner win the trick |
94 | 830 self.__excuse_hack(game_data, played, winner) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
831 players_data[elt["player"]]["levees"].extend(played) |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
832 # nothing left on the table |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
833 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
834 players_data[player]["played"] = None |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
835 if len(game_data["hand"][current_player]) == 0: |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
836 # no card left: the game is finished |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
837 elem = self.__give_scores( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
838 *self.__calculate_scores(game_data) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
839 ) |
714
ecc5a5b34ee1
plugins (games): add a method to send messages more easily
souliane <souliane@mailoo.org>
parents:
712
diff
changeset
|
840 self.send(room_jid, elem, profile=profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
841 game_data["init_player"] = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
842 game_data["init_player"] + 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
843 ) % len( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
844 game_data["players"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
845 ) # we change the dealer |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
846 for player in game_data["players"]: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
847 game_data["status"][player] = "init" |
94 | 848 return |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
849 # next player is the winner |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
850 next_player = game_data["first_player"] = self.__next_player( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
851 game_data, winner |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
852 ) |
94 | 853 else: |
854 next_player = self.__next_player(game_data) | |
855 | |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
856 # 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
|
857 to_jid = jid.JID(room_jid.userhost() + "/" + next_player) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
858 self.send(to_jid, "your_turn", profile=profile) |
93 | 859 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
860 elif elt.name == "your_turn": |
92 | 861 self.host.bridge.tarotGameYourTurn(room_jid.userhost(), profile) |
91 | 862 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
863 elif elt.name == "score": |
3028 | 864 form_elt = next(elt.elements(name="x", uri="jabber:x:data")) |
95 | 865 winners = [] |
866 loosers = [] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
867 for winner in elt.elements(name="winner", uri=NS_CG): |
3028 | 868 winners.append(str(winner)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
869 for looser in elt.elements(name="looser", uri=NS_CG): |
3028 | 870 loosers.append(str(looser)) |
95 | 871 form = data_form.Form.fromElement(form_elt) |
878
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
872 session_id, session_data = self._sessions.newSession(profile=profile) |
36c6495d86b0
plugin card_game: update to use the new XMLUI mechanism:
souliane <souliane@mailoo.org>
parents:
828
diff
changeset
|
873 session_data["room_jid"] = room_jid |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
874 xml_data = xml_tools.dataForm2XMLUI( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
875 form, self.__score_id, session_id |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
876 ).toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
877 self.host.bridge.tarotGameScore( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
878 room_jid.userhost(), xml_data, winners, loosers, profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
879 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
880 elif elt.name == "error": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
881 if elt["type"] == "invalid_cards": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
882 played_cards = self.__xml_to_list( |
3028 | 883 next(elt.elements(name="played", uri=NS_CG)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
884 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
885 invalid_cards = self.__xml_to_list( |
3028 | 886 next(elt.elements(name="invalid", uri=NS_CG)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
887 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
888 self.host.bridge.tarotGameInvalidCards( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
889 room_jid.userhost(), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
890 elt["phase"], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
891 played_cards, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
892 invalid_cards, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
893 profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
894 ) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
895 else: |
3028 | 896 log.error(_("Unmanaged error type: %s") % elt["type"]) |
99
63c9067a1499
Tarot game: invalid cards management
Goffi <goffi@goffi.org>
parents:
98
diff
changeset
|
897 else: |
3028 | 898 log.error(_("Unmanaged card game element: %s") % elt.name) |
825
e3f4d80f987d
plugins room_games, radiocol: better synchronization after a user joins a running game
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
899 |
1359
83127a4c89ce
plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes
souliane <souliane@mailoo.org>
parents:
1257
diff
changeset
|
900 def getSyncDataForPlayer(self, room_jid, nick): |
828
8f335c03eebb
plugins room_games, radiocol, libervia: small changes like refactorization to ease the maintenance
souliane <souliane@mailoo.org>
parents:
826
diff
changeset
|
901 return [] |