def applyQuest(self,taskId,taskType = 1):
     '''接受任务
     @param taskId: int 任务的id
     '''
     allMainTask = dbtask.ALL_MAIN_TASK
     allExtenTask = dbtask.ALL_EXTEN_TASK
     if taskId < 20000:
         taskInfo = allMainTask.get(taskId)
     else:
         taskInfo = allExtenTask.get(taskId)
     characterId = self._owner.baseInfo.id
     if not self.canReceived(taskId):
         return {'result':False,'message':Lg().g(444),\
                 'task_id':taskId}
     task = Quest(taskId,characterId = characterId)
     task.setProfession(self._owner.profession.getProfession())
     result = self.giveItemHandle(taskId)
     if not result.get('result'):
         return result
     res = task.InsertProcess()
     if res:
         if res and taskType==1:
             self._tasks[taskId] = task
         self.pushPlayerScenceNpcQuestStatus()
         self.pushPlayerQuestProcessList()
         return {'result':True,'message':Lg().g(445)%taskInfo['taskName'],\
                 'task_id':taskId}
     return {'result':False,'message':Lg().g(444),\
             'task_id':taskId}
 def giveItemHandle(self,taskId,taskType = 1):
     '''接受任务时给予物品的处理'''
     taskInfo = Quest( taskId)
     taskInfo.setProfession(self._owner.profession.getProfession())
     giveitems = taskInfo.resolveGiveItem()
     package = self._owner.pack._package.getPackageByType(1)
     bagCnt = package.findSparePositionNum()#包裹的格子剩余数量
     if len(giveitems)>bagCnt:
         return {'result':False,'message':Lg().g(16)}
     for item in giveitems:
         self._owner.pack.putNewItemInPackage(item)
     return {'result':True}
 def getCanReceivedQuestList(self):
     '''获取可接任务列表'''
     canReceivedQuestList = []
     lastMainTaskId =  self._MainRecord.get('mainRecord',10000)
     recordStatus = self._MainRecord.get('status',1)
     nowMainTaskId = lastMainTaskId
     if recordStatus:
         nowMainTaskId  = foundNextTaskID(dbtask.ALL_MAIN_TASK.keys(), nowMainTaskId)
     if nowMainTaskId!=lastMainTaskId and self.canReceived(nowMainTaskId):
         taskInfo = Quest( nowMainTaskId, characterId = self._owner.baseInfo.id,status=1)
         taskInfo.setProfession(self._owner.profession.getProfession())
         canReceivedQuestList.append(taskInfo)
     return canReceivedQuestList
 def initCharacterQuest(self):
     '''初始化角色任务'''
     characterId = self._owner.baseInfo.id
     processlist = dbtask.getAllProcessInfo(characterId)
     for process in processlist:
         questId = process.get('taskId')
         if process['finished']:
             self._finished.append(questId)
             continue
         quest = Quest(questId,characterId = self._owner.baseInfo.id)
         quest.initQuestData(process)
         quest.setProfession(self._owner.profession.getProfession())
         self._tasks[questId] = quest
 def formatNpcQuestInfo(self,NpcId,taskId,status,TaskType):
     '''格式化NPC任务信息
     @param taskId: int NPC
     @param NpcId: int NPC的ID
     @param status: int  0非法 1可接  2进行中 3完成
     '''
     npcInfo = dbNpc.ALL_NPCS.get(NpcId)
     if not npcInfo:
         log.err(u'坑爹呢NpcID不正确:%d'%NpcId)
     NpcQuestInfo = {}
     NpcQuestInfo['npc_id'] = NpcId
     NpcQuestInfo['npc_img'] = npcInfo.get('resourceid',0)
     NpcQuestInfo['npc_name'] = npcInfo.get('name',u'配置有误')
     NpcQuestInfo['npc_word'] = npcInfo.get('dialog',u'配置有误,id为%d的NPC不存在'%NpcId)
     NpcQuestInfo['ncp_task_item'] = {}
     if not taskId:
         return NpcQuestInfo
     NpcQuestInfo['ncp_task_item'] = None
     if taskId>0:
         taskInfo = Quest( taskId,status = status)
         taskInfo.setNpcName(npcInfo.get('name',u'配置有误'))
         taskInfo.setRoleName(self._owner.baseInfo.getName())
         taskInfo.setProfession(self._owner.profession.getProfession())
         NpcQuestInfo['ncp_task_item'] = taskInfo
     return NpcQuestInfo
 def autoApplyQuest(self,taskId):
     '''自动接受任务
     '''
     characterId = self._owner.baseInfo.id
     if not self.canReceived(taskId):
         return {'result':False,'message':Lg().g(444),\
                 'task_id':taskId}
     task = Quest(taskId,characterId = characterId)
     task.setProfession(self._owner.profession.getProfession())
     result = self.giveItemHandle(taskId)
     if not result.get('result'):
         return result
     res = task.InsertProcess()
     if res:
         self._tasks[taskId] = task
 def questBoundHandle(self,taskId,taskType = 1):
     '''任务奖励处理
     @param taskId: int 任务的奖励
     '''
     taskInfo = Quest( taskId)
     taskInfo.setProfession(self._owner.profession.getProfession())
     giveitems = taskInfo.resolveItemPrize()
     package = self._owner.pack._package.getPackageByType(1)
     bagCnt = package.findSparePositionNum()#包裹的格子剩余数量
     if len(giveitems)>bagCnt:
         return {'result':False,'message':Lg().g(16)}
     for item in giveitems:
         self._owner.pack.putNewItemInPackage(item)
         self.AfterGetNewEqupment(item)
     exp = taskInfo.format.get('ExpPrize')
     self.getExpBouns(exp)
     coin = taskInfo.format.get('CoinPrize')
     self.getCoinBouns(coin)
     gold = taskInfo.format.get('GoldPrize')
     self.getGoldBouns(gold)
     return {'result':True}
 def applyQuest(self,taskId,taskType = 1):
     '''接受任务
     @param taskId: int 任务的id
     '''
     allMainTask = dbtask.ALL_MAIN_TASK
     taskInfo = allMainTask.get(taskId)
     characterId = self._owner.baseInfo.id
     lastMainTaskId =  self._MainRecord.get('mainRecord',10000)
     if lastMainTaskId==taskId:
         return {'result':False,'message':Lg().g(453),\
                 'task_id':taskId}
     if not taskInfo:
         return {'result':False,'message':Lg().g(454),\
                 'task_id':taskId}
     if not self.canReceived(taskId):
         return {'result':False,'message':Lg().g(444),\
                 'task_id':taskId}
     task = Quest(taskId,characterId = self._owner.baseInfo.id)
     task.setProfession(self._owner.profession.getProfession())
     result = self.giveItemHandle(taskId)
     if not result.get('result'):
         return result
     res = task.InsertProcess()
     if res:
         if res and taskType==1:
             nowdate = datetime.datetime.now()
             props = {'mainRecord':taskId,'applyTime':str(nowdate),\
                      'status':0}
             dbtask.updateMainTaskRecord(characterId, props)
             self._MainRecord = {'mainRecord':taskId,'status':0}
             self._tasks[taskId] = task
         self.pushPlayerScenceNpcQuestStatus()
         self.pushPlayerQuestProcessList()
         return {'result':True,'message':Lg().g(445)%taskInfo['taskName'],\
                 'task_id':taskId}
     return {'result':False,'message':Lg().g(444),\
             'task_id':taskId}
 def initCharacterQuest(self):
     '''初始化角色任务'''
     characterId = self._owner.baseInfo.id
     self._MainRecord = dbtask.getMainTaskRecord(characterId)
     if not self._MainRecord:
         dbtask.InitMainTaskRecord(characterId)
         self._MainRecord = {'mainRecord':10000,'status':1}
     processlist = dbtask.getAllProcessInfo(characterId)
     for process in processlist:
         questId = process.get('taskId')
         quest = Quest(questId,characterId = self._owner.baseInfo.id)
         quest.initQuestData(process)
         quest.setProfession(self._owner.profession.getProfession())
         self._tasks[questId] = quest
 def formatNpcQuestInfo(self,NpcId):
     '''格式化NPC任务信息
     @param tasks: list(int) 任务列表
     @param NpcId: int NPC的ID
     @param status: int  0非法 1可接  2进行中 3完成
     '''
     npcInfo = dbNpc.ALL_NPCS.get(NpcId)
     if not npcInfo:
         log.err(u'坑爹呢NpcID不正确:%d'%NpcId)
         return {}
     NpcQuestInfo = {}
     NpcQuestInfo['npc_id'] = NpcId
     NpcQuestInfo['npc_img'] = npcInfo.get('resourceid',0)
     NpcQuestInfo['npc_name'] = npcInfo.get('name',u'配置有误')
     NpcQuestInfo['npc_word'] = npcInfo.get('dialog',u'配置有误,id为%d的NPC不存在'%NpcId)
     NpcQuestInfo['ncp_task_item'] = []
     tasks = self.getQuestOnNpc(NpcId)
     for taskId in tasks['cancomlist']:
         taskInfo = Quest( taskId,status = TASK_CANCOMMITED)
         taskInfo.setNpcName(npcInfo.get('name',u'配置有误'))
         taskInfo.setRoleName(self._owner.baseInfo.getName())
         taskInfo.setProfession(self._owner.profession.getProfession())
         NpcQuestInfo['ncp_task_item'].append(taskInfo)
     for taskId in tasks['execlist']:
         taskInfo = Quest( taskId,status = TASK_EXEC)
         taskInfo.setNpcName(npcInfo.get('name',u'配置有误'))
         taskInfo.setRoleName(self._owner.baseInfo.getName())
         taskInfo.setProfession(self._owner.profession.getProfession())
         NpcQuestInfo['ncp_task_item'].append(taskInfo)
     for taskId in tasks['canacceptlist']:
         taskInfo = Quest( taskId,status = TASK_ACCEPTABLE)
         taskInfo.setNpcName(npcInfo.get('name',u'配置有误'))
         taskInfo.setRoleName(self._owner.baseInfo.getName())
         taskInfo.setProfession(self._owner.profession.getProfession())
         NpcQuestInfo['ncp_task_item'].append(taskInfo)
     for taskId in tasks['doinglist']:
         taskInfo = Quest( taskId,status = TASK_PROCESSING)
         taskInfo.setNpcName(npcInfo.get('name',u'配置有误'))
         taskInfo.setRoleName(self._owner.baseInfo.getName())
         taskInfo.setProfession(self._owner.profession.getProfession())
         NpcQuestInfo['ncp_task_item'].append(taskInfo)
     return NpcQuestInfo