Beispiel #1
0
    def complete_battle(self, battle: BattleLogic, bypass=False):
        if not bypass:
            self.assert_running()
        self.set_dirty()
        btl_model = battle.model
        if not bypass and btl_model.offensiveCard is None:
            raise UserError("Нельзя завершить битву без карты атаки!")
        if not bypass:
            self.calculate_battle_falsics(battle)
        btl_model.isComplete = True
        if self.cur_round.isAccidentComplete:
            next_player = self.get_neighbour(
                PlayerLogic(self.db, btl_model.offendingPlayer))
            if next_player != self.get_players(True)[0].model:
                self.start_battle(PlayerLogic(self.db, next_player))

        if all(map(lambda b: b.model.isComplete, self.get_battles())):
            if btl_model.offensiveCard is not None and btl_model.offensiveCard.type.enumType == CardTypeEnum.ACCIDENT:
                print("Round", self.cur_round.roundNo,
                      "has accident completed")
                self.on_accident_played()
            else:
                print("Round", self.cur_round.roundNo, "is complete")
                self.on_round_completed()
                if not self.is_complete():
                    self.new_round()
Beispiel #2
0
 def calculate_battle_falsics(self, battle: BattleLogic):
     btl_model = battle.model
     if btl_model.offensiveCard.isCovid:
         transfer_amount = btl_model.defendingPlayer.money // 2
         PlayerLogic(
             self.db,
             self.get_neighbour(
                 PlayerLogic(self.db,
                             btl_model.defendingPlayer))).change_money(
                                 transfer_amount)
         PlayerLogic(
             self.db,
             btl_model.defendingPlayer).change_money(-transfer_amount)
     else:
         PlayerLogic(self.db, btl_model.defendingPlayer).change_money(
             -battle.get_curdamage())
Beispiel #3
0
 def get_players(self, only_live):
     all_players = [
         PlayerLogic(self.db, x, self) for x in self.model.players
     ]
     if only_live:
         return [p for p in all_players if p.is_alive()]
     else:
         return all_players
Beispiel #4
0
 def create_player(self, name: str, game: 'GameLogic') -> PlayerLogic:
     player = Player(name=name, game=game.model, money=0, isAdmin=False, isOnline=False)
     self.db.session.add(player)
     try:
         self.db.session.commit()
     except IntegrityError as e:
         print("Player creation problem: " + str(e))
         self.db.session.rollback()
         raise UserError("Игрок с таким именем уже существует. Пожалуйста, измените имя.",
                         UserError.ErrorType.INVALID_NAME)
     return PlayerLogic(self.db, player)
Beispiel #5
0
 def start_battle(self, offendingPlayer: PlayerLogic):
     self.assert_running()
     new_battle_no = 0
     if any(self.cur_round.battles):
         new_battle_no = max(
             map(lambda x: x.creationOrder, self.cur_round.battles)) + 1
     new_battle = RoundBattle(
         round=self.cur_round,
         offendingPlayer=None
         if offendingPlayer is None else offendingPlayer.model,
         isComplete=False,
         creationOrder=new_battle_no)
     self.db.session.add(new_battle)
     self.set_dirty()
     if not self.params.can_attack_anyone:
         self.attack(
             offendingPlayer,
             PlayerLogic(self.db,
                         self.get_neighbour(offendingPlayer),
                         game=self))
     return new_battle
Beispiel #6
0
 def get_player(self, id: int) -> PlayerLogic:
     player = Player.query.filter_by(id=id).first()
     if player is None:
         return None
     return PlayerLogic(self.db, player)