本文整理汇总了Python中sgLib.core.Gcore类的典型用法代码示例。如果您正苦于以下问题:Python Gcore类的具体用法?Python Gcore怎么用?Python Gcore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gcore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: startSiege
def startSiege(self, para):
'''开始城战'''
optId = 93002
body = self.mod.startSiege() #开始攻城战斗
if not isinstance(body, dict):
return Gcore.error(optId,body) #body 是错误编号
return Gcore.out(optId,body)
示例2: getLatestGeneralInfo
def getLatestGeneralInfo(self, Generals=None, TimeStamp=None, UserLevel=None,
GeneralIds=None, fields='*', IsClubTech=True):
'''获取玩家武将的最新信息'''
# 参数:
# + Generals - 武将表中所有武将的信息
# + fields - 已取消,兼容以前的程序,现返回所有的字段
# + GeneralIds - 要查询的武将
# + + int, long, str - 查询单个武将的信息
# + + list, tuple - 查询多个武将的信息
# + + None - 查询玩家所有武将的信息
# + IsClubTech - 是否加上军团科技和宝物对武将四维属性的加成
# 返回值:
# + 单个武将:dict or None
# + 多个武将:list
# + 都不是:False
if not TimeStamp:TimeStamp = time.time()
if not Generals:Generals = self.getMyGenerals()
if not UserLevel:UserLevel = self.getUserLevel()
#加上武馆训练的经验
modGround = Gcore.getMod('Building_ground', self.uid)
_, Generals = modGround.touchPractise(Generals, TimeStamp, UserLevel)
if IsClubTech: #四维属性加上各种加成
# + 军团科技影响
modClub = Gcore.getMod('Building_club', self.uid)
club_tech_effects = modClub.getClubTechAdd()
# + 宝物影响
treasure_effects = self.getEquipExEffect([General['GeneralId'] for General in Generals])
# + 四维加上各种加成
for General in Generals:
General["ForceValue"] += int(club_tech_effects[1])
General["WitValue"] += int(club_tech_effects[2])
General["LeaderValue"] += int(club_tech_effects[3])
General["SpeedValue"] += int(club_tech_effects[4])
treasure_effect = treasure_effects[General['GeneralId']]
General["ForceValue"] += int(General["ForceValue"] * treasure_effect['force'])
General["WitValue"] += int(General["WitValue"] * treasure_effect['wit'])
General["SpeedValue"] += int(General["SpeedValue"] * treasure_effect['speed'])
General["LeaderValue"] += int(General["LeaderValue"] * treasure_effect['leader'])
if not GeneralIds: #返回所有武将的信息
return Generals
elif isinstance(GeneralIds, (int, long, str)): #返回单个武将的信息
for General in Generals:
if General["GeneralId"] == int(GeneralIds):
return General
return None
elif isinstance(GeneralIds, (list, tuple)): #返回多个武将的信息
ret = []
for General in Generals:
if General["GeneralId"] in map(int, GeneralIds):
ret.append(General)
return ret
return False
示例3: SaveTrain
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, {})
示例4: __init__
def __init__(self):
#self.validate = Validate()
self.Clients = {} #所有用户信息库
Gcore.objCfg.loadAllCfg() #读取所有配置
Gcore.IsServer = True #定义为服务器核心
Gcore.startNotice() #开启公告自动发布协程
示例5: getActPoint
def getActPoint(self):
'''获得 剩余行动点数/最大行动点数'''
BuyActPoint = self.getUserInfo('BuyActPoint')
row = self._lastActRecord()
MaxPoint = Gcore.getCfg('tb_cfg_action_point',self.getUserLevel(),'ActPoint')
if not row:
RestPoint = MaxPoint + BuyActPoint
else:
nowtime = Gcore.common.nowtime()
PerIncrTime = Gcore.loadCfg(9101).get('ActPointRecoverTime',1200)
if Gcore.TEST and self.uid in [1001,43953]:
PerIncrTime = testPerIncrTime
if row['ActPoint']>=MaxPoint: #已满,不恢复
RestPoint = row['ActPoint']
else:
AccuTime = row['AccuTime'] + ( nowtime - row['LastWarTime'] )
incrTimes = AccuTime//PerIncrTime #回复一点需要多长时间 20分钟
#print 'incrTimes',incrTimes
print 'getActPoint.上次剩余',row['ActPoint']
print 'getActPoint.至已经恢复了',incrTimes
ActPoint = row['ActPoint'] + incrTimes
if ActPoint > MaxPoint:
ActPoint = MaxPoint
print 'getActPoint.剩余+累计越出上限,设为上限',ActPoint
#查看的时候 不更新累计时间 tb_war_action.AccuTime
RestPoint = ActPoint
#print '剩余次数 最大次数',RestPoint,MaxPoint, 前台显示的是: 剩余次数/最大次数
return (RestPoint,MaxPoint)
示例6: randomName
def randomName(self, icon):
'''随机名称 '''
SelectNum = 30
if icon > 2:
sex = 2
else:
sex = 1
pMod = Gcore.getMod('Player', 1001)
lastnameList = Gcore.getCfg('tb_cfg_nickname').get(0)
firstnameList = Gcore.getCfg('tb_cfg_nickname').get(sex)
lastnameList = random.sample(lastnameList,SelectNum)
firstnameList = random.sample(firstnameList,SelectNum)
nicknames=[]
for i in xrange(SelectNum):
nickname = lastnameList[i]+firstnameList[i]
nicknames.append(nickname)
where = pMod.db.inWhere('NickName',nicknames)
rows = pMod.db.out_rows('tb_user','NickName',where)
existNickNames = [r['NickName'] for r in rows]
notExistNickNames = list(set(nicknames)-set(existNickNames))
NickNames = []
for NickName in notExistNickNames:
if Gcore.common.filterInput(NickName,2,16)<0:
pass #过滤敏感词的名称
else:
NickNames.append(NickName)
return NickNames[0]
示例7: sendMail
def sendMail(self, toUserIds, subject, content, mailUserType=2):
'''
发送邮件
@param toUserIds:发送对象Id,列表类型
@param subject:标题
@param content:内容
@param mailUserType:邮件类型1为系统邮件,2为私人邮件
@return 返回成功发送个数
'''
if mailUserType == 1:
fromUserId = 0
else:
fromUserId = self.uid
timeStamp = int(time.time())
mailConId = self.insMailCon(content)
result = 0
if len(toUserIds) and mailConId:
vals = []
for toId in toUserIds:
v = {}
v['FromUserId'] = fromUserId
v['ToUserId'] = toId
v['Subject'] = subject
v['MailConId'] = mailConId
v['CreateTime'] = timeStamp
v['MailUserType'] = mailUserType
vals.append(v)
result = self.db.insertmany('tb_mail', vals)
Gcore.push(101, toUserIds)
return result
示例8: mqPush
def mqPush(self, ckey, optId, optKey, para):
"""来自mqReceiver的消息,告诉玩家正在被打"""
# print ' in mqPush',para
Users = para.get("UserId")
Type = para.get("Type")
Data = para.get("Data", {})
Gcore.push(105, Users, Data, Type)
示例9: login
def login(self,loginIp=None,loginMode=None):
'''登入时调用的方法'''
now = time.time()
sql = "UPDATE tb_user SET LastLoginTime=UNIX_TIMESTAMP(),Online=1,LoginTimes=LoginTimes+1 WHERE UserId=%s"%self.uid
self.db.execute(sql)
#if not self.uid in Gcore.StorageUser: #缓存基础用户信息
if 1: # fixed by zhoujingjiang
self.cacheUserData(self.uid)
UserType = Gcore.getUserData(self.uid,'UserType')
#添加登录日志
# loginLogTB = 'tb_log_login201306'
loginLogTB = self.tb_log_login()
data = {'UserId':self.uid,'LoginTime':now,'UserType':UserType,
'LoginModel':loginMode,'LoginIP':loginIp}
self.logId = self.db.insert(loginLogTB,data)
print self.uid,'login get logId:%s at %s'%(self.logId,now)
key = Gcore.redisKey(self.uid)
Gcore.redisM.hset('sgLogin',key,'1')
UserLevel = self.getUserLevel()
modActivity=Gcore.getMod('Activity',self.uid)
modActivity.signin(0,'')
if UserLevel>=Gcore.loadCfg(9301).get('FightLevel'):
row = {}
row['Online']=1
row['UserId']=self.uid
示例10: findOutFighter
def findOutFighter(self,num=10,rowUser=None):
'''跨服查找可攻城对象'''
#print ' --- findOutFighter ---'
try:
if not rowUser:
rowUser = self.getUserInfo(['UserCamp','UserLevel'])
url = Gcore.loadCoreCfg('PlatformUrl')
Post = {}
Post['ServerId'] = Gcore.getServerId()
Post['LOCKKEY'] = TokenDecode().makeLockKey()
Post['FUNC'] ="FindUI.FindFighter"
Post['PARAM'] ={
'FromServerId':Gcore.getServerId(),
'UserCamp':rowUser['UserCamp'],
'UserLevel':rowUser['UserLevel'],
'GetNum':num,
}
url+='?MSG='+json.dumps(Post)
#print 'findOutFighter>>',url
req = urllib2.Request(url)
f = urllib2.urlopen(req)
response = f.read()
lis = response.split('@[email protected]')
return json.loads(lis[1])
except:
return []
示例11: CheckFriend
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)
示例12: checkAndUpdate
def checkAndUpdate(self, table):
'''查找并更新数据库中建筑费用为NULL的数据'''
fields = ['BuildingId', 'UserId', 'BuildingType', 'BuildingLevel', 'CoinType', 'BuildingPrice', 'LastChangedTime', 'CompleteTime']
where = ' CoinType is NULL or BuildingPrice is NULL or LastChangedTime is NULL OR CoinType = 0 OR BuildingPrice = 0 '
tmpRows = self.db.out_rows(table, fields, where)
if tmpRows:
for row in tmpRows:
#print '==PrimaryData:',row
tmpData = json.dumps(row) + '\n'
self.fd.write(tmpData)
if not row['CoinType']:
row['CoinType'] = Gcore.getCfg('tb_cfg_building', row['BuildingType'], 'CoinType')
if not row['BuildingPrice']:
row['BuildingPrice'] = Gcore.getCfg('tb_cfg_building_up', (row['BuildingType'], row['BuildingLevel']), 'CostValue')
if not row['LastChangedTime'] and row['LastChangedTime'] != 0:
if row['CompleteTime']:
row['LastChangedTime'] = row['CompleteTime'] - Gcore.getCfg('tb_cfg_building_up', (row['BuildingType'], row['BuildingLevel']), 'CDValue')
else:
row['LastChangedTime'] = 0
if row['LastChangedTime'] < 0:
row['LastChangedTime'] = 0
where = 'BuildingId=%s'%row['BuildingId']
data = {'CoinType': row['CoinType'], 'BuildingPrice': row['BuildingPrice'], 'LastChangedTime': row['LastChangedTime']}
self.db.update(table, data, where)
#print '==ModifiedData:',data
tmpData = json.dumps(data) + '\n'
self.fd.write(tmpData)
示例13: MailList
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)
示例14: setReventProcess
def setReventProcess(self, process, flag=0, TimeStamp=None):
'''设置反抗进度:process-攻城进度;flag-0失败,1成功'''
#返回值:-2 反抗次数已达到最大 -1 参数错误 0 没达到成功条件 1达到成功条件
if not 0 <= process <=1:
return -1 #攻城进度取值范围不对
TimeStamp = TimeStamp if TimeStamp else time.time()
cnt, pro = self.calcRevent(TimeStamp)
ratio = 0.5 #读配置
maxnum = 5 #读配置
cnt_new = cnt + 1
pro_new = pro + float(ratio * process) #取攻城进度的50%。
if cnt_new > maxnum:
return -2
elif pro_new >= 1.0 or flag == 1: #累积进度达到100% ## 读配置
self.db.execute('DELETE FROM `tb_hold_revenge` WHERE UserId="%s"'%self.uid)
hsid,huid = self.getMyHolder()
if huid:
self.freed(huid, hsid) #让自己被释放
pMod = Gcore.getMod('Player', self.uid)
protectTime = Gcore.loadCfg(CFG_BUILDING_HOLD)['RvProtectHoldSecond']
pMod.addProtectHoldTime(protectTime)
return 1
else: #增加累计进度
arr = {}
arr['ProcessTotal'] = pro_new
arr['RevengeCount'] = cnt_new
arr['LastRevengeDate'] = datetime.date.strftime(
datetime.date.fromtimestamp(TimeStamp), '%Y-%m-%d')
self.db.update('tb_hold_revenge', arr, 'UserId="%s"'%self.uid)
示例15: GetHold
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})