|  |  |  | 
|---|
|  |  |  | import PyGameDataStruct | 
|---|
|  |  |  | import PlayerCompensation | 
|---|
|  |  |  | import ChPyNetSendPack | 
|---|
|  |  |  | import PlayerDBGSEvent | 
|---|
|  |  |  | import IpyGameDataPY | 
|---|
|  |  |  | import NetPackCommon | 
|---|
|  |  |  | import PlayerBourse | 
|---|
|  |  |  | 
|---|
|  |  |  | import ShareDefine | 
|---|
|  |  |  | import ChConfig | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import random | 
|---|
|  |  |  | import datetime | 
|---|
|  |  |  | import operator | 
|---|
|  |  |  | import time | 
|---|
|  |  |  | import math | 
|---|
|  |  |  | 
|---|
|  |  |  | return True | 
|---|
|  |  |  | return False | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def __GetAuctionSystemItemInfo(): | 
|---|
|  |  |  | key = "AuctionSystemItem" | 
|---|
|  |  |  | openServerDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_ServerDay) + 1 | 
|---|
|  |  |  | AuctionSystemItem = IpyGameDataPY.GetConfigEx(key) | 
|---|
|  |  |  | reloadSign = openServerDay | 
|---|
|  |  |  | if AuctionSystemItem and AuctionSystemItem[0] == reloadSign: | 
|---|
|  |  |  | GameWorld.DebugLog("已经加载过本日系统拍品处理信息!openServerDay=%s" % openServerDay) | 
|---|
|  |  |  | return AuctionSystemItem[1] | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 因为后面的时间判断都是精确到分的,而处理此逻辑的时候可能不是0秒,所以这里的datetime取当前时间精确到分的 | 
|---|
|  |  |  | serverTime = GameWorld.GetServerTime() | 
|---|
|  |  |  | curDateStr = "%d-%d-%d" % (serverTime.year, serverTime.month, serverTime.day) | 
|---|
|  |  |  | curDateTimeStr = "%d-%d-%d %02d:%02d:00" % (serverTime.year, serverTime.month, serverTime.day, serverTime.hour, serverTime.minute) | 
|---|
|  |  |  | curDateTime = datetime.datetime.strptime(curDateTimeStr, ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.Log("===== 加载本日系统拍品信息: %s,openServerDay=%s =====" % (curDateTime, openServerDay)) | 
|---|
|  |  |  | addSystemAuctionItemInfo = [] | 
|---|
|  |  |  | ipyDataMgr = IpyGameDataPY.IPY_Data() | 
|---|
|  |  |  | for index in xrange(ipyDataMgr.GetAuctionSystemItemCount()): | 
|---|
|  |  |  | ipyData = ipyDataMgr.GetAuctionSystemItemByIndex(index) | 
|---|
|  |  |  | cfgID = ipyData.GetCfgID() | 
|---|
|  |  |  | startDateStr = ipyData.GetStartDate() | 
|---|
|  |  |  | endDateStr = ipyData.GetEndDate() | 
|---|
|  |  |  | startTimeStr = ipyData.GetStartTime() | 
|---|
|  |  |  | endTimeStr = ipyData.GetEndTime() | 
|---|
|  |  |  | auctionCount = ipyData.GetAuctionCount() | 
|---|
|  |  |  | randMinuteRange = ipyData.GetRandMinuteRange() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | GameWorld.DebugLog("cfgID=%s,startDateStr=%s,endDateStr=%s,startTimeStr=%s,endTimeStr=%s,auctionCount=%s,randMinuteRange=%s" | 
|---|
|  |  |  | % (cfgID, startDateStr, endDateStr, startTimeStr, endTimeStr, auctionCount, randMinuteRange)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not startDateStr: | 
|---|
|  |  |  | startDateStr = curDateStr | 
|---|
|  |  |  | elif startDateStr.isdigit(): | 
|---|
|  |  |  | startServerDay = int(startDateStr) | 
|---|
|  |  |  | openServerDateTime = curDateTime + datetime.timedelta(days=(startServerDay-openServerDay)) | 
|---|
|  |  |  | startDateStr = "%d-%d-%d" % (openServerDateTime.year, openServerDateTime.month, openServerDateTime.day) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not endDateStr: | 
|---|
|  |  |  | endDateStr = curDateStr | 
|---|
|  |  |  | elif endDateStr.isdigit(): | 
|---|
|  |  |  | endServerDay = int(endDateStr) | 
|---|
|  |  |  | endServerDateTime = curDateTime + datetime.timedelta(days=(endServerDay-openServerDay)) | 
|---|
|  |  |  | endDateStr = "%d-%d-%d" % (endServerDateTime.year, endServerDateTime.month, endServerDateTime.day) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | startDate = datetime.datetime.strptime("%s 00:00:00" % (startDateStr), ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  | endDate = datetime.datetime.strptime("%s 23:59:00" % (endDateStr), ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  | if serverTime < startDate or serverTime > endDate: | 
|---|
|  |  |  | GameWorld.DebugLog("    不在上架日期内,不处理!") | 
|---|
|  |  |  | continue | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not startTimeStr: | 
|---|
|  |  |  | startTimeStr = "00:00" | 
|---|
|  |  |  | if not endTimeStr: | 
|---|
|  |  |  | endTimeStr = "23:59" | 
|---|
|  |  |  | startDatetime = datetime.datetime.strptime("%s %s:00" % (curDateStr, startTimeStr), ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  | endDatetime = datetime.datetime.strptime("%s %s:00" % (curDateStr, endTimeStr), ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  | if serverTime >= endDatetime: | 
|---|
|  |  |  | GameWorld.DebugLog("    已超过今日的上架时间段,不处理!") | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | if serverTime > startDatetime: | 
|---|
|  |  |  | startDatetime = curDateTime | 
|---|
|  |  |  |  | 
|---|
|  |  |  | addAuctionItemDatetimeList = [] | 
|---|
|  |  |  | nextAddAuctionItemDatetime = startDatetime | 
|---|
|  |  |  | for _ in xrange(auctionCount): | 
|---|
|  |  |  | if len(randMinuteRange) == 2: | 
|---|
|  |  |  | nextAddMinutes = random.randint(randMinuteRange[0], randMinuteRange[1]) | 
|---|
|  |  |  | elif len(randMinuteRange) == 1: | 
|---|
|  |  |  | nextAddMinutes = randMinuteRange[0] | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | nextAddAuctionItemDatetime += datetime.timedelta(minutes=nextAddMinutes) | 
|---|
|  |  |  | if nextAddAuctionItemDatetime > endDatetime: | 
|---|
|  |  |  | break | 
|---|
|  |  |  | GameWorld.DebugLog("    添加上架系统拍品时间: nextAddMinutes=%s %s" % (nextAddMinutes, nextAddAuctionItemDatetime)) | 
|---|
|  |  |  | addAuctionItemDatetimeList.append(nextAddAuctionItemDatetime) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if not addAuctionItemDatetimeList: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | GameWorld.DebugLog("    添加上架系统拍品时间: %s" % addAuctionItemDatetimeList) | 
|---|
|  |  |  | addSystemAuctionItemInfo.append([cfgID, ipyData, addAuctionItemDatetimeList]) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AuctionSystemItem = IpyGameDataPY.SetConfigEx(key, [reloadSign, addSystemAuctionItemInfo]) | 
|---|
|  |  |  | GameWorld.Log("本日系统拍品信息加载完毕!reloadSign=%s" % (reloadSign)) | 
|---|
|  |  |  | GameWorld.Log("本日系统拍品上架时间信息: %s" % addSystemAuctionItemInfo) | 
|---|
|  |  |  | GameWorld.Log("=============================================================") | 
|---|
|  |  |  | return AuctionSystemItem[1] | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def OnAuctionItemMinuteProcess(): | 
|---|
|  |  |  | ## 拍卖行拍品定时处理,每整分钟触发一次 | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 这里时间需精确到分钟,不然后面的比较会匹配不到 | 
|---|
|  |  |  | curDateTime = GameWorld.GetServerTime() | 
|---|
|  |  |  | curDateTime = datetime.datetime.strptime("%d-%d-%d %d:%d:00" % (curDateTime.year, curDateTime.month, curDateTime.day, | 
|---|
|  |  |  | curDateTime.hour, curDateTime.minute), ChConfig.TYPE_Time_Format) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | randMailKey = "" | 
|---|
|  |  |  | sysAuctionItemList = [] | 
|---|
|  |  |  | addSystemAuctionItemInfo = __GetAuctionSystemItemInfo() | 
|---|
|  |  |  | for cfgID, ipyData, addAuctionItemDatetimeList in addSystemAuctionItemInfo: | 
|---|
|  |  |  | if curDateTime not in addAuctionItemDatetimeList: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | #cfgID = ipyData.GetCfgID() | 
|---|
|  |  |  | addCountWeightList = ipyData.GetItemCountWeightList() | 
|---|
|  |  |  | auctionItemWeightList = ipyData.GetAuctionItemWeightList() | 
|---|
|  |  |  |  | 
|---|
|  |  |  | addCount = GameWorld.GetResultByWeightList(addCountWeightList) | 
|---|
|  |  |  | addSysItemList = [] | 
|---|
|  |  |  | for _ in xrange(addCount): | 
|---|
|  |  |  | itemInfo = GameWorld.GetResultByWeightList(auctionItemWeightList) | 
|---|
|  |  |  | if itemInfo != None: | 
|---|
|  |  |  | addSysItemList.append(itemInfo) | 
|---|
|  |  |  | GameWorld.Log("增加上架系统拍品信息: cfgID=%s,addCount=%s, %s" % (cfgID, addCount, addSysItemList)) | 
|---|
|  |  |  | sysAuctionItemList += addSysItemList | 
|---|
|  |  |  |  | 
|---|
|  |  |  | randMailKeyList = ipyData.GetRandMailKeyList() | 
|---|
|  |  |  | if randMailKeyList: | 
|---|
|  |  |  | randMailKey = random.choice(randMailKeyList) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 随机邮件通知 | 
|---|
|  |  |  | if randMailKey: | 
|---|
|  |  |  | playerIDList = [] | 
|---|
|  |  |  | addItemList = [] | 
|---|
|  |  |  | playerManager = GameWorld.GetPlayerManager() | 
|---|
|  |  |  | for i in xrange(playerManager.GetActivePlayerCount()): | 
|---|
|  |  |  | player = playerManager.GetActivePlayerAt(i) | 
|---|
|  |  |  | if player == None: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | if PlayerControl.GetIsTJG(player): | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | playerIDList.append(player.GetPlayerID()) | 
|---|
|  |  |  | PlayerCompensation.SendMailByKey(randMailKey, playerIDList, addItemList) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if sysAuctionItemList: | 
|---|
|  |  |  | DoAddSystemAuctionItem(sysAuctionItemList) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def OnAuctionItemTimeProcess(curTime, tick): | 
|---|
|  |  |  | ## 拍卖行拍品定时处理,每秒触发一次 | 
|---|
|  |  |  | allAuctionItemByEndTimeList = PyDataManager.GetAuctionItemManager().allAuctionItemByEndTimeList | 
|---|
|  |  |  | 
|---|
|  |  |  | PlayerCompensation.SendMailByKey("PaimaiMail7", [playerID], [], paramList, gold=givePlayerGold, | 
|---|
|  |  |  | detail=detail, moneySource=ChConfig.Def_GiveMoney_AuctionGain) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | GameWorld.Log("系统拍品成交: itemGUID=%s,itemID=%s" % (itemGUID, itemID)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AddAuctionRecord(auctionItem, AuctionRecordResult_SellOK) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #策划需求屏蔽掉成交广播 | 
|---|
|  |  |  | 
|---|
|  |  |  | endType = "Recycle" | 
|---|
|  |  |  | AddAuctionRecord(auctionItem, AuctionRecordResult_Recycle) | 
|---|
|  |  |  | # 个人拍品流拍,物品返还 | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | elif playerID: | 
|---|
|  |  |  | endType = "Return" | 
|---|
|  |  |  |  | 
|---|
|  |  |  | # 流拍返还物品邮件 | 
|---|
|  |  |  | 
|---|
|  |  |  | PlayerCompensation.SendMailByKey("PaimaiMail4", [playerID], addItemList, paramList, detail=detail) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AddAuctionRecord(auctionItem, AuctionRecordResult_SellFail) | 
|---|
|  |  |  | else: | 
|---|
|  |  |  | endType = "SystemDelete" | 
|---|
|  |  |  | GameWorld.Log("系统拍品流拍: itemGUID=%s,itemID=%s" % (itemGUID, itemID)) | 
|---|
|  |  |  |  | 
|---|
|  |  |  | drDict = {"AuctionItemInfo":__GetAuctionItemDRDict(auctionItem), "EndType":endType, "EndEvent":endEvent} | 
|---|
|  |  |  | DR_AuctionHouse(None, "EndAuctionItem", drDict) | 
|---|
|  |  |  | 
|---|
|  |  |  | notifyAddItemList = [] # 新增拍品通知 [[itemGUID, itemID, playerID], ...] | 
|---|
|  |  |  | notifyFamilyAddItemDict = {} # 新增仙盟拍品通知 {familyID:[auctionItem, ...], ...} | 
|---|
|  |  |  | for playerID, familyID, familyPlayerIDList, itemData in addAuctionItemList: | 
|---|
|  |  |  | if not playerID and not familyID: | 
|---|
|  |  |  | continue | 
|---|
|  |  |  | #系统拍品玩家ID、仙盟ID都为0,可上架,这里不再限制 | 
|---|
|  |  |  | #if not playerID and not familyID: | 
|---|
|  |  |  | #    continue | 
|---|
|  |  |  |  | 
|---|
|  |  |  | auctionItem = __DoAddAuctionItem(curPlayer, playerID, familyID, familyPlayerIDList, itemData) | 
|---|
|  |  |  | if not auctionItem: | 
|---|
|  |  |  | 
|---|
|  |  |  | GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_AddFamilyAuctionItem, [mapID, familyAuctionItemDict]) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|
|  |  |  | def DoAddSystemAuctionItem(sysAuctionItemList): | 
|---|
|  |  |  | ''' 上架系统拍品 | 
|---|
|  |  |  | ''' | 
|---|
|  |  |  | mapID = ChConfig.Def_FBMapID_MainCity | 
|---|
|  |  |  | GameWorld.Log("发送地图上架系统拍品: mapID=%s, %s" % (mapID, sysAuctionItemList)) | 
|---|
|  |  |  | GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_AddSystemAuctionItem, [mapID, sysAuctionItemList]) | 
|---|
|  |  |  | return | 
|---|
|  |  |  |  | 
|---|