Exemplo n.º 1
0
 def arenaClearing(self, battle_result):
     """战斗结束
     """
     if battle_result == 1:
         self._owner.coin += 10
         self._owner.score += 10
     else:
         self._owner.coin += 10
         self._owner.score += 10
     characterId = self._owner.cid
     mcha = Mcharacter(characterId, 'character%d' % characterId, mclient)
     mcha.update("score", self._owner.score)
 def arenaClearing(self,battle_result):
     """战斗结束
     """
     if battle_result==1:
         self._owner.coin+=10
         self._owner.score+=10
     else:
         self._owner.coin+=10
         self._owner.score+=10
     characterId = self._owner.cid
     mcha = Mcharacter(characterId,'character%d'%characterId,mclient)
     mcha.update("score", self._owner.score)
Exemplo n.º 3
0
 def creatNewCharacter(self ,nickname):
     '''创建新角色
     '''
     if len(nickname)<2 or len(nickname)>20:
         return {'result':False,'message':u'yhm_buhege'}
     if self.characterId:
         return {'result':False,'message':u'yijingchuangjian'}
     if not dbuser.checkCharacterName(nickname):
         return {'result':False,'message':u'yhm_yicunzai'}
     characterId = dbuser.creatNewCharacter(nickname, self.id)
     if characterId:
         self.characterId = characterId
         data = {}
         data['userId'] = self.id
         data['newCharacterId'] = characterId
         cinfo = {"id":characterId,"nickname":nickname,"score":0}
         mcha = Mcharacter(characterId,'character%d'%characterId,mclient)
         mcha.initData(cinfo)
         mcha.insert()
         return {'result':True,'message':u'创建角色成功','data':data}
     else:
         return {'result':False,'message':u'创建角色失败'}
Exemplo n.º 4
0
    def getRivalList(self):
        '''获取对手列表
        '''
        all_character_list = dbuser.getAllCharacterIdList()
        all_character_info_list = [Mcharacter(_cid,'character%d'%_cid,mclient).mcharacterinfo for \
                                    _cid in all_character_list]
        all_character_info_list = sorted(all_character_info_list,reverse=True,\
                            key = lambda d:d['score'])
        rival_list = []
        if len(all_character_info_list) <= MEM_CNT:
            for rival in all_character_info_list:
                info = rival
                info['ranking'] = all_character_info_list.index(rival)
                rival_list.append(info)
        else:
            for i in range(3):
                info = all_character_info_list[i]
                info['ranking'] = i + 1
                rival_list.append(info)
            index = 1
            for rival in all_character_info_list:
                if self._owner.cid == rival['id']:
                    index = all_character_info_list.index(rival) + 1
                    continue
            if index <= MEM_CNT:
                for i in range(3, MEM_CNT):
                    info = all_character_info_list[i]
                    info['ranking'] = i + 1
                    rival_list.append(info)
            else:
                for i in range(index - (MEM_CNT - 3), index):
                    info = all_character_info_list[i]
                    info['ranking'] = i + 1
                    rival_list.append(info)

        return rival_list
Exemplo n.º 5
0
 def creatNewCharacter(self, nickname):
     '''创建新角色
     '''
     if len(nickname) < 2 or len(nickname) > 20:
         return {'result': False, 'message': u'yhm_buhege'}
     if self.characterId:
         return {'result': False, 'message': u'yijingchuangjian'}
     if not dbuser.checkCharacterName(nickname):
         return {'result': False, 'message': u'yhm_yicunzai'}
     characterId = dbuser.creatNewCharacter(nickname, self.id)
     if characterId:
         self.characterId = characterId
         data = {}
         data['userId'] = self.id
         data['newCharacterId'] = characterId
         cinfo = {"id": characterId, "nickname": nickname, "score": 0}
         mcha = Mcharacter(characterId, 'character%d' % characterId,
                           mclient)
         mcha.initData(cinfo)
         mcha.insert()
         return {'result': True, 'message': u'创建角色成功', 'data': data}
     else:
         return {'result': False, 'message': u'创建角色失败'}