예제 #1
0
    def SpeedRapidPractise(self, param={}):
        '''加速突飞训练的冷却时间'''
        optId = 15094

        IsSpeed = param.get('IsSpeed')
        TimeStamp = param['ClientTime']

        TodayDate = time.strftime('%Y-%m-%d', time.localtime(TimeStamp))
        modGround = Gcore.getMod('Building_ground', self.uid)
        RapidRecord = modGround.getRapidRecord(TodayDate)

        if not RapidRecord:
            RapidCount = 0
            IsOverFlow = 0

            CDValue = 0
        else:
            RapidCount = RapidRecord['PractiseCount']
            IsOverFlow = RapidRecord['IsOverFlow']

            TotalCD = RapidRecord['CDValue']
            SecondsPast = TimeStamp - RapidRecord['LastRapidTime']
            CDValue = max(TotalCD - SecondsPast, 0)
            if CDValue <= 0:
                IsOverFlow = 0

        if not IsSpeed:  #不是加速
            body = {}
            body['TimeStamp'] = TimeStamp
            body['IsOverFlow'] = IsOverFlow
            body['CDValue'] = CDValue
            body['RapidCout'] = RapidCount
            return Gcore.out(optId, body=body)

        #加速冷却时间
        if CDValue <= 0:
            return Gcore.error(optId, -15094001)  #冷却时间为0

        CoinType = 1
        CoinValue = calSpeedCost(4, CDValue)

        #扣钱
        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = '%s.%s' % (self.__class__.__name__,
                                 sys._getframe().f_code.co_name)
        pay = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, param)
        if pay < 0:
            return Gcore.error(optId, -15094002)  #扣钱失败

        #更新突飞记录表
        modGround.speedCD()

        body = {}
        body['GoldenCost'] = pay
        body['CDValue'] = 0
        body['SpeedTime'] = CDValue
        body['IsOverFlow'] = 0
        body['TimeStamp'] = TimeStamp
        return Gcore.out(optId, body=body)
예제 #2
0
 def SpeedRapidPractise(self, param={}):
     '''加速突飞训练的冷却时间'''
     optId = 15094
     
     IsSpeed = param.get('IsSpeed')
     TimeStamp = param['ClientTime']
     
     TodayDate = time.strftime('%Y-%m-%d', time.localtime(TimeStamp))
     modGround = Gcore.getMod('Building_ground', self.uid)
     RapidRecord = modGround.getRapidRecord(TodayDate)
     
     if not RapidRecord:
         RapidCount = 0
         IsOverFlow = 0
         
         CDValue = 0
     else:
         RapidCount = RapidRecord['PractiseCount']
         IsOverFlow = RapidRecord['IsOverFlow']
         
         TotalCD = RapidRecord['CDValue']
         SecondsPast = TimeStamp - RapidRecord['LastRapidTime']
         CDValue = max(TotalCD - SecondsPast, 0)
         if CDValue <= 0:
             IsOverFlow = 0
     
     if not IsSpeed: #不是加速
         body = {}
         body['TimeStamp'] = TimeStamp
         body['IsOverFlow'] = IsOverFlow
         body['CDValue'] = CDValue
         body['RapidCout'] = RapidCount
         return Gcore.out(optId, body=body)
     
     #加速冷却时间
     if CDValue <= 0:
         return Gcore.error(optId, -15094001) #冷却时间为0
     
     CoinType = 1
     CoinValue = calSpeedCost(4, CDValue)
     
     #扣钱
     modCoin = Gcore.getMod('Coin', self.uid)
     classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name)
     pay = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, param)
     if pay < 0:
         return Gcore.error(optId, -15094002) #扣钱失败
     
     #更新突飞记录表
     modGround.speedCD()
     
     body = {}
     body['GoldenCost'] = pay
     body['CDValue'] = 0
     body['SpeedTime'] = CDValue
     body['IsOverFlow'] = 0
     body['TimeStamp'] = TimeStamp
     return Gcore.out(optId, body=body)
예제 #3
0
    def FullAddSoldier(self, param={}):
        '''填满兵营或工坊的剩余训练空间'''
        optId = 15031

        BuildingId = param['BuildingId']
        TimeStamp = param['ClientTime']

        modBuilding = Gcore.getMod('Building', self.uid)
        BuildingInfo = modBuilding.getBuildingById(BuildingId,
                                                   TimeStamp=TimeStamp)
        if not BuildingInfo:
            return Gcore.error(optId, -15031001)  #玩家没有该建筑
        if BuildingInfo['BuildingState'] == 1:
            return Gcore.error(optId, -15031002)  #建筑正在建造
        if BuildingInfo['BuildingType'] not in (6, 8):
            return Gcore.error(optId, -15031003)  #建筑不是兵营或工坊

        modCamp = Gcore.getMod('Building_camp', self.uid)
        spawn_detail = modCamp.getSoldierStorage(BuildingInfo, TimeStamp)

        MaxNum = Gcore.getCfg(
            'tb_cfg_building_up',
            (BuildingInfo['BuildingType'], BuildingInfo['BuildingRealLevel']),
            'MakeValue')
        buy_cnt = MaxNum - spawn_detail['StorageNum']
        print '兵营或工坊的最大数量', MaxNum
        print '当前时刻的数量', spawn_detail['StorageNum']
        print '购买数量', buy_cnt

        if buy_cnt < 0:
            return Gcore.error(optId, -15031004)  #兵营或工坊已满
        elif buy_cnt > 0:
            coin_need = calSpeedCost(3, buy_cnt)
            class_method = '%s.%s' % (self.__class__.__name__,
                                      sys._getframe().f_code.co_name)
            modCoin = Gcore.getMod('Coin', self.uid)
            pay = modCoin.PayCoin(optId, 1, coin_need, class_method, param)
            if pay < 0:
                return Gcore.error(optId, -15031005)  #支付失败

            #将兵营置满
            modCamp.fullAddSoldier(
                BuildingId, BuildingInfo['BuildingType'],
                BuildingInfo['BuildingRealLevel'],
                max(spawn_detail['LastChangedTime'], TimeStamp), TimeStamp)
        else:
            pay = 0

        body = {}
        body['StorageNum'] = MaxNum
        body['BuyCnt'] = buy_cnt
        body['GoldenCoinCost'] = pay
        body['TimeStamp'] = TimeStamp

        return Gcore.out(optId, body=body)
예제 #4
0
    def FullAddSoldier(self, param={}):
        '''填满兵营或工坊的剩余训练空间'''
        optId = 15031
        
        BuildingId = param['BuildingId']
        TimeStamp = param['ClientTime']
        
        modBuilding = Gcore.getMod('Building', self.uid)
        BuildingInfo = modBuilding.getBuildingById(BuildingId, TimeStamp=TimeStamp)
        if not BuildingInfo:
            return Gcore.error(optId, -15031001) #玩家没有该建筑
        if BuildingInfo['BuildingState'] == 1:
            return Gcore.error(optId, -15031002) #建筑正在建造
        if BuildingInfo['BuildingType'] not in (6, 8):
            return Gcore.error(optId, -15031003) #建筑不是兵营或工坊

        modCamp = Gcore.getMod('Building_camp', self.uid) 
        spawn_detail= modCamp.getSoldierStorage(BuildingInfo, TimeStamp)

        MaxNum = Gcore.getCfg('tb_cfg_building_up',
                              (BuildingInfo['BuildingType'], BuildingInfo['BuildingRealLevel']),
                              'MakeValue')
        buy_cnt = MaxNum - spawn_detail['StorageNum']
        print '兵营或工坊的最大数量', MaxNum
        print '当前时刻的数量', spawn_detail['StorageNum']
        print '购买数量', buy_cnt
        
        if buy_cnt < 0:
            return Gcore.error(optId, -15031004) #兵营或工坊已满
        elif buy_cnt > 0:
            coin_need = calSpeedCost(3, buy_cnt)
            class_method = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name)
            modCoin = Gcore.getMod('Coin', self.uid)
            pay = modCoin.PayCoin(optId, 1, coin_need, class_method, param)
            if pay < 0:
                return Gcore.error(optId, -15031005) #支付失败
            
            #将兵营置满
            modCamp.fullAddSoldier(BuildingId, BuildingInfo['BuildingType'], 
                                   BuildingInfo['BuildingRealLevel'],
                                   max(spawn_detail['LastChangedTime'], TimeStamp),
                                   TimeStamp)
        else:
            pay = 0

        body = {}
        body['StorageNum'] = MaxNum
        body['BuyCnt'] = buy_cnt
        body['GoldenCoinCost'] = pay
        body['TimeStamp'] = TimeStamp
        
        return Gcore.out(optId, body=body)
예제 #5
0
    def SpeedUpTech(self,p={}):
        '''加速学习科技'''
        optId = 15053
        buildingId = p.get('BuildingId') 
        now = p.get('ClientTime')
#         now = time.time()
        
        building = Gcore.getMod('Building',self.uid).getBuildingById(buildingId)
        if not building or building.get('BuildingType') not in [12,19]:
            return Gcore.error(optId,-15053901)#建筑不存在
        buildingType = building.get('BuildingType')
        
        tech = self.mod.getUpgradingTech(buildingId)
        if not tech:
            return Gcore.error(optId,-15053001)#科技已完成学习
        
        techCategory = tech.get('TechCategory')
        techType = tech.get('TechType')
        speedupTime = tech.get('LastEndTime')-now
        cost = com.calSpeedCost(2 if buildingType==12 else 6,speedupTime)
        coinMod = Gcore.getMod('Coin',self.uid)

        payStatus = coinMod.PayCoin(optId,1,cost,'BookUI.SpeedUpTech')
        if payStatus>0:
            data= {'LastEndTime':now}
            self.mod.updateTech(techCategory,techType,data)

        elif payStatus == -2:
            return Gcore.error(optId,-15053994)#货币不足
        else:
            return Gcore.error(optId,-15053995)#支付失败
        
        if techCategory==2:#内政科技,更新内政加成
            interMod = Gcore.getMod('Inter',self.uid)
            techLevel = tech.get('TechLevel')
            interMod.updateInterTech(techType,techLevel,now)
        
        recordData = {'uid':self.uid,'ValType':techCategory,'Val':1,'BuildingType':buildingType}#成就、任务记录  
        return Gcore.out(optId, {'TechCategory':techCategory,'TechType':techType,'Cost':cost},mission=recordData)
예제 #6
0
    def SpeedUpPractise(self, param={}):
        '''武馆:取消或加速训练'''
        optId = 15091

        GeneralId = param["GeneralId"]
        TimeStamp = param["ClientTime"]
        Flag = param.get('Flag')  #Flag-False加速训练 ;1取消训练

        modGeneral = Gcore.getMod('General', self.uid)
        Generals = modGeneral.getMyGenerals()
        GeneralsCopy = copy.deepcopy(Generals)

        PractiseQueues, Generals = self.mod.touchPractise(Generals, TimeStamp)

        if GeneralId not in [
                PractiseQueue["GeneralId"] for PractiseQueue in PractiseQueues
        ]:
            return Gcore.error(optId, -15091001)  #该武将没训练

        #计算花费,经验值
        TotalTime = 0
        SpeedTime = 0
        ExpValue = 0
        PractiseId = None
        for PractiseQueue in PractiseQueues:
            if PractiseQueue["GeneralId"] == GeneralId:
                TotalTime = PractiseQueue["CompleteTime"] - PractiseQueue[
                    "StartTime"]
                ExpValue = int(
                    math.ceil((TotalTime // 60) * PractiseQueue["TrainExp"]))
                SpeedTime = PractiseQueue["CompleteTime"] - PractiseQueue[
                    "StartTime"]
                PractiseId = PractiseQueue['PractiseId']
                TrainPay = PractiseQueue['TrainPay']

        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = '%s.%s' % (self.__class__.__name__,
                                 sys._getframe().f_code.co_name)

        body = {}  #返回信息

        #将当前的武将的信息删除
        body['Generals'] = [
            General for General in Generals
            if General['GeneralId'] != GeneralId
        ]
        #将当前武将的训练队列删除
        body['PractiseQueues'] = [
            PractiseQueue for PractiseQueue in PractiseQueues
            if PractiseQueue['GeneralId'] != GeneralId
        ]
        if not Flag:  #加速
            CoinType = 1
            CoinValue = calSpeedCost(4, SpeedTime)
            pay = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod,
                                  param)
            if pay < 0:
                return Gcore.error(optId, -15091002)  #支付失败

            #更新武将表
            General = self.mod.getGeneralById(GeneralsCopy, GeneralId)
            General = modGeneral.incGeneralExp(General, ExpValue)
            body['Generals'].append(General)

            #从训练表中删除记录
            self.mod.deletePractise(PractiseId)

            recordData = {'uid': self.uid, 'ValType': 0, 'Val': 1}  #成就、任务记录
            body['Cost'] = pay
            body['SpeedTime'] = SpeedTime
            return Gcore.out(optId, body=body, mission=recordData)
        elif Flag == 1:  #取消
            #返钱
            coinValue = (SpeedTime / TotalTime) * TrainPay
            gain = modCoin.GainCoin(optId, 3, coinValue, classMethod, param)
            if gain is False:
                return Gcore.error(optId, -15091003)  #增加货币失败

            #删除训练记录
            self.mod.deletePractise(PractiseId)

            #更新武将信息
            modGeneral = Gcore.getMod('General', self.uid)
            General = self.mod.getGeneralById(Generals, GeneralId)
            modGeneral.updateGeneralById(General, GeneralId)
            body['Generals'].append(General)

            body['GainValue'] = gain
            body['TheoryGainValue'] = coinValue
            body['CoinType'] = 3
            return Gcore.out(optId, body=body)
        else:
            return Gcore.error(optId, -15091004)  #Flag不正确
예제 #7
0
    def SpeedupProcess(self, param={}):
        '''通用:加速建造或升级'''
        optId = 15004

        BuildingId = param["BuildingId"]
        if not BuildingId:
            x = param["x"]
            y = param["y"]
            BuildingId = self.mod.getBuildingByCoord(x,y)
        if not BuildingId:
            return Gcore.error(optId, -15004002) #没有这个建筑
        TimeStamp = param['ClientTime']
        
        BuildingInfo = self.mod.getBuildingById(BuildingId, fields='*', TimeStamp=TimeStamp)
        if not BuildingInfo:
            return Gcore.error(optId, -15004003) #用户没有该建筑
        if BuildingInfo['BuildingState'] == 0:
            return Gcore.error(optId, -15004004) #建筑已建造或升级完成
        BuildingType = BuildingInfo['BuildingType']
        BuildingLevel = BuildingInfo['BuildingLevel']
        
        StopTime = BuildingInfo['CompleteTime']
        TimeRemained = StopTime - TimeStamp
        GoldenCoinNum = common.calSpeedCost(1, TimeRemained)
        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = '%s.%s' % (self.__class__.__name__, 
                                 sys._getframe().f_code.co_name)
        pay = modCoin.PayCoin(optId, 1, GoldenCoinNum, classMethod, param)
        if pay < 0:
            return Gcore.error(optId, -15004995) #支付失败

        #更新建筑表
        UpInfo = {"CompleteTime":TimeStamp, "LastOptType":3}
        self.mod.updateBuildingById(UpInfo, BuildingId)

        #不同类型的建筑进行不同的操作
        # + todo
        if BuildingType in (6, 8): #兵营 工坊
            BuildingInfo['BuildingRealLevel'] = BuildingInfo['BuildingLevel']
            BuildingInfo['LastOptType'] = 3
            BuildingInfo['CompleteTime'] = TimeStamp

            add_num = 0
            if BuildingInfo['BuildingState'] == 1:
                add_num = Gcore.getCfg('tb_cfg_building_up',
                                       (BuildingType, 1), 'MakeValue')
            else:
                add_num = Gcore.getCfg('tb_cfg_building_up',
                                       (BuildingType, BuildingInfo['BuildingRealLevel']), 'MakeValue') - \
                        Gcore.getCfg('tb_cfg_building_up',
                                     (BuildingType, BuildingInfo['BuildingRealLevel'] - 1), 'MakeValue')
            print '增加的新兵数量是', add_num
            
            modCamp = Gcore.getMod('Building_camp', self.uid)
            modCamp.getSoldierStorage(BuildingInfo, TimeStamp, is_sync=True, 
                                      set_cal_time=TimeStamp, add_num=add_num)
        if BuildingType == 18: #点将台
            print '点将台加速完成'
            modTrain = Gcore.getMod('Building_train', self.uid)
            if BuildingLevel == 1:
                num = Gcore.getCfg('tb_cfg_building_up',
                                   (18, 1), 'MakeValue')
            else:
                num = Gcore.getCfg('tb_cfg_building_up',
                                   (18, BuildingLevel),
                                   'MakeValue') - \
                      Gcore.getCfg('tb_cfg_building_up',
                                   (18, BuildingLevel-1),
                                   'MakeValue')
            print '增加的数量', num
            modTrain.normalAddTrainNum(num=num, TimeStamp=TimeStamp)
        
        recordData = {'uid':self.uid,'ValType':BuildingType,'Val':1,
                      'BuildingLevel':BuildingLevel}#成就、任务记录 
        return Gcore.out(optId, {'Coin%s'%1:modCoin.getCoinNum(1),
                                 "Cost":pay, 
                                 "TimeRemained":TimeRemained},
                         mission=recordData)
예제 #8
0
    def SpeedUpTraining(self, param = {}):
        '''兵营:加速征兵  或  工坊:加速制造 或  佣兵处:雇佣''' 
        optId = 15032

        BuildingId = param['BuildingId']
        SoldierType = param['SoldierType']
        TimeStamp = param['ClientTime']
        Flag = param['Flag'] #Flag:1,兵营;2,工坊;3,佣兵处。

        SoldierCfg = Gcore.getCfg('tb_cfg_soldier')
        if Flag == 3:
            HireNum = param['HireNum']
            if HireNum <= 0:
                return Gcore.error(optId, -15032001) #雇佣数量必须大于0
            HireSoldierType = [k for (k, v) in SoldierCfg.iteritems() if v["SoldierSide"] == 4]
            if SoldierType not in HireSoldierType:
                return Gcore.error(optId, -15032002) #兵种不是雇佣兵

        modCamp = Gcore.getMod('Building_camp', self.uid)
        modBuilding = Gcore.getMod('Building', self.uid)
        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name)

        Buildings = modBuilding.getBuildingByType(7, TimeStamp=TimeStamp)
        Soldiers = modCamp.getSoldierNum(TimeStamp)
        SoldierNum = sum(Soldiers.values()) if Soldiers else 0
        MaxNum = modCamp.getMaxSoldierNum(Buildings)

        if Flag == 3: #佣兵处
            #当天已雇佣的数量
            TodayDate = time.strftime('%Y-%m-%d', time.localtime(TimeStamp))
            HireInfo = modCamp.getHireByDate(BuildingId, TodayDate)
            print '今天已佣兵', HireInfo
            
            if not HireInfo: #当天未雇佣 或 雇佣表中没有该佣兵处的雇佣记录。
                print '今天尚未佣兵'
                HireInfo = {}
                for st in HireSoldierType:
                    HireInfo['Soldier%s'%st] = 0
                AlreadyHireNum = 0
            else:
                AlreadyHireNum = sum(HireInfo.values())

            #雇佣上限
            BuildingInfo = modBuilding.getBuildingById(BuildingId, TimeStamp=TimeStamp)
            if not BuildingInfo:
                return Gcore.error(optId, -15032003) #玩家没有该建筑 
            if BuildingInfo['BuildingState'] == 1:
                return Gcore.error(optId, -15032004) #建筑正在建造
            if BuildingInfo["BuildingType"] != 9:
                return Gcore.error(optId, -15032005) #建筑不是佣兵处

            BuildingLevel = BuildingInfo["BuildingRealLevel"]
            MakeValue = Gcore.getCfg('tb_cfg_building_up', (9, BuildingLevel), 'MakeValue')

            HireSpace = MaxNum - SoldierNum
            if HireNum > HireSpace:
                return Gcore.error(optId, -15032006) #大于校场屯兵数
            if AlreadyHireNum + HireNum > MakeValue:
                return Gcore.error(optId, -15032007) #超过了雇佣上限

            #计算花费
            MakeCost = Gcore.getCfg('tb_cfg_soldier_up', (SoldierType, 0), 'MakeCost')
            MakeCostType = Gcore.getCfg('tb_cfg_soldier_up', (SoldierType, 0), 'MakeCostType')
            Cost = MakeCost * int(math.ceil(HireNum / 200.0))
            pay = modCoin.PayCoin(optId,MakeCostType,Cost,classMethod,param)        
            if pay <= 0 :
                return Gcore.error(optId, -15032008) #支付失败

            #增加士兵
            Num = Soldiers['Soldier%s'%SoldierType] + HireNum
            modCamp.updateSoldierNum(SoldierType, Num)

            HireInfo['Soldier%s'%SoldierType] += HireNum
            #更新tb_soldier_hire
            modCamp.updateSoldierHire(HireInfo, BuildingId, TodayDate)
            
            print '现在的佣兵数量是', HireInfo
            
            recordData = {'uid':self.uid,'ValType':SoldierType,'Val':HireNum}#成就、任务记录 
            return Gcore.out(optId, {"Cost":Cost, "TimeStamp":TimeStamp,"HireNum":HireNum}
                             ,mission=recordData,achieve=recordData)

        SoldierProcess = modCamp.getSoldierProcess(BuildingId)
        if not SoldierProcess:
            return Gcore.error(optId, -15032009) #用户当前没有征兵记录

        NumInTraining = 0
        ProcessId = None
        BuildingLevel = None
        for Process in SoldierProcess:
            if Process["SoldierType"] == SoldierType:
                NumInTraining = Process['SpawnNumRest']
                ProcessId = Process['ProcessId']
                BuildingLevel = Process['BuildingLevel']
        if NumInTraining == 0:
            return Gcore.error(optId, -15032010) #没有训练该兵种 
        if SoldierNum + NumInTraining > MaxNum:
            return Gcore.error(optId, -15032011) #训练数量大于校场的剩余容量

        #加速时间
        #注意:配置中是小时产量。
        #speed = Gcore.getCfg('tb_cfg_building_up', (6, BuildingLevel), 'HourValue')
        #TotalTimeNeed = int(math.ceil(NumInTraining/(speed/3600+0.0)))
        GoldCost = calSpeedCost(3, NumInTraining)
        pay = modCoin.PayCoin(optId,1,GoldCost,classMethod,param)
        if pay < 0:
            return Gcore.error(optId, -15032012) #黄金不足

        #加速征兵记录
        modCamp.speedupSoldierProcess(ProcessId)
        #更新士兵表 或更新器械表
        Num = NumInTraining + Soldiers['Soldier%s'%SoldierType]
        modCamp.updateSoldierNum(SoldierType, Num)
        
        recordData = {'uid':self.uid,'ValType':SoldierType,'Val':1}#成就、任务记录 
        return Gcore.out(optId, {"SpeedNum":NumInTraining, "GoldCost":pay, "TimeStamp":TimeStamp}
                         ,mission=recordData,achieve=recordData)
예제 #9
0
    def SpeedUpPractise(self, param={}):
        '''武馆:取消或加速训练'''
        optId = 15091

        GeneralId = param["GeneralId"]
        TimeStamp = param["ClientTime"]
        Flag = param.get('Flag') #Flag-False加速训练 ;1取消训练

        modGeneral = Gcore.getMod('General', self.uid)
        Generals = modGeneral.getMyGenerals()
        GeneralsCopy = copy.deepcopy(Generals)

        PractiseQueues, Generals = self.mod.touchPractise(Generals, TimeStamp)

        if GeneralId not in [PractiseQueue["GeneralId"] for PractiseQueue in PractiseQueues]:
            return Gcore.error(optId, -15091001) #该武将没训练

        #计算花费,经验值
        TotalTime = 0
        SpeedTime = 0
        ExpValue = 0
        PractiseId = None
        for PractiseQueue in PractiseQueues:
            if PractiseQueue["GeneralId"] == GeneralId:
                TotalTime = PractiseQueue["CompleteTime"] - PractiseQueue["StartTime"]
                ExpValue = int(math.ceil((TotalTime//60) * PractiseQueue["TrainExp"]))
                SpeedTime = PractiseQueue["CompleteTime"] - PractiseQueue["StartTime"]
                PractiseId = PractiseQueue['PractiseId']
                TrainPay = PractiseQueue['TrainPay']
                
        modCoin = Gcore.getMod('Coin', self.uid)
        classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name)
        
        body = {} #返回信息

        #将当前的武将的信息删除
        body['Generals'] = [General for General in Generals 
                            if General['GeneralId'] != GeneralId]
        #将当前武将的训练队列删除
        body['PractiseQueues'] = [PractiseQueue for PractiseQueue in PractiseQueues
                                  if PractiseQueue['GeneralId'] != GeneralId]
        if not Flag: #加速
            CoinType = 1
            CoinValue = calSpeedCost(4, SpeedTime)
            pay = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, param)
            if pay < 0:
                return Gcore.error(optId, -15091002) #支付失败
        
            #更新武将表
            General = self.mod.getGeneralById(GeneralsCopy, GeneralId)
            General = modGeneral.incGeneralExp(General, ExpValue)
            body['Generals'].append(General)
            
            #从训练表中删除记录
            self.mod.deletePractise(PractiseId)
            
            recordData = {'uid':self.uid,'ValType':0,'Val':1}#成就、任务记录
            body['Cost'] = pay
            body['SpeedTime'] = SpeedTime
            return Gcore.out(optId, body=body,
                             mission=recordData)
        elif Flag == 1: #取消
            #返钱
            coinValue = (SpeedTime / TotalTime) * TrainPay
            gain = modCoin.GainCoin(optId, 3, coinValue, classMethod, param)
            if gain is False:
                return Gcore.error(optId, -15091003) #增加货币失败
            
            #删除训练记录
            self.mod.deletePractise(PractiseId)
            
            #更新武将信息
            modGeneral = Gcore.getMod('General', self.uid)
            General = self.mod.getGeneralById(Generals, GeneralId)
            modGeneral.updateGeneralById(General, GeneralId)
            body['Generals'].append(General)

            
            body['GainValue'] = gain
            body['TheoryGainValue'] = coinValue
            body['CoinType'] = 3
            return Gcore.out(optId, body=body)
        else:
            return Gcore.error(optId, -15091004) #Flag不正确