Beispiel #1
0
    def on_boost_press(self) -> None:
        """Boost was pressed."""
        from bastd.ui import account
        from bastd.ui import getcurrency
        if _ba.get_account_state() != 'signed_in':
            account.show_sign_in_prompt()
            return

        if _ba.get_account_ticket_count() < self._boost_tickets:
            ba.playsound(ba.getsound('error'))
            getcurrency.show_get_tickets_prompt()
            return

        ba.playsound(ba.getsound('laserReverse'))
        _ba.add_transaction(
            {
                'type': 'PARTY_QUEUE_BOOST',
                't': self._boost_tickets,
                'q': self._queue_id
            },
            callback=ba.WeakCall(self.on_update_response))
        # lets not run these immediately (since they may be rapid-fire,
        # just bucket them until the next tick)

        # the transaction handles the local ticket change, but we apply our
        # local boost vis manually here..
        # (our visualization isn't really wired up to be transaction-based)
        our_dude = self._dudes_by_id.get(-1)
        if our_dude is not None:
            our_dude.boost(self._boost_strength, self._smoothing)
Beispiel #2
0
    def _on_continue_press(self) -> None:
        from bastd.ui import getcurrency

        # Disallow for first second.
        if self._start_count - self._count < 2:
            ba.playsound(ba.getsound('error'))
        else:
            # If somehow we got signed out...
            if _ba.get_account_state() != 'signed_in':
                ba.screenmessage(ba.Lstr(resource='notSignedInText'),
                                 color=(1, 0, 0))
                ba.playsound(ba.getsound('error'))
                return

            # If it appears we don't have enough tickets, offer to buy more.
            tickets = _ba.get_account_ticket_count()
            if tickets < self._cost:
                # FIXME: Should we start the timer back up again after?
                self._counting_down = False
                ba.textwidget(edit=self._counter_text, text='')
                ba.playsound(ba.getsound('error'))
                getcurrency.show_get_tickets_prompt()
                return
            if not self._transitioning_out:
                ba.playsound(ba.getsound('swish'))
                self._transitioning_out = True
                ba.containerwidget(edit=self._root_widget,
                                   transition='out_scale')
                self._continue_call()
    def _start_stop_button_press(self) -> None:
        if (self._waiting_for_start_stop_response
                or self._waiting_for_initial_state):
            return

        if _ba.get_account_state() != 'signed_in':
            ba.screenmessage(ba.Lstr(resource='notSignedInErrorText'))
            ba.playsound(ba.getsound('error'))
            self._refresh_sub_tab()
            return

        if self._hostingstate.unavailable_error is not None:
            ba.playsound(ba.getsound('error'))
            return

        ba.playsound(ba.getsound('click01'))

        # If we're not hosting, start.
        if self._hostingstate.party_code is None:

            # If there's a ticket cost, make sure we have enough tickets.
            if self._hostingstate.tickets_to_host_now > 0:
                ticket_count: Optional[int]
                try:
                    ticket_count = _ba.get_account_ticket_count()
                except Exception:
                    # FIXME: should add a ba.NotSignedInError we can use here.
                    ticket_count = None
                ticket_cost = self._hostingstate.tickets_to_host_now
                if ticket_count is not None and ticket_count < ticket_cost:
                    getcurrency.show_get_tickets_prompt()
                    ba.playsound(ba.getsound('error'))
                    return
            self._last_action_send_time = time.time()
            _ba.add_transaction(
                {
                    'type': 'PRIVATE_PARTY_START',
                    'config': dataclass_to_dict(self._hostingconfig),
                    'region_pings': ba.app.net.region_pings,
                    'expire_time': time.time() + 20,
                },
                callback=ba.WeakCall(self._hosting_state_response))
            _ba.run_transactions()

        else:
            self._last_action_send_time = time.time()
            _ba.add_transaction(
                {
                    'type': 'PRIVATE_PARTY_STOP',
                    'expire_time': time.time() + 20,
                },
                callback=ba.WeakCall(self._hosting_state_response))
            _ba.run_transactions()
        ba.playsound(ba.getsound('click01'))

        self._waiting_for_start_stop_response = True
        self._refresh_sub_tab()
Beispiel #4
0
    def buy(self, item: str) -> None:
        """Attempt to purchase the provided item."""
        from ba.internal import (get_available_sale_time,
                                 get_store_item_name_translated)
        from bastd.ui import account
        from bastd.ui.confirm import ConfirmWindow
        from bastd.ui import getcurrency

        # Prevent pressing buy within a few seconds of the last press
        # (gives the buttons time to disable themselves and whatnot).
        curtime = ba.time(ba.TimeType.REAL)
        if self._last_buy_time is not None and (curtime -
                                                self._last_buy_time) < 2.0:
            ba.playsound(ba.getsound('error'))
        else:
            if _ba.get_account_state() != 'signed_in':
                account.show_sign_in_prompt()
            else:
                self._last_buy_time = curtime

                # Pro is an actual IAP; the rest are ticket purchases.
                if item == 'pro':
                    ba.playsound(ba.getsound('click01'))

                    # Purchase either pro or pro_sale depending on whether
                    # there is a sale going on.
                    self._do_purchase_check('pro' if get_available_sale_time(
                        'extras') is None else 'pro_sale')
                else:
                    price = _ba.get_account_misc_read_val(
                        'price.' + item, None)
                    our_tickets = _ba.get_account_ticket_count()
                    if price is not None and our_tickets < price:
                        ba.playsound(ba.getsound('error'))
                        getcurrency.show_get_tickets_prompt()
                    else:

                        def do_it() -> None:
                            self._do_purchase_check(item,
                                                    is_ticket_purchase=True)

                        ba.playsound(ba.getsound('swish'))
                        ConfirmWindow(
                            ba.Lstr(resource='store.purchaseConfirmText',
                                    subs=[
                                        ('${ITEM}',
                                         get_store_item_name_translated(item))
                                    ]),
                            width=400,
                            height=120,
                            action=do_it,
                            ok_text=ba.Lstr(resource='store.purchaseText',
                                            fallback_resource='okText'))
    def _on_pay_with_tickets_press(self) -> None:
        from bastd.ui import getcurrency

        # If we're already entering, ignore.
        if self._entering:
            return

        if not self._have_valid_data:
            ba.screenmessage(ba.Lstr(resource='tournamentCheckingStateText'),
                             color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        # If we don't have a price.
        if self._purchase_price is None:
            ba.screenmessage(ba.Lstr(resource='tournamentCheckingStateText'),
                             color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        # Deny if it looks like the tourney has ended.
        if self._seconds_remaining == 0:
            ba.screenmessage(ba.Lstr(resource='tournamentEndedText'),
                             color=(1, 0, 0))
            ba.playsound(ba.getsound('error'))
            return

        # Deny if we don't have enough tickets.
        ticket_count: Optional[int]
        try:
            ticket_count = _ba.get_account_ticket_count()
        except Exception:
            # FIXME: should add a ba.NotSignedInError we can use here.
            ticket_count = None
        ticket_cost = self._purchase_price
        if ticket_count is not None and ticket_count < ticket_cost:
            getcurrency.show_get_tickets_prompt()
            ba.playsound(ba.getsound('error'))
            return

        cur_time = ba.time(ba.TimeType.REAL, ba.TimeFormat.MILLISECONDS)
        self._last_ticket_press_time = cur_time
        assert isinstance(ticket_cost, int)
        _ba.in_game_purchase(self._purchase_name, ticket_cost)

        self._entering = True
        _ba.add_transaction({
            'type': 'ENTER_TOURNAMENT',
            'fee': self._fee,
            'tournamentID': self._tournament_id
        })
        _ba.run_transactions()
        self._launch()
    def _purchase(self) -> None:
        from bastd.ui import getcurrency
        if self._items == ['pro']:
            _ba.purchase('pro')
        else:
            ticket_count: Optional[int]
            try:
                ticket_count = _ba.get_account_ticket_count()
            except Exception:
                ticket_count = None
            if ticket_count is not None and ticket_count < self._price:
                getcurrency.show_get_tickets_prompt()
                ba.playsound(ba.getsound('error'))
                return

            def do_it() -> None:
                _ba.in_game_purchase(self._items[0], self._price)

            ba.playsound(ba.getsound('swish'))
            do_it()
Beispiel #7
0
    def _purchase(self) -> None:
        from ba.internal import get_store_item_name_translated
        from bastd.ui import getcurrency
        from bastd.ui import confirm
        if self._offer['item'] == 'pro':
            _ba.purchase('pro_sale')
        elif self._offer['item'] == 'pro_fullprice':
            _ba.purchase('pro')
        elif self._is_bundle_sale:
            # With bundle sales, the price is the name of the IAP.
            _ba.purchase(self._offer['price'])
        else:
            ticket_count: Optional[int]
            try:
                ticket_count = _ba.get_account_ticket_count()
            except Exception:
                ticket_count = None
            if (ticket_count is not None
                    and ticket_count < self._offer['price']):
                getcurrency.show_get_tickets_prompt()
                ba.playsound(ba.getsound('error'))
                return

            def do_it() -> None:
                _ba.in_game_purchase('offer:' + str(self._offer['id']),
                                     self._offer['price'])

            ba.playsound(ba.getsound('swish'))
            confirm.ConfirmWindow(ba.Lstr(
                resource='store.purchaseConfirmText',
                subs=[('${ITEM}',
                       get_store_item_name_translated(self._offer['item']))]),
                                  width=400,
                                  height=120,
                                  action=do_it,
                                  ok_text=ba.Lstr(
                                      resource='store.purchaseText',
                                      fallback_resource='okText'))
Beispiel #8
0
    def _on_upgrade_press(self) -> None:
        from bastd.ui import getcurrency
        if self._status is None:
            # If it appears we don't have enough tickets, offer to buy more.
            tickets = _ba.get_account_ticket_count()
            if tickets < self._cost:
                ba.playsound(ba.getsound('error'))
                getcurrency.show_get_tickets_prompt()
                return
            ba.screenmessage(ba.Lstr(resource='purchasingText'),
                             color=(0, 1, 0))
            self._status = 'pre_upgrading'

            # Now we tell the original editor to save the profile, add an
            # upgrade transaction, and then sit and wait for everything to
            # go through.
            edit_profile_window = self._edit_profile_window()
            if edit_profile_window is None:
                print('profile upgrade: original edit window gone')
                return
            success = edit_profile_window.save(transition_out=False)
            if not success:
                print('profile upgrade: error occurred saving profile')
                ba.screenmessage(ba.Lstr(resource='errorText'),
                                 color=(1, 0, 0))
                ba.playsound(ba.getsound('error'))
                return
            _ba.add_transaction({
                'type': 'UPGRADE_PROFILE',
                'name': self._name
            })
            _ba.run_transactions()
            self._status = 'upgrading'
            self._upgrade_start_time = time.time()
        else:
            ba.playsound(ba.getsound('error'))