Ejemplo n.º 1
0
def take_credit(pid: int, amount: int):
    if amount > 0:
        ps: PlayerState = db_connector.get_player_state_pid(pid)
        taken: int = ps.take_credit(amount)
        emit("taken_credit", taken)
    if db_connector.get_game_pid(pid).update_progress():
        emit('wait_build_request', room=db_connector.get_game_id(pid))
Ejemplo n.º 2
0
def get_player_state(nick: str):
    ps: PlayerState = db_connector.get_player_state_pid(
        db_connector.get_player(nick).id)
    return [
        ps.player_id, ps.esm, ps.egp, ps.fabrics_1, ps.fabrics_2, ps.game_id,
        ps.money, ps.rang
    ]
Ejemplo n.º 3
0
def next_turn(pid: int):
    ps: PlayerState = db_connector.get_player_state_pid(pid)
    ps.pay_taxes()
    game: Game = db_connector.get_game_pid(pid)
    if game.update_progress():
        define_bankrupts(db_connector.get_game_pid(pid))
        socket.emit('new_market_lvl', game.get_new_market_lvl(), room=game.id)
Ejemplo n.º 4
0
def build_request(pid: int, is_auto: bool, is_skip: bool):
    if not is_skip:
        ps: PlayerState = db_connector.get_player_state_pid(pid)
        ps.build_fabric(is_auto)
    if db_connector.get_game_pid(pid).update_progress():
        define_bankrupts(db_connector.get_game_pid(pid))
        emit('wait_upgrade_request', room=(db_connector.get_game_id(pid)))
Ejemplo n.º 5
0
def leave_game(pid: int, sid: int):
    game_instance: Game = db_connector.get_game_pid(pid)
    is_senior: bool = db_connector.get_player_state_pid(
        pid).rang == game_instance.turn_num % game_instance.max_players
    if is_senior:
        senior_leave(game_instance.id)
    leave_room(game_instance.id, sid)
    game_instance.player_leave(pid)
Ejemplo n.º 6
0
def get_player_info(pid: int):
    ps: PlayerState = db_connector.get_player_state_pid(pid)
    nicknames = []
    for ps in db_connector.get_player_state_gid(db_connector.get_game_id(pid)):
        nicknames.append(db_connector.get_player_pid(ps.player_id).nickname)
    return [
        ps.player_id, ps.esm, ps.egp, ps.fabrics_1, ps.fabrics_2, ps.game_id,
        ps.money, ps.rang, nicknames
    ]
Ejemplo n.º 7
0
def produce(pid: int, quantity: int, fabrics_1: int, fabrics_2: int):
    player_state = db_connector.get_player_state_pid(pid)
    result = player_state.get_egp(quantity, fabrics_1, fabrics_2)
    if isinstance(result, int) and result == 0:
        emit('production_error')
        return
    emit('produced', (result[0], result[1]))
    game: Game = db_connector.get_game_pid(pid)
    if game.update_progress():
        emit('wait_egp_request', room=game.id)
Ejemplo n.º 8
0
def egp_request(pid: int, price: int, qty: int):
    game: Game = db_connector.get_game_pid(pid)
    is_senior: bool = db_connector.get_player_state_pid(
        pid).rang == game.turn_num % game.max_players
    egp_orders.append(Order(game.id, pid, price, qty, is_senior))
    if game.update_progress():
        game_orders: list = []
        i: int = 0
        while i < len(egp_orders):
            order: Order = egp_orders[i]
            if order.game_id == game.id:
                print('game_id ' + str(order.game_id) + ' ' + str(game.id))
                game_orders.append(order)
                egp_orders.remove(order)
            else:
                i += 1
        send_egp_approved(game.start_egp_auction(game_orders), game.id)
        pay_bank_percent(game, game.id)
Ejemplo n.º 9
0
 def sort_egp_orders(self) -> list:
     game_orders: list = self.egp_orders.copy()
     game_orders.sort(key=self.sort_esm, reverse=False)
     tmp_index: int = 0
     for order in game_orders:
         ps: PlayerState = db_connector.get_player_state_pid(
             order.player_id)
         if ps.egp < order.quantity:
             order.quantity = 0
         if order.price > self.market[self.market_lvl - 1][4]:
             order.quantity = 0
         if order.is_senior:
             tmp_index = game_orders.index(order)
             break
     if tmp_index != 0 and game_orders[tmp_index].price == game_orders[
             tmp_index - 1].price:
         a = game_orders[tmp_index]
         game_orders[tmp_index] = game_orders[tmp_index - 1]
         game_orders[tmp_index - 1] = a
     return game_orders
Ejemplo n.º 10
0
 def sort_esm_orders(self) -> list:
     game_orders: list = self.esm_orders.copy()
     # game_orders.sort(key=lambda obj: obj[2])
     game_orders.sort(key=self.sort_esm, reverse=True)
     tmp_index: int = 0
     for order in game_orders:
         ps: PlayerState = db_connector.get_player_state_pid(
             order.player_id)
         if ps.money < order.quantity * order.price:
             order.quantity = 0
         if order.price < self.market[self.market_lvl - 1][2]:
             order.quantity = 0
         if order.is_senior:
             tmp_index = game_orders.index(order)
             break
     if tmp_index != 0 and game_orders[tmp_index].price == game_orders[
             tmp_index - 1].price:
         a = game_orders[tmp_index]
         game_orders[tmp_index] = game_orders[tmp_index - 1]
         game_orders[tmp_index - 1] = a
     return game_orders
Ejemplo n.º 11
0
def get_player_state(pid: int):
    ps: PlayerState = db_connector.get_player_state_pid(pid)
    return [
        ps.player_id, ps.esm, ps.egp, ps.fabrics_1, ps.fabrics_2, ps.game_id,
        ps.money, ps.rang
    ]
Ejemplo n.º 12
0
def upgrade_request(pid: int, do: bool):
    ps: PlayerState = db_connector.get_player_state_pid(pid)
    ps.upgrade_fabric(do)
    if db_connector.get_game_pid(pid).update_progress():
        define_bankrupts(db_connector.get_game_pid(pid))
        emit('wait_next_turn', room=db_connector.get_game_id(pid))
Ejemplo n.º 13
0
 def pay_credit(self, credit_id: int, amount: int):
     current_money = db_connector.get_player_state_pid(self.id).money
     db_connector.set_money(self.id, current_money - amount)
     db_connector.credit_payoff(credit_id)