Exemplo n.º 1
0
    def reward(self, base_prize):
        self.is_rewarding = 1

        for range_id in range(1, len(self.LV_RANGE) + 1):
            k = self.getRangePrizeKey(range_id)
            prize = self.get(k)

            pool = 0
            if prize:
                pool = base_prize + int(prize)
                player_num = self.getPlayerNum(range_id)

                max_win_player = max(1, int(player_num * Config.WIN_PRIZE_RATE))

                total_w = 0
                total_n = 0
                for (n, w) in Config.PRIZE:
                    if total_n >= max_win_player:
                        break

                    total_n += n
                    total_w += n * w

                win_player_list = self.getTopPlayer(range_id, total_n)
                rank = 1
                for (n, w) in Config.PRIZE:
                    for i in range(n):
                        if win_player_list:
                            uid = win_player_list.pop(0)
                            prize = int((w * 1.0 / total_w) * pool)
                            tid = self.key_

                            #TODO: skip robots
                            if 563<= int(uid) <= 662:
                                continue

                            User(uid).coin += prize
                            Log.debug('reward uid=%s, rank=%d, prize=%d' % (uid, rank, prize))
                            UserRewardLog.create(uid, tid, rank, prize)

                            # notify
                            Notice(uid).push({'type':Notice.TYPE_TOURNAMENT,
                                'rank': rank,
                                'tid': tid,
                                'prize': prize,
                                'time': int(time.time())})

                            rank += 1

                            data = {'tournament_prize': prize}
                            Stat().incr(data)
Exemplo n.º 2
0
    def spin(cls, para):
        if not checkPara(para, ['uid', 'machine_id', 'lines', 'bet', 'is_free']):
            return Error.INVALID_PARAM

        uid = para['uid']
        game_id = para['machine_id']
        lines = para['lines']
        bet = para['bet']
        is_free = para['is_free']

        fake_flag = 0
        if 'fakeflag' in para:
            fake_flag = int(para['fakeflag'])

        lv = User(uid).level

        #check
        if not ConfMgr.isMachineLocked(game_id, lv):
            return Error.MACHINE_LOCKED

        if not ConfMgr.isLineValid(game_id, lines):
            return Error.LINE_EXCEEDED

        if not ConfMgr.isBetValid(lv, bet):
            return Error.BET_EXCEEDED

        pay_in = 0
        user = User(uid)
        cur_coin = user.coin

        # may change wild_tune for this user
        user.addSpin()

        if not is_free:
            user.clearWinRec()

        if not is_free:
            pay_in = lines * bet
            if cur_coin < pay_in:
                Log.error('no enough coin to spin')
                return Error.NO_COIN
        else:
            # pick saved bet and lines for free spin
            free_spin = FreeSpin(uid, game_id)
            ret = free_spin.consume()

            if ret is False:
                return Error.NO_FREE_SPIN

            # override
            (lines, bet) = ret

        machine = cls(game_id)

        # ignore bonus if skip playing it
        game_type = BonusGameType.getBonusGameType(game_id)
        bonus_game = game_type(uid, game_id)
        bonus_game.remove()

        (response, win, bonus_num, spin_num) = machine.doSpin(game_id, lv, lines, bet, is_free, fake_flag)

        if bonus_num > 0:
            game_type.create(uid, game_id, bonus_num, bet)
            Log.debug('created bonus games: bonus_num=%s'%bonus_num)

        if spin_num > 0:
            free_spin = FreeSpin(uid, game_id)
            free_spin.add(spin_num, lines, bet)
            response['is_new_freespin'] = True
            Log.debug('added free spin=%s'%spin_num)

        # save for big/mega win
        user.addWinRec(win / bet)

        # Tournament update
        Tournament.compete(uid, game_id, win)

        # compose reponse
        now_coin = cur_coin - pay_in + win
        user.coin = now_coin
        response['coin'] = now_coin

        (now_exp, lv_up) = user.addExp(lines*bet)
        response['exp'] = now_exp

        response['level'] = user.level

        free_spin = FreeSpin(uid, game_id).getAll()
        if free_spin:
            response['free_spin'] = free_spin

        win_info = user.checkWinRec()
        if win_info:
            response.update(win_info)

        rank_info = Tournament.getRank({'uid': uid, 'machine_id': game_id})
        if rank_info != Error.TOUR_NOT_OPEN:
            response['rank_info'] = rank_info

        # share gift flag
        share = UserShareGift(uid)
        if '5combo' in response:
            share.setFlag(UserShareGift.TYPE_COMBO)

        # bonus may also trigger it
        if 'is_mega' in response:
            share.setFlag(UserShareGift.TYPE_MEGA)

        if lv_up:
            share.setFlag(UserShareGift.TYPE_LEVELUP)

        #only for stat
        data = {'bet': pay_in,
                'win': win,
                'spin': 1,
                'trigger_freespin': 1 if spin_num > 0 else 0,
                'trigger_bonus': 1 if bonus_num > 0 else 0,
                'free_spin': 1 if is_free else 0,
                }
        Stat().incr(data)

        return response