コード例 #1
0
 def makeCardObject(self, cardset, deck):
     data = Objects.card(self, cardset, deck=deck)
     url = UrlMaker.deckset(target=self.__target)
     url = OSAUtil.addQuery(url, Defines.URLQUERY_INDEX,
                            self.__selected_index)
     url = OSAUtil.addQuery(url, Defines.URLQUERY_CARD, cardset.id)
     data['url_deck'] = self.makeAppLinkUrl(url)
     return data
コード例 #2
0
    def process(self):

        args = self.getUrlArgs('/deckmember/')
        target = args.get(0)

        self.__cardlist = None

        self.loadSortParams()
        try:
            idx = int(self.request.get(Defines.URLQUERY_INDEX, None))
        except:
            raise CabaretError(u'引数が想定外です', CabaretError.Code.ILLEGAL_ARGS)
        self.__selected_index = idx

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

        deck = None
        if target == 'raid':
            # レイド.
            deck = BackendApi.get_raid_deck(uid,
                                            model_mgr,
                                            using=settings.DB_READONLY)
        else:
            target = 'normal'
            deck = BackendApi.get_deck(uid,
                                       model_mgr,
                                       using=settings.DB_READONLY)
        self.__target = target
        self.__deck = deck

        deck_idlist = deck.to_array()
        deck_cardlist = BackendApi.get_cards(deck_idlist,
                                             model_mgr,
                                             using=settings.DB_READONLY)
        idx = min(max(0, idx), len(deck_cardlist))

        if idx < len(deck_cardlist):
            # 設定中のカード.
            current_card = Objects.card(self, deck_cardlist[idx], deck=deck)
            url = None
            if 0 < idx:
                url = OSAUtil.addQuery(UrlMaker.deckset(target=target),
                                       Defines.URLQUERY_CARD,
                                       deck_cardlist[idx].id)
                url = OSAUtil.addQuery(url, Defines.URLQUERY_INDEX, -1)
                url = self.makeAppLinkUrl(url)
            current_card['url_remove'] = url
            self.html_param['current_card'] = current_card

        cost = 0
        for i in xrange(len(deck_cardlist)):
            if i == idx:
                continue
            cost += deck_cardlist[i].master.cost
        rest = v_player.deckcapacity - cost
        self.__cost_max = rest

        self.putCardList()

        # 店舗に配属されているキャスト.
        store_castidlist = BackendApi.get_cabaretclub_active_cast_list(
            model_mgr, uid, OSAUtil.get_now(), using=settings.DB_READONLY)
        self.html_param['store_castidlist'] = store_castidlist

        self.html_param['deck_edit_target'] = target

        self.writeBoxHtml('deck/member')
コード例 #3
0
ファイル: deck.py プロジェクト: hitandaway100/caba
    def process(self):

        args = self.getUrlArgs('/deck/')
        target = args.get(0)

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

        # デッキ.
        deck = None
        if target == 'raid':
            self.setFromPage(Defines.FromPages.DECK_RAID, [])
            deck = BackendApi.get_raid_deck(uid,
                                            model_mgr,
                                            using=settings.DB_READONLY)
            if isinstance(deck, Deck):
                # 通常のデッキをレイドデッキに移す.
                def tr(cardidlist):
                    model_mgr = ModelRequestMgr()
                    BackendApi.set_raid_deck(v_player, cardidlist, model_mgr)
                    model_mgr.write_all()
                    return model_mgr

                db_util.run_in_transaction(tr, deck.to_array()).write_end()

        if deck is None:
            target = 'normal'
            self.setFromPage(Defines.FromPages.DECK_NORMAL, [])
            deck = BackendApi.get_deck(uid,
                                       model_mgr,
                                       using=settings.DB_READONLY)

        cardidlist = deck.to_array()

        # メンバーに加えるカードを先に選択するフローがあるので引数にカードのIDが来ることがある.
        arg_card_id = self.request.get(Defines.URLQUERY_CARD, None)
        selected_card = None
        selected_card_cost = 0
        if arg_card_id:
            try:
                arg_card_id = int(arg_card_id)
                if arg_card_id in cardidlist:
                    # デッキに設定済み.
                    arg_card_id = None
                else:
                    cardset = BackendApi.get_cards(
                        [arg_card_id], model_mgr,
                        using=settings.DB_READONLY)[0]
                    if cardset.card.uid != v_player.id:
                        arg_card_id = None
                    else:
                        self.html_param['selected_card'] = Objects.card(
                            self, cardset)
                        selected_card = cardset
                        selected_card_cost = selected_card.master.cost
            except:
                if settings_sub.IS_LOCAL:
                    raise

        # カードを取得.
        cardlist = BackendApi.get_cards(cardidlist,
                                        model_mgr,
                                        using=settings.DB_READONLY)

        url = UrlMaker.deckset(auto=True, target=target)
        self.html_param['url_auto'] = self.makeAppLinkUrl(url)
        if len(cardlist) == 0:
            # どうしようか..自動選択に飛ばしておくか..
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return

        if selected_card:
            urlbase = OSAUtil.addQuery(UrlMaker.deckset(target=target),
                                       Defines.URLQUERY_CARD, selected_card.id)
        else:
            urlbase = UrlMaker.deckmember(target=target)

        url_removebase = UrlMaker.deckset(target=target)
        if selected_card:
            url_removebase = OSAUtil.addQuery(url_removebase,
                                              Defines.URLQUERY_CURRENT,
                                              selected_card.id)

        obj_cardlist = []
        cost = 0
        power_total = 0
        for cardset in cardlist:
            obj = Objects.card(self, cardset, deck=deck)
            url = OSAUtil.addQuery(urlbase, Defines.URLQUERY_INDEX,
                                   len(obj_cardlist))
            obj['url_deck'] = self.makeAppLinkUrl(url)

            url = OSAUtil.addQuery(url_removebase, Defines.URLQUERY_CARD,
                                   cardset.id)
            url = OSAUtil.addQuery(url, Defines.URLQUERY_INDEX, -1)
            obj['url_remove'] = self.makeAppLinkUrl(url)

            obj_cardlist.append(obj)

            cost += cardset.master.cost
            power_total += cardset.power

        if selected_card_cost:
            for obj_card in obj_cardlist:
                tmp = cost - obj_card['master']['cost'] + selected_card_cost
                if v_player.deckcapacity < tmp:
                    # コストオーバー.
                    obj_card['cost_over'] = True

        if len(cardlist) < Defines.DECK_CARD_NUM_MAX and (
                cost + selected_card_cost) < v_player.deckcapacity:
            url = OSAUtil.addQuery(urlbase, Defines.URLQUERY_INDEX,
                                   len(obj_cardlist))
            self.html_param['url_addmember'] = self.makeAppLinkUrl(url)

        self.html_param['leader'] = obj_cardlist[0]
        self.html_param['memberlist'] = obj_cardlist[1:]

        self.html_param['cost'] = cost
        self.html_param['capacity'] = v_player.deckcapacity
        self.html_param['power_total'] = power_total

        self.html_param['deck_edit_target'] = target

        self.putFromBackPageLinkUrl()

        if self.is_pc:
            self.html_param['change_leader'] = obj_cardlist[0]

        self.writeAppHtml('deck/deck')