def doFight(self,characterId):
     '''执行战斗
     @param characterId: int 对手的ID
     '''
     if self.surplustimes<=0:
         return {'result':False,'message':u"竞技场今日战斗次数已满"}
     from app.game.core.character.PlayerCharacter import PlayerCharacter
     from app.game.core.PlayersManager import PlayersManager
     from app.game.core.fight.fight import DoFight
     player = PlayersManager().getPlayerByID(characterId)
     if not player:
         player = PlayerCharacter(characterId)
     nowHp = self._owner.attribute.getHp()
     player.attribute.Restoration()
     self._owner.attribute.Restoration()
     fig = DoFight([self._owner], [player], 1000)
     self.afterFight(fig.battleResult,player)
     self._owner.attribute.setHp(nowHp)
     self.lasttime = datetime.datetime.now()#更新最后战斗的时间
     pid = self._owner.baseInfo.id
     props = {'lasttime':str(self.lasttime)}
     dbarena.updateCharacterArenaInfo(pid, props)
     setData = {'coin':0,'exp':0,'star':0,
                'item':[],'huoli':0}
     return {'result':True,'data':{'fight':fig,'setData':setData}}
 def doFight(self,characterId):
     """执行战斗
     @param characterId: int 对手的ID
     """
     if self.surplustimes<=0:
         return {'result':False,'message':u"竞技场今日战斗次数已满"}
     from app.game.core.character.PlayerCharacter import PlayerCharacter
     from app.game.core.PlayersManager import PlayersManager
     from app.game.core.fight.fight import DoFight
     player = PlayersManager().getPlayerByID(characterId)
     if not player:
         player = PlayerCharacter(characterId)
     nowHp = self._owner.attribute.getHp()
     player.attribute.Restoration()
     self._owner.attribute.Restoration()
     fig = DoFight([self._owner], [player], 1000)
     self.afterFight(fig.battleResult,player)
     self._owner.attribute.setHp(nowHp)
     self.lasttime = datetime.datetime.now()#更新最后战斗的时间
     pid = self._owner.baseInfo.id
     props = {'lasttime':str(self.lasttime)}
     dbarena.updateCharacterArenaInfo(pid, props)
     setData = {'coin':0,'exp':0,'star':0,
                'item':[],'huoli':0}
     return {'result':True,'data':{'fight':fig,'setData':setData}}
 def resetArenaData(self):
     """重置竞技场信息
     """
     characterId = self._owner.baseInfo.id
     self.liansheng = 0
     self.lastresult = 0
     self.surplustimes = 15
     self.buytimes = 0
     self.receive = 0
     self.recorddate = datetime.date.today()
     props = {'recorddate':str(self.recorddate),'liansheng':0,
             'lastresult':0,'surplustimes':15,'buytimes':0,'receive':0}
     dbarena.updateCharacterArenaInfo(characterId, props)
 def resetArenaData(self):
     '''重置竞技场信息
     '''
     characterId = self._owner.baseInfo.id
     self.liansheng = 0
     self.lastresult = 0
     self.surplustimes = 15
     self.buytimes = 0
     self.receive = 0
     self.recorddate = datetime.date.today()
     props = {'recorddate':str(self.recorddate),'liansheng':0,
             'lastresult':0,'surplustimes':15,'buytimes':0,'receive':0}
     dbarena.updateCharacterArenaInfo(characterId, props)
 def receiveAward(self):
     '''获取竞技场奖励
     '''
     if self.receive:  #如果已经领取过,则不再领取
         return False
     self.getRanking()
     coinbound = getRankingCoinBound(self.ranking)
     self._owner.finance.addCoin(coinbound)
     self.receive = 1
     self._owner.icon.removeIcon(self._owner.icon.ARENA_AWARD)
     characterId = self._owner.baseInfo.id
     props = {'receive': self.receive}
     dbarena.updateCharacterArenaInfo(characterId, props)
     return True
 def receiveAward(self):
     """获取竞技场奖励
     """
     if self.receive:#如果已经领取过,则不再领取
         return False
     self.getRanking()
     coinbound = getRankingCoinBound(self.ranking)
     self._owner.finance.addCoin(coinbound)
     self.receive = 1
     self._owner.icon.removeIcon(self._owner.icon.ARENA_AWARD)
     characterId = self._owner.baseInfo.id
     props = {'receive':self.receive}
     dbarena.updateCharacterArenaInfo(characterId, props)
     return True
 def AddSurplustimes(self):
     """添加竞技场剩余次数"""
     reqGold = (self.buytimes+1)*10
     if reqGold>self._owner.finance.getGold():
         return {'result':False,'message':u"您的钻不足,请您充值"}
     self._owner.finance.consGold(reqGold,12)#添加剩余次数
     self.buytimes +=1
     self.surplustimes +=1
     characterId = self._owner.baseInfo.id
     props = {'buytimes':1,'surplustimes':self.surplustimes}
     dbarena.updateCharacterArenaInfo(characterId, props)
     reqCoin = (self.buytimes+1)*10
     info = {'bCount':self.surplustimes,'addCount':self.buytimes,'reqCoin':reqCoin}
     return {'result':True,'data':info}
 def AddSurplustimes(self):
     '''添加竞技场剩余次数'''
     reqGold = (self.buytimes+1)*10
     if reqGold>self._owner.finance.getGold():
         return {'result':False,'message':u"您的钻不足,请您充值"}
     self._owner.finance.consGold(reqGold,12)#添加剩余次数
     self.buytimes +=1
     self.surplustimes +=1
     characterId = self._owner.baseInfo.id
     props = {'buytimes':1,'surplustimes':self.surplustimes}
     dbarena.updateCharacterArenaInfo(characterId, props)
     reqCoin = (self.buytimes+1)*10
     info = {'bCount':self.surplustimes,'addCount':self.buytimes,'reqCoin':reqCoin}
     return {'result':True,'data':info}
 def clearCD(self):
     '''清除竞技场冷却时间
     '''
     CD = self.getCD()
     if CD < 0:
         return {'result': False, 'message': u"竞技场冷却中"}
     reqgold = int(math.ceil(CD * 1.0 / 60))
     if self._owner.finance.getGold() < reqgold:
         return {'result': False}
     self.lasttime = datetime.datetime(2012, 6, 20, 12)
     self._owner.finance.consGold(reqgold, 3)  #竞技场冷却时间
     characterId = self._owner.baseInfo.id
     props = {'lasttime': str(self.lasttime)}
     dbarena.updateCharacterArenaInfo(characterId, props)
     self.pushArenaCD()
     return {'result': True}
 def clearCD(self):
     """清除竞技场冷却时间
     """
     CD = self.getCD()
     if CD<0:
         return {'result':False,'message':u"竞技场冷却中"}
     reqgold = int(math.ceil(CD*1.0/60))
     if self._owner.finance.getGold()<reqgold:
         return {'result':False}
     self.lasttime = datetime.datetime(2012,6,20,12)
     self._owner.finance.consGold(reqgold,3)#竞技场冷却时间
     characterId = self._owner.baseInfo.id
     props = {'lasttime':str(self.lasttime)}
     dbarena.updateCharacterArenaInfo(characterId, props)
     self.pushArenaCD()
     return {'result':True}
 def afterFight(self, result, toplayer):
     '''战斗结果处理
     '''
     self._owner.finance.addCoin(500, state=0)
     self.surplustimes -= 1
     if result == 1:  #战斗胜利
         self.liansheng += 1
         characterId = self._owner.baseInfo.id
         tocharacterId = toplayer.baseInfo.id
         fname = self._owner.baseInfo.getName()
         tname = toplayer.baseInfo.getName()
         success = 1
         rankingChange = toplayer.arena.getRanking()
         if rankingChange < self.ranking:  #战胜比自己排名高的人时互换排名
             dbarena.updateCharacterArenaInfo(
                 characterId, {
                     'ranking': rankingChange,
                     'surplustimes': self.surplustimes,
                     'liansheng': self.liansheng
                 })
             dbarena.updateCharacterArenaInfo(tocharacterId,
                                              {'ranking': self.ranking})
         else:
             rankingChange = 0
             dbarena.updateCharacterArenaInfo(characterId, {
                 'surplustimes': self.surplustimes,
                 'liansheng': self.liansheng
             })
         dbarena.insertBattleLog(characterId, tocharacterId,\
                                  fname, tname, success, rankingChange)
     else:
         self.liansheng += 0
         characterId = self._owner.baseInfo.id
         tocharacterId = toplayer.baseInfo.id
         fname = self._owner.baseInfo.getName()
         tname = toplayer.baseInfo.getName()
         success = 0
         rankingChange = 0
         dbarena.updateCharacterArenaInfo(characterId, {
             'surplustimes': self.surplustimes,
             'liansheng': self.liansheng
         })
         dbarena.insertBattleLog(characterId, tocharacterId,\
                                  fname, tname, success, rankingChange)
    def ScoreHandler(self, result, toplayer, scorechange):
        '''验证加减分'''
        if result == 1:  #胜利
            self.liansheng += 1
            characterId = self._owner.baseInfo.id
            tocharacterId = toplayer.baseInfo.id
            fname = self._owner.baseInfo.getName()
            tname = toplayer.baseInfo.getName()
            success = 1

            rankingChange = toplayer.arena.getRanking()
            if rankingChange < self.ranking:  #战胜比自己排名高的人时互换排名
                dbarena.updateCharacterArenaInfo(characterId, {
                    'ranking': rankingChange,
                    'liansheng': self.liansheng
                })
                dbarena.updateCharacterArenaInfo(tocharacterId,
                                                 {'ranking': self.ranking})
            else:
                rankingChange = 0
                dbarena.updateCharacterArenaInfo(characterId,
                                                 {'liansheng': self.liansheng})
            dbarena.insertBattleLog(characterId, tocharacterId,\
                      fname, tname, success, rankingChange)
        else:
            self.liansheng += 0
            characterId = self._owner.baseInfo.id
            tocharacterId = toplayer.baseInfo.id
            fname = self._owner.baseInfo.getName()
            tname = toplayer.baseInfo.getName()
            success = 0
            rankingChange = 0
            dbarena.updateCharacterArenaInfo(characterId, {
                'surplustimes': self.surplustimes,
                'liansheng': self.liansheng
            })
            dbarena.insertBattleLog(characterId, tocharacterId,\
                                     fname, tname, success, rankingChange)
 def afterFight(self,result,toplayer):
     '''战斗结果处理
     '''
     self._owner.finance.addCoin(500,state=0)
     self._owner.finance.addPrestige(2,state=0)
     self.surplustimes -=1
     if result==1:#战斗胜利
         self.liansheng +=1
         characterId = self._owner.baseInfo.id
         tocharacterId = toplayer.baseInfo.id
         fname = self._owner.baseInfo.getName()
         tname = toplayer.baseInfo.getName()
         success = 1
         rankingChange = toplayer.arena.getRanking()
         if rankingChange<self.ranking:#战胜比自己排名高的人时互换排名
             dbarena.updateCharacterArenaInfo(characterId, {'ranking':rankingChange,
                                                        'surplustimes':self.surplustimes,
                                                        'liansheng':self.liansheng})
             dbarena.updateCharacterArenaInfo(tocharacterId, {'ranking':self.ranking})
         else:
             rankingChange = 0
             dbarena.updateCharacterArenaInfo(characterId, {'surplustimes':self.surplustimes,
                                                        'liansheng':self.liansheng})
         dbarena.insertBattleLog(characterId, tocharacterId,\
                                  fname, tname, success, rankingChange)
     else:
         self.liansheng +=0
         characterId = self._owner.baseInfo.id
         tocharacterId = toplayer.baseInfo.id
         fname = self._owner.baseInfo.getName()
         tname = toplayer.baseInfo.getName()
         success = 0
         rankingChange = 0
         dbarena.updateCharacterArenaInfo(characterId, {'surplustimes':self.surplustimes,
                                                        'liansheng':self.liansheng})
         dbarena.insertBattleLog(characterId, tocharacterId,\
                                  fname, tname, success, rankingChange)