Exemple #1
0
def sync_arena_lottery(p, req):
    ''' 
    翻牌奖励进玩家背包 
    @param: msg_notice-0:无走马灯,1-走马灯广播'''
    res_err = UNKNOWN_ERROR
    cid, [item_type, item_id, item_num, msg_notice] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( res_err )

    _model = ITEM_MODELs.get( item_type, None )
    if not _model:
        log.error('Unknown item type. item_type: {0}.'.format( item_type ))
        defer.returnValue( UNKNOWN_ITEM_ERROR )

    res_err, value = yield _model( user, ItemID=item_id, ItemNum=item_num, AddType=WAY_LOTTERY_AWARD, CapacityFlag=False )
    if res_err:
        defer.returnValue( res_err )

    # 翻牌得到稀有道具
    if msg_notice:
        message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_LOTTERY, [user.base_att.nick_name, item_type, item_id, item_num]]]
        gw_broadcast('sync_broadcast', [message])

    defer.returnValue( value )
    def onekey_receive_reward(self, user):
        res = CONSTELLATION_REWARD_RECEIVED

        self.synced = False

        items_return = []
        for idx, reward in enumerate(self.rewards):
            if reward[3]:
                continue

            if self.score >= Constellation.stars_need( idx ):
                _add_func = ITEM_MODELs.get(reward[0], None)

                if _add_func:
                    res_err, res_value = yield _add_func( user, ItemID = reward[1], ItemNum = reward[2], AddType=WAY_CONSTELLATION_AWARD, CapacityFlag=False )
                    if not res_err:
                        for _v in res_value:
                            items_return = total_new_items(_v, items_return)
                    reward = list(reward)
                    reward[3] = 1
                    self.rewards[idx] = reward
                    res = NO_ERROR
                else:
                    log.error('[ Constellation.receve_reward ]no such item type: {0}.', reward[0])
            else:
                log.warn('user too few score. cid:{0}, score:{1}, idx:{2}, stars need:{3}.'.format( user.cid, self.score, idx, Constellation.stars_need(idx)) )
                break

        defer.returnValue( (res, self.rewards, items_return) )
Exemple #3
0
    def exchange(self, user, exchange_id, exchange_count):
        '''
        @summary: 竞技场中 用声望兑换道具
        '''
        conf = get_arena_exchange( exchange_id )
        if not conf:
            log.error('Can not find conf. exchange_id: {0}.'.format( exchange_id ))
            defer.returnValue( NOT_FOUND_CONF )
        # 检查主角等级限制
        if user.base_att.level < conf['NeedLevel']:
            log.error('User level limit. NeedLevel: {0}, cur level: {1}.'.format( conf['NeedLevel'], user.base_att.level ))
            defer.returnValue( REQUEST_LIMIT_ERROR )

        cur_time = int(time())
        # read redis data
        data = yield redis.hget(HASH_ARENA_EXCHANGE, user.cid)
        if data:
            data = loads(data)
        else:
            data = {}

        old_excharge    = data.setdefault( exchange_id, [cur_time, exchange_id, 0, 0] )
        reset_timestamp = get_reset_timestamp()
        if old_excharge[0] <= reset_timestamp:
            old_excharge[0] = cur_time
            old_excharge[3] = 0
        # 检查可兑换次数限制
        if conf['MaxExchangeCount'] > 0:
            if (old_excharge[2] + exchange_count) > conf['MaxExchangeCount']:
                log.error('max count: {0}, used count: {1}, exchange_count: {2}.'.format( conf['MaxExchangeCount'], old_excharge[2], exchange_count ))
                defer.returnValue( ARENA_EXCHANGE_MAX_NUM )
        if conf['DailyExchangeCount'] > 0:
            if (old_excharge[3] + exchange_count) > conf['DailyExchangeCount']:
                log.error('daily_max_count: {0}, used count: {1}, exchange_count: {2}.'.format( conf['DailyExchangeCount'], old_excharge[3], exchange_count ))
                defer.returnValue( ARENA_EXCHANGE_MAX_NUM )
        # 检查声望值
        need_prestige = exchange_count * conf['NeedPrestige']
        if need_prestige > user.base_att.prestige:
            log.error('prestige. need: {0}, cur: {1}.'.format( need_prestige, user.base_att.prestige ))
            defer.returnValue( CHAR_PRESTIGE_NOT_ENOUGH )
        # 扣声望值
        user.consume_prestige( need_prestige, WAY_ARENA_EXCHANGE )
        # 向背包中新增道具
        model = ITEM_MODELs.get( conf['ItemType'], None )
        if not model:
            log.error('Can not find model. item type: {0}.'.format( conf['ItemType'] ))
            defer.returnValue( ITEM_TYPE_ERROR )
        res_err, add_items = yield model( user, ItemID=conf['ItemID'], ItemNum=exchange_count*conf['ItemNum'], AddType=WAY_ARENA_EXCHANGE, CapacityFlag=False )
        if res_err:
            defer.returnValue( res_err )

        # 更新已兑换记录
        if conf['MaxExchangeCount'] > 0:
            old_excharge[2] += exchange_count
        if conf['DailyExchangeCount'] > 0:
            old_excharge[3] += exchange_count
        yield redis.hset(HASH_ARENA_EXCHANGE, user.cid, dumps(data))

        defer.returnValue( (user.base_att.prestige, old_excharge[2], old_excharge[3], add_items) )
Exemple #4
0
    def upgrade_random_level(self):
        ''' 将当前鉴玉等级提升到特定等级(暂定4级宝玉) '''
        items_return = []
        total_num, item_attribs = yield self.user.bag_item_mgr.get_items(
            ITEM_JADE_UPGRADE_ID)
        if total_num > 0:
            res_err, used_attribs = yield self.user.bag_item_mgr.use(
                ITEM_JADE_UPGRADE_ID, 1)
            if res_err:
                defer.returnValue(res_err)
            else:
                self.random_jade_level = JADE_UPGRADE_LEVEL
                yield redis.hset(HASH_RANDOM_JADE_LEVEL, self.cid,
                                 JADE_UPGRADE_LEVEL)
                # used_attribs-已使用的道具
                for _a in used_attribs:
                    items_return.append([
                        _a.attrib_id, ITEM_TYPE_ITEM, ITEM_JADE_UPGRADE_ID,
                        _a.item_num
                    ])
                    # add syslog
                    syslogger(LOG_ITEM_LOSE, self.cid, self.user.level,
                              self.user.vip_level, self.user.alliance_id,
                              _a.attrib_id, ITEM_JADE_UPGRADE_ID, 1,
                              WAY_JADE_UPGRADE_LEVEL)
        else:
            if JADE_UPGRADE_LEVEL_CREDITS > self.user.credits:
                defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
            else:
                self.random_jade_level = JADE_UPGRADE_LEVEL
                yield redis.hset(HASH_RANDOM_JADE_LEVEL, self.cid,
                                 JADE_UPGRADE_LEVEL)
                yield self.user.consume_credits(JADE_UPGRADE_LEVEL_CREDITS,
                                                WAY_JADE_UPGRADE_LEVEL)

        item_rand = yield package_open(self.user, JADE_UPGRADE_CHEST_ID)
        if not item_rand:
            defer.returnValue(NOT_FOUND_CONF)
        add_item = []
        _model = ITEM_MODELs.get(item_rand[0], None)
        if _model:
            res_err, value = yield _model(self.user,
                                          ItemID=item_rand[1],
                                          ItemNum=item_rand[2],
                                          AddType=WAY_JADE_UPGRADE_LEVEL)
            if not res_err and value:
                add_item = value[0]
        if not add_item:
            defer.returnValue(UNKNOWN_ERROR)

        defer.returnValue((self.user.credits, self.random_jade_level,
                           items_return, add_item))
Exemple #5
0
    def receive_reward(self, user):
        res, data = UNKNOWN_ERROR, None

        self.synced = False

        items_return = []
        for idx, reward in enumerate(self.rewards):
            received = reward[3]

            if not received:
                if self.score >= Constellation.stars_need(idx):
                    _add_func = ITEM_MODELs.get(reward[0], None)

                    if _add_func:
                        res_err, res_value = yield _add_func(
                            user,
                            ItemID=reward[1],
                            ItemNum=reward[2],
                            AddType=WAY_CONSTELLATION_AWARD,
                            CapacityFlag=False)
                        if not res_err:
                            for _v in res_value:
                                items_return = total_new_items(
                                    _v, items_return)
                        reward = list(reward)
                        reward[3] = 1
                        self.rewards[idx] = reward
                        res = NO_ERROR
                    else:
                        log.error(
                            '[ Constellation.receve_reward ]no such item type: {0}.',
                            reward[0])
                else:
                    log.error(
                        '[ Constellation.receve_reward ]too few score. score:{0}, idx:{1}, stars need:{2}.',
                        self.score, idx, Constellation.stars_need(idx))

                break
            else:
                res = CONSTELLATION_REWARD_RECEIVED

        data = self.rewards

        defer.returnValue((res, data, items_return))
Exemple #6
0
def sync_arena_lottery(p, req):
    ''' 
    翻牌奖励进玩家背包 
    @param: msg_notice-0:无走马灯,1-走马灯广播'''
    res_err = UNKNOWN_ERROR
    cid, [item_type, item_id, item_num, msg_notice] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format(cid))
        defer.returnValue(res_err)

    _model = ITEM_MODELs.get(item_type, None)
    if not _model:
        log.error('Unknown item type. item_type: {0}.'.format(item_type))
        defer.returnValue(UNKNOWN_ITEM_ERROR)

    res_err, value = yield _model(user,
                                  ItemID=item_id,
                                  ItemNum=item_num,
                                  AddType=WAY_LOTTERY_AWARD,
                                  CapacityFlag=False)
    if res_err:
        defer.returnValue(res_err)

    # 翻牌得到稀有道具
    if msg_notice:
        message = [
            RORATE_MESSAGE_ACHIEVE,
            [
                ACHIEVE_TYPE_LOTTERY,
                [user.base_att.nick_name, item_type, item_id, item_num]
            ]
        ]
        gw_broadcast('sync_broadcast', [message])

    defer.returnValue(value)
def plunder_streak(p, req):
    '''
    @summary: 连续10次抢夺机器人, 非玩家
    '''
    res_err = UNKNOWN_ERROR

    cid, [plunder_cid, shard_id] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( res_err )
    # 等级限制 或者 VIP等级开关
    vip_conf = get_vip_conf( user.vip_level )
    res_err  = user.check_function_open(FUNCTION_TEN_PLUNDER)
    if res_err and (not vip_conf.get('TreasureTenPlunder', 0)):
        log.error('cid:{0}, level:{1}, vip_level:{2}.'.format( cid, user.level, user.vip_level ))
        defer.returnValue( CHAR_VIP_LEVEL_LIMIT )

    # 玩家的斗战点不足
    if user.base_att.douzhan < PVP_NEED_DOUZHAN:
        log.error('douzhan of user {0} have been zero!!!'.format( cid ))
        defer.returnValue( CHAR_DOUZHAN_NOT_ENOUGH )
    # 只能连续抢机器人
    if plunder_cid > 0:
        log.error('Can not plunder streak user. plunder_cid: {0}.'.format( plunder_cid ))
        defer.returnValue( REQUEST_LIMIT_ERROR )

    #抢夺,自动去除自己的免战
    yield redis.hdel( HASH_AVOID_WAR_TIME, cid ) 

    battle_count   = 0 # 抢夺的次数
    plunder_result = 0 # 未抢到
    new_shard      = []
    # 翻牌得到的幸运道具
    lottery_items = []
    for _i in range(0, 10):
        # 扣斗战点
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
        # 抢夺次数加1
        battle_count += 1
        # 幸运道具奖励
        new_item = yield random_lottery_items( cid, user.level, user.base_att.vip_level, rand_count=1 )
        if len(new_item) > 0:
            lottery_items.append( new_item[0] )
        else:
            log.error('No lottery items. cid: {0}, level: {1}, vip_level: {2}.'.format( cid, level, vip_level ))
        # 随机碎片
        err, add_items = yield AvoidWarMgr.rand_shard( user, shard_id, plunder_cid )
        if not err and (len(add_items) > 0): #抢到
            plunder_result = 1
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level, user.alliance_id, 1, 1, add_items[0][0], add_items[0][2])
            new_shard = [add_items[0][0], add_items[0][2]]
            break
        # 玩家的斗战点不足
        if user.base_att.douzhan < PVP_NEED_DOUZHAN:
            log.error('douzhan of user {0} have been zero!!!'.format( cid ))
            break
    # 幸运道具进背包
    items_return = []
    for _type, _id, _num, _ in lottery_items:
        model = ITEM_MODELs.get( _type, None )
        if not model:
            log.error('Unknown decomposition item type. item type: {0}.'.format( _type ))
            continue
        res_err, res_value = yield model(user, ItemID=_id, ItemNum=_num, AddType=WAY_LOTTERY_AWARD, CapacityFlag=False)
        if not res_err:
            for _v in res_value:
                items_return = total_new_items(_v, items_return)
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_5, battle_count )
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest( OPEN_SERVER_QUEST_ID_8, battle_count)
    yield user.achievement_mgr.update_achievement_status(ACHIEVEMENT_QUEST_ID_8, battle_count)

    defer.returnValue( (plunder_result, user.base_att.douzhan, new_shard, items_return, lottery_items) )
Exemple #8
0
    def exchange_items(self, user, exchange_id, exchange_count):
        ''' 荣誉兑换道具 '''
        conf = get_joust_exchange_conf(exchange_id)
        if not conf:
            log.error('Can not find conf. cid: {0}, exchange_id: {1}.'.format(
                user.cid, exchange_id))
            defer.returnValue(NOT_FOUND_CONF)
        # 检查主角等级限制
        if user.base_att.level < conf['NeedLevel']:
            log.error(
                'User level limit. cid: {0}, NeedLevel: {1}, cur level: {2}.'.
                format(user.cid, conf['NeedLevel'], user.base_att.level))
            defer.returnValue(CHAR_LEVEL_LIMIT)

        cur_time = int(time())
        # read redis data
        _exchanged = yield redis.hget(HASH_JOUST_HONOR_EXCHANGE, user.cid)
        if _exchanged:
            _exchanged = loads(_exchanged)
        else:
            _exchanged = {}

        _old_excharge = _exchanged.setdefault(exchange_id,
                                              [cur_time, exchange_id, 0, 0, 0])
        _status = timestamp_is_week(_old_excharge[0])
        if 2 == _status:  # 已隔周
            _old_excharge[3], _old_excharge[4] = 0, 0
        elif 1 == _status:  # 已隔天
            _old_excharge[4] = 0
        # 检查可兑换次数限制
        if conf['MaxExchangeCount'] > 0:
            if (_old_excharge[2] + exchange_count) > conf['MaxExchangeCount']:
                defer.returnValue(JOUST_EXCHANGE_COUNT_ERROR)
        if conf['WeekExchangeCount'] > 0:
            if (_old_excharge[3] + exchange_count) > conf['WeekExchangeCount']:
                defer.returnValue(JOUST_EXCHANGE_COUNT_ERROR)
        if conf['DailyExchangeCount'] > 0:
            if (_old_excharge[4] +
                    exchange_count) > conf['DailyExchangeCount']:
                defer.returnValue(JOUST_EXCHANGE_COUNT_ERROR)
        # 检查荣誉值
        _need_honor = exchange_count * conf['NeedHonor']
        if _need_honor > user.honor:
            defer.returnValue(CHAR_HONOR_NOT_ENOUGH)
        # 扣荣誉值
        user.base_att.honor -= _need_honor
        # 向背包中新增道具
        model = ITEM_MODELs.get(conf['ItemType'], None)
        if not model:
            log.error('Can not find model. item type: {0}.'.format(
                conf['ItemType']))
            defer.returnValue(ITEM_TYPE_ERROR)
        res_err, add_items = yield model(user,
                                         ItemID=conf['ItemID'],
                                         ItemNum=exchange_count *
                                         conf['ItemNum'],
                                         AddType=WAY_JOUST_EXCHANGE,
                                         CapacityFlag=False)
        if res_err:
            defer.returnValue(res_err)

        # 更新已兑换记录
        if conf['MaxExchangeCount'] > 0:
            _old_excharge[2] += exchange_count
        if conf['WeekExchangeCount'] > 0:
            _old_excharge[3] += exchange_count
        if conf['DailyExchangeCount'] > 0:
            _old_excharge[4] += exchange_count
        _exchanged[exchange_id] = _old_excharge
        yield redis.hset(HASH_JOUST_HONOR_EXCHANGE, user.cid,
                         dumps(_exchanged))

        defer.returnValue((user.honor, exchange_id, _old_excharge[2],
                           _old_excharge[3], _old_excharge[4], add_items))
Exemple #9
0
    def random_new_jade(self, random_times):
        ''' 获取新的玉魄 '''
        # 检查等级限制条件
        if random_times == JADE_RANDOM_TIMES_TEN:
            if (self.user.level < JADE_RANDOM_TEN_LEVEL) and (
                    self.user.vip_level < JADE_RANDOM_TEN_VIP_LEVEL):
                defer.returnValue(JADE_RANDOM_TEN_ERROR)

        # 鉴玉
        new_jades, new_items = [], []
        msg_item_ids = []  # 需要走马灯通告的道具信息

        _curr_random_level = self.random_jade_level
        _golds_cost, _credits_cost, _left_golds, _left_credits = 0, 0, self.user.golds, self.user.credits

        for _idx in range(0, random_times):
            cost_conf = get_jade_cost_conf(_curr_random_level)
            # 检查消耗数量限制
            if not cost_conf:
                defer.returnValue(NOT_FOUND_CONF)
            if ITEM_TYPE_MONEY != cost_conf['CostItemType']:
                defer.returnValue(UNKNOWN_ITEM_ERROR)
            if ITEM_MONEY_GOLDS == cost_conf['CostItemID']:
                if _left_golds < cost_conf['CostItemNum']:
                    defer.returnValue(CHAR_GOLD_NOT_ENOUGH)
                _left_golds -= cost_conf['CostItemNum']
                _golds_cost += cost_conf['CostItemNum']
            elif ITEM_MONEY_CREDITS == cost_conf['CostItemID']:
                if _left_credits < cost_conf['CostItemNum']:
                    defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
                _left_credits -= cost_conf['CostItemNum']
                _credits_cost += cost_conf['CostItemNum']
            else:
                defer.returnValue(UNKNOWN_ITEM_ERROR)

            _chest_id = JADE_RANDOM_POOLS[_curr_random_level]
            _item_rand = yield package_open(self.user, _chest_id)
            if not _item_rand:
                defer.returnValue(NOT_FOUND_CONF)

            new_jades.append(_item_rand[:3])
            if _item_rand[3]:
                msg_item_ids.append(_item_rand[:3])

            # 鉴玉等级会有一定几率提示、不变、回到初始等级, 并有一定概率获得额外的道具
            _next_level, _extra_item = self.random_next_level(
                _curr_random_level)
            if _next_level != _curr_random_level:
                _curr_random_level = _next_level
                yield redis.hset(HASH_RANDOM_JADE_LEVEL, self.cid, _next_level)
            if _extra_item:
                new_items.append(_extra_item)
        # 扣金币或钻石
        if _golds_cost:
            self.user.consume_golds(_golds_cost, WAY_JADE_RANDOM)
        if _credits_cost:
            yield self.user.consume_credits(_credits_cost, WAY_JADE_RANDOM)
        # 更新最新等级
        self.random_jade_level = _curr_random_level

        #log.info('For Test. _golds_cost: {0}, _credits_cost: {1}, new_jades: {2}, new_items: {3}.'.format( _golds_cost, _credits_cost, new_jades, new_items ))
        add_jades, add_items = [], []
        q = 0
        for _type, _id, _num in new_jades:
            _model = ITEM_MODELs.get(_type, None)
            if not _model:
                log.error('Unknown item type. cid: {0}, ItemType: {1}.'.format(
                    self.cid, _type))
                continue
            res_err, value = yield _model(self.user,
                                          ItemID=_id,
                                          ItemNum=_num,
                                          CapacityFlag=False,
                                          AddType=WAY_JADE_RANDOM)
            _quality = get_item_by_itemid(_id).get('Quality', 0)
            if _quality >= 2:
                #品质大于2,开服狂欢
                q += 1
            if not res_err and value:
                add_jades.extend(value)
            else:
                log.warn(
                    'User add items error. cid: {0}, res_err: {1}, value: {2}.'
                    .format(self.cid, res_err, value))
        # 开服狂欢
        yield self.user.open_server_mgr.update_open_server_activity_quest(
            OPEN_SERVER_QUEST_ID_16, q)
        yield self.user.achievement_mgr.update_achievement_status(
            ACHIEVEMENT_QUEST_ID_16, q)
        # 新增额外掉落的道具
        for _type, _id, _num in new_items:
            _model = ITEM_MODELs.get(_type, None)
            if not _model:
                log.error('Unknown item type. cid: {0}, ItemType: {1}.'.format(
                    self.cid, _type))
                continue
            res_err, value = yield _model(self.user,
                                          ItemID=_id,
                                          ItemNum=_num,
                                          CapacityFlag=False,
                                          AddType=WAY_JADE_RANDOM)
            if not res_err and value:
                add_items.extend(value)
            else:
                log.warn(
                    'User add items error. cid: {0}, res_err: {1}, value: {2}.'
                    .format(self.cid, res_err, value))
        if msg_item_ids:
            message = [
                RORATE_MESSAGE_ACHIEVE,
                [
                    ACHIEVE_TYPE_RARE_ITEM,
                    [self.user.nick_name, _chest_id, msg_item_ids]
                ]
            ]
            gw_broadcast('sync_broadcast', [message])

        defer.returnValue((self.user.golds, self.user.credits,
                           _curr_random_level, add_jades, add_items))
def plunder_streak(p, req):
    '''
    @summary: 连续10次抢夺机器人, 非玩家
    '''
    res_err = UNKNOWN_ERROR

    cid, [plunder_cid, shard_id] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format(cid))
        defer.returnValue(res_err)
    # 等级限制 或者 VIP等级开关
    vip_conf = get_vip_conf(user.vip_level)
    res_err = user.check_function_open(FUNCTION_TEN_PLUNDER)
    if res_err and (not vip_conf.get('TreasureTenPlunder', 0)):
        log.error('cid:{0}, level:{1}, vip_level:{2}.'.format(
            cid, user.level, user.vip_level))
        defer.returnValue(CHAR_VIP_LEVEL_LIMIT)

    # 玩家的斗战点不足
    if user.base_att.douzhan < PVP_NEED_DOUZHAN:
        log.error('douzhan of user {0} have been zero!!!'.format(cid))
        defer.returnValue(CHAR_DOUZHAN_NOT_ENOUGH)
    # 只能连续抢机器人
    if plunder_cid > 0:
        log.error('Can not plunder streak user. plunder_cid: {0}.'.format(
            plunder_cid))
        defer.returnValue(REQUEST_LIMIT_ERROR)

    #抢夺,自动去除自己的免战
    yield redis.hdel(HASH_AVOID_WAR_TIME, cid)

    battle_count = 0  # 抢夺的次数
    plunder_result = 0  # 未抢到
    new_shard = []
    # 翻牌得到的幸运道具
    lottery_items = []
    for _i in range(0, 10):
        # 扣斗战点
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
        # 抢夺次数加1
        battle_count += 1
        # 幸运道具奖励
        new_item = yield random_lottery_items(cid,
                                              user.level,
                                              user.base_att.vip_level,
                                              rand_count=1)
        if len(new_item) > 0:
            lottery_items.append(new_item[0])
        else:
            log.error(
                'No lottery items. cid: {0}, level: {1}, vip_level: {2}.'.
                format(cid, level, vip_level))
        # 随机碎片
        err, add_items = yield AvoidWarMgr.rand_shard(user, shard_id,
                                                      plunder_cid)
        if not err and (len(add_items) > 0):  #抢到
            plunder_result = 1
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level,
                      user.alliance_id, 1, 1, add_items[0][0], add_items[0][2])
            new_shard = [add_items[0][0], add_items[0][2]]
            break
        # 玩家的斗战点不足
        if user.base_att.douzhan < PVP_NEED_DOUZHAN:
            log.error('douzhan of user {0} have been zero!!!'.format(cid))
            break
    # 幸运道具进背包
    items_return = []
    for _type, _id, _num, _ in lottery_items:
        model = ITEM_MODELs.get(_type, None)
        if not model:
            log.error(
                'Unknown decomposition item type. item type: {0}.'.format(
                    _type))
            continue
        res_err, res_value = yield model(user,
                                         ItemID=_id,
                                         ItemNum=_num,
                                         AddType=WAY_LOTTERY_AWARD,
                                         CapacityFlag=False)
        if not res_err:
            for _v in res_value:
                items_return = total_new_items(_v, items_return)
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest(DAILY_QUEST_ID_5,
                                                  battle_count)
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest(
        OPEN_SERVER_QUEST_ID_8, battle_count)
    yield user.achievement_mgr.update_achievement_status(
        ACHIEVEMENT_QUEST_ID_8, battle_count)

    defer.returnValue((plunder_result, user.base_att.douzhan, new_shard,
                       items_return, lottery_items))