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_check_result(self, item: str, is_ticket_purchase: bool, result: Optional[Dict[str, Any]]) -> None: if result is None: ba.playsound(ba.getsound('error')) ba.screenmessage( ba.Lstr(resource='internal.unavailableNoConnectionText'), color=(1, 0, 0)) else: if is_ticket_purchase: if result['allow']: price = _ba.get_account_misc_read_val( 'price.' + item, None) if (price is None or not isinstance(price, int) or price <= 0): print('Error; got invalid local price of', price, 'for item', item) ba.playsound(ba.getsound('error')) else: ba.playsound(ba.getsound('click01')) _ba.in_game_purchase(item, price) else: if result['reason'] == 'versionTooOld': ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.versionTooOldText'), color=(1, 0, 0)) else: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.unavailableText'), color=(1, 0, 0)) # Real in-app purchase. else: if result['allow']: _ba.purchase(item) else: if result['reason'] == 'versionTooOld': ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.versionTooOldText'), color=(1, 0, 0)) else: ba.playsound(ba.getsound('error')) ba.screenmessage(ba.Lstr( resource='getTicketsWindow.unavailableText'), color=(1, 0, 0))
def do_it() -> None: _ba.in_game_purchase('offer:' + str(self._offer['id']), self._offer['price'])
def do_it() -> None: _ba.in_game_purchase(self._items[0], self._price)