예제 #1
0
def processTransferPointOpsReq(session, msg):
    print('processTransferPointOpsReq', msg)
    player = session.player
    destCfg = MapMgr.getMapMgr().getTransferPointCfg(msg.cfgid)
    if not destCfg:
        session.sendMsg(
            MsgDef.ServerCmd.ERROR_MSG,
            buildErrMsg(MsgDef.ClientCmd.TRANSFER_POINT_OPS,
                        Base.lang('传送点不存在')))
        return
    #添加player到地图管理器中
    mapObj = MapMgr.getMapMgr().allocMap(destCfg.tomapid)
    if not mapObj:
        ffext.error('processTransferPointOpsReq %s not exist' %
                    (str(destCfg.tomapid)))
        session.sendMsg(
            MsgDef.ServerCmd.ERROR_MSG,
            buildErrMsg(MsgDef.ClientCmd.TRANSFER_POINT_OPS,
                        Base.lang('传送点不存在!')))
        return
    # if msg.cfgid == 7:#TODO
    #     from model.copymap import TestCopy
    #     mapObj = TestCopy.create(destCfg.tomapid)
    ffext.dump('transfer ', mapObj.mapname, mapObj.showName)
    if mapObj.showName.find('副本') >= 0:
        player.taskCtrl.trigger(Base.Action.COPY_MAP, int(mapObj.mapname), 1)
    mapObj.playerEnterMap(player, destCfg.tox, destCfg.toy)
    return
예제 #2
0
 def _doClear(self):
     # 释放副本,直接全部传出
     MapMgr.getMapMgr().closeCopyMap(self.mapname, '10001', 74, 35)
     self.attackGuild = None
     self.defendGuild = None
     self.statueMonster = None
     self.startTime = 0
예제 #3
0
 def onEnd(self):
     ffext.dump('CopyMapHandler onEnd', self.mapname)
     mapObj = MapMgr.getMapMgr().allocMap(self.mapname)
     ffext.dump('CopyMapHandler mapObj.allPlayer', len(mapObj.allPlayer))
     for k, v in mapObj.allPlayer.iteritems():
         v.sendMsg(MsgDef.ServerCmd.COPYMAP_END, MsgDef.CopymapEndRet(0, 0, 0, []))
     MapMgr.getMapMgr().closeCopyMap(self.mapname, '10001', 47, 171)
예제 #4
0
 def onEnd(self):
     ffext.dump('CopyMapHandler onEnd', self.mapname)
     mapObj = MapMgr.getMapMgr().allocMap(self.mapname)
     ffext.dump('CopyMapHandler mapObj.allPlayer', mapObj.getPlayerNum())
     #for k, v in mapObj.allPlayer.iteritems():
     #    v.sendMsg(MsgDef.ServerCmd.COPYMAP_END, MsgDef.CopymapEndRet(0, 0, 0, []))
     MapMgr.getMapMgr().closeCopyMap(self.mapname, '10001', 74, 35)
     self.guildInfo.closeCopyMap()
예제 #5
0
def processEnterMapReq(session, msg, flagLogin=False):
    print('processEnterMapReq', msg)

    player = session.player

    player.mapname = msg.mapname
    #添加player到地图管理器中
    mapObj = MapMgr.getMapMgr().allocMap(player.mapname)
    if not mapObj:
        mapObj = MapMgr.getMapMgr().getDefaultMap(player)
    mapObj.playerEnterMap(player, msg.x, msg.y)

    return
예제 #6
0
 def cb():
     player = playerref()
     if not player:
         return
     if not player.isDeath():
         return
     player.hp = int(player.hpMax * 10 / 100)
     x = player.x
     y = player.y
     mapObj = player.mapObj
     if mapObj.cfg.reviveMap != None:
         mapName = mapObj.cfg.reviveMap.mapname
         x = mapObj.cfg.reviveMap.x
         y = mapObj.cfg.reviveMap.y
         mapObj = MapMgr.getMapMgr().allocMap(mapName)
         #ffext.info('reborn name=%s, offlineMap=%s, x=%d, y=%d' % (player.name, player.mapname, x, y))
     #发送重生消息
     retMsg = buildPlayerInfoRet(player)
     retMsg.mapname = mapObj.mapname
     retMsg.x = x
     retMsg.y = y
     player.sendMsg(MsgDef.ServerCmd.REBORN, MsgDef.RebornRet(retMsg))
     mapObj.playerEnterMap(player, x, y, False)
     #ffext.info('reborn2 name=%s, offlineMap=%s, x=%d, y=%d' % (player.name, player.mapname, x, y))
     # 角色重生也要出发到副本
     if mapObj.copyMapHandler:
         try:
             mapObj.copyMapHandler.handlePlayerRevive(mapObj, player)
         except:
             ffext.error(
                 'mapObj.copyMapHandler.handlePlayerRevive failed mapname=%s player=%s'
                 % (mapObj.mapname, player.name))
     return
예제 #7
0
def create(attackGuild, defendGuild, mgr, srcMap=CITYWAR_MAP_ID):
    ffext.dump(__name__, srcMap)
    h = CityWarCopy(attackGuild, defendGuild, mgr)
    mapObj = MapMgr.getMapMgr().createCopyMap(srcMap, h)
    h.mapname = mapObj.mapname

    return mapObj
예제 #8
0
def create(srcMap = '10002'):
    ffext.dump(__name__, srcMap)
    h = ArenaCopy()
    mapObj = MapMgr.getMapMgr().createCopyMap(srcMap, h)
    h.mapname = mapObj.mapname
    
    return mapObj
예제 #9
0
def create(guildInfo, srcMap='10002'):
    ffext.dump(__name__, srcMap)
    h = GuildCopy(guildInfo)
    mapObj = MapMgr.getMapMgr().createCopyMap(srcMap, h)
    h.mapname = mapObj.mapname

    return mapObj
예제 #10
0
def create(srcMap='10002'):
    ffext.dump(__name__, srcMap)
    h = TestCopy()
    mapObj = MapMgr.getMapMgr().createCopyMap(srcMap, h)
    h.mapname = mapObj.mapname
    for k in MonsterModel.getMonsterMgr().mnstergen:
        MonsterModel.genMonster(mapObj.mapname, k[1], k[2], k[3], k[4], k[5],
                                k[6])
        break
    return mapObj
예제 #11
0
def genMonster(mapName,
               monName,
               x,
               y,
               num,
               rangeMax,
               rebornSec=10,
               autoattackFlag=0):
    ret = []
    propCfg = getMonsterMgr().getCfgByName(monName)
    if not propCfg:
        ffext.error('propCfg not found mosntername=%s' % (monName))
        return ret
    mapObj = MapMgr.getMapMgr().allocMap(mapName)
    if None == mapObj:
        ffext.error('mon gen map failed %s %s %d %d %d %d' %
                    (mapName, monName, x, y, num, rangeMax))
        return ret
    for i in range(num):
        mon = Monster(propCfg)
        #mon.showName = monName
        mon.aiFlag = autoattackFlag
        mon.bornX = x
        mon.bornY = y
        rangeMinX = -1 * rangeMax
        if mon.bornX + rangeMinX < 0:
            rangeMinX = -1 * mon.bornX
        rangeMinY = -1 * rangeMax
        if mon.bornY + rangeMinY < 0:
            rangeMinY = -1 * mon.bornY
        newPos = None
        for kk in range(rangeMax * rangeMax):
            x = mon.bornX + random.randint(rangeMinX, rangeMax)
            y = mon.bornY + random.randint(rangeMinY, rangeMax)

            bFlag = mapObj.canMove(x, y)
            if bFlag:
                mon.bornX = x
                mon.bornY = y
                break

        if not mapObj.monsterEnterMap(mon, mon.bornX, mon.bornY):
            ffext.error(
                'mon gen pos failed %s %s %d %d %d %d' %
                (mapName, monName, mon.bornX, mon.bornY, num, rangeMax))
            continue
        mon.fsm.changeState(ffext.singleton(MonsterAI.StateIdle))
        mon.rebornSec = rebornSec
        #print('genMonster=%s'%(mon))
        ffext.info('genMonster name=%s,map=%s,x=%d,y=%d' %
                   (monName, mapName, x, y))
        ret.append(mon)
    return ret
예제 #12
0
def processCreateRoleReq(session, msg):
    print('CreateRoleReq', msg)
    if msg.gender != Base.Gender.MALE and msg.gender != Base.Gender.FEMAIL:
        msg.gender = Base.Gender.MALE
    roleTmp = PlayerModel.Role()
    roleTmp.uid = idtool.allocUid()
    if session.isWebDebug:
        msg.name = msg.name.encode('utf-8')
    roleTmp.name = msg.name
    roleTmp.job = msg.job
    roleTmp.gender = msg.gender
    if roleTmp.gender != Base.Gender.MALE and roleTmp.gender != Base.Gender.FEMAIL:
        roleTmp.gender = Base.Gender.MALE

    if roleTmp.job < Base.Job.ZHANSHI or roleTmp.job > Base.Job.YOUXIA:
        roleTmp.job = Base.Job.ZHANSHI

    def callback(db):
        retMsg = MsgDef.CreateRoleRet()
        if db.isOk():
            retMsg.flag = True
            retMsg.uid = roleTmp.uid
            session.user.addRole(roleTmp)
        else:
            retMsg.flag = False
            retMsg.errMsg = '角色名已经存在'
        session.sendMsg(MsgDef.ServerCmd.CREATE_ROLE_RET, retMsg)
        MailModel.createMailRecrodAtFirstTime(roleTmp.uid)
        # 新增每日活动记录
        DbService.getPlayerService().createDailyLoginAct(
            session.user.accountid)
        if retMsg.flag == True:
            # 创角(old)-记录log
            LogModel.logLoginData(session.user.accountid, roleTmp.uid,
                                  roleTmp.name,
                                  LogModel.LoginOpType.CREATE_PLAYER, 0)

    mapName = 10001
    x = 27
    y = 188
    mapObj = MapMgr.getMapMgr().allocMap(mapName)
    if mapObj.cfg.reviveMap != None:
        mapName = mapObj.cfg.reviveMap.mapname
        x = mapObj.cfg.reviveMap.x
        y = mapObj.cfg.reviveMap.y

    DbService.getPlayerService().createRole(session.user, roleTmp, mapName, x,
                                            y, callback)
    return
예제 #13
0
    def onTimer(self):
        #print ('Ontimer', __name__)
        nowMs = ffext.getTimeMs()
        allMap = MapMgr.getMapMgr().allMap
        for mapName, mapObj in allMap.iteritems():
            if mapObj.getPlayerNum() <= 0:
                if nowMs - mapObj.lastMonsterUpdateMs >= 10 * 1000:
                    continue
            else:
                mapObj.lastMonsterUpdateMs = nowMs
            allMonster = [v for k, v in mapObj.allMonter.iteritems()]
            for monster in allMonster:
                monster.fsm.update(monster, nowMs)

        return True
예제 #14
0
파일: NpcModel.py 프로젝트: fanchy/spython
    def init(self):  #读取任务配置
        name2DuiBai = self.readdNpcDuibaiCfg()
        db = ffext.allocDbConnection('cfg', ffext.getConfig('-cfg'))
        ret = db.queryResult(
            'select name,appr,mapid,x,y,script,direction,cfgid from npc')
        self.allCfg = {}
        for row in ret.result:
            npcCfg = NpcCfg()
            npcCfg.name = row[0]
            npcCfg.appr = int(row[1])
            npcCfg.mapname = row[2]
            npcCfg.x = int(row[3])
            npcCfg.y = int(row[4])
            npcCfg.script = row[5]
            npcCfg.direction = int(row[6])
            npcCfg.cfgid = int(row[7])
            npcCfg.defaultDuiBai = name2DuiBai.get(npcCfg.name,
                                                   '勇士你好!我是%s' % (npcCfg.name))
            self.allCfg[npcCfg.cfgid] = npcCfg
            mapObj = MapMgr.getMapMgr().allocMapByFile(npcCfg.mapname)
            if not mapObj:
                ffext.warn(
                    'gen npc failed name=%s, script=%s, map=%s not in this gs'
                    % (npcCfg.name, npcCfg.script, npcCfg.mapname))
            #ffext.dump('load npc ', npcCfg)
            npc = Npc()
            npc.name = npcCfg.name
            npc.appr = npcCfg.appr
            npc.mapname = npcCfg.mapname
            npc.script = npcCfg.script
            npc.direction = npcCfg.direction
            npc.cfg = npcCfg
            try:
                npc.scriptMod = __import__('npc.' + npc.script,
                                           fromlist=[npc.script])

            except:
                ffext.error(
                    'gen npc failed name=%s, script=%s map=%s,%d,%d' %
                    (npc.name, npc.script, npcCfg.mapname, npcCfg.x, npcCfg.y))
            try:
                mapObj.npcEnterMap(npc, npcCfg.x, npcCfg.y)
            except:
                ffext.error(
                    'gen npc failed2 name=%s, script=%s map=%s,%d,%d' %
                    (npc.name, npc.script, npcCfg.mapname, npcCfg.x, npcCfg.y))
        ffext.dump('load npc num=%d' % (len(self.allCfg)))
        return True
예제 #15
0
def jump(session, args):
    if len(args) < 2:
        ret_msg.chatMsg = '参数 @jump mapi x y'
        session.player.sendMsg(MsgDef.ServerCmd.CHAT_MSG, ret_msg)
        return
    mapname = args[1]
    x = None
    y = None
    if len(args) >= 4:
        x = int(args[2])
        y = int(args[3])
    mapObj = MapMgr.getMapMgr().allocMap(mapname)
    if not mapObj:
        ret_msg.chatMsg = '地图不存在'
        session.player.sendMsg(MsgDef.ServerCmd.CHAT_MSG, ret_msg)
        return
    mapObj.playerEnterMap(session.player, x, y)
예제 #16
0
def transfer(session, msg):
    mapname = msg.cfgid
    mapObj = MapMgr.getMapMgr().allocMap(mapname)
    mapObj.playerEnterMap(session.player, msg.x, msg.y, True)
예제 #17
0
def processListFriend(session, msg):
    #声明好友列表以FriendListMsgRet格式传输,客户端识别指令为FRIENDLIST_MSG传输格式
    #print(msg)
    ret_msg = MsgDef.FriendListMsgRet()
    ret_msg.opstype = msg.opstype
    ret_msg.allPlayerInfo = []
    ret_msg.allEnemyInfo = []
    ret_msg.allShieldInfo = []
    if msg.opstype == MsgDef.FriendListClientCmd.GET_FRIENDLIST:
        online = True
        #遍历allFriend字典,获取好友属性
        for uid, val in session.player.friendCtrl.getFriend().iteritems():
            if None == ffext.getSessionMgr().findByUid(val.uid):
                online = False
            else:
                online = True
            #将好友信息赋值,传递给客户端
            ret_msg.allPlayerInfo.append(
                processFriendPlayerMsg(val.uid, val.name, val.job, val.gender,
                                       val.level, online))
        for uid, val in session.player.friendCtrl.getEnemy().iteritems():
            if None == ffext.getSessionMgr().findByUid(val.uid):
                online = False
            else:
                online = True
            #将仇人信息赋值,传递给客户端
            ret_msg.allEnemyInfo.append(
                processFriendPlayerMsg(val.uid, val.name, val.job, val.gender,
                                       val.level, online))
        for uid, val in session.player.friendCtrl.getShieldPerson().iteritems(
        ):
            if None == ffext.getSessionMgr().findByUid(val.uid):
                online = False
            else:
                online = True
            #将屏蔽信息赋值,传递给客户端
            ret_msg.allShieldInfo.append(
                processFriendPlayerMsg(val.uid, val.name, val.job, val.gender,
                                       val.level, online))
        session.sendMsg(MsgDef.ServerCmd.FRIENDLIST_MSG, ret_msg)
        return
    # if msg.opstype == MsgDef.FriendListClientCmd.GET_FRIENDLIST_TEMP:
    #     #遍历allFriend字典,获取好友属性
    #     for uid, val in session.player.friendCtrl.getFriendTemp().iteritems():
    #         ret_msg.allPlayerInfo.append(processFriendPlayerMsg(val.uid, val.name))
    #     session.sendMsg(MsgDef.ServerCmd.FRIENDLIST_MSG, ret_msg)
    #     return
    #仇人追击
    if msg.opstype == MsgDef.FriendListClientCmd.GET_ENEMY:
        enemyUid = msg.uid
        for uid, val in session.player.friendCtrl.getEnemy().iteritems():
            if uid == enemyUid:
                enemyPlayer = ffext.getSessionMgr().findByUid(enemyUid).player
                if None == enemyPlayer:
                    online = False
                    retErr = Base.lang('仇人处于离线状态!')
                    session.sendMsg(
                        MsgDef.ServerCmd.ERROR_MSG,
                        buildErrMsg(MsgDef.FriendListClientCmd.GET_ENEMY,
                                    retErr))
                    return
                else:
                    online = True
                    ret_msg.allEnemyInfo.append(
                        processFriendPlayerMsg(val.uid, val.name, val.job,
                                               val.gender, val.level, online,
                                               enemyPlayer.mapname,
                                               enemyPlayer.x, enemyPlayer.y))
                    session.sendMsg(MsgDef.ServerCmd.FRIENDLIST_MSG, ret_msg)
                    return
        else:
            retErr = Base.lang('仇人不存在!')
            session.sendMsg(
                MsgDef.ServerCmd.ERROR_MSG,
                buildErrMsg(MsgDef.FriendListClientCmd.GET_ENEMY, retErr))
            return
    if msg.opstype == MsgDef.FriendListClientCmd.JUMP_ENEMY:
        enemyUid = msg.uid
        for uid, val in session.player.friendCtrl.getEnemy().iteritems():
            if uid == enemyUid:
                enemyPlayer = ffext.getSessionMgr().findByUid(enemyUid).player
                if None == enemyPlayer:
                    online = False
                    retErr = Base.lang('仇人处于离线状态!')
                    session.sendMsg(
                        MsgDef.ServerCmd.ERROR_MSG,
                        buildErrMsg(MsgDef.FriendListClientCmd.GET_ENEMY,
                                    retErr))
                    return
                else:
                    online = True
                    mapname = enemyPlayer.mapname
                    x = enemyPlayer.x
                    y = enemyPlayer.y
                    mapObj = MapMgr.getMapMgr().allocMap(mapname)
                    if not mapObj:
                        retErr = Base.lang('地图不存在!')
                        session.sendMsg(
                            MsgDef.ServerCmd.ERROR_MSG,
                            buildErrMsg(MsgDef.FriendListClientCmd.JUMP_ENEMY,
                                        retErr))
                        return
                    mapObj.playerEnterMap(session.player, x, y)
                    return
        else:
            retErr = Base.lang('仇人不存在!')
            session.sendMsg(
                MsgDef.ServerCmd.ERROR_MSG,
                buildErrMsg(MsgDef.FriendListClientCmd.GET_ENEMY, retErr))
            return