Exemple #1
0
 def dropPortals(self, portalId, sendList=[]):
     '''删除一个传送门
     @param portalId: int 传送门的id
     '''
     self._portals.remove(portalId)
     if not sendList:
         sendList = self.getSendList()
     pushRemovePlayerInMap(portalId, sendList)
 def dropPortals(self,portalId,sendList = []):
     '''删除一个传送门
     @param portalId: int 传送门的id
     '''
     self._portals.remove(portalId)
     if not sendList:
         sendList = self.getSendList()
     pushRemovePlayerInMap(portalId,sendList)
 def dropMonster(self,monsterId):
     '''移除场景中的一个怪物
     '''
     try:
         del self._monsters[monsterId]
         pushRemovePlayerInMap(monsterId,\
             [PlayersManager().getPlayerByID(player).getDynamicId()\
               for player in self._playerlist])
     except Exception,e:
         log.msg('delete monster %d error! %s'%(monsterId,e))
         return
Exemple #4
0
 def dropMonster(self, monsterId):
     '''移除场景中的一个怪物
     '''
     try:
         del self._monsters[monsterId]
         pushRemovePlayerInMap(monsterId,\
             [PlayersManager().getPlayerByID(player).getDynamicId()\
               for player in self._playerlist])
     except Exception, e:
         log.msg('delete monster %d error! %s' % (monsterId, e))
         return
 def dropPet(self,petId):
     '''移除一个宠物'''
     sendList = self.getSendList()
     pushRemovePlayerInMap(petId, sendList)
 def dropNPC(self,npcId,sendList = []):
     '''移除一个npc'''
     self._npclist.remove(npcId)
     if not sendList:
         sendList = self.getSendList()
     pushRemovePlayerInMap(npcId,sendList)
     sendList = self.getSendList()
     pushRemovePlayerInMap(petId, sendList)
     
 def dropMonster(self,monsterId):
     '''移除场景中的一个怪物
     '''
     try:
         del self._monsters[monsterId]
         pushRemovePlayerInMap(monsterId,\
             [PlayersManager().getPlayerByID(player).getDynamicId()\
               for player in self._playerlist])
     except Exception,e:
         log.msg('delete monster %d error! %s'%(monsterId,e))
         return
     sendList = self.getSendList()
     pushRemovePlayerInMap(monsterId,sendList)
 
 def produceMonster(self,templateId,positionX = 600,positionY =400,\
                    matrixId=100009,rule = []):
     '''产生一个怪物'''
     monster = self.createMonster(templateId)
     monster.baseInfo.setStaticPosition((positionX,positionY))
     monster.setMatrixId(matrixId)
     monster.setRule(rule)
     self.addMonster(monster)
 
 def pushSceneInfo(self,rate):
     '''给每一个在场景中的玩家推送场景信息
     @param rate: int 移动的频率
     '''
     if not self._playerlist:
Exemple #8
0
class BaseScene(object):
    '''基础场景类'''
    def __init__(self, id, type=1, group=0):
        '''
        @param id: int 公共场景的id
        '''
        self._id = id  #场景的id
        self._name = ''  #场景的名称
        self._type = type  #场景的类型
        self._levelRequired = 1  #场景的等级需求
        self._memberRequired = 500  #场景可容纳人数
        self._height = 500  #场景的高度
        self._width = 2000  #场景的宽度
        self._init_X = 200  #场景进入的初始化x坐标
        self._init_Y = 400  #场景进入的初始化Y坐标
        self._resourceid = 1000  #场景的资源IDER
        self._npclist = []  #场景的npc资源
        self._portals = []  #传送门列表
        self._playerlist = []  #角色列表
        self._canRec = set([])  #能够接受场景消息的角色的ID的列表
        self._monsters = {}  #怪物列表
        self._identitytag = 1001  #怪物动态身份标识
        self._movetag = 0  #怪物移动标识控制怪物移动的频率
        self._group = group
        self.initSceneInfo()

    def initSceneInfo(self):
        '''初始化场景信息'''
        pass

    def getID(self):
        '''获取场景的ID'''
        return self._id

    def getNPC(self):
        '''获取场景中的NPC列表'''
        return self._npclist

    def getInitPosition(self):
        '''获取进入场景的初始坐标'''
        return (self._init_X, self._init_Y)

    def formatSceneInfo(self):
        '''格式化场景信息'''
        sceneInfo = {}
        sceneInfo['id'] = self._id  #场景的ID
        sceneInfo['resourceId'] = self._resourceid  #场景的资源类型
        sceneInfo['sceneType'] = self._type  #场景的类型
        sceneInfo['scenename'] = self._name  #场景的名称
        sceneInfo['npclist'] = [dbNpc.ALL_NPCS.get(npcID) for\
                                 npcID in self._npclist] #场景的npc信息
        sceneInfo['portals'] = [dbPortals.ALL_PORTALS.get(portalId) for\
                                 portalId in self._portals] #场景中传送门的信息
        if self._type == 1:  #公共场景时
            colonizeInfo = ColonizeManage().getCityByCityid(self._id)
            if colonizeInfo:
                sceneInfo['corpsName'] = colonizeInfo.get('gname')
                sceneInfo['rewardCorpsName'] = colonizeInfo.get('pname')
        elif self._type == 2:  #副本场景时
            colonizeInfo = ColonizeManage().getInstanceInfoByid(self._group)
            if colonizeInfo:
                sceneInfo['corpsName'] = colonizeInfo.get('gname')
                sceneInfo['rewardCorpsName'] = colonizeInfo.get('pname')

        return sceneInfo

    def addPlayer(self, playerId):
        '''添加一个角色到当前场景
        @param playerId: int 角色的id
        '''
        if playerId in self._playerlist:
            self.dropPlayer(playerId)
        self._playerlist.append(playerId)
        player = PlayersManager().getPlayerByID(playerId)  #根据角色id获取角色实例
        if player:
            player.quest.setNpcList(self.getNPC())
            dyid = player.getDynamicId()
            sendList = [dyid]
            initx = self._init_X + random.randint(-GAPX, GAPX)
            inity = self._init_Y + random.randint(-GAPY, GAPY)
            player.baseInfo.initPosition((initx, inity))
            self.pushEnterPlace(sendList)

    def pushEnterPlace(self, sendList):
        '''推送进入场景的信息'''
        sceneInfo = self.formatSceneInfo()
        pushEnterPlace_new(sceneInfo, sendList)

    def dropPlayer(self, playerId, sendList=[]):
        '''清除场景中的角色
        @param playerId: int 角色的id
        '''
        try:
            if playerId in self._playerlist:
                self._playerlist.remove(playerId)
                log.msg("scene drop player playerId")
                self._canRec.remove(playerId)
                log.msg("scene canRec drop player playerId")
        except Exception, e:
            log.msg(e)
        if not sendList:
            sendList = self.getSendList()
        pushRemovePlayerInMap(playerId, sendList)
Exemple #9
0
 def dropPet(self, petId):
     '''移除一个宠物'''
     sendList = self.getSendList()
     pushRemovePlayerInMap(petId, sendList)
Exemple #10
0
 def dropNPC(self, npcId, sendList=[]):
     '''移除一个npc'''
     self._npclist.remove(npcId)
     if not sendList:
         sendList = self.getSendList()
     pushRemovePlayerInMap(npcId, sendList)
Exemple #11
0
        sendList = self.getSendList()
        pushRemovePlayerInMap(petId, sendList)

    def dropMonster(self, monsterId):
        '''移除场景中的一个怪物
        '''
        try:
            del self._monsters[monsterId]
            pushRemovePlayerInMap(monsterId,\
                [PlayersManager().getPlayerByID(player).getDynamicId()\
                  for player in self._playerlist])
        except Exception, e:
            log.msg('delete monster %d error! %s' % (monsterId, e))
            return
        sendList = self.getSendList()
        pushRemovePlayerInMap(monsterId, sendList)

    def produceMonster(self,templateId,positionX = 600,positionY =400,\
                       matrixId=100009,rule = []):
        '''产生一个怪物'''
        monster = self.createMonster(templateId)
        monster.baseInfo.setStaticPosition((positionX, positionY))
        monster.setMatrixId(matrixId)
        monster.setRule(rule)
        self.addMonster(monster)

    def pushSceneInfo(self, rate):
        '''给每一个在场景中的玩家推送场景信息
        @param rate: int 移动的频率
        '''
        if not self._playerlist:
Exemple #12
0
class BaseMap(object):
    '''基础地图类'''
    def __init__(self, mid):
        '''
        @param id: int 地图的ID
        '''
        self._id = mid  #场景的ID
        self._name = ''  #场景的名称
        self._country = 1  #场景所属的国家
        self._level = 0  #场景进入的等级限制
        self._member_cnt = 500  #场景的最大人数限制
        self._height = 2000  #场景的高度
        self._width = 2000  #场景的宽度
        self._resourceid = 1000  #场景的资源ID
        self._npclist = []  #场景的npc资源
        self._portals = []  #传送门列表
        self._playerlist = set([])  #角色列表
        self._canRec = set([])  #能够接受场景消息的角色的ID的列表
        self._monsters = {}  #场景中的怪物列表
        self._tag = 1000  #怪物的起始ID
        self._movetag = 1  #控制怪物的移动频率
        self._killed = []  #记录被杀死的怪物,一遍下次定时刷怪
        self.initMap()

    def initMap(self):
        '''初始化地图的信息
        '''
        sceneInfo = dbMap.ALL_MAP_INFO.get(self._id)
        if not sceneInfo:
            log.err('map %d does not exist' % self._id)
            return
        self._name = sceneInfo['name']
        self._level = sceneInfo['level']
        self._member_cnt = sceneInfo['member_cnt']
        self._height = sceneInfo['height']
        self._width = sceneInfo['width']
        self._resourceid = sceneInfo['resourceid']
        self._npclist = [npc['id'] for npc in dbNpc.ALL_NPCS.values() \
                                if npc['sceneId']==self._id]
        self._portals = [door['id'] for door in dbMap.ALL_DOOR_INFO.values() \
                                if door['mapid']==self._id]
        self._killed = [(mconfig['id'],0) for mconfig in dbMap.ALL_MAP_MONSTER.values() \
                            if mconfig['map_id'] ==self._id]
        self._mProducers = self.produceMonster()
        self._mProducers.next()

    def getID(self):
        '''获取场景的ID'''
        return self._id

    def getSceneName(self):
        '''获取场景的名称'''
        return self._name

    def getCamp(self):
        '''获取场景所属阵营
        '''
        from app.scense.core.campaign.FortressManager import FortressManager
        f = FortressManager().getFortressBySceneId(self._id)
        if not f:
            return 0
        if not f.isOccupied:
            return 0
        if not f.kimori:
            return 0
        guildId = f.kimori
        return guildId

    def getSceneGuildName(self):
        '''获取城镇占领国的名称
        '''
        from app.scense.core.campaign.FortressManager import FortressManager
        from app.scense.core.guild.GuildManager import GuildManager
        f = FortressManager().getFortressBySceneId(self._id)
        if not f:
            return ''
        if not f.isOccupied:
            return ''
        if not f.kimori:
            return ''
        guildId = f.kimori
        guild = GuildManager().getGuildById(guildId)
        return guild.name

    def getNPCInfoList(self):
        '''获取NPC信息列表
        '''
        guildname = self.getSceneGuildName()
        if not guildname:
            return [npc for npc in dbNpc.ALL_NPCS.values() \
                                if npc['sceneId']==self._id]
        npclist = []
        for npcid in self._npclist:
            npcinfo = dbNpc.ALL_NPCS.get(npcid)
            _npcinfo = dict(npcinfo)
            _npcinfo['name'] = u'【%s】%s' % (guildname, npcinfo['name'])
            npclist.append(_npcinfo)
        return npclist

    def formatSceneInfo(self):
        '''格式化场景信息'''
        sceneInfo = {}
        sceneInfo['id'] = self._id  #场景的ID
        sceneInfo['resourceId'] = self._resourceid  #场景的资源类型
        sceneInfo['sceneType'] = 1  #场景的类型
        sceneInfo['scenename'] = self._name  #场景的名称
        sceneInfo['npclist'] = self.getNPCInfoList()  #场景的npc信息
        sceneInfo['portals'] = [dbMap.ALL_DOOR_INFO.get(portalId) for\
                                 portalId in self._portals] #场景中传送门的信息
        return sceneInfo

    def getSendList(self):
        '''获取可发送的客户端列表'''
        sendList = []
        for pId in self._playerlist:
            pl = PlayersManager().getPlayerByID(pId)
            if pl and (pId in self._canRec) and pl.baseInfo.getStatus() != 4:
                sendList.append(pl.getDynamicId())
        return sendList

    def KilledMonster(self, mconfigId, monstertag):
        '''记录被杀死的怪物
        @param mconfigId: int 被杀死的怪物的配置ID
        '''
        if monstertag < 10:
            self._killed.append((mconfigId, 300))
        else:
            self._killed.append((mconfigId, 10))
        self.dropMonster(monstertag)

    def addMonster(self, monster):
        '''添加一个怪物
        @param monster: Monster instance 怪物的实例
        '''
        if self._monsters.has_key(monster.baseInfo.id):
            raise Exception("系统记录冲突")
        self._monsters[monster.baseInfo.id] = monster
        self._tag += 1

    def produceMonster(self):
        '''产生怪物
        '''
        while True:
            mconfigId = yield
            configinfo = dbMap.ALL_MAP_MONSTER.get(mconfigId)
            templateId = configinfo.get('monster')
            position = (configinfo.get('position_x'),
                        configinfo.get('position_y'))
            rule = configinfo.get('rule', [])
            monster = Monster(id=self._tag, templateId=templateId)
            monster.baseInfo.setStaticPosition(position)
            monster.setRule(rule)
            monster.setMconfig(mconfigId)
            self.addMonster(monster)

    def produce(self):
        '''定时生成怪物
        '''
        _killed = []
        for mconfigid, delta in self._killed:
            if delta == 0:
                self._mProducers.send(mconfigid)
            else:
                delta -= 1
                _killed.append((mconfigid, delta))
        self._killed = _killed

    def pushEnterPlace(self, sendList):
        '''推送进入场景的信息
        '''
        sceneInfo = self.formatSceneInfo()
        response = EnterSceneMessage_605_pb2.EnterSceneMessage()
        response.sceneId = sceneInfo.get('id', 0)
        response.resourceId = sceneInfo.get('resourceId', 0)
        response.sceneType = sceneInfo.get('sceneType', 0)
        response.scenename = sceneInfo.get('scenename', u'')
        response.corpsName = sceneInfo.get('corpsName', Lg().g(601))
        response.rewardCorpsName = sceneInfo.get('rewardCorpsName',
                                                 Lg().g(601))
        npclist = response.npclist
        for npc in sceneInfo.get('npclist', []):
            if not npc:
                continue
            npcInfo = npclist.add()
            npcInfo.npcId = npc['id']
            npcInfo.npcName = npc['name']
            npcInfo.resourceId = npc['resourceid']
            npcInfo.funcType = npc['featureType']
            npcInfo.positionX = npc['position_X']
            npcInfo.positionY = npc['position_Y']
        portals = response.portals
        for portal in sceneInfo['portals']:
            if not portal:
                continue
            portalInfo = portals.add()
            portalInfo.portalId = portal['id']
            portalInfo.portalName = portal['name']
            portalInfo.funcType = portal['functionType']
            portalInfo.positionX = portal['position_x']
            portalInfo.positionY = portal['position_y']
            portalInfo.resourceId = portal['resourceId']
        msg = response.SerializeToString()
        pushApplyMessage(605, msg, sendList)

    def addPlayer(self, playerId):
        '''添加一个角色到当前场景
        @param playerId: int 角色的id
        '''
        self._playerlist.add(playerId)
        self.checkPlayerCamp(playerId)

    def checkPlayerCamp(self, playerId):
        '''检测角色的阵营是否属于本场景,不是发出警告
        '''
        player = PlayersManager().getPlayerByID(playerId)
        camp = player.guild.getID()
        mapCamp = self.getCamp()
        if camp != 0 and camp != mapCamp and mapCamp != 0:  #发出警告
            guildname = player.guild.getGuildName()
            nickname = player.baseInfo.getName()
            pushSystemInfo(u'%s国的【%s】进入%s境内' %
                           (guildname, nickname, self._name))

    def dropPlayer(self, playerId, sendList=[]):
        '''清除场景中的角色
        @param playerId: int 角色的id
        '''
        try:
            if playerId in self._playerlist:
                self._playerlist.remove(playerId)
                self._canRec.remove(playerId)
        except Exception, e:
            log.msg(e)
        if not sendList:
            sendList = self.getSendList()
        pushRemovePlayerInMap(playerId, sendList)