class CBattle(object): '''一场战斗 游戏内会涉及到多种战斗模式,竞技场战斗,副本战斗,国战战斗……均可由CBattle派生,保证扩展性。 ''' def __init__(self, uid): ''' ''' print '构造CBattle' self.uid = uid self.mod = BattleMod(uid) #别用Gcore.getMod() 此处不缓存 self.startTime = time.time() #战斗开始时间 self.updateTime = time.time() #战斗更新时间 def createWar(self, para): '''创建战役战斗 para: 'WarId' 剧情战场ID ''' print 'ps createBattle ',para optId = 90001 if 'WarId' not in para: return Gcore.error(optId,-90001999) #参考错误 initResult = self.mod.initWar(para['WarId']) if initResult == -1: return Gcore.error(optId,-90001001) #没有兵出场 elif initResult == -2: return Gcore.error(optId,-90001002) #越出每日可打上限 elif initResult == -3: return Gcore.error(optId,-90001003) #战役未达到 else: body = self.mod.getWarInfo() if not body: return Gcore.error(optId,-90001997) #系统错误 return Gcore.out(optId,body) def createRankFight(self, para): '''创建比武战斗''' optId = 94001 if 'OpUserId' not in para: return Gcore.error(optId,-94001999) #参考错误 initResult = self.mod.initRankFight( para.get('OpUserId') ) if initResult == -1: return Gcore.error(optId,-94001001) #没有兵出场 elif initResult == -2: return Gcore.error(optId,-94001002) #越出每日可打上限 elif initResult == -3: return Gcore.error(optId,-94001003) #不可与自己比武 else: body = self.mod.getRankInfo() if not body: return Gcore.error(optId,-90001997) #系统错误 return Gcore.out(optId,body) def findSiege(self, para): '''创建攻城 查找攻城战斗 @param fromType': 1, #1查找 2复仇 3反抗 4抢夺 (#@todo战斗结束后具体效果还没做) @param serverId': 0, #1查找时不需要 @param targetUserId': 0, #1查找时不需要 ''' print 'ps findSiege ',para optId = 93001 initResult = self.mod.initWar(0) if initResult<0: #重复@todo优化 if initResult==-1: return Gcore.error(optId,-93001001) #尚未派兵出征,请先布阵 elif initResult==-2: return Gcore.error(optId,-93001008) #剩余行动力不足 elif initResult==-3: return Gcore.error(optId,-93001010) #战役未达到,不可攻打 elif initResult==-4: return Gcore.error(optId,-93001009) #等级未达到,不可攻城 else: return Gcore.error(optId,-93001997) #系统错误 if para.get('serverId') == Gcore.getServerId() and para.get('targetUserId') == self.uid: return Gcore.error(optId,-93001002) #不可攻打自己 try: body = self.mod.findSiege(para) #查找攻城 except Exception,e: if Gcore.TEST: raise return Gcore.error(optId,-93001997,{'Exception':str(e)} ) #系统错误 if not isinstance(body, dict): return Gcore.error(optId,body) #body 是错误编号 return Gcore.out(optId,body)
class CBattle(object): '''一场战斗 游戏内会涉及到多种战斗模式,竞技场战斗,副本战斗,国战战斗……均可由CBattle派生,保证扩展性。 ''' def __init__(self, uid): ''' ''' print '构造CBattle' self.uid = uid self.mod = BattleMod(uid) #别用Gcore.getMod() 此处不缓存 self.startTime = time.time() #战斗开始时间 self.updateTime = time.time() #战斗更新时间 def createWar(self, para): '''创建战役战斗 para: 'WarId' 剧情战场ID ''' print 'ps createBattle ', para optId = 90001 if 'WarId' not in para: return Gcore.error(optId, -90001999) #参考错误 initResult = self.mod.initWar(para['WarId']) if initResult == -1: return Gcore.error(optId, -90001001) #没有兵出场 elif initResult == -2: return Gcore.error(optId, -90001002) #越出每日可打上限 elif initResult == -3: return Gcore.error(optId, -90001003) #战役未达到 else: body = self.mod.getWarInfo() if not body: return Gcore.error(optId, -90001997) #系统错误 return Gcore.out(optId, body) def createRankFight(self, para): '''创建比武战斗''' optId = 94001 if 'OpUserId' not in para: return Gcore.error(optId, -94001999) #参考错误 initResult = self.mod.initRankFight(para.get('OpUserId')) if initResult == -1: return Gcore.error(optId, -94001001) #没有兵出场 elif initResult == -2: return Gcore.error(optId, -94001002) #越出每日可打上限 elif initResult == -3: return Gcore.error(optId, -94001003) #不可与自己比武 else: body = self.mod.getRankInfo() if not body: return Gcore.error(optId, -90001997) #系统错误 return Gcore.out(optId, body) def findSiege(self, para): '''创建攻城 查找攻城战斗 @param fromType': 1, #1查找 2复仇 3反抗 4抢夺 (#@todo战斗结束后具体效果还没做) @param serverId': 0, #1查找时不需要 @param targetUserId': 0, #1查找时不需要 ''' print 'ps findSiege ', para optId = 93001 initResult = self.mod.initWar(0) if initResult < 0: #重复@todo优化 if initResult == -1: return Gcore.error(optId, -93001001) #尚未派兵出征,请先布阵 elif initResult == -2: return Gcore.error(optId, -93001008) #剩余行动力不足 elif initResult == -3: return Gcore.error(optId, -93001010) #战役未达到,不可攻打 elif initResult == -4: return Gcore.error(optId, -93001009) #等级未达到,不可攻城 else: return Gcore.error(optId, -93001997) #系统错误 if para.get('serverId') == Gcore.getServerId() and para.get( 'targetUserId') == self.uid: return Gcore.error(optId, -93001002) #不可攻打自己 try: body = self.mod.findSiege(para) #查找攻城 except Exception, e: if Gcore.TEST: raise return Gcore.error(optId, -93001997, {'Exception': str(e)}) #系统错误 if not isinstance(body, dict): return Gcore.error(optId, body) #body 是错误编号 return Gcore.out(optId, body)