ServerPython/CoreServerGroup/GameServer/Script/GameWorldLogic/GameWorldOpenServerCampaign.py
@@ -15,43 +15,133 @@
#"""Version = 2018-03-06 11:00"""
#-------------------------------------------------------------------------------
import GameWorld
import ShareDefine
import IpyGameDataPY
import PlayerDBGSEvent
import PlayerCompensation
import PlayerFamilyRedPacket
(
OSC_BillLimitValue, # 上榜限制值
OSC_StartDay, # 开启开服天
OSC_EndDay, # 结束开服天
) = range(3)
def CanGiveCampaignAward(curPlayer, msgList):
    ## 可否领取开服活动榜单奖励
    if not curPlayer:
        return msgList
    campTypeList, isEndMail = msgList
    queryResultList = []
    for oscType in campTypeList:
        queryResultList.append(__GetGiveCampaignAwardInfo(curPlayer, oscType))
    msgList.append(queryResultList)
    GameWorld.DebugLog("请求领取开服活动奖励: campTypeList=%s,isEndMail=%s,queryResultList=%s"
                       % (campTypeList, isEndMail, queryResultList), curPlayer.GetPlayerID())
    # 不可手动领取榜单奖励,改为过天直接结算发放
    return msgList
#    if not curPlayer:
#        return msgList
#
#    campTypeList, isEndMail = msgList
#
#    queryResultList = []
#    for oscType in campTypeList:
#        queryResultList.append(__GetGiveCampaignAwardInfo(curPlayer, oscType))
#    msgList.append(queryResultList)
#
#    GameWorld.DebugLog("请求领取开服活动奖励: campTypeList=%s,isEndMail=%s,queryResultList=%s"
#                       % (campTypeList, isEndMail, queryResultList), curPlayer.GetPlayerID())
#    return msgList
#
#def __GetGiveCampaignAwardInfo(curPlayer, campaignType):
#    ## 获取领奖所需的信息
#
#    awardBillboardType = ShareDefine.Def_Campaign_Billboard_Dict.get(campaignType)
#    if not awardBillboardType:
#        return 0
#
#    billBoard = GameWorld.GetBillboard().FindBillboard(awardBillboardType)
#    if not billBoard:
#        return 0
#
#    curPlayerID = curPlayer.GetPlayerID()
#    order = billBoard.IndexOfByID(curPlayerID) + 1  # 玩家在排行榜中的名次
#    GameWorld.DebugLog("    奖励榜: campaignType=%s,order=%s" % (campaignType, order), curPlayerID)
#    return order
def __GetGiveCampaignAwardInfo(curPlayer, campaignType):
    ## 获取领奖所需的信息
def DoOnDay():
    
    awardBillboardType = ShareDefine.Def_Campaign_Billboard_Dict.get(campaignType)
    if not awardBillboardType:
        return 0
    openServerDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_ServerDay) + 1
    billAwardVerDay = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_OSCBillAwardVerDay)
    billAwardRecord = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_OSCBillAwardRecord)
    if not billAwardVerDay:
        billAwardVerDay = openServerDay - 1
        PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_OSCBillAwardVerDay, billAwardVerDay)
        GameWorld.Log("设置开服冲榜结算版本天:  billAwardVerDay=%s" % (billAwardVerDay))
    GameWorld.DebugLog("过天处理开服活动榜单结算: billAwardVerDay=%s,openServerDay=%s,billAwardRecord=%s" % (billAwardVerDay, openServerDay, billAwardRecord))
    
    billBoard = GameWorld.GetBillboard().FindBillboard(awardBillboardType)
    OSCBillboardDataLimitDict = IpyGameDataPY.GetFuncEvalCfg("OSCBillboardOpen", 1)
    for campType in ShareDefine.Def_Campaign_Type_List:
        campTypeS = str(campType)
        if campTypeS not in OSCBillboardDataLimitDict:
            continue
        endOpenServerDay = OSCBillboardDataLimitDict[campTypeS][OSC_EndDay]
        if endOpenServerDay < billAwardVerDay:
            GameWorld.DebugLog("    该开服活动结算天在结算版本天之前,不处理!  campType=%s,endOpenServerDay=%s < billAwardVerDay=%s"
                               % (campType, endOpenServerDay, billAwardVerDay))
            continue
        if openServerDay <= endOpenServerDay:
            GameWorld.DebugLog("    该开服活动还未结束,无需结算!  campType=%s,openServerDay=%s <= endOpenServerDay=%s"
                               % (campType, openServerDay, endOpenServerDay))
            continue
        DoGiveOSCBillAward(openServerDay, campType)
    return
def DoGiveOSCBillAward(openServerDay, campType):
    billAwardRecord = PlayerDBGSEvent.GetDBGSTrig_ByKey(PlayerDBGSEvent.Def_OSCBillAwardRecord)
    if billAwardRecord & pow(2, campType):
        GameWorld.DebugLog("    该开服活动排行奖励已经结算过!  campType=%s" % (campType))
        return
    billboardType = ShareDefine.Def_Campaign_Billboard_Dict.get(campType)
    GameWorld.Log("结算开服活动榜单!   openServerDay=%s,campType=%s,billboardType=%s,billAwardRecord=%s"
                  % (openServerDay, campType, billboardType, billAwardRecord))
    billBoard = GameWorld.GetBillboard().FindBillboard(billboardType)
    if not billBoard:
        return 0
        return
    
    curPlayerID = curPlayer.GetPlayerID()
    order = billBoard.IndexOfByID(curPlayerID) + 1  # 玩家在排行榜中的名次
    GameWorld.DebugLog("    奖励榜: campaignType=%s,order=%s" % (campaignType, order), curPlayerID)
    return order
    billRankAwardIpyList = IpyGameDataPY.GetIpyGameDataList("OSCBillRankAward", campType)
    if not billRankAwardIpyList:
        return
    orderAwardDict = {}
    for billRankIpyData in billRankAwardIpyList:
        orderAwardDict[int(billRankIpyData.GetRankB())] = billRankIpyData.GetRankAward()
    updBillAwardRecord = billAwardRecord | pow(2, campType)
    PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_OSCBillAwardRecord, updBillAwardRecord)
    redPacketIDDict = IpyGameDataPY.GetFuncEvalCfg('OSCRankRedpackAward', 1, {})
    GameWorld.Log("    campType=%s,updBillAwardRecord=%s,orderAwardDict=%s,redPacketIDDict=%s"
                  % (campType, updBillAwardRecord, orderAwardDict, redPacketIDDict))
    for index in xrange(billBoard.GetCount()):
        billBoardData = billBoard.At(index)
        if not billBoardData:
            continue
        order = index + 1
        playerID = billBoardData.GetID()
        job = billBoardData.GetType2()
        jobAwardDict = GameWorld.GetOrderValueByDict(orderAwardDict, order, False)
        if not jobAwardDict:
            #GameWorld.ErrLog("没有开服活动榜单奖励! campType=%s,order=%s,playerID=%s" % (campType, order, playerID))
            continue
        if str(job) not in jobAwardDict:
            GameWorld.ErrLog("没有配置该职业对应的开服活动榜单奖励! campType=%s,order=%s,job=%s,jobAwardDict=%s"
                             % (campType, order, job, jobAwardDict))
            continue
        awardItemList = jobAwardDict[str(job)]
        paramList = [order]
        GameWorld.Log("发放开服活动榜单奖励: campType=%s,billboardType=%s,order=%s,playerID=%s,job=%s,awardItemList=%s"
                      % (campType, billboardType, order, playerID, job, awardItemList))
        PlayerCompensation.SendMailByKey("OSCBillAward%s" % campType, [playerID], awardItemList, paramList)
        #红包奖励
        redPacketID = GameWorld.GetDictValueByRangeKey(redPacketIDDict, order, 0)
        if redPacketID:
            PlayerFamilyRedPacket.CreateSystemRedPacket(redPacketID)
    return