예제 #1
0
    def load(cls, para):
        if not checkPara(para, ['uid', 'machine_id']):
            return Error.INVAILD_PARAM

        mid = para['machine_id']
        uid = para['uid']

        ret = {'machine_id': mid}
        machine = cls(mid)
        init = machine.genInitLayout()
        init_left = machine.genInitLayoutLeft(mid, init)

        ret['symbols'] = init_left + init

        free_spin = FreeSpin(uid, mid).getAll()
        if free_spin:
            ret['free_spin'] = free_spin

        game_type = BonusGameType.getBonusGameType(mid)
        bonus_game = game_type(uid, mid).load()
        if bonus_game is not None:
            ret['bonus'] = bonus_game

        # reset in case last spin is free
        User(uid).clearWinRec()

        return ret
예제 #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