Example #1
0
    def get_one_award(self, user, data, items_return):
        '''
        @summary: 往玩家背包中添加道具
        @param  : items-返回给client的数据
        '''
        res_err, items_list = get_award_conf(data[1], *data[2])
        if res_err:
            defer.returnValue(items_return)

        add_type = ADD_WAYs.get(data[1], WAY_UNKNOWN)
        # 道具进背包
        for _type, _id, _num in items_list:
            model = ITEM_MODELs.get(_type, None)
            if not model:
                log.error('Unknown item type. cid:{0}, item info: {1}.'.format(
                    user.cid, (_type, _id, _num)))
                continue
            res_err, value = yield model(user,
                                         ItemID=_id,
                                         ItemNum=_num,
                                         AddType=add_type,
                                         CapacityFlag=False)
            if not res_err and value:
                for _v in value:
                    items_return = total_new_items(_v, items_return)
        # 发邮件
        if AWARD_TYPE_JOUSTRANK == data[1] and items_list:
            ms_send('write_mail', (user.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_2,
                                   [data[2][1], items_list], data[2][0]))
        elif AWARD_TYPE_ARENARANK == data[1] and items_list:
            ms_send('write_mail',
                    (user.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_1,
                     [data[2][0], data[2][1], items_list], data[2][0]))
        defer.returnValue(items_return)
Example #2
0
    def join_alliance(self, alliance, position=ALLIANCE_POSITION_NORMAL):
        if not self.alliance:
            self.alliance   = alliance
            # add syslog
            syslogger(LOG_ALLIANCE_POSITION, self.__cid, self.__level, self.__vip_level, self.alliance.aid, self.__position, position)

            self.__position = position
            yield self.sync(force=True)
            gs_send('gs_alliance_info', (self.__cid, (self.alliance.aid, self.alliance.name)))
            ms_send('ms_alliance_info', (self.__cid, (self.alliance.aid, self.alliance.name, self.__position)))
            gw_send( self.__cid, 'sync_multicast', [SYNC_MULTICATE_TYPE_7, []] )
Example #3
0
    def reject_all(self):
        # 对方没有公会时发送邮件
        for _cid, _r in self.__requests.iteritems():
            _m = yield g_UserMgr.get_offline_user( _cid )
            if _m and not _m.alliance:
                ms_send('write_mail', (_r.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_4, [self.__name]))

        # 删除所有的入会申请
        yield self.del_all_requests()
        self.__requests = {}

        defer.returnValue( NO_ERROR )
Example #4
0
    def clean_alliance( self ):
        ''' 被踢出仙盟或其它 '''
        # add syslog
        _alliance_id = self.alliance.aid if self.alliance else 0
        syslogger(LOG_ALLIANCE_POSITION, self.__cid, self.__level, self.__vip_level, _alliance_id, self.__position, ALLIANCE_POSITION_NONE)

        self.alliance   = None
        self.__position = ALLIANCE_POSITION_NONE
        self.__contribution = self.__contribution_total = 0
        yield self.sync(force=True)
        gs_send('gs_alliance_info', (self.__cid, (0, '')))
        ms_send('ms_alliance_info', (self.__cid, (0, '', self.__position)))
        gw_send( self.__cid, 'sync_multicast', [SYNC_MULTICATE_TYPE_5, []] )
Example #5
0
def handle_friend_invite(p, req):
    ''' 处理好友请求邮件 
    @param : status:2-同意, 3-拒绝;
    '''
    cid, [mail_id, status] = req

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

    # 更新原邮件状态 
    _key = HASH_MAIL_CONTENT % (MAIL_PAGE_FRIEND, cid)
    _value = yield redis.hget(_key, mail_id)
    if not _value:
        log.error('Unknown mail id. cid: {0}, mail_id: {1}, status: {2}.'.format( cid, mail_id, status ))
        defer.returnValue( UNKNOWN_MAIL_REQUEST )

    _value = loads(_value)
    if _value[2] != MAIL_PAGE_FRIEND or _value[3] != MAIL_FRIEND_1 or status not in [2, 3]:
        log.error('Unknown mail id. cid: {0}, mail_id: {1}, status: {2}.'.format( cid, mail_id, status ))
        defer.returnValue( UNKNOWN_MAIL_REQUEST )

    _value[-1][3] = status
    target_cid    = _value[-1][0]
    yield redis.hset(_key, mail_id, dumps(_value))

    # 同意时添加双方的friends列表. 发送新邮件
    if status == 2:
        # 判断自己的好友人数
        if len(user.friends) >= MAX_FRIENDS_COUNT:
            log.error('User friends count has max. cid: {0}.'.format( cid ))
            defer.returnValue( FRIENDS_COUNT_SELF_ERROR )

        # 处理对方
        offline_user = yield gs_offline_login( target_cid )
        if offline_user:
            reactor.callLater(SESSION_LOGOUT_REAL, gs_offline_logout, target_cid)
            # 判断对方好友人数限制
            if len(offline_user.friends) >= MAX_FRIENDS_COUNT:
                log.error('User friends count has max. target_cid: {0}.'.format( target_cid ))
                defer.returnValue( FRIENDS_COUNT_OTHER_ERROR )
            user.add_friends( target_cid )
            offline_user.add_friends( cid )
            ms_send('write_mail', (target_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_2, [user.lead_id, user.nick_name]))
    else:
        ms_send('write_mail', (target_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_3, [user.lead_id, user.nick_name]))

    defer.returnValue( NO_ERROR )
Example #6
0
    def leave_alliance( self ):
        ''' 主动离开仙盟 '''
        # add syslog
        _alliance_id = self.alliance.aid if self.alliance else 0
        syslogger(LOG_ALLIANCE_POSITION, self.__cid, self.__level, self.__vip_level, _alliance_id, self.__position, ALLIANCE_POSITION_NONE)

        self.alliance   = None
        self.__position = ALLIANCE_POSITION_NONE
        self.__contribution = self.__contribution_total = 0
        self.cd_time = int( time() ) + ALLIANCE_LEAVE_CD_TIME

        yield self.sync(force=True)
        gs_send('gs_alliance_info', (self.__cid, (0, '')))
        ms_send('ms_alliance_info', (self.__cid, (0, '', self.__position)))
        gw_send( self.__cid, 'sync_multicast', [SYNC_MULTICATE_TYPE_5, []] )
Example #7
0
def friend_leave_msg(p, req):
    ''' 好友留言 '''
    cid, [rcv_cid, content] = req

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

    if rcv_cid not in user.friends:
        log.error('User has not in your friends list. cid: {0}, rcv_cid: {1}.'.format( cid, rcv_cid ))
        return USER_HAS_NOT_YOUR_FRIEND

    ms_send('write_mail', (rcv_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_4, [cid, user.lead_id, user.nick_name, content]))

    return NO_ERROR
Example #8
0
    def del_request(self, cid, join_flag=False, action_member=None):
        '''
        param  join_flag: True-同意加入公会 False-拒绝加入公会
        '''
        _r = self.__requests.get(cid, None)
        if not _r:
            defer.returnValue( ALLIANCE_REQUEST_UNKNOWN )

        _m = yield g_UserMgr.get_offline_user( cid )
        if not _m:
            log.warn('Unknown member. cid: {0}.'.format( cid ))
            defer.returnValue( NO_ERROR )

        # 对方没有公会且拒绝加入时发送邮件
        if not join_flag and not _m.alliance:
            ms_send('write_mail', (cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_4, [self.__name]))

        # 同意加入公会时检查公会成员人数限制之后再删除请求
        if join_flag:
            # 判断公会成员数量
            _conf = get_alliance_level_conf(self.__level)
            if not _conf:
                log.error('Can not find the conf. alliance_level: {0}.'.format( self.__level ))
                defer.returnValue( ALLIANCE_MEMBERS_MAX_ERROR )
            if len(self.__members) >= _conf['MembersCount']:
                defer.returnValue( ALLIANCE_MEMBERS_MAX_ERROR )

        del self.__requests[cid]
        yield redis.lrem( TPL_LIST_ALLIANCE_REQUEST % self.__id, 0, dumps(_r.info) )
        del_request_to_dict( [_r] )

        # 同意加入公会
        if join_flag:
            # 判断对方的公会状态
            if _m.alliance:
                defer.returnValue( ALLIANCE_OTHER_HAD_IN )
            yield _m.join_alliance( self )
            # 维护公会的公共信息
            self.__members.append( cid )
            self.dirty()
            self.update_might( _r.might )
            # 公会动态
            self.new_action( (ALLIANCE_ACTION_1, int(time()), action_member.cid, \
                    action_member.lead_id, action_member.nick_name, action_member.level, [_m.lead_id, _m.nick_name]) )
            # 给对方发送邮件
            ms_send('write_mail', (cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_3, [self.__name]))
        defer.returnValue( NO_ERROR )
Example #9
0
    def update_position(self, position, sync=True):
        '''
        @param: sync-True需要通知, False不需要通知
        '''
        if self.__position == position:
            return
        # 异常玩家
        if self.alliance and not self.__position:
            self.__position = ALLIANCE_POSITION_NORMAL
        # add syslog
        syslogger(LOG_ALLIANCE_POSITION, self.__cid, self.__level, self.__vip_level, self.alliance.aid, self.__position, position)

        self.__position = position
        self.__dirty = True
        ms_send('ms_alliance_position', (self.__cid, position))
        # 是否需要通知职位变化的在线玩家
        if sync and self.alliance:
            gw_send( self.__cid, 'sync_multicast', [SYNC_MULTICATE_TYPE_4, [self.alliance.aid, position]] )
Example #10
0
 def del_member(self, member, action_member=None):
     ''' 在公会成员退出时不用实时更新公会战力 '''
     if member.cid in self.__members:
         self.__members.remove( member.cid )
         self.dirty()
     else:
         log.warn('delete member not in alliance member lists. cid: {0}, alliance_id: {1}.'.format( member.cid,  self.__id))
     if member.cid in self.__vice_leaders:
         self.__vice_leaders.remove( member.cid )
     if action_member:
         yield member.clean_alliance()
         ms_send('write_mail', (member.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_6, [self.__name]))
         # 公会动态
         self.new_action( (ALLIANCE_ACTION_3, int(time()), action_member.cid, \
                 action_member.lead_id, action_member.nick_name, action_member.level, [member.lead_id, member.nick_name]) )
     else:
         yield member.leave_alliance()
         ms_send('write_mail', (member.cid, MAIL_PAGE_SYSTEM, MAIL_SYSTEM_5, [self.__name]))
         # 公会动态
         self.new_action( (ALLIANCE_ACTION_2, int(time()), member.cid, member.lead_id, member.nick_name, member.level, []) )
     defer.returnValue( NO_ERROR )
Example #11
0
def friend_invite(p, req):
    ''' 向玩家发送好友邀请 '''
    cid, [target_cid, content] = req

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

    if cid == target_cid:
        defer.returnValue( USER_HAD_YOUR_FRIEND )

    # 已经是好友了
    if target_cid in user.friends:
        log.error('Target user has been your friend. cid: {0}, target_cid:{1}.'.format( cid, target_cid ))
        defer.returnValue( USER_HAD_YOUR_FRIEND )

    # 判断自己的好友人数
    if len(user.friends) >= MAX_FRIENDS_COUNT:
        log.error('User friends count has max. cid: {0}.'.format( cid ))
        defer.returnValue( FRIENDS_COUNT_SELF_ERROR )

    # 已经发送了好友邀请
    _key = HASH_MAIL_CONTENT % (MAIL_PAGE_FRIEND, target_cid)
    _all = yield redis.hgetall( _key )
    for _field, _value in _all.iteritems():
        if _field == MAIL_PRIMARY_INC:
            continue
        _value = loads(_value)
        if _value[3] != MAIL_FRIEND_1:
            continue
        if cid == _value[-1][0] and _value[-1][3] == 1:
            log.error('Target User has been invited. cid: {0}, target_cid: {1}.'.format( cid, target_cid ))
            defer.returnValue( INVITE_FRIEND_REPEAT )
    
    yield user.achievement_mgr.update_achievement_status(20, len(user.friends))
    # 发送邮件给target_cid
    ms_send('write_mail', (target_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_1, [cid, user.lead_id, user.nick_name, 1, content]))

    defer.returnValue( NO_ERROR )
Example #12
0
def friend_discard(p, req):
    ''' 删除好友 '''
    cid, [target_cid] = req

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

    user.del_friends( target_cid )

    offline_user = yield gs_offline_login( target_cid )
    if offline_user:
        ms_send('write_mail', (target_cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_6, [user.lead_id, user.nick_name]))

        offline_user.del_friends( cid )
        ms_send('write_mail', (cid, MAIL_PAGE_FRIEND, MAIL_FRIEND_5, [offline_user.lead_id, offline_user.nick_name]))
        reactor.callLater(SESSION_LOGOUT_REAL, gs_offline_logout, target_cid)

    # 删除双方互相赠送的斗战点
    yield redis.hdel( HASH_FRIENDS_GIFT_DOUZHAN % cid, target_cid )
    yield redis.hdel( HASH_FRIENDS_GIFT_DOUZHAN % target_cid, cid )

    defer.returnValue( NO_ERROR )
Example #13
0
def plunder(p, req):
    '''
    @summary: 夺宝结算
    '''
    res_err = UNKNOWN_ERROR

    cid, ( plunder_cid, shard_id, won ) = req

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

    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 )

    item_conf = get_item_by_itemid( shard_id )
    treasure_id = 0
    if item_conf:
        _, treasure_id, _ = item_conf['ChangeList'][0]

    response = [0, 0, [], []]

    # 对玩家进行抢夺,免战自动解除
    if plunder_cid > 0: # 玩家
        yield redis.hdel( HASH_AVOID_WAR_TIME, cid )
        AvoidWarMgr.stop_plunder_shard( treasure_id, plunder_cid )
        _user_plundered = yield gs_offline_login( plunder_cid )
        if _user_plundered:
            reactor.callLater(SESSION_LOGOUT_REAL, gs_offline_logout, plunder_cid)
    else:
        _user_plundered = None

    if won:
        response[3] = yield random_lottery_items( cid, user.level, user.base_att.vip_level )
        err, add_items = yield AvoidWarMgr.rand_shard( user, shard_id, plunder_cid )

        if not err and (len(add_items) > 0): #抢到
            response[0] = 1
            response[2] = add_items[0][0], add_items[0][2]
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level, user.alliance_id, 0, won, add_items[0][0],add_items[0][2])
            if _user_plundered:
                ms_send('write_mail', (plunder_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_7, [user.lead_id, user.nick_name, shard_id]))
                yield _user_plundered.bag_treasureshard_mgr.dec_shard( shard_id )
            else:
                log.warn('No user be plundered. cid: {0}, plunder_cid: {1}.'.format( cid, plunder_cid ))
        else: # 未抢到
            response[0] = 0
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level, user.alliance_id, 0, won, 0, 0)
    else: # 战斗输了
        if _user_plundered:
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level, user.alliance_id, 0, won, 0, 0)
            ms_send('write_mail', (plunder_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_6, [user.lead_id, user.nick_name, shard_id]))
 
    if user.base_att.douzhan >= PVP_NEED_DOUZHAN:
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_5, 1 )
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest( OPEN_SERVER_QUEST_ID_8, 1)
    yield user.achievement_mgr.update_achievement_status(ACHIEVEMENT_QUEST_ID_8, 1)

    response[1] = user.base_att.douzhan

    defer.returnValue( response )
Example #14
0
    def request_joust_battle(self, battle_type, user, position, status):
        ''' 
        @param: battle_type-挑战类型。1:普通挑战; 2:复仇
        @param: battle_type=1时position-挑战前对手的位置。1-上, 2-左, 3-右。battle_type=2时position=enemy_cid.
        @param: 战斗结果 status 0:lose, 1:win
        '''
        res_err = []
        _is_open = self.check_time_status()
        # 判断是否处于活动时间
        if _is_open:
            defer.returnValue(_is_open)

        # 挑战次数是否充足
        _last_score = yield self.get_char_score(user.cid)
        _last_rank = yield self.get_char_rank(user.cid)
        _joust_data, _ = yield self.get_joust_data(user.cid, _last_score,
                                                   _last_rank)
        _left_count = JOUST_FREE_COUNT + _joust_data[2] - _joust_data[1]
        if _left_count < 1:
            defer.returnValue(JOUST_BATTLE_COUNT_NOT_ENOUGH)
        if _joust_data[2] > 0:
            _joust_data[2] -= 1
        else:
            _joust_data[1] += 1
        # 扣斗战点 2点
        if user.douzhan < PVP_NEED_DOUZHAN:
            defer.returnValue(CHAR_DOUZHAN_NOT_ENOUGH)
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
        # 对手
        if battle_type == JOUST_BATTLE_NORMAL:
            _other_cid = _joust_data[3][position - 1]
        else:
            _other_cid = position
        # 挑战失败, 给玩家 发送邮件
        if not status:
            ms_send('write_mail', (_other_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_4,
                                   [user.lead_id, user.nick_name]))
            yield redis.hset(HASH_JOUST_INFO, user.cid, dumps(_joust_data))
            if battle_type == JOUST_BATTLE_NORMAL:
                res_err = (_last_rank, _last_score, user.douzhan,
                           _left_count - 1, [], [], user.honor)
            else:
                res_err = (_last_score, user.douzhan, _left_count - 1, [],
                           user.honor)
            defer.returnValue(res_err)

        # win-荣誉/翻牌道具/刷新对手/邮件/积分/仇敌
        user.base_att.honor += JOUST_HONOR

        _score, _score_reduce = yield self.get_battle_score(
            user.cid, _other_cid)
        # 给玩家 发送邮件
        ms_send('write_mail', (_other_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_5,
                               [user.lead_id, user.nick_name, _score_reduce]))
        # 翻牌道具
        _lottery_items = yield random_lottery_items(user.cid, user.level,
                                                    user.vip_level)

        if battle_type == JOUST_BATTLE_NORMAL:
            # 新增仇敌 非机器人
            if _other_cid > JOUST_ROBOT_CID:
                yield self.update_enemy_cids(user.cid, _other_cid)
            # 刷新对手
            _rank = yield self.get_char_rank(user.cid)
            _joust_data[3] = yield self.refresh_cids(user.cid, _score, _rank)
            _details = yield self.get_joust_details(_joust_data[3])

            res_err = (_rank, _score, user.douzhan, _left_count - 1,
                       _lottery_items, _details, user.honor)
        else:
            # 挑战仇敌成功时,该仇敌移出列表
            if _other_cid > JOUST_ROBOT_CID:
                yield self.update_enemy_cids(_other_cid, user.cid, True)
                yield self.update_enemy_cids(user.cid, _other_cid)
            res_err = (_score, user.douzhan, _left_count - 1, _lottery_items,
                       user.honor)
        yield redis.hset(HASH_JOUST_INFO, user.cid, dumps(_joust_data))

        defer.returnValue(res_err)
Example #15
0
    def lottery_items(self, user, client_my_rank, enemy_rank, battle_status):
        '''
        @summary: 挑战胜利后,替换双方的排名,并返回可供翻牌的道具列表。长度为3。
        '''
        items_list = []
        # 判断是否处于结算时间 22:00-22:15
        _dt_now    = datetime.now()
        if _dt_now.hour == ARENA_RANK_REWARD_HOUR and _dt_now.minute < 15:
            defer.returnValue( ARENA_IN_REWARD_TIME )

        # 扣斗战点 2点
        if user.base_att.douzhan < PVP_NEED_DOUZHAN:
            log.error('user douzhan is 0. cid: {0}.'.format( user.cid ))
            defer.returnValue( CHAR_DOUZHAN_NOT_ENOUGH )
        user.base_att.douzhan -= PVP_NEED_DOUZHAN

        # 获取我的排名
        my_rank = yield self.get_char_rank( user.cid )
        if my_rank != client_my_rank:
            log.error('Client arena rank info need update. cid: {0}, client_my_rank: {1}, my_rank: {2}.'.format( user.cid, client_my_rank, my_rank ))
        # 每日任务计数
        yield user.daily_quest_mgr.update_daily_quest( DAILY_QUEST_ID_6, 1 )

        if not battle_status:
            # 失败获得10声望值
            user.get_prestige( 10, WAY_ARENA_BATTLE )
            enemy_detail = yield self.get_rank_detail( enemy_rank, flag=False )
            if not enemy_detail:
                log.error('No enemy rank data. cid: {0}, enemy_rank: {1}.'.format( user.cid, enemy_rank ))
                defer.returnValue( (items_list, user.base_att.douzhan) )

            ms_send('write_mail', (enemy_detail[0], MAIL_PAGE_BATTLE, MAIL_BATTLE_1, [user.base_att.lead_id, user.base_att.nick_name]))
            defer.returnValue( (items_list, user.base_att.douzhan) )

        # 胜利获得20声望值
        user.get_prestige( 20, WAY_ARENA_BATTLE )
        items_list = yield random_lottery_items( user.cid, user.base_att.level, user.base_att.vip_level )
        # 名次越靠前, 数字越小; 没有排名时也直接替换
        enemy_detail = yield self.get_rank_detail( enemy_rank, flag=False )
        if not enemy_detail:
            log.error('No enemy rank data. cid: {0}, enemy_rank: {1}.'.format( user.cid, enemy_rank ))
            defer.returnValue( (items_list, user.base_att.douzhan) )
        if my_rank == 0 or enemy_rank < my_rank:
            # 对方是玩家时 互换玩家信息
            if enemy_detail[0] > 0:
                old_enemy_rank = yield self.get_char_rank( enemy_detail[0] )
                if my_rank == 0: # 在排名5000(机器人总数)之外
                    yield redis.zrem( SET_ARENA_CID_RANK, enemy_detail[0] )
                    alli_send('sync_char_data', (enemy_detail[0], SYNC_ARENA_RANK, 0))
                else:
                    if old_enemy_rank == enemy_rank:
                        ms_send('write_mail', (enemy_detail[0], MAIL_PAGE_BATTLE, MAIL_BATTLE_2, [user.base_att.lead_id, user.base_att.nick_name, my_rank]))
                        yield redis.zadd( SET_ARENA_CID_RANK, enemy_detail[0], my_rank )
                        alli_send('sync_char_data', (enemy_detail[0], SYNC_ARENA_RANK, my_rank))
                        old_rank_detail = dumps( [enemy_detail[0], enemy_detail[1], enemy_detail[2], my_rank, 0, 0, [], enemy_detail[7]] )
                        yield redis.hset( HASH_ARENA_RANK, my_rank, old_rank_detail )
            elif my_rank > 0: # 对手是机器人, 恢复当前排名机器人数据
                old_rank_detail = dumps( [0, 0, '', my_rank, 0, 0, [], 0] )
                yield redis.hset( HASH_ARENA_RANK, my_rank, old_rank_detail )

            # 更新自己的rank数据
            yield redis.zadd( SET_ARENA_CID_RANK, user.cid, enemy_rank )
            alli_send('sync_char_data', (user.cid, SYNC_ARENA_RANK, enemy_rank))
            # 保存当前的camp
            #yield user.sync_camp_to_redis(update=True)
            new_rank_detail = dumps( [user.cid, user.level, user.nick_name, enemy_rank, 0, 0, [], user.lead_id] )
            yield redis.hset( HASH_ARENA_RANK, enemy_rank, new_rank_detail )
            # 夺得竞技场前十名, 全服广播
            if enemy_rank < 11:
                message = [RORATE_MESSAGE_ACHIEVE, [ACHIEVE_TYPE_ARENA, [user.base_att.nick_name, enemy_rank]]]
                gw_broadcast('sync_broadcast', [message])
        elif enemy_rank > my_rank:
            ms_send('write_mail', (enemy_detail[0], MAIL_PAGE_BATTLE, MAIL_BATTLE_3, [user.base_att.lead_id, user.base_att.nick_name]))
        #开服狂欢
        enemy_rank = enemy_rank if enemy_rank < my_rank else my_rank
        yield user.open_server_mgr.update_open_server_activity_quest( OPEN_SERVER_QUEST_ID_7, enemy_rank)
        yield user.achievement_mgr.update_achievement_status( ACHIEVEMENT_QUEST_ID_7, enemy_rank)
        defer.returnValue( (items_list, user.base_att.douzhan) )
Example #16
0
def use_named_card(p, req):
    cid, [c_type, card_id, new_name] = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        defer.returnValue( CONNECTION_LOSE )
    
    if c_type == 0 or c_type == 2:
        totalnum, attrs = yield user.bag_item_mgr.get_items(card_id)
        if totalnum == 0:
            defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
    elif (c_type == 1 or c_type == 3 ) and card_id == 0:
        cost_credits = get_game_limit_value(16) if c_type == 1 else get_game_limit_value(17)
        if user.credits < cost_credits:
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
    else:
        defer.returnValue(NAMED_TYPE_IS_WRONG)

    left_res = []
    if c_type == 0 or c_type == 1:
        had_cid = yield redis.hget(DICT_NICKNAME_REGISTERED, new_name)
        if had_cid:
            defer.returnValue(NICK_NAME_IS_USED)
        if c_type == 0:
            res = yield item_use_normal_item(user, ItemType = ITEM_TYPE_ITEM, ItemID = card_id, ItemNum = 1)
            left_res = (res[1][0][0], res[1][0][1], res[1][0][2], res[1][0][3])
        else:
            yield user.consume_credits(cost_credits, WAY_TO_NAMED)

        yield redis.hdel(DICT_NICKNAME_REGISTERED, user.nick_name) 
        user.base_att.nick_name = new_name
        yield redis.hset(DICT_NICKNAME_REGISTERED, new_name, user.cid)
        #alliance
        _s = yield redis.hget(HASH_ALLIANCE_MEMBER, cid)
        if _s:
            _s = list(loads(_s))
            _s[1] = new_name
            yield redis.hset(HASH_ALLIANCE_MEMBER, cid, dumps(_s))
        alli_send('revise_member_name', [cid, new_name])
        #msg
        ms_send('revise_name', [cid, new_name])
        #arena
        _rank = yield g_ArenaMgr.get_char_rank(cid)
        _detail = yield redis.hget( HASH_ARENA_RANK, _rank)
        if _detail:
            _detail = loads(_detail)
            _detail[2] = new_name
            yield redis.hset( HASH_ARENA_RANK, _rank, dumps(_detail))
        
        alliance_info = yield alli_call('get_alliance_info', [cid])
        if alliance_info[0] != 0:
            if alliance_info[2] == ALLIANCE_POSITION_LEADER:
                res = yield alli_call('revise_leader', [user.alliance_id, new_name])

    elif c_type == 2 or c_type ==3:
        alliance_info = yield alli_call('get_alliance_info', [cid])
        if alliance_info[0] != 0:
            if alliance_info[2] != ALLIANCE_POSITION_LEADER:
                defer.returnValue(ALLIANCE_AUTHORITY_ERROR)
            res = yield alli_call('check_alliance_name', [new_name, user.alliance_id]) 
            user.alliance_name = new_name
            if res != 0:
                defer.returnValue(res)
            if c_type == 2:
                res = yield item_use_normal_item(user, ItemType = ITEM_TYPE_ITEM, ItemID = card_id, ItemNum = 1)
                left_res = (res[1][0][0], res[1][0][1], res[1][0][2], res[1][0][3])
            else:
                yield user.consume_credits(cost_credits, WAY_TO_NAMED)
        else:
            defer.returnValue(ALLIANCE_UNKNOWN_ERROR)
    else:
        defer.returnValue(NAMED_TYPE_IS_WRONG)

    defer.returnValue([left_res, user.credits])
Example #17
0
def use_named_card(p, req):
    cid, [c_type, card_id, new_name] = req

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

    if c_type == 0 or c_type == 2:
        totalnum, attrs = yield user.bag_item_mgr.get_items(card_id)
        if totalnum == 0:
            defer.returnValue(CHAR_ITEM_NOT_ENOUGH)
    elif (c_type == 1 or c_type == 3) and card_id == 0:
        cost_credits = get_game_limit_value(
            16) if c_type == 1 else get_game_limit_value(17)
        if user.credits < cost_credits:
            defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
    else:
        defer.returnValue(NAMED_TYPE_IS_WRONG)

    left_res = []
    if c_type == 0 or c_type == 1:
        had_cid = yield redis.hget(DICT_NICKNAME_REGISTERED, new_name)
        if had_cid:
            defer.returnValue(NICK_NAME_IS_USED)
        if c_type == 0:
            res = yield item_use_normal_item(user,
                                             ItemType=ITEM_TYPE_ITEM,
                                             ItemID=card_id,
                                             ItemNum=1)
            left_res = (res[1][0][0], res[1][0][1], res[1][0][2], res[1][0][3])
        else:
            yield user.consume_credits(cost_credits, WAY_TO_NAMED)

        yield redis.hdel(DICT_NICKNAME_REGISTERED, user.nick_name)
        user.base_att.nick_name = new_name
        yield redis.hset(DICT_NICKNAME_REGISTERED, new_name, user.cid)
        #alliance
        _s = yield redis.hget(HASH_ALLIANCE_MEMBER, cid)
        if _s:
            _s = list(loads(_s))
            _s[1] = new_name
            yield redis.hset(HASH_ALLIANCE_MEMBER, cid, dumps(_s))
        alli_send('revise_member_name', [cid, new_name])
        #msg
        ms_send('revise_name', [cid, new_name])
        #arena
        _rank = yield g_ArenaMgr.get_char_rank(cid)
        _detail = yield redis.hget(HASH_ARENA_RANK, _rank)
        if _detail:
            _detail = loads(_detail)
            _detail[2] = new_name
            yield redis.hset(HASH_ARENA_RANK, _rank, dumps(_detail))

        alliance_info = yield alli_call('get_alliance_info', [cid])
        if alliance_info[0] != 0:
            if alliance_info[2] == ALLIANCE_POSITION_LEADER:
                res = yield alli_call('revise_leader',
                                      [user.alliance_id, new_name])

    elif c_type == 2 or c_type == 3:
        alliance_info = yield alli_call('get_alliance_info', [cid])
        if alliance_info[0] != 0:
            if alliance_info[2] != ALLIANCE_POSITION_LEADER:
                defer.returnValue(ALLIANCE_AUTHORITY_ERROR)
            res = yield alli_call('check_alliance_name',
                                  [new_name, user.alliance_id])
            user.alliance_name = new_name
            if res != 0:
                defer.returnValue(res)
            if c_type == 2:
                res = yield item_use_normal_item(user,
                                                 ItemType=ITEM_TYPE_ITEM,
                                                 ItemID=card_id,
                                                 ItemNum=1)
                left_res = (res[1][0][0], res[1][0][1], res[1][0][2],
                            res[1][0][3])
            else:
                yield user.consume_credits(cost_credits, WAY_TO_NAMED)
        else:
            defer.returnValue(ALLIANCE_UNKNOWN_ERROR)
    else:
        defer.returnValue(NAMED_TYPE_IS_WRONG)

    defer.returnValue([left_res, user.credits])
def plunder(p, req):
    '''
    @summary: 夺宝结算
    '''
    res_err = UNKNOWN_ERROR

    cid, (plunder_cid, shard_id, won) = req

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

    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)

    item_conf = get_item_by_itemid(shard_id)
    treasure_id = 0
    if item_conf:
        _, treasure_id, _ = item_conf['ChangeList'][0]

    response = [0, 0, [], []]

    # 对玩家进行抢夺,免战自动解除
    if plunder_cid > 0:  # 玩家
        yield redis.hdel(HASH_AVOID_WAR_TIME, cid)
        AvoidWarMgr.stop_plunder_shard(treasure_id, plunder_cid)
        _user_plundered = yield gs_offline_login(plunder_cid)
        if _user_plundered:
            reactor.callLater(SESSION_LOGOUT_REAL, gs_offline_logout,
                              plunder_cid)
    else:
        _user_plundered = None

    if won:
        response[3] = yield random_lottery_items(cid, user.level,
                                                 user.base_att.vip_level)
        err, add_items = yield AvoidWarMgr.rand_shard(user, shard_id,
                                                      plunder_cid)

        if not err and (len(add_items) > 0):  #抢到
            response[0] = 1
            response[2] = add_items[0][0], add_items[0][2]
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level,
                      user.alliance_id, 0, won, add_items[0][0],
                      add_items[0][2])
            if _user_plundered:
                ms_send('write_mail',
                        (plunder_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_7,
                         [user.lead_id, user.nick_name, shard_id]))
                yield _user_plundered.bag_treasureshard_mgr.dec_shard(shard_id)
            else:
                log.warn(
                    'No user be plundered. cid: {0}, plunder_cid: {1}.'.format(
                        cid, plunder_cid))
        else:  # 未抢到
            response[0] = 0
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level,
                      user.alliance_id, 0, won, 0, 0)
    else:  # 战斗输了
        if _user_plundered:
            syslogger(LOG_AVOID_WAR, cid, user.level, user.vip_level,
                      user.alliance_id, 0, won, 0, 0)
            ms_send('write_mail',
                    (plunder_cid, MAIL_PAGE_BATTLE, MAIL_BATTLE_6,
                     [user.lead_id, user.nick_name, shard_id]))

    if user.base_att.douzhan >= PVP_NEED_DOUZHAN:
        user.base_att.douzhan -= PVP_NEED_DOUZHAN
    # 每日任务计数
    yield user.daily_quest_mgr.update_daily_quest(DAILY_QUEST_ID_5, 1)
    # 开服七天
    yield user.open_server_mgr.update_open_server_activity_quest(
        OPEN_SERVER_QUEST_ID_8, 1)
    yield user.achievement_mgr.update_achievement_status(
        ACHIEVEMENT_QUEST_ID_8, 1)

    response[1] = user.base_att.douzhan

    defer.returnValue(response)