Exemple #1
0
    def nas_gacha_status(self):
        all_receive_nas_num = scan_user_receive_nas_num(self.user_id)
        latest_nas_gacha_record = load_latest_nas_gacha_record(self.user_id)
        if latest_nas_gacha_record == {}:
            remain_nas_gacha = 1
            return remain_nas_gacha

        remain_nas_gacha = int(
            (all_receive_nas_num -
             int(latest_nas_gacha_record['used_nas_num'])) / NAS_GACHA_COST)
        return remain_nas_gacha
Exemple #2
0
    def calc_until_next_time_nas_num(self):
        all_receive_nas_num = scan_user_receive_nas_num(self.user_id)
        latest_nas_gacha_record = load_latest_nas_gacha_record(self.user_id)
        if latest_nas_gacha_record == {}:
            until_next_time_nas_num = 0
            return until_next_time_nas_num

        diff_remain_used_num = all_receive_nas_num - int(
            latest_nas_gacha_record['used_nas_num'])

        until_next_time_nas_num = NAS_GACHA_COST - diff_remain_used_num if diff_remain_used_num < NAS_GACHA_COST else 0
        return until_next_time_nas_num
Exemple #3
0
    def check_can_run_gacha(self):
        all_receive_nas_num = scan_user_receive_nas_num(self.user_id)
        latest_nas_gacha_record = load_latest_nas_gacha_record(self.user_id)
        if latest_nas_gacha_record == {}:
            return True
        already_used_nas_num = int(
            latest_nas_gacha_record['used_nas_num']) + NAS_GACHA_COST

        if already_used_nas_num >= all_receive_nas_num:
            print(all_receive_nas_num)
            return False

        return True
Exemple #4
0
    def use_nas_gacha_tickets(self, ticket_name):
        latest_nas_gacha_record = load_latest_nas_gacha_record(self.user_id)
        if latest_nas_gacha_record == {}:
            print('empty gacha record')
            return False

        has_tickets = latest_nas_gacha_record['has_tickets']
        if ticket_name not in has_tickets.keys():
            print('not exist the ticket in your has tickets')
            return False

        now = datetime.now()
        all_receive_nas_num = scan_user_receive_nas_num(self.user_id)
        already_used_nas_num = latest_nas_gacha_record['used_nas_num']
        has_tickets[ticket_name] -= 1

        if has_tickets[ticket_name] <= 0:
            del has_tickets[ticket_name]

        create_nas_gacha_record(self.user_id, Decimal(now.timestamp()),
                                all_receive_nas_num, already_used_nas_num,
                                has_tickets)
        return True
Exemple #5
0
    def nas_gacha(self):
        now = datetime.now()
        all_receive_nas_num = scan_user_receive_nas_num(self.user_id)
        latest_nas_gacha_record = load_latest_nas_gacha_record(self.user_id)

        gacha_result = roll_a_gacha()
        if latest_nas_gacha_record == {}:
            already_used_nas_num = 0
            has_tickets = {}
            if gacha_result != '':
                has_tickets[gacha_result] = 1
        else:
            already_used_nas_num = int(
                latest_nas_gacha_record['used_nas_num']) + NAS_GACHA_COST
            has_tickets = latest_nas_gacha_record['has_tickets']
            if gacha_result != '':
                has_tickets[gacha_result] = has_tickets.get(gacha_result,
                                                            0) + 1

        create_nas_gacha_record(self.user_id, Decimal(now.timestamp()),
                                all_receive_nas_num, already_used_nas_num,
                                has_tickets)
        return gacha_result