def doFight(self,characterId):
     '''执行战斗
     @param characterId: int 对手的ID
     '''
     if self.getCD()>0:
         return {'result':False,'message':Lg().g(244)}
     if self.surplustimes<=0:
         return {'result':False,'message':Lg().g(245)}
     from app.scense.core.character.PlayerCharacter import PlayerCharacter
     from app.scense.core.PlayersManager import PlayersManager
     from app.scense.core.fight.fight_new 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], 550)
     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)
     self.pushArenaCD()
     self._owner.quest.specialTaskHandle(122)#成功后的特殊任务通知
     data = {'message':Lg().g(246),'fight':fig}
     bound = {'coin':500,'popularity':2,'name':self._owner.baseInfo.getName()}
     return {'result':True,'data':data,'bound':bound}
 def doFight(self, characterId):
     '''执行战斗
     @param characterId: int 对手的ID
     '''
     if self.getCD() > 0:
         return {'result': False, 'message': Lg().g(244)}
     if self.surplustimes <= 0:
         return {'result': False, 'message': Lg().g(245)}
     from app.scense.core.character.PlayerCharacter import PlayerCharacter
     from app.scense.core.PlayersManager import PlayersManager
     from app.scense.core.fight.fight_new 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], 550)
     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)
     self.pushArenaCD()
     self._owner.quest.specialTaskHandle(122)  #成功后的特殊任务通知
     data = {'message': Lg().g(246), 'fight': fig}
     bound = {
         'coin': 500,
         'popularity': 2,
         'name': self._owner.baseInfo.getName()
     }
     return {'result': True, 'data': data, 'bound': bound}
 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 clearCD(self):
     '''清除竞技场冷却时间
     '''
     CD = self.getCD()
     if CD < 0:
         return {'result': False, 'message': Lg().g(239)}
     reqgold = int(math.ceil(CD * 1.0 / 60))
     if self._owner.finance.getGold() < reqgold:
         return {'result': False, 'message': Lg().g(190)}
     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':Lg().g(239)}
     reqgold = int(math.ceil(CD*1.0/60))
     if self._owner.finance.getGold()<reqgold:
         return {'result':False,'message':Lg().g(190)}
     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 AddSurplustimes(self):
     '''添加竞技场剩余次数'''
     viplevel = self._owner.baseInfo._viptype
     nowtimes = self.buytimes
     if not vipCertification('arenatimes', viplevel,nowtimes = nowtimes):
         return {'result':False,'message':Lg().g(217)}
     reqGold = (self.buytimes+1)*10
     if reqGold>self._owner.finance.getGold():
         return {'result':False,'message':Lg().g(190)}
     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 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)
         msg = ''
         if self.liansheng == 10:
             msg = Lg().g(240) % (fname)
         if rankingChange == 1:
             msg = Lg().g(241) % (fname)
         if msg:
             self.pushGonggao(msg)
         self._owner.msgbox.putFightMsg(Lg().g(242))
     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)
         self._owner.msgbox.putFightMsg(Lg().g(243))
 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 AddSurplustimes(self):
     '''添加竞技场剩余次数'''
     viplevel = self._owner.baseInfo._viptype
     nowtimes = self.buytimes
     if not vipCertification('arenatimes', viplevel, nowtimes=nowtimes):
         return {'result': False, 'message': Lg().g(217)}
     reqGold = (self.buytimes + 1) * 10
     if reqGold > self._owner.finance.getGold():
         return {'result': False, 'message': Lg().g(190)}
     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 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)
         msg = ''
         if self.liansheng==10:
             msg = Lg().g(240)%(fname)
         if rankingChange==1:
             msg = Lg().g(241)%(fname)
         if msg:
             self.pushGonggao(msg)
         self._owner.msgbox.putFightMsg(Lg().g(242))
     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)
         self._owner.msgbox.putFightMsg(Lg().g(243))