Beispiel #1
0
    def post(self):
        bodyData = self.request.body
        dictData = MessageTools.decode(bodyData)
        token = dictData.get('token')
        result = dictData.get('result', 0)
        targetID = dictData.get('target_id')
        lowRank = dictData.get('lowRank',0)
        tap_count = dictData.get('tap_count')
        crital_count = dictData.get('crital_count')
        target_hp = dictData.get('target_hp',0)  # the data need verify.
        player = playerDataManager.getPlayerByToken(token)
        returnDict = {}
        returnData = MessData()



        if player == None:
            returnData = MessData(ErrorCode.tokenOutData)
        elif player.player_id == targetID:
            returnData = MessData(ErrorCode.cannotAttackYourself)
        elif not pvpDataManger.fightFinished(player.player_id,targetID):
                returnData = MessData(ErrorCode.fightTargetNotMatch)
        elif self.verifyPVPFight(tap_count,crital_count,player,target_hp):
            # 玩家connect id检测
            connect_id = dictData.get('connect_id', '')    # 玩家连接id
            ck_connectid = playerDataManager.check_connect_id(obj=player, post_connect_id=connect_id)
            if ck_connectid[0] is False:
                returnData = MessData(ck_connectid[1])
                self.write(MessageTools.encode(returnData))
                self.finish()
                return

            if result == 1 and lowRank == 0:
                rankManager.pvpWin(player.player_id,targetID)
            else:
                pass
            fightRewards = pvpFightRewardTable.getPvpFightRewardByResult(result)
            for reward in fightRewards:
                type = reward.type
                value = reward.value
                player.addResource(type,value)

            rank_num = rankManager.getRankNumByPlayerid(player.player_id)
            target_num = rankManager.getRankNumByPlayerid(targetID)
            self.saveResult(player.player_id,targetID,result,rank_num,target_num,lowRank)
            rankList = rankManager.getRankList(rank_num)
            returnDict['rank_num'] = rank_num
            returnDict['rankList'] = rankList
            returnData.data = returnDict
        else:
            returnData = MessData(ErrorCode.pvpVerifyError)
        str = MessageTools.encode(returnData,False)
        self.write(str)
        self.finish()
    def get(self):
        bodyData = self.get_argument('data')
        print('data:%s' % bodyData)
        dictData = MessageTools.decode(bodyData)
        token = dictData.get('token')
        player = playerDataManager.getPlayerByToken(token)

        returnData = MessData()
        if player == None:
            returnData = MessData(ErrorCode.tokenOutData)
        elif player.getSkillInfo(7).skillLevel == 0 and player.getSkillInfo(0).skillLevel < static.pvp_level_limit:
            returnData = MessData(ErrorCode.pvpNOTUnlockNow)
        else:
            # Íæ¼Òconnect id¼ì²â
            connect_id = dictData.get('connect_id', '')    # Íæ¼ÒÁ¬½Óid
            ck_connectid = playerDataManager.check_connect_id(obj=player, post_connect_id=connect_id)
            if ck_connectid[0] is False:
                returnData = MessData(ck_connectid[1])
                self.write(MessageTools.encode(returnData))
                self.finish()
                return

            player_id = player.player_id
            if not rankManager.checkPlayerInRanking(player_id):
                rankManager.addRank(player_id)

            rank_num = rankManager.getRankNumByPlayerid(player_id)

            rankList = rankManager.getRankList(rank_num)
            pvpDataManger.addTargetList(player_id,rankList)
            # for pvpPlayerInfoInRanking in rankList:
            #     if pvpPlayerInfoInRanking.player_id == player_id:
            #         rankList.remove(pvpPlayerInfoInRanking)

            rankData = {}
            rankData['rank_num'] = rank_num
            rankData['rankList'] = rankList
            returnData.data = rankData
        str = MessageTools.encode(returnData,False)

        self.write(str)
        self.finish()
    def post(self):
        bodyData = self.request.body
        dictData = MessageTools.decode(bodyData)
        token = dictData.get('token')
        player = playerDataManager.getPlayerByToken(token)

        returnData = MessData()
        if player == None:
            returnData = MessData(ErrorCode.tokenOutData)
        # elif player.getSkillInfo(7).skillLevel == 0 and player.getSkillInfo(0).skillLevel < 60:
        #         returnData = MessData(ErrorCode.pvpNOTUnlockNow)
        else:
            # Íæ¼Òconnect id¼ì²â
            connect_id = dictData.get('connect_id', '')    # Íæ¼ÒÁ¬½Óid
            ck_connectid = playerDataManager.check_connect_id(obj=player, post_connect_id=connect_id)
            if ck_connectid[0] is False:
                returnData = MessData(ck_connectid[1])
                self.write(MessageTools.encode(returnData))
                self.finish()
                return

            player_id = player.player_id
            if not rankManager.checkPlayerInRanking(player_id):
                rankManager.addRank(player_id)

            rank_num = rankManager.getRankNumByPlayerid(player_id)

            rankList = rankManager.getTopRankList()

            rankData = {}
            rankData['rank_num'] = rank_num
            rankData['rankList'] = rankList
            returnData.data = rankData
        str = MessageTools.encode(returnData,False)

        self.write(str)
        self.finish()