本文整理汇总了Python中sgLib.core.Gcore.setUserData方法的典型用法代码示例。如果您正苦于以下问题:Python Gcore.setUserData方法的具体用法?Python Gcore.setUserData怎么用?Python Gcore.setUserData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sgLib.core.Gcore
的用法示例。
在下文中一共展示了Gcore.setUserData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AgreeApply
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
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)
示例2: vipAddTotal
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def vipAddTotal(self, optId, goldNum):
'''
:玩家充值黄金,增加玩家累积黄金,更新Vip等级
@param goldNum:增加的黄金数量
'''
userInfo = self.getUserInfo(['VipLevel','VipTotalPay'])
curLevel = userInfo.get('VipLevel')
curVipTotal = userInfo.get('VipTotalPay')
totalPay = goldNum+curVipTotal
levelCfg = Gcore.getCfg('tb_cfg_vip_up')
levelUp = max([levelCfg[level]['VipLevel'] for level in levelCfg if totalPay>=levelCfg[level]['TotalPay']])
data = {'VipTotalPay':totalPay,'VipLevel':levelUp}
self.db.update('tb_user',data,'UserId=%s'%self.uid)
if levelUp>curLevel:#VIP升级
interMod = Gcore.getMod('Inter',self.uid)
interMod.updateInterVip()#更新VIP内政加成
Gcore.setUserData(self.uid,{'VipLevel':levelUp}) #更新用户缓存 Lizr
Gcore.push(107,self.uid,{'VipLevel':levelUp}) #推送给前端升级 Lizr
if curVipTotal==0:
#增加首冲奖励
Gcore.getMod('Activity',self.uid).insertGifts(1,0)
#发送系统邮件
mailMod = Gcore.getMod('Mail', self.uid)
mailMod.sendSystemMail(self.uid, [], optId, other=[goldNum,])
return levelUp
示例3: ApplyClub
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
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})#不允许加入
示例4: addUserExp
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def addUserExp(self,getWay,amount=0,optId=0):
'''
:增加主角经验(动作触发)
@param getWay: 用户获得经验方式0:直接加经验,1-99:消耗加经验 101-199: 事件加经验
@param amount: if getWay==0:amount='增加的经验值';elif 1<1getWay<99:amount='消耗货币量';
@return: 返回主角经验等级,当前经验
'''
expCfg = Gcore.getCfg('tb_cfg_exp_get',getWay)
fields = ['UserLevel','UserExp']
userInfo = self.db.out_fields('tb_user',fields,'UserId=%s'%self.uid)
userLevel = userInfo['UserLevel']
userExp = userInfo['UserExp']
getExp = 0
if expCfg:#动作增加经验方式
segment = getWay/100#判断是消耗还是事件
if segment==0:#消耗
factor1 = expCfg.get('Factor1',0)
factor2 = expCfg.get('Factor2',0)
getExp = int(factor1*amount+factor2*userLevel)
elif segment==1 and self._getLimitOfEvent(getWay):#事件
baseExp = expCfg.get('BaseExp',0)
getExp = int(baseExp*(userLevel+1)*(1+userLevel/200.0)+1)
elif getWay==0:#直接加经验
getExp=amount
#增加经验,同时更新等级
if getExp>0:
updateExp = self._calUserLevel(userLevel, userExp+getExp)
self.db.update('tb_user',updateExp,'UserId=%s'%self.uid)
newLevel = updateExp.get('UserLevel')
#获得经验记录
logData = {'UserId':self.uid,'GetWay':getWay,'OptId':optId,
'UserType':Gcore.getUserData(self.uid,'UserType'),
'UserLevel':newLevel,'ExpValue':getExp,'CreateTime':time.time()}
self.db.insert('tb_log_exp',logData,isdelay=True)
#主角升级
if newLevel>userLevel:
#升级推送
Gcore.push(108,self.uid,{'UserLevel':newLevel})
mMod = Gcore.getMod('Mission',self.uid)
mMod.getNewMission(userLevel=newLevel)#用户升级查看有没有新任务
Gcore.setUserData(self.uid, {'UserLevel':newLevel}) #更新缓存中的用户等级 Lizr
Gcore.getMod('General',self.uid).touchGeneralLv(newLevel)
Gcore.getMod('War',self.uid).touchActPoint(userLevel,newLevel) #更新行动力
modActivity=Gcore.getMod('Activity',self.uid)#报错
modActivity.growUpAward(newLevel, userLevel)#成长奖励活动Yew
if newLevel >= Gcore.loadCfg(Gcore.defined.CFG_RANK_FIGHT).get('RankFightOpenLevel',20):
Gcore.getMod('RankFight',self.uid).joinRankFight() #每次升级都尝试加入排行榜 防止有漏
return updateExp
else:
return userInfo
示例5: _getMissionCache
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def _getMissionCache(self,action=''):
'''获取任务缓存'''
activeMission = Gcore.getUserData(self.uid,'ActiveMission')#缓存查询
if (activeMission is None) or (not isinstance(activeMission,dict)):
myLog = Gcore.getLogger('zhanggh','mission')
myLog.error("任务缓存有异常,UserId:%s,动作:%s,用户缓存内容:"%(self.uid,action))
myLog.error( Gcore.StorageUser.get(self.uid))
activeMission = self.db.out_rows('tb_mission',['MissionId','GetValue'],'UserId=%s AND Status in (1,2)'%self.uid)
activeMission = {k['MissionId']:k for k in activeMission}
Gcore.setUserData(self.uid,{'ActiveMission':activeMission})
return activeMission
示例6: _getAchieveCache
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def _getAchieveCache(self,action=''):
'''获取成就缓存'''
activeAchieve = Gcore.getUserData(self.uid, 'ActiveAchieve')#缓存活跃成就
if (activeAchieve is None) or (not isinstance(activeAchieve,list or tuple)):
myLog = Gcore.getLogger('zhanggh','achieve')
myLog.error("成就缓存有异常,UserId:%s,动作:%s,用户缓存内容:"%(self.uid,action))
myLog.error( Gcore.StorageUser.get(self.uid))
activeAchieve = self.getAchievements()
activeAchieve = [k for k in activeAchieve if activeAchieve[k]['Finished']==0]
Gcore.setUserData(self.uid,{'ActiveAchieve':activeAchieve})
return activeAchieve
示例7: initMission
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def initMission(self,mIds,userId=None,pushMsg=True):
'''
:给玩家添加一个或者多个任务
@param mId:任务Id,一个或者多个
@param userId:用户ID
'''
if userId is None:
userId = self.uid
if not isinstance(mIds, (list, tuple)):
mIds = [mIds]
tb_m = 'tb_mission'
mCfgs = Gcore.getCfg('tb_cfg_mission')
now = time.time()
insertdata = []
missionCaches = {}
pushMids = []
for mid in mIds:
data = {'MissionId':mid,'UserId':userId,
'GetValue':0,'Status':1,
'CreateTime':now,'CompleteTime':0}
missionCache = {}
#处理需要特需处理的任务
getVal = self.getMissionUpdateVal(mid)
if getVal:
data['GetValue'] = getVal
paramB = mCfgs[mid]['ParamB']
if getVal>=paramB:#任务完成
data['GetValue'] = paramB
data['Status'] = 3
data['CompleteTime'] = now
else:
missionCache = {'MissionId':mid,'GetValue':getVal}
else:
missionCache = {'MissionId':mid,'GetValue':0}
if self.db.insert(tb_m,data):
insertdata.append(data)
pushMids.append(mid)
if missionCache:#增加缓存
missionCaches[mid] = missionCache
# 更新任务缓存
if missionCaches:
activeMission = self._getMissionCache('initMision')
activeMission.update(missionCaches)
Gcore.setUserData(self.uid, {'ActiveMission':activeMission})
# 推送新任务
if pushMsg and pushMids:
Gcore.push(102,self.uid,{'MT':1,'MIDS':pushMids})
return insertdata
示例8: updateAchieve
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def updateAchieve(self,aData):
'''更新成就,(更新相应缓存)'''
aCfgs = Gcore.getCfg('tb_cfg_achieve')
activeAction = self._getAchieveCache('updateAchieve')
#
# print 'Building_homeMod更新成就',aData
pusAID = []
updateNum = 0
for aType in aData:
data = aData[aType]
curAchieve = data.get('CurrentAchieve')
nextAchieveId = data.get('NextAchieveId')
finished = data.get('Finished')
overMax = 0
#判断成就是否达成
if curAchieve and nextAchieveId:
aCfg = aCfgs[aType]
nextAchieve = aCfg[nextAchieveId]['AchieveRequire']#下一成就值
if curAchieve>=nextAchieve:
pusAID.append(aType)
#成就记录不能超出最成就值
maxAchieve = aCfg[max(aCfg.keys())]['AchieveRequire']
if curAchieve>=maxAchieve:
overMax = 1
data['CurrentAchieve'] = maxAchieve
#更新缓存
if (aType in activeAction) and (overMax or finished):
activeAction.remove(aType)
flag = self.db.update('tb_achieve',data,'UserId=%s AND AchieveType=%s'%(self.uid,aType))
if flag:
updateNum += 1
#更新缓存
Gcore.setUserData(self.uid, {'ActiveAchieve':activeAction})
#成就达成推送
if pusAID:
print '成就达成',pusAID
#暂不推送
# Gcore.push(103,self.uid,{'ACT':pusAID})
return updateNum
示例9: ExitClub
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def ExitClub(self,p={}):
'''退出军团'''
optId = 15072
building = self.mod.getClubBuildingInfo()
if building is None:
return Gcore.error(optId,-15072901)#外史院建筑不存在
clubId = self.mod.getUserClubId()
if not clubId:
return Gcore.error(optId,-15072920)#军团不存在
userType = 3#普通成员
clubLeader = self.mod.getClubLeader(clubId)
if self.uid == clubLeader.get('UserId'):
userType = 1#团长
self.mod.dismissMember(optId, clubId, self.uid, way=3, userType=userType)
Gcore.setUserData(self.uid, {'ClubId':0})#更新用户缓存
return Gcore.out(optId,{})
示例10: CreateClub
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def CreateClub(self,p={}):
'''创建军团
@logoId :1-6
'''
optId = 15060
CfgClub = Gcore.loadCfg(defined.CFG_BUILDING_CLUB)
s_Name = p.get('ClubName')
LogoId = p.get('LogoId')
i_Min = CfgClub.get('ClubNameLimitMin')
i_Max = CfgClub.get('ClubNameLimitMax')
flag = com.filterInput(s_Name, i_Min, i_Max)
if flag == -1:
return Gcore.error(optId, -15060993) #长度不符合要求
elif flag == -2:
return Gcore.error(optId, -15060992) #不能含有敏感字符
building = self.mod.getClubBuildingInfo()
if building is None:
return Gcore.error(optId,-15060901)#外史院建筑不存在
MyClubId = self.mod.getUserClubId()
if MyClubId:
return Gcore.error(optId, -15060001) #你已加入军团,不能创建
if self.mod.hadSameName(s_Name):
return Gcore.error(optId, -15060002) #该军团名称已存在
#开始支付
CoinType = CfgClub.get('ClubCreateCostType')
CoinValue = CfgClub.get('ClubCreateCost')
modCoin = Gcore.getMod('Coin',self.uid)
classMethod = self.__class__.__name__+'.CreateClub'
result = modCoin.PayCoin(optId, CoinType, CoinValue, classMethod, p)
if result < 0:
return Gcore.error(optId,-15060995) #支付失败
else:
ClubId = self.mod.createClub(LogoId,s_Name) #创建军团
Gcore.setUserData(self.uid, {'ClubId':ClubId})#更新用户缓存
body = {'ClubId':ClubId}
recordData = {'uid':self.uid,'ValType':0,'Val':1}#任务
return Gcore.out(optId,body,mission=recordData)
示例11: warSweepNew
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def warSweepNew(self,warId,SweepTimes):
'''扫荡'''
result = {}
UserData = self.getUserInfo(['ProcessWarId'])
ProcessWarId = UserData['ProcessWarId']
rowStar = self.db.out_fields('tb_war_star','*','UserId=%s'%self.uid)
RestPoint,MaxPoint = self.getActPoint()
if warId>ProcessWarId or not rowStar.get('War%s'%warId):
return False
if RestPoint< Gcore.getCfg('tb_cfg_pve',warId,'ActPointNeed')*SweepTimes:
return False
else:
Gcore.setUserData(self.uid, {'Sweeping':True} )
#@todo 自动补兵
for i in xrange(SweepTimes):
restTimes = SweepTimes-i-1
if not Gcore.getUserData(self.uid, 'Sweeping'): #用户落线也会停止
break
else:
gevent.sleep( Gcore.loadCfg(9101).get('SweepSleep') ) #每场间隔3秒 读配置
modBattle = Gcore.getMod('Battle',self.uid,True)
initWarResult = modBattle.initWar(warId,1) #定义为扫荡战役
if not initWarResult:
print '初始化战斗失败'
break
modBattle.getWarInfo()
re = modBattle.endBattle({"resultType":5})
#print '战斗结果',re
result[warId] = re #结构不能更改 需要和前台一样
self.warlog(WarId=warId,IsWarSweep=1,Result=re.get('Result',0)) #@todo 添加更完整战役结果
Gcore.push(111,self.uid,{'result':result,'restPoint':RestPoint,'restTimes':restTimes})
if not re.get('Result'):
break
else:
RestPoint-=1
return True
示例12: updateMissions
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def updateMissions(self,mData):
'''更新多个任务(更新相应的任务缓存数据)
@param mData: {MId:updateData} MId:任务ID,updateData:更新内容
@return: 更新数目
'''
tb_m = 'tb_mission'
mCfg = Gcore.getCfg('tb_cfg_mission')
activeMission = Gcore.getUserData(self.uid, 'ActiveMission')
# print '更新任务信息=>',mData
# print '任务缓存信息=>',activeMission
pusMId = []
updateNum = 0
for mId in mData:
data = mData[mId]
getVal = data.get('GetValue',0)
paramB = mCfg[mId]['ParamB']
#如果任务完成推送消息
if getVal>=paramB:
data['GetValue']=paramB
data['Status']=3
data['CompleteTime'] = time.time()
pusMId.append(mId)
activeMission.pop(mId,None)#任务完成删除缓存任务
elif getVal:
activeMission[mId]['GetValue'] = getVal#更新缓存任务信息
if self.db.update(tb_m,data,'UserId=%s AND MissionId=%s'%(self.uid,mId)):
updateNum +=1
#更新任务缓存
Gcore.setUserData(self.uid, {'ActiveMission':activeMission})
#推送通知任务完成
if pusMId:
print '任务完成',str(pusMId)
Gcore.push(102,self.uid,{'MT':2,'MIDS':pusMId})
return updateNum
示例13: DismissMember
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def DismissMember(self,p={}):
'''
:开除成员(团长操作)
'''
optId = 15068
userId = p.get('UserId')
building = self.mod.getClubBuildingInfo()
if building is None:
return Gcore.error(optId,-15068901)#外史院建筑不存在
clubId = self.mod.getUserClubId()
if not clubId:
return Gcore.error(optId,-15068920)#军团不存在
clubLeader = self.mod.getClubLeader(clubId)
if self.uid != clubLeader.get('UserId') or self.uid == userId:
return Gcore.error(optId,-15068998)#非法权限
userClubId = self.mod.getUserClubId(userId)
if userClubId != clubId:
return Gcore.error(optId,-15068002)#该用户非军团成员
self.mod.dismissMember(optId, clubId, userId)
Gcore.setUserData(userId, {'ClubId':0})#更新被开除成员的军团信息
Gcore.push(113,userId,{'ClubId':0})#推送军团ID
return Gcore.out(optId)
示例14: cacheUserData
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def cacheUserData(self, UserId=None, CacheAll=True):
'''获取用户的信息,用于缓存,登录时调用'''
#获取用户的阵营
if not UserId:
UserId = self.uid
print 'LoginMod.cacheUserInfo()',UserId
#UserCamp ,NickName 暂不会改变
row = self.getUserInfo(['UserCamp', 'NickName','VipLevel','UserLevel','UserIcon','UserType'])
if not row:
print 'error: not found user %s'%UserId
return
UserCamp = row['UserCamp']
NickName = row['NickName']
VipLevel = row['VipLevel']
UserLevel = row['UserLevel']
UserIcon = row['UserIcon']
UserType = row['UserType']
if CacheAll:
#获取用户的军团,用户更换军团的时候必须调用Gcore.setUserData(self.uid,{'ClubId':'xx'})
ClubId = self.db.out_field('tb_club_member', 'ClubId', 'UserId="%s" AND MemberState="%s"' % (UserId, 1))
#玩家未完成的成就
activeAchieve = Gcore.getMod('Building_home',self.uid).getAchievements()
activeAchieve = [k for k in activeAchieve if activeAchieve[k]['Finished']==0]
#玩家活跃任务
activeMission = self.db.out_rows('tb_mission',['MissionId','GetValue'],'UserId=%s AND Status in (1,2)'%UserId)
activeMission = {k['MissionId']:k for k in activeMission}
#用户升级或Vip升级的时候必须调用Gcore.setUserData(self.uid,{'xxx':'xx'})
DataDict = {'UserCamp':UserCamp, 'UserIcon':UserIcon, 'ClubId':ClubId, 'NickName':NickName,
'VipLevel':VipLevel,'UserLevel':UserLevel,'UserType':UserType,
'ActiveMission':activeMission,'ActiveAchieve':activeAchieve}
else: #战斗服务器使用
DataDict = {'UserCamp':UserCamp, 'NickName':NickName,'VipLevel':VipLevel,'UserLevel':UserLevel, 'UserIcon':UserIcon}
Gcore.setUserData(UserId, DataDict)
示例15: StopSweep
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import setUserData [as 别名]
def StopSweep(self,para={}):
'''停止 扫荡'''
optId = 91006
Gcore.setUserData(self.uid, {'Sweeping':False} )
return Gcore.out(optId)