| | |
| | | except ValueError:
|
| | | return defValue
|
| | |
|
| | | def ToFloat(input, defValue = 0):
|
| | | try:
|
| | | result = float(input)
|
| | | return result
|
| | | |
| | | except ValueError:
|
| | | return defValue
|
| | | |
| | | ## 判断2个对象是否同国籍
|
| | | # @param srcObj 起点对象
|
| | | # @param desObj 目标对象
|
| | |
| | | ## 服务器组ID,必须唯一,代表这台物理服务器
|
| | | return ToIntDef(ReadChConfig.GetPyMongoConfig("platform", "GroupID"), 0)
|
| | |
|
| | | def GetMainServerID(serverID):
|
| | | ## 获取服务器ID所属主服ID
|
| | | ServerIDMainServerDict = IpyGameDataPY.GetConfigEx("ServerIDMainServerDict")
|
| | | if ServerIDMainServerDict == None:
|
| | | filePath = ChConfig.GetDBPath() + ("\\MixServerMap_%s.json" % GetPlatform())
|
| | | if not os.path.isfile(filePath):
|
| | | SendGameErrorEx("GetMainServerIDError", "file can not found. %s" % filePath)
|
| | | else:
|
| | | fileObj = open(filePath, 'rb')
|
| | | content = fileObj.read()
|
| | | fileObj.close()
|
| | | MixServerMapDict = eval(content)
|
| | | |
| | | ServerIDMainServerDict = {}
|
| | | for mainServerIDStr, serverIDList in MixServerMapDict.items():
|
| | | mainServerID = int(mainServerIDStr)
|
| | | for sID in serverIDList:
|
| | | ServerIDMainServerDict[sID] = mainServerID
|
| | | IpyGameDataPY.SetConfigEx("ServerIDMainServerDict", ServerIDMainServerDict)
|
| | | Log("加载 ServerIDMainServerDict=%s" % ServerIDMainServerDict)
|
| | | |
| | | if not ServerIDMainServerDict:
|
| | | return serverID
|
| | | return ServerIDMainServerDict.get(serverID, serverID)
|
| | |
|
| | | def GetPlatformServerNum(platform):
|
| | | # 获取服务器的平台编号
|
| | | platformNumDict = ReadChConfig.GetDBEvalChConfig("DBPlatformNum")
|
| | |
| | | ##获取玩家所属区服ID
|
| | | # @param curPlayer
|
| | | # @return
|
| | | def GetPlayerServerID(curPlayer):
|
| | | accID = curPlayer.GetAccID()
|
| | | def GetPlayerServerID(curPlayer): return GetAccIDServerID(curPlayer.GetAccID())
|
| | | def GetAccIDServerID(accID):
|
| | | infoList = accID.split(Def_AccID_Split_Sign)
|
| | | return 0 if len(infoList) < 3 else int(infoList[-1][1:])
|
| | | return 0 if len(infoList) < 3 else ToIntDef(infoList[-1][1:])
|
| | |
|
| | | def GetPlayerServerSID(curPlayer):
|
| | | # 返回含s的serverID
|
| | |
| | | return mainServerID
|
| | | return 0
|
| | |
|
| | | def CheckServerIDInList(serverID, serverIDList):
|
| | | if serverIDList == None:
|
| | | return False
|
| | | if not serverIDList:
|
| | | return True
|
| | | for serverIDInfo in serverIDList:
|
| | | if (isinstance(serverIDInfo, tuple) and serverIDInfo[0] <= serverID <= serverIDInfo[1]) \
|
| | | or (isinstance(serverIDInfo, list) and serverIDInfo[0] <= serverID <= serverIDInfo[1]) \
|
| | | or (isinstance(serverIDInfo, int) and serverIDInfo == serverID):
|
| | | return True
|
| | | return False
|
| | |
|
| | | #===============================================================================
|
| | | # ƽ̨ID = appid
|
| | |
| | | return tagPlayer.GetRealMapID()
|
| | |
|
| | | #---------------------------------------------------------------------
|
| | |
|
| | | def GetTemplateID(ipyData, cfgID, dayIndex):
|
| | | if cfgID == None or dayIndex == None or not ipyData:
|
| | | return 0
|
| | | templateIDList = ipyData.GetTemplateIDList()
|
| | | if not templateIDList:
|
| | | return 0
|
| | | templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]
|
| | | return templateID
|
| | |
|
| | | def GetTemplateIDByList(templateIDList, dayIndex):
|
| | | if dayIndex == None:
|
| | | return 0
|
| | | if not templateIDList:
|
| | | return 0
|
| | | templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex]
|
| | | return templateID
|
| | |
|
| | | def GetOperationActionDateStr(ipyData):
|
| | | ## 获取运营活动对应日期,存数字代表开服天配置,需要转化为对应的日期
|
| | |
| | | return pastTimeDelta.days * 24 * 60 * 60 + pastTimeDelta.seconds
|
| | |
|
| | | #---------------------------------------------------------------------
|
| | |
|
| | | def GetDiff_Day(timeA , timeB):
|
| | | ## 获取 timeA - timeB 相差的日期天数
|
| | | dateTimeA = ChangeTimeNumToDatetime(timeA)
|
| | | dateTimeA = datetime.datetime(dateTimeA.year, dateTimeA.month, dateTimeA.day, 0, 0, 0)
|
| | | dateTimeB = ChangeTimeNumToDatetime(timeB)
|
| | | dateTimeB = datetime.datetime(dateTimeB.year, dateTimeB.month, dateTimeB.day, 0, 0, 0)
|
| | | return (dateTimeA - dateTimeB).days
|
| | |
|
| | | ##设置世界服务器字典
|
| | | # @param key 字典值
|
| | | # @param tick 时间戳
|
| | |
| | | return ReadChConfig.GetPyMongoConfig("Merge", "CrossZoneName")
|
| | | return PyGameData.g_crossZoneName
|
| | |
|
| | | def GetCrossServerTimeStr():
|
| | | ## 跨服服务器时间
|
| | | if IsCrossServer():
|
| | | return GetCurrentDataTimeStr()
|
| | | lastCrossServerTime, lastServerTime, _ = PyGameData.g_crossServerTimeInfo
|
| | | if not lastCrossServerTime:
|
| | | return GetCurrentDataTimeStr()
|
| | | curTime = int(time.time())
|
| | | crossServerTime = lastCrossServerTime + (curTime - lastServerTime)
|
| | | return ChangeTimeNumToStr(crossServerTime)
|
| | |
|
| | | ## 获取玩家的区服名,仅在跨服有效
|
| | | # @param curPlayer 玩家实例
|
| | | # @return: 区服名
|
| | |
| | |
|
| | | return fullName
|
| | |
|
| | | def MergeItemList(itemList):
|
| | | ## 合并物品列表,将相同物品数量合并
|
| | | itemDict = {}
|
| | | for itemInfo in itemList:
|
| | | if len(itemInfo) == 3:
|
| | | itemID, itemCount, isAuctionItem = itemInfo
|
| | | elif len(itemInfo) == 2:
|
| | | itemID, itemCount = itemInfo
|
| | | isAuctionItem = None
|
| | | else:
|
| | | continue
|
| | | key = (itemID, isAuctionItem)
|
| | | itemDict[key] = itemDict.get(key, 0) + itemCount
|
| | | |
| | | mItemList = []
|
| | | for key, itemCount in itemDict.items():
|
| | | itemID, isAuctionItem = key
|
| | | if isAuctionItem == None:
|
| | | mItemList.append([itemID, itemCount])
|
| | | else:
|
| | | mItemList.append([itemID, itemCount, isAuctionItem])
|
| | | return mItemList
|
| | |
|
| | | ## 从列表中产生物品,[[几率,object], ....],万分率
|
| | | # @param itemList 待选列表
|
| | |
| | | # @param order 名次,从1开始
|
| | | # @param isDefaultLast 找不到的名次是否默认取最后一名的
|
| | | # @return obj or None
|
| | | def GetOrderValueByDict(orderDict, order, isDefaultLast=True):
|
| | | def GetOrderValueByDict(orderDict, order, isDefaultLast=True, defaultValue=None):
|
| | | if order in orderDict:
|
| | | return orderDict[order]
|
| | |
|
| | |
| | | return orderDict[dOrder]
|
| | |
|
| | | # 找不到的默认取最后一名
|
| | | return orderDict[orderList[-1]] if isDefaultLast else None
|
| | | return orderDict[orderList[-1]] if isDefaultLast else defaultValue
|
| | |
|
| | | ##概率相关, 这个事件是否能够出现
|
| | | # @param rate 基础几率
|
| | |
| | |
|
| | | return 0
|
| | |
|
| | | def DebugAnswer(curPlayer, text):
|
| | | def DebugAnswer(curPlayer, text, isLog=True):
|
| | | '''转码后再发DebugAnswer'''
|
| | | #===========================================================================
|
| | | # if not GetGameWorld().GetDebugLevel():
|
| | | # return
|
| | | #===========================================================================
|
| | | DebugLog(text)
|
| | | if isLog:
|
| | | DebugLog(text)
|
| | | text = text.decode(ShareDefine.Def_Game_Character_Encoding).encode(GetCharacterEncoding())
|
| | | curPlayer.DebugAnswer(text)
|
| | | return
|
| | |
|
| | | def CrossServerMsg_DebugAnswer(msgData):
|
| | | playerID, text = msgData
|
| | | curPlayer = GetPlayerManager().FindPlayerByID(playerID)
|
| | | if not curPlayer:
|
| | | return
|
| | | curPlayer.DebugAnswer(text)
|
| | | return
|
| | |
|
| | | def DebugAnswerCross(playerID, serverGroupID, text):
|
| | | DebugLog(text)
|
| | | text = text.decode(ShareDefine.Def_Game_Character_Encoding).encode(GetCharacterEncoding())
|
| | | |
| | | import CrossRealmMsg
|
| | | dataMsg = [playerID, text]
|
| | | serverGroupIDList = [serverGroupID]
|
| | | CrossRealmMsg.SendMsgToClientServer(ShareDefine.CrossServerMsg_DebugAnswer, dataMsg, serverGroupIDList)
|
| | | return
|
| | |
|
| | | def GetMap(mapID): return IpyGameDataPY.GetIpyGameData("ChinMap", mapID)
|
| | |
| | | SendGameError("GameServerRaiseException", errorMsg)
|
| | | return
|
| | |
|
| | | def SendGameErrorEx(errType, msgInfo="", playerID=0):
|
| | | ErrLog("SendGameErrorEx: %s -> %s" % (errType, msgInfo), playerID)
|
| | | if GetGameWorld().GetDebugLevel():
|
| | | raise Exception("%s -> %s" % (errType, msgInfo))
|
| | | else:
|
| | | SendGameError(errType, msgInfo)
|
| | | return
|
| | |
|
| | | def SendGameError(errType, msgInfo=""):
|
| | | ''' 向运维发送邮件,用于需要紧急处理的信息
|
| | | @param errType: 错误类型,自定义即可
|