def cubic(game_obj): a = GameData.get_data() if a.player.admin: return ( [a.player.get_id()], ErrorActAnswer("AdminCannotThrowCubic").get_ret_object(), ) if not a.player.turn or a.player.player_state != PlayerState.set_numcubic_state( ): return IGNORE() t = 0 a.player.cubic_thrown = True t = random.randint(1, 6) a.player.get_state().cube_point = t lp = a.player.cur_position_num a.player.cur_position_num += t if a.player.cur_position_num > GC.GAME_CONSTANTS[ "FIELD_LAST_NUM"] and lp < 17: a.player.cur_position_num = GC.GAME_CONSTANTS["FIELD_LAST_NUM"] + 1 a.player.player_state = PlayerState.set_moving_state() sec = Cubic.gen_sequence(random.randint(8, 15), t) DelayedSend.set_send( a.active_players_spct, Answer(a.player, GC.ACTION_LIST["cubic"], sec).get_ret_object(), ) return ( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_throw_num"], False, True).get_ret_object(), )
def anim_end(game_obj): a = GameData.get_data() if not a.player.turn: if not a.player.show_turn: a.player.show_turn = True return IGNORE() if a.player.clr_flag: a.player.resources = None a.player.can_take_resource = False a.player.clr_flag = False if a.player.clr_elvl_flag: a.player.rune = None a.player.open_elevel = False a.player.clr_elvl_flag = False if a.player.player_state == PlayerState.set_moving_state(): return ( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_move"], True, True).get_ret_object(), ) if a.player.player_state == PlayerState.set_numcubic_state(): DelayedSend.set_send( a.active_players_spct, Answer(a.player, GC.ACTION_LIST["clr_trgr_res"], True, True).get_ret_object(), ) return ( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_throw_num"], True, True).get_ret_object(), ) return IGNORE()
def my_turn(game_obj): a = GameData.get_data() if a.player.admin: return ( [a.player.get_id()], ErrorActAnswer("AdminCannotThrowCubic").get_ret_object(), ) t = a.player.get_turn() + 1 if a.player.show_turn: sec = Cubic.gen_sequence(0, t) DelayedSend.set_send( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["cubic"], sec, True).get_ret_object(), ) else: sec = Cubic.gen_sequence(random.randint(8, 15), t) DelayedSend.set_send( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["cubic"], sec, True).get_ret_object(), ) return ( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_throw_num"], False, True).get_ret_object(), )
def move(game_obj): x = game_obj.get("x") y = game_obj.get("y") if x is None or y is None: return IGNORE() try: x = float(x) y = float(y) except BaseException: return IGNORE() a = GameData.get_data() if not a.player.turn or a.player.player_state != PlayerState.set_moving_state( ): return [a.player.get_id()], Answer(a.player).get_ret_object() if x > 1 or x < 0 or y > 1 or y < 0: return [a.player.get_id() ], ErrorActAnswer("Wrong Values XY").get_ret_object() pos = a.player.get_state() if pos is None: return IGNORE() pos.set_x_y(x, y) post = a.player.cur_position_num if is_in_field_num(x + 0.036, y, post): a.player.player_state = PlayerState.set_thinking_state() if post == 18: a.player.penalty = GC.PENALTY_LIST["win"] elif post == 17: pass elif post == 0: a.player.penalty = GC.PENALTY_LIST["stop"] a.player.cubic_thrown = False a.player.rune = None a.player.open_elevel = False a.player.resources = None a.player.open_resource = False elif post == -2 or post == -10 or post == -13 or post == -16 or post == -6: rn = a.player.get_rune() a.player.rune = rn DelayedSend.set_send( a.active_players_spct, Answer(a.player, GC.ACTION_LIST["elvl"], rn).get_ret_object(), ) else: a.player.open_elevel = True DelayedSend.set_send( a.active_players_spct, Answer(a.player, GC.ACTION_LIST["elvl"], post).get_ret_object(), ) DelayedSend.set_send( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_move"], False, True).get_ret_object(), ) return a.active_players_spct, Answer(a.player).get_ret_object()
def ycubic(game_obj): a = GameData.get_data() if not a.player.turn: return IGNORE() if not a.player.player_state == PlayerState.set_yncubic_state(): return ([a.player.get_id()], ErrorActAnswer("CantThrowYCubic").get_ret_object()) a.player.yncubic_thrown = True DelayedSend.set_send( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_throw_yn"], False, True).get_ret_object(), ) t = random.randint(1, 6) a.player.get_state().yncube_point = t DelayedSend.set_send( a.active_players_spct, Answer( a.player, GC.ACTION_LIST["yncubic"], Cubic.gen_sequence(random.randint(12, 17), t), ).get_ret_object(), ) t = t % 2 a.player.clr_flag = True post = a.player.cur_position_num if t != 0: a.player.clr_elvl_flag = True if post == 2 or post == 10 or post == 13 or post == 16 or post == 6: if t == 0: a.player.clr_elvl_flag = False a.player.cur_position_num = -1 * a.player.cur_position_num a.player.player_state = PlayerState.set_moving_state() else: a.player.player_state = PlayerState.set_numcubic_state() elif post == -2 or post == -10 or post == -13 or post == -16 or post == -6: if t == 0: a.player.cur_position_num = 0 a.player.player_state = PlayerState.set_moving_state() else: a.player.cur_position_num = -1 * a.player.cur_position_num a.player.player_state = PlayerState.set_numcubic_state() else: if t == 0: a.player.player_state = PlayerState.set_thinking_state() else: if not post == 17: a.player.player_state = PlayerState.set_numcubic_state() else: a.player.player_state = PlayerState.set_moving_state() a.player.cur_position_num = 18 return IGNORE()
def reg(game_obj): name = game_obj.get("name") target = game_obj.get("target") if name is None or target is None: return IGNORE() a = GameData.get_data() if a.player.set_reg_data: return ( [a.player.get_id()], ErrorActAnswer("U had already set name").get_ret_object(), ) a.player.target = str(target) a.player.name = str(name) a.player.set_reg_data = True return a.active_players_spct, Answer(a.player).get_ret_object()
def session(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() game = SingletonGame.get_game() cli = game.stepping_cli() if cli is None or cli.player_state != PlayerState.set_thinking_state(): return ( [a.player.get_id()], ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(), ) if cli.points < 3: return ([a.player.get_id()], ErrorActAnswer("NotEnoughPoints").get_ret_object()) cli.points -= 3 return a.active_players_spct, Answer(cli).get_ret_object()
def allow_res(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() game = SingletonGame.get_game() cli = game.stepping_cli() if cli is None or cli.player_state != PlayerState.set_thinking_state(): return ( [a.player.get_id()], ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(), ) if cli.points < 1: return ([a.player.get_id()], ErrorActAnswer("NotEnoughPoints").get_ret_object()) cli.can_take_resource = True return ( [cli.get_id()], Answer(cli, GC.ACTION_LIST["can_take_resource"], True, True).get_ret_object(), )
def allow_yn(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() game = SingletonGame.get_game() cli = game.stepping_cli() if cli is None: return ( [a.player.get_id()], ErrorActAnswer("NoActiveCliOrGameNotStarted").get_ret_object(), ) if cli.penalty is not None: return [a.player.get_id() ], ErrorActAnswer("CliHavePenalty").get_ret_object() if cli.player_state != PlayerState.set_thinking_state(): return [a.player.get_id() ], ErrorActAnswer("PlayerStillMoving").get_ret_object() cli.player_state = PlayerState.set_yncubic_state() return ( [cli.get_id()], Answer(cli, GC.ACTION_LIST["can_throw_yn"], True, True).get_ret_object(), )
def next_step(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() game = SingletonGame.get_game() if game.game_state == GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"]: return [a.player.get_id() ], ErrorActAnswer("GameNotStarted").get_ret_object() ns = game.next_step() if not ns: return [a.player.get_id() ], ErrorActAnswer("NoPlayers").get_ret_object() cli = game.stepping_cli() cli.cubic_thrown = False cli.yncubic_thrown = False cl_data = CliRetPosAnswer(cli) for cr in cl_data.get_my_ret_obj(): DelayedSend.set_send([cli.get_id()], cr) for cr in cl_data.get_pub_ret_obj(): DelayedSend.set_send(a.active_players_spct, cr) return a.active_players_spct, Answer( cli, GC.ACTION_LIST["step"]).get_ret_object()
def get_resource(game_obj): a = GameData.get_data() if not a.player.turn: return IGNORE() if (a.player.points <= 0 or a.player.open_resource or a.player.player_state != PlayerState.set_thinking_state() or not a.player.can_take_resource): return [a.player.get_id() ], ErrorActAnswer("YouHaveNoPoints").get_ret_object() DelayedSend.set_send( [a.player.get_id()], Answer(a.player, GC.ACTION_LIST["can_take_resource"], False, True).get_ret_object(), ) a.player.points -= 1 a.player.open_resource = True a.player.can_take_resource = False rs = a.player.get_resource() a.player.resources = rs return ( a.active_players_spct, Answer(a.player, GC.ACTION_LIST["resource"], rs).get_ret_object(), )
def game_start(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() game = SingletonGame.get_game() if game.game_state != GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"]: return [a.player.get_id() ], ErrorActAnswer("GameStarted").get_ret_object() clients = game.get_all_ids() game.game_state = GC.GAME_CONSTANTS["GAME_START"] game.start_game() ns = game.next_step() if not ns: game.game_state = GC.GAME_CONSTANTS["GAME_STATE_W8_CLIENTS"] return [a.player.get_id() ], ErrorActAnswer("NoPlayers").get_ret_object() cli = game.stepping_cli() DelayedSend.set_send( a.active_players_spct, Answer( cli, GC.ACTION_LIST["card_data"], print_step_set(game, "ИГРА НАЧАЛАСЬ! Порядок ходов:\n"), lowpack=True, ).get_ret_object(), ) for c in clients: r = game.get_player(c) r.show_turn = True DelayedSend.set_send([r.get_id()], Answer(r, GC.ACTION_LIST["get_info"], True).get_ret_object()) return [a.player.get_id()], ErrorActAnswer("GameSTARTED").get_ret_object()
def bun_unban(game_obj): a = GameData.get_data() if not a.player.admin: return IGNORE() fnm = game_obj.get("fnm", None) if fnm is None: return IGNORE() game = SingletonGame.get_game() cli = game.get_player_fnum(fnm) if cli is None: return IGNORE() if cli.penalty is None: cli.penalty = GC.PENALTY_LIST["stop"] elif cli.penalty == GC.PENALTY_LIST["win"]: return IGNORE() else: cli.penalty = None if cli.penalty is None: return ( game.get_spectrators_and_ids(), Answer(cli, GC.ACTION_LIST["rem_pen"]).get_ret_object(), ) else: return (game.get_spectrators_and_ids(), Answer(cli).get_ret_object())
def n_func(uid, game_obj): GameData.set_new_data(uid) if not GameData.exist(): return WorkerParser.KICK_PLAYER(uid) return f(game_obj)