def GetMyClub(self, p={}): '''获取我的军团信息 ''' optId = 15062 clubId = self.mod.getUserClubId() clubInfo = { 'BaseInfo': 0, 'MemberNum': 0, 'DevoteValue': 0, 'LeaderInfo': 0, 'HasClub': 0, 'MyInfo': 0 } if not clubId: return Gcore.out(optId, clubInfo) #没有军团 ClubInfo = self.mod.getClubInfo(clubId) #军团基础信息 #by Lizr 前台没有这些值,,抽取 del ClubInfo['ClubTotalExp'] del ClubInfo['ClubLevelTotalExp'] del ClubInfo['CreatDate'] clubInfo['BaseInfo'] = ClubInfo clubInfo['MemberNum'] = self.mod.getClubMemberNum(clubId) #军团成员数量 clubInfo['DevoteValue'] = self.mod.getTodayDevote(clubId, 2) #当天贡献值 clubInfo['LeaderInfo'] = self.mod.getClubLeader(clubId) #团长信息 clubInfo['MyInfo'] = self.mod.getMemberInfo( clubId, self.uid, ['DevoteCurrent', 'DevoteTotal']) clubInfo['HasClub'] = 1 clubInfo['DevoteLogs'] = com.list2dict(self.mod.getDevoteLogs(clubId), 1) clubInfo['DevoteBase'] = Gcore.loadCfg( defined.CFG_BUILDING_CLUB).get('ClubGiveBase') return Gcore.out(optId, clubInfo)
def GetMyTech(self,p={}): '''获取我学习的所有科技''' optId = 15051 buildingId = p['BuildingId'] building = Gcore.getMod('Building',self.uid).getBuildingById(buildingId) if not building: return Gcore.out(optId) buildingType = building.get('BuildingType') st = self.mod.getTechs(1)#兵种科技 soldierTechs = []#书院研究科技 wallTechs = []#城墙研究科技 for k,v in enumerate(st): if v['TechType']>=200: wallTechs.append(v) else: soldierTechs.append(v) if buildingType==12:#书院 interTechs = self.mod.getTechs(2)#内政科技 reData = {'SoldierTechs':soldierTechs,'InterTechs':interTechs} else: reData = {'WallTechs':wallTechs} return Gcore.out(optId,reData)
def GetMyClub(self,p={}): '''获取我的军团信息 ''' optId = 15062 clubId = self.mod.getUserClubId() clubInfo = {'BaseInfo':0,'MemberNum':0, 'DevoteValue':0,'LeaderInfo':0, 'HasClub':0,'MyInfo':0} if not clubId: return Gcore.out(optId,clubInfo)#没有军团 ClubInfo = self.mod.getClubInfo(clubId)#军团基础信息 #by Lizr 前台没有这些值,,抽取 del ClubInfo['ClubTotalExp'] del ClubInfo['ClubLevelTotalExp'] del ClubInfo['CreatDate'] clubInfo['BaseInfo'] = ClubInfo clubInfo['MemberNum'] = self.mod.getClubMemberNum(clubId)#军团成员数量 clubInfo['DevoteValue'] = self.mod.getTodayDevote(clubId,2)#当天贡献值 clubInfo['LeaderInfo'] = self.mod.getClubLeader(clubId)#团长信息 clubInfo['MyInfo'] = self.mod.getMemberInfo(clubId,self.uid,['DevoteCurrent','DevoteTotal']) clubInfo['HasClub'] = 1 clubInfo['DevoteLogs'] = com.list2dict(self.mod.getDevoteLogs(clubId), 1) clubInfo['DevoteBase'] = Gcore.loadCfg(defined.CFG_BUILDING_CLUB).get('ClubGiveBase') return Gcore.out(optId,clubInfo)
def ApplyClub(self,p={}): ''' :申请加入 ''' optId = 15064 clubId = p['ClubId'] building = self.mod.getClubBuildingInfo() if building is None: return Gcore.error(optId,-15064901)#外史院建筑不存在 clubInfo = self.mod.getClubInfo(clubId) if not clubInfo: return Gcore.error(optId,-15064920)#军团不存在 if self.mod.getUserClubId(): return Gcore.error(optId,-15064001)#只能加入一个军团 if not self.mod.validApplyInterval(): return Gcore.error(optId,-15064004)#离上次退出军团时间间隔不合法 memberNum = self.mod.getClubMemberNum(clubId) if memberNum.get('CurNum')>=memberNum.get('MaxNum'): return Gcore.error(optId,-15064002)#军团成员已满 allowState = clubInfo.get('AllowState') if allowState == 1:#需要审核 self.mod.applyClub(clubId) return Gcore.out(optId,{'Passed':0,'ClubId':clubId})#申请成功,审核中 elif allowState ==2:#不需审核 self.mod.applyClub(clubId) self.mod.agreeApply(optId, clubId, self.uid) Gcore.setUserData(self.uid, {'ClubId':clubId})#更新用户缓存 recordData = {'uid':self.uid,'ValType':0,'Val':1}#任务 return Gcore.out(optId,{'Passed':1,'ClubId':clubId},mission=recordData)#成功加入军团 else: return Gcore.out(optId,{'Passed':2})#不允许加入
def BuyActPoint(self,para={}): '''购买行动点数''' optId = 91004 MaxBuyActTimes = Gcore.loadCfg(9101).get('MaxBuyActTimes') TodayBuyTimes = self.mod.getTodayBuyTimes() print 'TodayBuyTimes',TodayBuyTimes if MaxBuyActTimes <= TodayBuyTimes: Gcore.out(optId, -91004001) #已达可购买上限 else: TodayBuyTimes += 1 CostValue = Gcore.loadCfg(9101).get('BuyTimesPrice').get( str(TodayBuyTimes) ) if CostValue is None: CostValue = max( Gcore.loadCfg(9101).get('BuyTimesPrice').values() ) #开始支付 modCoin = Gcore.getMod('Coin', self.uid) pay = modCoin.PayCoin(optId, 1, CostValue, 'WarUI.BuyActTimes', para) if pay < 0: return Gcore.error(optId, -91004995) #支付失败 else: result = self.mod.buyActPoint() if not result: return Gcore.error(optId, -91004002) #系统错误 body = {} body['CanBuy'] = 1 if TodayBuyTimes < MaxBuyActTimes else 0 RestPoint,MaxPoint = self.mod.getActPoint() body['RestPoint'] = RestPoint body['MaxPoint'] = MaxPoint return Gcore.out(optId, body)
def BuyActPoint(self, para={}): '''购买行动点数''' optId = 91004 MaxBuyActTimes = Gcore.loadCfg(9101).get('MaxBuyActTimes') TodayBuyTimes = self.mod.getTodayBuyTimes() print 'TodayBuyTimes', TodayBuyTimes if MaxBuyActTimes <= TodayBuyTimes: Gcore.out(optId, -91004001) #已达可购买上限 else: TodayBuyTimes += 1 CostValue = Gcore.loadCfg(9101).get('BuyTimesPrice').get( str(TodayBuyTimes)) if CostValue is None: CostValue = max( Gcore.loadCfg(9101).get('BuyTimesPrice').values()) #开始支付 modCoin = Gcore.getMod('Coin', self.uid) pay = modCoin.PayCoin(optId, 1, CostValue, 'WarUI.BuyActTimes', para) if pay < 0: return Gcore.error(optId, -91004995) #支付失败 else: result = self.mod.buyActPoint() if not result: return Gcore.error(optId, -91004002) #系统错误 body = {} body['CanBuy'] = 1 if TodayBuyTimes < MaxBuyActTimes else 0 RestPoint, MaxPoint = self.mod.getActPoint() body['RestPoint'] = RestPoint body['MaxPoint'] = MaxPoint return Gcore.out(optId, body)
def MoveGeneral(self, param={}): '''校杨:移动武将''' optId = 15102 GeneralId = param['GeneralId'] PosId = param.get('PosId') modGeneral = Gcore.getMod('General', self.uid) EmbattleInfo = modGeneral.getMyGeneralsOnEmbattle( ['GeneralId', 'PosId']) OnEmbattle = [ General['PosId'] for General in EmbattleInfo if General['GeneralId'] == GeneralId ] IsOccupy = [ General['GeneralId'] for General in EmbattleInfo if General['PosId'] == PosId ] GeneralNum = len(EmbattleInfo) recordData = { 'uid': self.uid, 'ValType': 0, 'Val': 1, 'GNum': 0 } #成就、任务记录 if (not OnEmbattle) and (not PosId): return Gcore.error(optId, -15102001) #武将不在阵上无法移除 if OnEmbattle and (not PosId): #从阵上移除武将 GeneralNum -= 1 self.mod.deletePos(GeneralId) recordData['GNum'] = GeneralNum return Gcore.out(optId, body={}, mission=recordData) if PosId not in range(1, 10, 1): #位置是1-9 return Gcore.error(optId, -15102004) if OnEmbattle and IsOccupy: #互换两名武将的位置 stat = self.mod.exchangePos(GeneralId, OnEmbattle[0], IsOccupy[0], PosId) if OnEmbattle and (not IsOccupy): stat = self.mod.movePos(GeneralId, PosId) if (not OnEmbattle) and IsOccupy: stat = self.mod.insteadPos(GeneralId, IsOccupy[0], PosId) if (not OnEmbattle) and (not IsOccupy): #判断阵上武将是否满员 if len(EmbattleInfo) >= 5: return Gcore.error(optId, -15102002) #阵上武将已满 GeneralNum += 1 stat = self.mod.addPos(GeneralId, PosId) if not stat: return Gcore.error(optId, -15102003) #布阵操作失败 recordData['GNum'] = GeneralNum return Gcore.out(optId, body={}, mission=recordData)
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)
def CheckClubExist(self,p={}): '''检查军团是否存在''' optId = 15080 clubId = self.mod.getUserClubId() if clubId: curDevote = self.mod.getMemberInfo(clubId,self.uid,['DevoteCurrent']).get('DevoteCurrent',0) return Gcore.out(optId,{'IsExisted':1,'DevoteCurrent':curDevote}) else: return Gcore.out(optId,{'IsExisted':0})
def OnCacheAll(self, param={}): '''缓存竞技场所需信息''' optId = 30001 modRedis = Gcore.getMod('Redis', self.uid) try: modRedis.onCacheAll() except Exception: return Gcore.out(optId, -30001001) else: return Gcore.out(optId)
def GetInviteUI(self, param={}): """招贤馆:招募界面""" optId = 15006 BuildingId = param["BuildingId"] RequestTimeStamp = param["ClientTime"] InviteInfo = self.mod.getInvite() modBuilding = Gcore.getMod("Building", self.uid) BuildingInfo = modBuilding.getBuildingById(BuildingId, TimeStamp=RequestTimeStamp) if not BuildingInfo: return Gcore.error(optId, -15006901) # 用户没有该建筑 if BuildingInfo["BuildingState"] == 1: return Gcore.error(optId, -15006902) # 建筑正在建造 if BuildingInfo["BuildingType"] != 13: return Gcore.error(optId, -15006903) # 该建筑不是招贤馆 BuildingLevel = BuildingInfo["BuildingRealLevel"] if not InviteInfo: print "第一次招募" ChosenGenerals = self.mod.chooseGenerals(GeneralNum=3, IsFirst=True) self.mod.insertInvite(ChosenGenerals, BuildingLevel, RequestTimeStamp) RemainedTime = Gcore.getCfg("tb_cfg_building_up", key=(13, BuildingLevel), field="RefreshValue") return Gcore.out( optId, body={"RemainedTime": RemainedTime, "Generals": ChosenGenerals, "CostValue": 5} ) # 系统错误 (招募表中此玩家初始记录) print "InviteInfo", InviteInfo # SpeedCount = self.mod.cacSpeedCount(InviteInfo['SpeedCount'], InviteInfo['LastSpeedDate'], RequestTimeStamp) # SpeedCount += 1 # CostValue = SpeedCount * 2 CostValue = 5 # 读配置 - 招贤馆每次刷新所用的黄金数量 RetDic = {} RetDic["CostValue"] = CostValue if RequestTimeStamp < InviteInfo["EndTime"]: RefreshTimeRemained = InviteInfo["EndTime"] - RequestTimeStamp RetDic["RemainedTime"] = RefreshTimeRemained RetDic["Generals"] = [InviteInfo["GeneralId1"], InviteInfo["GeneralId2"], InviteInfo["GeneralId3"]] return Gcore.out(optId, RetDic) else: RefreshValue = Gcore.getCfg("tb_cfg_building_up", key=(13, BuildingLevel), field="RefreshValue") RefreshTimeRemained = RefreshValue - (RequestTimeStamp - InviteInfo["EndTime"]) % RefreshValue RefreshTimeStamp = RequestTimeStamp - (RequestTimeStamp - InviteInfo["EndTime"]) % RefreshValue ChosenGenerals = self.mod.chooseGenerals() self.mod.updateInvite(ChosenGenerals, BuildingLevel, RefreshTimeStamp) RetDic["RemainedTime"] = RefreshTimeRemained RetDic["Generals"] = ChosenGenerals return Gcore.out(optId, RetDic)
def GetReward(self, p={}): '''领取奖励''' optId = 15112 achieveType = p['AchieveType'] achiCfg = Gcore.getCfg('tb_cfg_achieve', achieveType) if achiCfg is None: return Gcore.error(optId, -15112001) #无此项成就 achieve = self.mod.getAchieveInfo(achieveType) #查询成就信息 current = achieve.get('CurrentAchieve') currentAchieveId = achieve.get('CurrentAchieveId') rewAchieveId = achieve.get('NextAchieveId') #领取的奖励 rewAchieve = achiCfg.get(rewAchieveId).get('AchieveRequire') if current < rewAchieve: return Gcore.error(optId, -15112002) #成就未达成 if achieve['Finished'] == 1: return Gcore.out(optId, { 'Finished': 1, 'GetAchieve': rewAchieveId }) #成就已完成 maxAchieveId = max(achiCfg.keys()) #最大成就值 if rewAchieveId == maxAchieveId: #成就完成 data = { 'NextAchieveId': rewAchieveId, 'Finished': 1, 'CurrentAchieveId': rewAchieveId } mission = {'uid': self.uid, 'ValType': 0, 'Val': 1} #任务记录 else: data = { 'NextAchieveId': rewAchieveId + 1, 'Finished': 0, 'CurrentAchieveId': rewAchieveId } mission = {} updateWhere = 'UserId=%s AND AchieveType=%s AND CurrentAchieveId=%s' % ( self.uid, achieveType, currentAchieveId) if self.mod.updateAchieveByWhere(data, updateWhere): achiCfg = achiCfg.get(rewAchieveId) rewardType = achiCfg.get('RewardType') rewardValue = achiCfg.get('AchieveReward') coinMod = Gcore.getMod('Coin', self.uid) coinMod.GainCoin(optId, rewardType, rewardValue, 'Building_homeUI.GetReward', p) return Gcore.out(optId, data, mission=mission) else: return Gcore.error(optId, -15112996) #操作失败
def MoveGoods(self,p={}): '''调整物品''' optId = 13062 pFrom = p['From'] pTo = p['To'] bagSize = self.mod.getBagSize() if not(0<pFrom<=bagSize) or not(0<pTo<=bagSize): return Gcore.error(optId, -13062001)#背包位置不合法 if pFrom == pTo:#会删除道具 return Gcore.out(optId,{}) gFrom = self.mod.getFromPosition(pFrom) gTo = self.mod.getFromPosition(pTo) if not gFrom: return Gcore.error(optId,-13062002)#当前没有物品 #改变物品位置 if not gTo:#将物品移动到空格 # print '移动到',pFrom,pTo # print 'F',gFrom self.mod.updateBag(gFrom['BagId'],{'Position':pTo}) #相同道具叠加 elif gFrom['GoodsType']==gTo['GoodsType']==2 and gFrom['GoodsId']==gTo['GoodsId']: # print '道具叠加',pFrom,pTo # print 'F',gFrom # print 'T',gTo gFromNum = gFrom['GoodsNum'] gToNum = gTo['GoodsNum'] gToMax = Gcore.getCfg('tb_cfg_item',gTo['GoodsId'],'OverlayNum') if gToNum<gToMax: gToNum = gToNum+gFromNum if gToNum>gToMax: gFromNum = gToNum-gToMax gToNum = gToMax else: gFromNum = 0 self.mod.updateBag(gTo['BagId'],{'GoodsNum':gToNum}) self.mod.updateBag(gFrom['BagId'],{'GoodsNum':gFromNum}) #两物品交换位置 else: # print '交换位置',pFrom,pTo # print 'F',gFrom # print 'T',gTo self.mod.updateBag(gFrom['BagId'],{'Position':pTo}) self.mod.updateBag(gTo['BagId'],{'Position':pFrom}) return Gcore.out(optId,{})
def CheckClubExist(self, p={}): '''检查军团是否存在''' optId = 15080 clubId = self.mod.getUserClubId() if clubId: curDevote = self.mod.getMemberInfo(clubId, self.uid, ['DevoteCurrent']).get( 'DevoteCurrent', 0) return Gcore.out(optId, { 'IsExisted': 1, 'DevoteCurrent': curDevote }) else: return Gcore.out(optId, {'IsExisted': 0})
def GetHireNum(self, param={}): '''获取当天雇佣数量 ''' optId = 15035 BuildingId = param['BuildingId'] TimeStamp = param['ClientTime'] modCamp = Gcore.getMod('Building_camp', self.uid) TodayDate = time.strftime('%Y-%m-%d', time.localtime(TimeStamp)) HireInfo = modCamp.getHireByDate(BuildingId, TodayDate) if not HireInfo: return Gcore.out(optId, {'TodayHireNum':0}) return Gcore.out(optId,{'TodayHireNum':sum(HireInfo.values())})
def getRecCamp(self,optId): '''推荐阵营by zhanggh (将弃 by Lizr)''' userNum=self.db.out_field('tb_user','count(1)','1=1')/3 # 推荐阵营算法 add by Yew if userNum>=20: for uc in range(1,4): ucNum=self.db.out_field('tb_user','count(1)','UserCamp=%s'%uc) if ucNum<userNum*0.8: return Gcore.out(optId,{'RC':uc,'RCKey':uc}) import random uc = random.randint(1,3) #1:魏,2:蜀,3:吴 result = {'RC':uc,'RCKey':uc} return Gcore.out(optId,result)
def getRecCamp(self, optId): '''推荐阵营by zhanggh (将弃 by Lizr)''' userNum = self.db.out_field('tb_user', 'count(1)', '1=1') / 3 # 推荐阵营算法 add by Yew if userNum >= 20: for uc in range(1, 4): ucNum = self.db.out_field('tb_user', 'count(1)', 'UserCamp=%s' % uc) if ucNum < userNum * 0.8: return Gcore.out(optId, {'RC': uc, 'RCKey': uc}) import random uc = random.randint(1, 3) #1:魏,2:蜀,3:吴 result = {'RC': uc, 'RCKey': uc} return Gcore.out(optId, result)
def BuyItemEquip(self, param={}): '''商城购买装备或道具''' optId = 20006 ieSaleId = param['IeSaleId'] ieSaleCfg = Gcore.getCfg('tb_cfg_shop_ie_sale', ieSaleId) if ieSaleCfg is None: return Gcore.error(optId, -20006001)#商品不存在 modCoin = Gcore.getMod('Coin', self.uid) modBag = Gcore.getMod('Bag', self.uid) if not modBag.inclueOrNot(ieSaleCfg['SaleType'], ieSaleCfg['GoodsId'], ieSaleCfg['OnceNum']): return Gcore.error(optId, -20006002)#背包空间不足 classMethod = '%s,%s'%(self.__class__.__name__,sys._getframe().f_code.co_name) res = modCoin.PayCoin(optId, 1, ieSaleCfg['Price'], classMethod, param) if res == -2: return Gcore.error(optId, -20006994)#货币不足 if res < 0: return Gcore.error(optId, -20006995)#支付失败或者非法操作 modBag = Gcore.getMod('Bag', self.uid) buyId = modBag.addGoods(ieSaleCfg['SaleType'], ieSaleCfg['GoodsId'], ieSaleCfg['OnceNum'], addLog=optId) recordData = {'uid': self.uid, 'ValType': ieSaleCfg['GoodsId'], 'Val': ieSaleCfg['OnceNum'], 'GoodsType': ieSaleCfg['SaleType']}#成就、任务记录 return Gcore.out(optId, {'Result': buyId}, mission = recordData)
def CheckFriend(self, param={}): '''查看好友''' optId = 19007 friendUserId = param['FriendUserId'] if not self.mod.validateUser(friendUserId): return Gcore.error(optId, -19007001) #用户不存在 player = Gcore.getMod('Player', friendUserId) fileds = [ 'UserId', 'NickName', 'UserLevel', 'VipLevel', 'UserIcon', 'UserHonour', 'UserCamp' ] result = player.getUserBaseInfo(fileds) #获得基本信息 result['Rank'] = player.getHonRankNum(result) buildingClub = Gcore.getMod('Building_club', friendUserId) cId = buildingClub.getUserClubId() clubInfo = buildingClub.getClubInfo(cId, 'ClubName') if clubInfo: result['ClubName'] = clubInfo['ClubName'] #获得军团名字 else: result['ClubName'] = '' general = Gcore.getMod('General', friendUserId) generalNum = general.getMyGenerals('count(1) as gNum') result['GeneralNum'] = generalNum[0]['gNum'] #获得武将个数 buildingNum = self.mod.getBuildingCount(friendUserId) result['BuildingNum'] = buildingNum #获得建筑数量 return Gcore.out(optId, result)
def GetActivitiesUI(self, param={}): '''返回参数1首次充值2签到3成长奖励4活跃度礼包5鸿运当头6在线奖励''' optId = 23001 activities = Gcore.getCfg('tb_cfg_act') data = {} acts = [] for act in activities: if activities[act]['Status'] == 1: actId = activities[act]['ActivityId'] if actId == 1: #首冲活动 playerMod = Gcore.getMod('Player', self.uid) vipTotalPay = playerMod.getUserBaseInfo( ['VipTotalPay']).get('VipTotalPay') if vipTotalPay: giftState = self.mod.getGift(1, 0, ['isGet']).get('isGet') data['Recharged'] = 1 if giftState == 0 else 0 else: data['Recharged'] = 1 #新号要显示首冲活动 if not data['Recharged']: #1表示可以领首冲礼包或者新号显示首冲活动,0表示不显示 continue elif actId == 5: luckyLog = self.mod.getLuckLog() luckyLog['AwardId'] += 1 goodLuckCfg = Gcore.getCfg('tb_cfg_act_lucky_award', luckyLog['AwardId']) if not goodLuckCfg: continue acts.append(actId) data['Activities'] = acts return Gcore.out(optId, data)
def checkOpt(self,ckey,optId,optKey,para): if optId == 888888: result = Gcore.reload() print 'Gcore.reload()' msg = '<font color=green>Reload Success!</font>' if result is True else "<font color=red>"+str(result)+"</font>" response = Gcore.out(optId,{'Result':msg}) self.Send(ckey,response) elif 10001<=optId<=10005: #帐户相关: 10001登录,10002创建帐号,10003随机姓名,10004推荐阵营,10005检查帐户名是否合法 self.checkLogin(ckey,optId,optKey,para) else: if optId == 8888: #测试 #print 'Gcore.getDB(uid)>',Gcore.getDB(uid) self.mqPush(ckey,optId,optKey,para) else: uid = self.Clients[ckey]['uid'] if uid==0: response = Gcore.error(optId,-88888888) self.Send(ckey,response) print 'Please login first' return response = proManager.checkOpt(uid, optId, para) if type(response) is not dict: #print 'type(response)',type(response),response response = Gcore.error(optId,-33333333) #协议号未定义 或返回出错 response['opt_key'] = optKey self.Send(ckey,response)
def IfShowRevolt(self): '''是否需要显示反抗按键 @use: 点理藩院建筑时调用 ''' optId = 15129 show = 1 if self.mod.hasHolder() else 0 return Gcore.out(optId,{'show':show})
def CheckMissionStatus(self ,p={}): '''检查任务状态''' optId = 22005 self.mod.updateAllMissions() Gcore.getMod('Building_home',self.uid).updateAllAchieves() return Gcore.out(optId)
def CleanWallDefense(self,p={}): '''回收损毁的防御工事''' optId = 92012 CoinValue = self.mod.clearWallDefense() if CoinValue: Gcore.getMod('Coin',self.uid).GainCoin(optId,2,CoinValue,'WallUI.CleanWallDefense',p)#返回军资 reward = self.mod.getWallBoxReward() #获取遗落宝箱的奖励 if reward:#有奖励 rewardType = reward['RewardType'] goodsId = reward['GoodsId'] goodsNum = reward['GoodsNum'] ids = Gcore.getMod('Reward',self.uid).reward(optId,p,rewardType,goodsId,goodsNum) #reward['WillGet'] = 1 if rewardType==1: if isinstance(ids,list): reward['EquipIds'] = ids else: reward['EquipIds'] = [] else:#无奖励 #reward = {'WillGet':0} reward = {} recordData = {'uid':self.uid,'ValType':0,'Val':1,'WillGet':reward.get('WillGet')} body = {"CoinType":2,"CoinValue":CoinValue,"Reward":reward} return Gcore.out(optId,body,mission=recordData) else: return Gcore.error(optId,-92012001) #没有可回收的防御工事
def BuyMap(self, p={}): '''购买地图''' optId = 14002 if 'x' not in p or 'y' not in p: return Gcore.error(optId, -14002001) #非法参数 x = p['x'] y = p['y'] if not self.mod.checkBuyStartCoord(x, y): print self.mod.db.sql return Gcore.error(optId, -14002002) #所传的坐标非可购买坐标的起点 if self.mod.checkHadBuy(x, y): return Gcore.error(optId, -14002003) #你已经购买过此坐标 MapBuyTimes = Gcore.getMod('Player', self.uid).getMapBuyTimes() CostValue = Gcore.getCfg('tb_cfg_map_cost', MapBuyTimes, 'Cost') print CostValue #开始支付 modCoin = Gcore.getMod('Coin', self.uid) classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name) pay = modCoin.PayCoin(optId, 3, CostValue, classMethod, p) achieve = {'uid': self.uid, 'ValType': 0, 'Val': 1} #成就记录 if pay < 0: Gcore.error(optId, -14002995) #支付失败 else: if not self.mod.doBuyMap(x, y): return Gcore.error(optId, -14002004) #购买失败 else: return Gcore.out(optId, achieve=achieve)
def GetSpawnNum(self, param={}): '''获取当前时刻,兵营或工坊的新兵数量''' optId = 15030 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, -15030001) #玩家没有该建筑 if BuildingInfo['BuildingState'] == 1: return Gcore.error(optId, -15030002) #建筑正在建造 if BuildingInfo['BuildingType'] not in (6, 8): return Gcore.error(optId, -15030003) #建筑不是兵营或工坊 print '建筑ID', BuildingId print '建筑类型', BuildingInfo['BuildingType'] print '建筑等级', BuildingInfo['BuildingLevel'] modCamp = Gcore.getMod('Building_camp', self.uid) spawn_detail = modCamp.getSoldierStorage(BuildingInfo, TimeStamp) body = {} body['StorageNum'] = spawn_detail['StorageNum'] body['LastChangedTime'] = spawn_detail['LastChangedTime'] return Gcore.out(optId, body=body)
def CheckMissionStatus(self, p={}): '''检查任务状态''' optId = 22005 self.mod.updateAllMissions() Gcore.getMod('Building_home', self.uid).updateAllAchieves() return Gcore.out(optId)
def Say(self, para={}): '''发送聊天信息 @para : Channel => int 聊天类型:1,世界。2,势力。3,军团。4,私聊。5,系统。6,喇叭。 7, 系统公告(用于GM发布系统公告用)。8,活动。9,广播 @para : Content => string 消息体 @para : ToName => int or str 消息接受者(用于私聊) @note : 需要注意前玩家在游戏中 改变军团(退出或加入)时要更新Gcore.StorageUser['club'] ''' optId = 11001 #print 'say',para channel = para.get('Channel') content = para.get('Content') toName = para.get('ToName') #re=1 re = self.mod.say(optId, channel, content, toName) if re == -1: return Gcore.error(optId, -11001001) #聊天间隔限制 elif re == -2: return Gcore.error(optId, -11001002) #消息未通过验证 elif re == -3: return Gcore.error(optId, -11001003) #发送对象不在线 elif re == -4: return Gcore.error(optId, -11001004) #喇叭使用条件不足 elif re == -5: return Gcore.error(optId, -11001999) #聊天类型错误 elif re == -6: return Gcore.error(optId, -11001005) #不能私聊自己 elif re == -7: return Gcore.error(optId, -11001006) #权限不足 elif re == -8: return Gcore.error(optId, -11001007) #被禁言 else: #return Gcore.out(optId,{'Result':re}) return Gcore.out(optId)
def GetHolder(self, param={}): '''获取主人''' optId = 15125 holder = self.mod.getHolder() holder = holder if holder is not None else {} return Gcore.out(optId, body={'Holder': holder})
def IfShowRevolt(self): '''是否需要显示反抗按键 @use: 点理藩院建筑时调用 ''' optId = 15129 show = 1 if self.mod.hasHolder() else 0 return Gcore.out(optId, {'show': show})
def SaveTrain(self, param = {}): '''点将台:保留培养的属性''' optId = 15011 GeneralId = param["GeneralId"] modTrain = Gcore.getMod('Building_train', self.uid) TrainInfo = modTrain.getTrainRandoms(GeneralId) if not TrainInfo: return Gcore.error(optId, -15011001) #没有该武将的培养信息 #培养所得的属性值 TrainForce = TrainInfo["RandomForce"] TrainWit = TrainInfo["RandomWit"] TrainSpeed = TrainInfo["RandomSpeed"] TrainLeader = TrainInfo["RandomLeader"] modTrain.cancTrainRandoms() #先将培养信息置为无效 #更新武将表 if TrainForce or TrainWit or TrainSpeed or TrainLeader: #如果全是0,直接返回。 stat = modTrain.saveTrainGeneral(GeneralId, TrainForce, TrainWit, TrainSpeed, TrainLeader) if not stat: return Gcore.error(optId, -15011002) #用户没有该武将 return Gcore.out(optId, {})
def MoveElement(self,p={}): '''批量移动布防内的元素''' optId = 92002 ''' 参数例子: p = {} p['DefenseInfo'] = [ {'WallDefenseId':4,'x':1,'y':1,'xSize':1,'ySize':3}, {'WallDefenseId':5,'x':11,'y':13,'xSize':2,'ySize':2}, ] p['GeneralInfo'] = [ {'GeneralId':1,'x':8,'y':14}, {'GeneralId':2,'x':4,'y':43}, ] ''' # if 'DefenseInfo' in p: # WallDefenseIds = [ r['WallDefenseId'] for r in p['DefenseInfo'] ] # # rows = self.mod.getDefenseInfo(WallDefenseIds) # for row in rows: # SoldierType = row['SoldierType'] # xSize = row['xSize'] # ySize = row['ySize'] # Size = Gcore.getCfg('tb_cfg_soldier',SoldierType,'Size') # # if str(xSize)+'*'+str(ySize)!=Size and str(ySize)+'*'+str(xSize)!=Size: # return Gcore.error(optId,-92002998) #非法操作 # #@todo 坐标验证 result = self.mod.moveElement(p) if not result: return Gcore.error(optId,-92002997) #系统错误 else: return Gcore.out(optId)
def DeleteFriend(self, param={}): '''删除好友''' optId = 19006 friendUserId = param['FriendUserId'] self.mod.updateFriendShip(self.uid, friendUserId, 3) self.mod.updateFriendShip(friendUserId, self.uid, 3) return Gcore.out(optId, {})
def GetHold(self, param={}): ''' @旧:我的藩国(如果我有主人就显示主人信息): 获取主人和奴隶的信息 @新:显示我的藩国列表 ''' optId = 15123 #holder = self.mod.getHolder() #if not holder: if True: holder = {"hServerId": 0, "hUserId": 0} Slaves = self.mod.getHold() for Slave in Slaves: suid, ssid = Slave['UserId'], Slave.get( 'ServerId', Gcore.getServerId()) stat = self.mod.isMyHold(suid, ssid) if not stat: Slave['Jcoin'], Slave['Gcoin'] = 0, 0 else: Slave['Jcoin'], Slave['Gcoin'] = stat Slave.setdefault('ServerId', Gcore.getServerId()) else: Slaves = [] return Gcore.out(optId, {'Holder': holder, 'Holds': Slaves})
def AgreeApply(self, p={}): ''' :同意申请 ''' optId = 15070 userId = p.get('UserId') building = self.mod.getClubBuildingInfo() if building is None: return Gcore.error(optId, -15070901) #外史院建筑不存在 clubId = self.mod.getUserClubId() if not clubId: return Gcore.error(optId, -15070920) #军团不存在 memberNum = self.mod.getClubMemberNum(clubId) if memberNum.get('CurNum') >= memberNum.get('MaxNum'): return Gcore.error(optId, -15070001) #军团成员已满 if self.uid == userId: return Gcore.error(optId, -15070998) #对自己操作,非法权限 memberInfo = self.mod.getMemberInfo(clubId, userId) if not memberInfo: return Gcore.error(optId, -15070002) #没有申请记录 elif memberInfo.get('MemberState') != 0 and memberInfo.get( 'MemberState') != 4: return Gcore.error(optId, -15070996) #操作失败 self.mod.agreeApply(optId, clubId, userId) Gcore.setUserData(userId, {'ClubId': clubId}) #成员被允许加入,更新的军团信息 Gcore.push(113, userId, {'ClubId': clubId}) #推送军团ID recordData = {'uid': userId, 'ValType': 0, 'Val': 1} return Gcore.out(optId, mission=recordData)
def MailList(self, param={}): ''' 收件箱/发件箱列表 @param param['MailType']=1 表示收件箱 param['MailType']=2 表示发件箱 ''' optId = 18003 mailType = int(param['MailType']) page = int(param['Page']) #页码 if not page: #默认为第一页 page = 1 if mailType not in (1, 2): return Gcore.error(optId, -18003999) #MailType值不对 mailCfg = Gcore.loadCfg(Gcore.defined.CFG_MAIL) pagePerNum = int(mailCfg['MailShowPerPageMax']) #每页的邮件数 mailCount = int(self.mod.mailCountByType(mailType)) #收件箱/发件箱中邮件总数 mailDatas = self.mod.getMailList(mailType, page, pagePerNum) #每页显示的邮件数据 subjShowMax = mailCfg['SubjectShowMax'] #邮件主题显示最大长度 self.mod.finMailDatas(mailDatas, subjShowMax) totalPage = int(math.ceil(1.0 * mailCount / pagePerNum)) body = { 'mailDatas': mailDatas, 'page': page, 'mailCount': mailCount, 'totalpage': totalPage } return Gcore.out(optId, body=body)
def test(self,p={}): '''测试获取当前缓存的用户信息''' optId = 99001 Gcore.getUserData(1001, 'UserLevel') body = { 'Gcore.StorageUser': str(Gcore.StorageUser) } print 'body',body return Gcore.out(optId,body)
def GetSignInLog(self, param={}): '''获取签到日志''' optId = 23006 data = self.mod.getSigninLog() a = list(data['SignInDate']) data['SignInDate'] = ','.join(a) #获取全勤奖励信息 awards = Gcore.getCfg('tb_cfg_act_signin_award').values() fullWorkAwards = filter(lambda dic:dic['AwardId']>=3000 and dic['AwardId']<4000, awards) now = datetime.datetime.now() data['FullWorkAwardId'] = fullWorkAwards[now.month-1]['AwardId'] #获取周期奖励信息 finalAwards = Gcore.loadCfg(CFG_ACT_SIGNIN)['FinalAwardId'] #awards = finalAwards.split(',') awards = finalAwards signCount = data['SignInCount'] n = signCount / 30 % len(awards) if signCount % 30 == 0: n -= 1 awardId = int(awards[n]) data['FinalAwardId'] = awardId signCount = signCount % 30 data['SignInDays'] = signCount if signCount else 30 #用于前台显示当前周期内的天数,30天一周期 data['Refill'] = 5 - data['Refill'] return Gcore.out(optId, data)
def GetSignInLog(self, param={}): '''获取签到日志''' optId = 23006 data = self.mod.getSigninLog() a = list(data['SignInDate']) data['SignInDate'] = ','.join(a) #获取全勤奖励信息 awards = Gcore.getCfg('tb_cfg_act_signin_award').values() fullWorkAwards = filter( lambda dic: dic['AwardId'] >= 3000 and dic['AwardId'] < 4000, awards) now = datetime.datetime.now() data['FullWorkAwardId'] = fullWorkAwards[now.month - 1]['AwardId'] #获取周期奖励信息 finalAwards = Gcore.loadCfg(CFG_ACT_SIGNIN)['FinalAwardId'] #awards = finalAwards.split(',') awards = finalAwards signCount = data['SignInCount'] n = signCount / 30 % len(awards) if signCount % 30 == 0: n -= 1 awardId = int(awards[n]) data['FinalAwardId'] = awardId signCount = signCount % 30 data[ 'SignInDays'] = signCount if signCount else 30 #用于前台显示当前周期内的天数,30天一周期 data['Refill'] = 5 - data['Refill'] return Gcore.out(optId, data)
def GetActivitiesUI(self, param={}): '''返回参数1首次充值2签到3成长奖励4活跃度礼包5鸿运当头6在线奖励''' optId = 23001 activities = Gcore.getCfg('tb_cfg_act') data = {} acts = [] for act in activities: if activities[act]['Status'] == 1: actId = activities[act]['ActivityId'] if actId == 1:#首冲活动 playerMod = Gcore.getMod('Player',self.uid) vipTotalPay = playerMod.getUserBaseInfo(['VipTotalPay']).get('VipTotalPay') if vipTotalPay: giftState = self.mod.getGift(1, 0, ['isGet']).get('isGet') data['Recharged'] = 1 if giftState == 0 else 0 else: data['Recharged'] = 1 #新号要显示首冲活动 if not data['Recharged']: #1表示可以领首冲礼包或者新号显示首冲活动,0表示不显示 continue elif actId == 5: luckyLog = self.mod.getLuckLog() luckyLog['AwardId'] += 1 goodLuckCfg = Gcore.getCfg('tb_cfg_act_lucky_award', luckyLog['AwardId']) if not goodLuckCfg: continue acts.append(actId) data['Activities'] = acts return Gcore.out(optId, data)
def Say(self,para={}): '''发送聊天信息 @para : Channel => int 聊天类型:1,世界。2,势力。3,军团。4,私聊。5,系统。6,喇叭。 7, 系统公告(用于GM发布系统公告用)。8,活动。9,广播 @para : Content => string 消息体 @para : ToName => int or str 消息接受者(用于私聊) @note : 需要注意前玩家在游戏中 改变军团(退出或加入)时要更新Gcore.StorageUser['club'] ''' optId = 11001 #print 'say',para channel=para.get('Channel') content=para.get('Content') toName=para.get('ToName') #re=1 re=self.mod.say(optId, channel,content,toName) if re==-1: return Gcore.error(optId,-11001001)#聊天间隔限制 elif re==-2: return Gcore.error(optId,-11001002)#消息未通过验证 elif re==-3: return Gcore.error(optId,-11001003)#发送对象不在线 elif re==-4: return Gcore.error(optId,-11001004)#喇叭使用条件不足 elif re==-5: return Gcore.error(optId,-11001999)#聊天类型错误 elif re==-6: return Gcore.error(optId,-11001005)#不能私聊自己 elif re==-7: return Gcore.error(optId,-11001006)#权限不足 elif re==-8: return Gcore.error(optId,-11001007)#被禁言 else: #return Gcore.out(optId,{'Result':re}) return Gcore.out(optId)
def GetUpgradingTech(self,p={}): '''查询正在学习中的科技''' optId = 15050 buildingId = p.get('BuildingId') tech = self.mod.getUpgradingTech(buildingId) flag = 1 if tech else 0 return Gcore.out(optId,{'IsUpgrading':flag,'Tech':tech})
def Exchange(self, para={}): '''货币兑换 by Lizr''' optId = 20001 CoinType = para['CoinType'] CoinValue = para['CoinValue'] if CoinType not in (2, 3): return Gcore.error(optId, -20001998) #非法操作 if type(CoinValue) not in (int, long) or CoinValue <= 0: return Gcore.error(optId, -20001998) #非法操作 storageSpace = Gcore.getMod('Building', self.uid).cacStorageSpace(CoinType) addPercent = CoinValue / storageSpace rateInfos = Gcore.getCfg('tb_cfg_shop_res_sale') rateInfoList = filter(lambda dic:dic['AddPercent'] <= addPercent and dic['CoinType'] == CoinType, rateInfos.values()) rateInfo = max(rateInfoList, key=lambda sale:sale['AddPercent']) rate = rateInfo['kPrice1'] * (storageSpace ** rateInfo['kPrice2']) GoldValue = int(math.ceil(CoinValue * rate)) # rate = Gcore.loadCfg(2001).get('exchange').get(str(CoinType)) # GoldValue = math.ceil(CoinValue/rate) modCoin = Gcore.getMod('Coin', self.uid) classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name) pay = modCoin.PayCoin(optId, 1, GoldValue, classMethod, para) if pay < 0: return Gcore.error(optId, -20001995) #支付失败 else: #GainValue = GoldValue*rate #GainValue = int(math.ceil(GoldValue / rate)) #result = modCoin.GainCoin(optId, CoinType, GainValue, classMethod, para) result = modCoin.GainCoin(optId, CoinType, CoinValue, classMethod, para) body = {"CoinType": CoinType, "CoinValue": CoinValue, "GoldUsed": pay} return Gcore.out(optId, body)
def checkLogin(self,ckey,optId,optKey,para): """登录验证,不同于城市场景的登录""" from sgLib.pyMcrypt import TokenDecode #tokenDict: {u'TotalServiceId': u'42', u'LoginMode': 2, u'PlayerId': 0, u'LoginVersion': 101, u'Lan': 1, u'LockTime': 1367994093} response = None try: objToken = TokenDecode() tokenDict = objToken.getTokenMsg(para.get("pyKey")) print 'tokenDict > ',tokenDict if not self.Clients[ckey]['uid']: c = Login() uid = c.getUserIdByAccount(tokenDict.get('TotalServiceId')) self.Clients[ckey]['uid'] = uid print 'Player %s logined'%self.Clients[ckey]['uid'] else: print 'Developer %s logined'%self.Clients[ckey]['uid'] uid = self.Clients[ckey]['uid'] Gcore.onlineUser[uid] = 1 response = Gcore.out(optId,{'ServerTime':time.time()}) #Gcore.setUserData(uid, {'Channel':self.Clients[ckey]['Channel']}) #储存用户channel 推送需要 except Exception: pass if not response: response = Gcore.error(optId,-10001003) #登录验证失败 response['opt_key'] = optKey self.Send(ckey,response)
def checkOpt(self, ckey, optId, optKey, para): if optId == 888888: result = Gcore.reload() print 'Gcore.reload()' msg = '<font color=green>Reload Success!</font>' if result is True else "<font color=red>" + str( result) + "</font>" response = Gcore.out(optId, {'Result': msg}) self.Send(ckey, response) elif 10001 <= optId <= 10005: #帐户相关: 10001登录,10002创建帐号,10003随机姓名,10004推荐阵营,10005检查帐户名是否合法 self.checkLogin(ckey, optId, optKey, para) else: if optId == 8888: #测试 #print 'Gcore.getDB(uid)>',Gcore.getDB(uid) self.mqPush(ckey, optId, optKey, para) else: uid = self.Clients[ckey]['uid'] if uid == 0: response = Gcore.error(optId, -88888888) self.Send(ckey, response) print 'Please login first' return response = proManager.checkOpt(uid, optId, para) if type(response) is not dict: #print 'type(response)',type(response),response response = Gcore.error(optId, -33333333) #协议号未定义 或返回出错 response['opt_key'] = optKey self.Send(ckey, response)
def GetPatchNum(self, para={}): '''获取碎片的数量''' optId = 15132 #获得碎片的数量 patchs_num = self.mod.getPatchNum() #获得各种武将卡的数量 cards_num = self.mod.getGeneralCardNum() #是个字典 #武将卡的所有类型 item_ids = Gcore.getCfg('tb_cfg_general_patch').keys() #组合成返回结果 rels = [] for item_id in item_ids: item = { 'ItemId': item_id, 'Number': cards_num.get(item_id, 0), 'Patch1': 0, 'Patch2': 0, 'Patch3': 0, 'Patch4': 0, } for patch_num in patchs_num: if patch_num['ItemId'] == item_id: item.update(patch_num) break #if item['Number'] or item['Patch1'] or item['Patch2'] or \ # item['Patch3'] or item['Patch4']: rels.append(copy.deepcopy(item)) return Gcore.out(optId, rels)
def test(self, p={}): '''测试获取当前缓存的用户信息''' optId = 99001 Gcore.getUserData(1001, 'UserLevel') body = {'Gcore.StorageUser': str(Gcore.StorageUser)} print 'body', body return Gcore.out(optId, body)
def GetHold(self, param={}): ''' @旧:我的藩国(如果我有主人就显示主人信息): 获取主人和奴隶的信息 @新:显示我的藩国列表 ''' optId = 15123 #holder = self.mod.getHolder() #if not holder: if True: holder = {"hServerId":0, "hUserId":0} Slaves = self.mod.getHold() for Slave in Slaves: suid, ssid = Slave['UserId'], Slave.get('ServerId', Gcore.getServerId()) stat = self.mod.isMyHold(suid, ssid) if not stat: Slave['Jcoin'], Slave['Gcoin'] = 0, 0 else: Slave['Jcoin'], Slave['Gcoin'] = stat Slave.setdefault('ServerId', Gcore.getServerId()) else: Slaves = [] return Gcore.out(optId, {'Holder':holder, 'Holds':Slaves})
def StripEquip(self, param={}): '''点将台:将武将某个部位的装备脱下来''' optId = 15016 GeneralId = param['GeneralId'] EquipPart = param['EquipPart'] Flag = param.get('Flag') #False脱装备;1脱宝物;其他脱兵书 modGeneral = Gcore.getMod('General', self.uid) General = modGeneral.getGeneralInfo(GeneralId) if not General: return Gcore.error(optId, -15016001) #玩家无此武将 if not Flag: stat = modGeneral.stripEquip(General, EquipPart) if stat == -1: return Gcore.error(optId, -15016002) #装备部位不正确或该武将在该部位上没有装备 if stat == -2: return Gcore.error(optId, -15016003) #向背包中增加装备失败 else: stat = modGeneral.stripEquip_EX(GeneralId, Flag) if stat == -1: return Gcore.error(optId, -15016004) #没穿兵书或宝物 if stat == -2: return Gcore.error(optId, -15016005) #背包已满 #返回 return Gcore.out(optId, body={})
def GetHolder(self, param={}): '''获取主人''' optId = 15125 holder = self.mod.getHolder() holder = holder if holder is not None else {} return Gcore.out(optId, body = {'Holder':holder})
def GetPatchNum(self, para={}): """获取碎片的数量""" optId = 15132 # 获得碎片的数量 patchs_num = self.mod.getPatchNum() # 获得各种武将卡的数量 cards_num = self.mod.getGeneralCardNum() # 是个字典 # 武将卡的所有类型 item_ids = Gcore.getCfg("tb_cfg_general_patch").keys() # 组合成返回结果 rels = [] for item_id in item_ids: item = { "ItemId": item_id, "Number": cards_num.get(item_id, 0), "Patch1": 0, "Patch2": 0, "Patch3": 0, "Patch4": 0, } for patch_num in patchs_num: if patch_num["ItemId"] == item_id: item.update(patch_num) break # if item['Number'] or item['Patch1'] or item['Patch2'] or \ # item['Patch3'] or item['Patch4']: rels.append(copy.deepcopy(item)) return Gcore.out(optId, rels)
def SlaveOperand(self, param={}): '''对藩国的操作 纳贡 或 释放''' optId = 15121 typ = param['typ'] #操作类型:1,纳贡。2,释放。 uid = param['uid'] #藩国UserId sid = param['sid'] #藩国ServerId ts = param['ClientTime'] #客户端时间戳 recordData = {}#成就记录 stat = self.mod.isMyHold(uid, sid) if not stat: #不是玩家的藩国 return Gcore.error(optId, -15121001) Jcoin, Gcoin = stat[0], stat[1] modCoin = Gcore.getMod('Coin', self.uid) classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name) if typ == 1: #1,纳贡 if Jcoin == 0 and Gcoin == 0: return Gcore.error(optId, -15121002) #不可收集 j = modCoin.GainCoin(optId, 2, Jcoin, classMethod, param) g = modCoin.GainCoin(optId, 3, Gcoin, classMethod, param) if j < -1 or g < -1: return Gcore.error(optId, -15121003) #增加货币操作失败 j = 0 if Jcoin==0 else j g = 0 if Gcoin==0 else g self.mod.collect(uid, sid, j, g, ts) recordData = {'uid':self.uid,'ValType':0,'Val':1}#成就记录 elif typ == 2: #2,释放。 j = modCoin.GainCoin(optId, 2, Jcoin, classMethod, param) g = modCoin.GainCoin(optId, 3, Gcoin, classMethod, param) self.mod.free(uid, sid, ts) else: return Gcore.error(optId, -15121005) #操作类型错误 return Gcore.out(optId, body = {"Jcoin":j, "Gcoin":g},mission=recordData)
def BuyMap(self,p={}): '''购买地图''' optId = 14002 if 'x' not in p or 'y' not in p: return Gcore.error(optId,-14002001) #非法参数 x = p['x'] y = p['y'] if not self.mod.checkBuyStartCoord(x,y): print self.mod.db.sql return Gcore.error(optId,-14002002) #所传的坐标非可购买坐标的起点 if self.mod.checkHadBuy(x,y): return Gcore.error(optId,-14002003) #你已经购买过此坐标 MapBuyTimes = Gcore.getMod('Player',self.uid).getMapBuyTimes() CostValue = Gcore.getCfg('tb_cfg_map_cost',MapBuyTimes,'Cost') print CostValue #开始支付 modCoin = Gcore.getMod('Coin',self.uid) classMethod = '%s.%s' % (self.__class__.__name__, sys._getframe().f_code.co_name) pay = modCoin.PayCoin(optId, 3, CostValue, classMethod, p) achieve = {'uid':self.uid,'ValType':0,'Val':1}#成就记录 if pay < 0: Gcore.error(optId, -14002995) #支付失败 else: if not self.mod.doBuyMap(x,y): return Gcore.error(optId,-14002004) #购买失败 else: return Gcore.out(optId,achieve=achieve)
def ModifyClub(self, p={}): ''' :修改军团信息(团长) ''' optId = 15065 logoId = p.get('LogoId') clubNotice = p.get('ClubNotice') allowState = p.get('AllowState') building = self.mod.getClubBuildingInfo() if building is None: return Gcore.error(optId, -15065901) #外史院建筑不存在 cfgClub = Gcore.loadCfg(defined.CFG_BUILDING_CLUB) noticeLimit = cfgClub.get('ClubNoticeLimit') flag = com.filterInput(clubNotice, 0, noticeLimit) if flag == -1: return Gcore.error(optId, -15065993) #长度不符合要求 elif flag == -2: return Gcore.error(optId, -15065992) #不能含有敏感字符 if logoId not in range(1, 7): return Gcore.error(optId, -15065999) #参数错误 clubId = self.mod.getUserClubId() if not clubId: return Gcore.error(optId, -15065920) #军团不存在 clubLeader = self.mod.getClubLeader(clubId) if self.uid != clubLeader.get('UserId'): return Gcore.error(optId, -15065998) #非法权限 data = { 'ClubLogoId': logoId, 'ClubNotice': clubNotice, 'AllowState': allowState } self.mod.modifyClub(clubId, data) return Gcore.out(optId, data)