Product selection message handler
This commit is contained in:
@ -5,11 +5,7 @@ from typing import Optional
|
||||
|
||||
from hopper.countdown_timer import CountdownTimer
|
||||
from hopper.enums import Direction, GameState, PlayerMoveResult, PlayerState
|
||||
from hopper.errors import (
|
||||
Collision,
|
||||
GameLockForMovement,
|
||||
PositionOutOfBounds,
|
||||
)
|
||||
from hopper.errors import Collision, GameLockForMovement, PositionOutOfBounds
|
||||
from hopper.models.board import (
|
||||
BOARD_DUMP_CHARS,
|
||||
BoardLayout,
|
||||
@ -179,24 +175,17 @@ class GameEngine:
|
||||
await self.ws_server.send_player_reached_destination_message(player=player)
|
||||
|
||||
logging.info(
|
||||
f"Starting purchase countdown timer for {settings.purchase_timeout} seconds"
|
||||
f"Starting product selection countdown timer for {settings.purchase_timeout} seconds"
|
||||
)
|
||||
|
||||
def on_purchase_timer_tick(time_left) -> None:
|
||||
logging.info(f"Purchase countdown timer tick, time left: {time_left}")
|
||||
asyncio.run(
|
||||
self.ws_server.send_product_purchase_time_left_message(
|
||||
player=player, time_left=time_left
|
||||
)
|
||||
)
|
||||
logging.info(f"Product selection countdown timer tick, time left: {time_left}")
|
||||
|
||||
def on_purchase_timer_done() -> None:
|
||||
logging.info("Ding ding! Purchase countdown timer timeout")
|
||||
logging.info("Ding ding! Product selection countdown timer timeout")
|
||||
self._purchase_countdown_timer = None
|
||||
asyncio.run(
|
||||
self.ws_server.send_product_purchase_done_message(
|
||||
player=player, product=None
|
||||
)
|
||||
self.ws_server.send_product_selection_done_message()
|
||||
)
|
||||
self.game_state = GameState.RUNNING
|
||||
asyncio.run(self.send_game_dump())
|
||||
@ -210,16 +199,12 @@ class GameEngine:
|
||||
|
||||
await asyncio.sleep(settings.game.PURCHASE_START_DELAY)
|
||||
|
||||
# async def purchase_product(self, player: Player, product: Product) -> None:
|
||||
# if not player.state == PlayerState.ON_DESTINATION:
|
||||
# raise PurchaseForbiddenForPlayer()
|
||||
# if self._purchase_countdown_timer:
|
||||
# self._purchase_countdown_timer.stop()
|
||||
# await self.ws_server.send_product_purchase_done_message(
|
||||
# player=player, product=product
|
||||
# )
|
||||
# await asyncio.sleep(settings.game.PURCHASE_FINISHED_DELAY)
|
||||
# await self.reset_game()
|
||||
async def product_selection_done(self) -> None:
|
||||
logging.info("Product selection done, unlocking game")
|
||||
if self._purchase_countdown_timer:
|
||||
self._purchase_countdown_timer.stop()
|
||||
await self.ws_server.send_product_selection_done_message()
|
||||
await self.reset_game()
|
||||
|
||||
def _reset_player(self, player) -> None:
|
||||
# move player to start position
|
||||
|
||||
Reference in New Issue
Block a user