Example #1
0
    def process(self):

        self.setFromPage(None)

        v_player = self.getViewerPlayer()
        battleplayer = self.getBattlePlayer()
        if battleplayer is None or not battleplayer.lpvtime or OSAUtil.get_now(
        ) <= battleplayer.lpvtime:
            self.appRedirect(self.makeAppLinkUrlRedirect(UrlMaker.battlelp()))
            return

        # 現在のランク.
        rankmaster = self.getBattleRankMaster()

        # プレイヤー.
        self.html_param['player'] = Objects.player(self, v_player)

        # バトル情報.
        self.html_param['battleplayer'] = Objects.battleplayer(
            self, battleplayer, rankmaster)

        # 対戦相手検索のUrl.
        self.html_param['url_battlepre'] = self.makeAppLinkUrl(
            UrlMaker.battlepre())

        # 気力回復のUrl.
        self.html_param['url_bprecover'] = self.makeAppLinkUrl(
            UrlMaker.bprecover())

        # 最大ランク.
        model_mgr = self.getModelMgr()
        self.html_param['max_rank'] = BackendApi.get_battlerank_max(
            model_mgr, using=settings.DB_READONLY)

        # 鍵情報.
        self.html_param['treasurekey'] = Objects.key(self, v_player)

        # イベント開催中判定.
        cur_eventmaster = BackendApi.get_current_battleevent_master(
            model_mgr, using=settings.DB_READONLY)
        self.html_param['battleevent'] = Objects.battleevent(
            self, cur_eventmaster) if cur_eventmaster else None
        self.html_param['url_battleevent_top'] = self.makeAppLinkUrl(
            UrlMaker.battleevent_top())

        # 書き込み.
        self.writeAppHtml('battle/battle')
Example #2
0
 def __makeBackLinkUrlBattlePre(self, args):
     return {
         'url': self.makeAppLinkUrl(UrlMaker.battlepre(),
                                    add_frompage=False),
         'text': u'キャバ王への道へ戻る'
     }
Example #3
0
    def process(self):

        try:
            args = self.getUrlArgs('/battledo/')
            battleid = int(args.get(0, 0))
        except:
            if settings_sub.IS_LOCAL:
                raise CabaretError(u'引数が正しくありません',
                                   CabaretError.Code.ILLEGAL_ARGS)
            url = UrlMaker.battle()
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return

        # バトル情報.
        battleplayer = self.getBattlePlayer(using=settings.DB_DEFAULT)
        if battleplayer is None:
            if settings_sub.IS_LOCAL:
                raise CabaretError(u'対戦相手が見つかりませんでした',
                                   CabaretError.Code.NOT_DATA)
            self.redirectToOppSelect()
            return
        elif battleplayer.result and battleid != battleplayer.result:
            url = self.makeAppLinkUrlRedirect(UrlMaker.battleanim())
            self.appRedirect(url)
            return

        model_mgr = self.getModelMgr()
        v_player = self.getViewerPlayer()

        # 対戦相手.
        oid = battleplayer.opponent
        o_player = None
        if oid and v_player.id != oid:
            arr = BackendApi.get_players(self, [oid], [PlayerExp],
                                         using=settings.DB_READONLY)
            if arr:
                o_player = arr[0]
        if o_player is None:
            if settings_sub.IS_LOCAL:
                raise CabaretError(u'対戦相手が見つかりませんでした',
                                   CabaretError.Code.NOT_DATA)
            self.redirectToOppSelect()
            return

        if battleid == battleplayer.result:
            # お互いのカード.
            v_deck = BackendApi.get_deck(v_player.id,
                                         model_mgr,
                                         using=settings.DB_READONLY)
            o_deck = BackendApi.get_deck(o_player.id,
                                         model_mgr,
                                         using=settings.DB_READONLY)
            v_deck_cardlist = BackendApi.get_cards(v_deck.to_array(),
                                                   model_mgr,
                                                   using=settings.DB_READONLY)
            o_deck_cardlist = BackendApi.get_cards(o_deck.to_array(),
                                                   model_mgr,
                                                   using=settings.DB_READONLY)

            # 計算.
            rand = AppRandom()
            data = BackendApi.battle(v_player, v_deck_cardlist, o_player,
                                     o_deck_cardlist, rand)

            v_deck_cardidlist = v_deck.to_array()
            o_deck_cardidlist = o_deck.to_array()
            try:
                model_mgr, _ = db_util.run_in_transaction(
                    self.tr_write, v_player.id, oid, v_deck_cardidlist,
                    o_deck_cardidlist, data, battleid)
                model_mgr.write_end()
            except CabaretError, err:
                if err.code == CabaretError.Code.ALREADY_RECEIVED:
                    pass
                elif settings_sub.IS_LOCAL:
                    raise err
                else:
                    url = self.makeAppLinkUrlRedirect(UrlMaker.battlepre())
                    self.appRedirect(url)
                    return
Example #4
0
    def process(self):
        def allEnd(url, err=None):
            if err and settings_sub.IS_LOCAL:
                raise err
            else:
                self.appRedirect(self.makeAppLinkUrlRedirect(url))

        try:
            args = self.getUrlArgs('/battleoppselect/')
            postcnt = int(args.get(0))
        except:
            allEnd(
                UrlMaker.battle(),
                CabaretError(u'引数が正しくありません', CabaretError.Code.ILLEGAL_ARGS))
            return

        battleplayer = self.getBattlePlayer(get_instance=False)

        pre_o_player = None
        if battleplayer and battleplayer.opponent:
            arr = BackendApi.get_players(self, [battleplayer.opponent], [],
                                         using=settings.DB_READONLY)
            if arr:
                pre_o_player = arr[0]

        if pre_o_player is None:
            postcnt = 0
            do_remove_count = False
            opplist = []
        else:
            if postcnt == battleplayer.change_cnt:
                # 書き込み済み.
                allEnd(
                    UrlMaker.battlepre(),
                    CabaretError(u'設定済みです',
                                 CabaretError.Code.ALREADY_RECEIVED))
                return
            elif postcnt != (battleplayer.change_cnt + 1):
                # 想定外.
                allEnd(
                    UrlMaker.battle(),
                    CabaretError(u'引数が正しくありません',
                                 CabaretError.Code.ILLEGAL_ARGS))
                return
            opplist = battleplayer.rankopplist[:]
            do_remove_count = True

        model_mgr = self.getModelMgr()
        v_player = self.getViewerPlayer()

        excludes = [v_player.id]
        excludes.extend(opplist)
        excludes.extend(
            BackendApi.get_friend_idlist(v_player.id,
                                         arg_model_mgr=model_mgr,
                                         using=settings.DB_READONLY))

        arr = BackendApi.get_battleopponents_by_levelband(v_player.level,
                                                          num=1,
                                                          excludes=excludes)
        oid = None
        if arr:
            oid = arr[0]
        else:
            if battleplayer:
                while battleplayer.opponent in opplist:
                    opplist.remove(battleplayer.opponent)
            # 見つからなかったので戦ったことのある人を設定しておこう..
            if opplist:
                oid = random.choice(opplist)
        if oid is None:
            # ここは...
            raise CabaretError(u'対戦相手が見つかりませんでした', CabaretError.Code.NOT_DATA)

        try:
            model_mgr = db_util.run_in_transaction(Handler.tr_write,
                                                   v_player.id, oid, postcnt,
                                                   do_remove_count)
            model_mgr.write_end()
        except Exception, err:
            allEnd(UrlMaker.battle(), err)
            return