xdh
2019-07-17 fd94cf4a58cb44cc2c34e711a2d48a3ec60789ff
ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py
@@ -30,6 +30,7 @@
import PlayerFamilyRedPacket
import time
import re
## 获取投资理财玩家数据库字典信息值
@@ -55,7 +56,8 @@
#  @param curPlayer 玩家
#  @return
def OnLogin(curPlayer):
    __CheckOldInvest(curPlayer)
    CheckOldInvestMail(curPlayer)
    __CheckInvestReset(curPlayer)
    for iType in ChConfig.GoldInvestTypeList:
        Sync_GoldInvestInfo(curPlayer, iType)
    return
@@ -65,7 +67,7 @@
#  @param curPlayer 玩家
#  @return
def OnDay(curPlayer):
    __CheckOldInvest(curPlayer)
    CheckOldInvestMail(curPlayer)
    #vip投资过了整个周期则重置
    __CheckInvestReset(curPlayer)
    
@@ -79,57 +81,97 @@
def __CheckInvestReset(curPlayer):
    ##检查vip投资重置 超过28天或28天奖励已领取可重置
    investType = ChConfig.GoldInvestType_VIP
    investGoldRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
    if not investGoldRecord:
        return
    curDay = __GetInvestCurDay(curPlayer, investType)
    investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
    maxDay = investMaxDayDict.get(str(investType), 0)
    if curDay > maxDay or __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, maxDay)):
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Time % investType, 0)
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType, 0)
        for i in xrange(1, maxDay+1):
            __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, i), 0)
    Sync_GoldInvestInfo(curPlayer, investType, isForce=True)
    for investType in ChConfig.CanRepeatInvestType:
        investGoldRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
        if not investGoldRecord:
            continue
        curDay = __GetInvestCurDay(curPlayer, investType)
        investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
        maxDay = investMaxDayDict.get(str(investType), 0)
        if curDay > maxDay or __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, maxDay)):
            __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Time % investType, 0)
            __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType, 0)
            for i in xrange(1, maxDay+1):
                __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, i), 0)
        Sync_GoldInvestInfo(curPlayer, investType, isForce=True)
    return
def __CheckOldInvest(curPlayer):
    #旧版本投资补偿
    investType = ChConfig.GoldInvestType_VIP
    investGoldRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
    if investGoldRecord != 300:
        return
    maxDay = 28
    curDay = __GetInvestCurDay(curPlayer, investType)
    if curDay > maxDay:
        return
    if __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, curDay)):
        sendDayList = range(curDay+1,maxDay+1)
    else:
        sendDayList = range(curDay, maxDay+1)
    if sendDayList:
        sendItemDict = {}
        for day in sendDayList:
            index = day%7
            if index == 0:
                index = 7
            ipyData = IpyGameDataPY.GetIpyGameData('Invest', investType*100+index)
def CheckOldInvestMail(curPlayer):
    ## 老号旧投资邮件补偿
    investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
    for oldInvestType in [ChConfig.GoldInvestType_Month, ChConfig.GoldInvestType_Week]:
        investGoldRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % oldInvestType)
        if not investGoldRecord:
            continue
        curDay = __GetInvestCurDay(curPlayer, oldInvestType)
        maxDay = investMaxDayDict.get(str(oldInvestType), 0)
        hasGotGold, lostGold, notGetGold, notGetDays = 0, 0, 0, 0 #已领取,错过领取,未领取,还有几天可领
        for day in xrange(1, maxDay+1):
            ipyData = IpyGameDataPY.GetIpyGameData('Invest', oldInvestType*100+day)
            if not ipyData:
                continue
            itemList = ipyData.GetReward()['1']
            for itemID, itemCnt, isBind in itemList:
                sendItemDict[itemID] = sendItemDict.get(itemID, 0) + itemCnt
        sendItemList = [(itemID, itemCnt, 1) for itemID, itemCnt in sendItemDict.items()]
        PlayerControl.SendMailByKey('VIPInvest', [curPlayer.GetID()], sendItemList, [len(sendDayList)])
        GameWorld.Log('    旧版本投资补偿 sendDay=%s, sendItemList=%s'%(len(sendDayList), sendItemList), curPlayer.GetID())
            rewardDict = ipyData.GetReward()
            awardData = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % oldInvestType, 1)
            if str(awardData) not in rewardDict:
                GameWorld.DebugLog('    旧投资邮件补偿, rewardDict=%s, 没有key=%s'%(rewardDict, awardData))
                continue
            rewardList = rewardDict[str(awardData)]
            gold = rewardList[0][1]
            rewardRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (oldInvestType, day))
            if rewardRecord:
                hasGotGold += gold
            elif day < curDay:
                lostGold += gold
            else:
                notGetGold += gold
                notGetDays += 1
        GameWorld.DebugLog('旧投资邮件补偿 oldInvestType=%s,hasGotGold=%s, lostGold=%s, notGetGold=%s,notGetDays=%s'%
                           (oldInvestType, hasGotGold, lostGold, notGetGold, notGetDays))
        if not notGetGold:
            continue
        if oldInvestType == ChConfig.GoldInvestType_Week:
            PlayerControl.SendMailByKey('WeekCardMail', [curPlayer.GetID()], [], [notGetDays, notGetGold], notGetGold)
        elif oldInvestType == ChConfig.GoldInvestType_Month:
            newInvestType = ChConfig.GoldInvestType_NewMonth
            newMaxDay = investMaxDayDict.get(str(newInvestType), 0)
            newTotalGold = 0
            for day in xrange(1, newMaxDay+1):
                ipyData = IpyGameDataPY.GetIpyGameData('Invest', newInvestType*100+day)
                if not ipyData:
                    continue
                rewardDict = ipyData.GetReward()
                awardData = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % newInvestType, 1)
                if str(awardData) not in rewardDict:
                    GameWorld.DebugLog('    旧投资邮件补偿, rewardDict=%s, 没有key=%s'%(rewardDict, awardData))
                    continue
                rewardList = rewardDict[str(awardData)]
                gold = rewardList[0][1]
                newTotalGold+=gold
            oldTotalGold = hasGotGold+ lostGold+notGetGold
            giveGold = newTotalGold-oldTotalGold + notGetGold
            if not giveGold:
                continue
            if lostGold:
                paramList = [newTotalGold, oldTotalGold, hasGotGold, lostGold, notGetGold, notGetGold, newTotalGold-oldTotalGold]
            else:
                paramList = [newTotalGold, oldTotalGold, hasGotGold, notGetGold, notGetGold, newTotalGold-oldTotalGold]
            PlayerControl.SendMailByKey('MonthCardMail2' if lostGold else 'MonthCardMail1', [curPlayer.GetID()], [], paramList, giveGold)
        #重置数据
        valueKey = ChConfig.Def_PDict_GoldInvest_Time % oldInvestType
        PlayerControl.NomalDictSetProperty(curPlayer, valueKey, 0, ChConfig.Def_PDictType_GoldInvest)
        
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Time % investType, 0)
    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType, 0)
    for i in xrange(1, maxDay+1):
        __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, i), 0)
        valueKey = ChConfig.Def_PDict_GoldInvest_Gold % oldInvestType
        PlayerControl.NomalDictSetProperty(curPlayer, valueKey, 0, ChConfig.Def_PDictType_GoldInvest)
        valueKey = ChConfig.Def_PDict_GoldInvest_AwardData % oldInvestType
        PlayerControl.NomalDictSetProperty(curPlayer, valueKey, 0, ChConfig.Def_PDictType_GoldInvest)
        for i in xrange(1, maxDay+1):
            valueKey = ChConfig.Def_PDict_GoldInvest_GotRewardValue % (oldInvestType, i)
            PlayerControl.NomalDictSetProperty(curPlayer, valueKey, 0, ChConfig.Def_PDictType_GoldInvest)
    return
#// A5 40 投资理财 #tagCMGoldInvest
#
#struct    tagCMGoldInvest
@@ -145,8 +187,6 @@
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    investType = clientData.InvestType
    investGold = clientData.InvestGold
    GameWorld.DebugLog("投资理财:investType=%s,investGold=%s" % (investType, investGold))
    investCostDict = IpyGameDataPY.GetFuncEvalCfg('InvestCost')
    if str(investType) not in investCostDict:
        return
@@ -154,17 +194,36 @@
    if investGold not in costList:
        GameWorld.DebugLog('    投资理财 投资额度不存在 investGold=%s, investType=%s'%(investGold, investType))
        return
    awardData = costList.index(investGold) + 1
    if investType == ChConfig.GoldInvestType_VIP:
        awardData = __GetInvestLVData(curPlayer)
        needVIPLV = IpyGameDataPY.GetFuncCfg('VIPInvest', 2)
        if curPlayer.GetVIPLv() < needVIPLV:
            GameWorld.DebugLog('    投资理财 需要VIP%s'%(needVIPLV))
            return
    __DoLogicInvest(curPlayer, investType, investGold, awardData)
    return
def InvestByCTG(curPlayer, ctgID):
    ## 充值投资
    ctgInvestDict = IpyGameDataPY.GetFuncEvalCfg('InvestCost', 3, {})
    for investType, ctgIDList in ctgInvestDict.items():
        if ctgID in ctgIDList:
            __DoLogicInvest(curPlayer, int(investType), ctgID, 1)
            GameWorld.Log('投资理财 investType=%s,ctgID=%s'%(investType, ctgID), curPlayer.GetID())
            break
    return
def __DoLogicInvest(curPlayer, investType, investGold, awardData):
    GameWorld.DebugLog("投资理财:investType=%s,investGold=%s, awardData=%s" % (investType, investGold, awardData))
    needVIPLVDict = IpyGameDataPY.GetFuncEvalCfg('InvestCost', 2, {})
    needVIPLV = needVIPLVDict.get(str(investType), 0)
    if curPlayer.GetVIPLv() < needVIPLV:
        GameWorld.DebugLog('    投资理财 需要VIP%s'%(needVIPLV))
        return
    
        
    deductGold = investGold
    if str(investType) in IpyGameDataPY.GetFuncEvalCfg('InvestCost', 3, {}):
        deductGold = 0 #充钱的不用扣仙玉
    investGoldRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
    if investGoldRecord:
        curDay = __GetInvestCurDay(curPlayer, investType)
@@ -196,11 +255,11 @@
        else:
            GameWorld.DebugLog("    investType = %s 已投资过,不可重复投资" % investType)
            return
    elif investType in ChConfig.InvestGoldTypeList:
        goldInvestLVLimit = IpyGameDataPY.GetFuncEvalCfg('GoldInvestLVLimit', 1, {}).get(investType, 0)
        if goldInvestLVLimit and curPlayer.GetLV() > goldInvestLVLimit:
            GameWorld.DebugLog('    仙玉投资理财 等级不能高于%s'%(goldInvestLVLimit))
            return
#    elif investType in ChConfig.InvestGoldTypeList:
#        goldInvestLVLimit = IpyGameDataPY.GetFuncEvalCfg('GoldInvestLVLimit', 1, {}).get(investType, 0)
#        if goldInvestLVLimit and curPlayer.GetLV() > goldInvestLVLimit:
#            GameWorld.DebugLog('    仙玉投资理财 等级不能高于%s'%(goldInvestLVLimit))
#            return
        
    __DoGoldInvest(curPlayer, investType, investGold, deductGold, awardData)
    return
@@ -232,7 +291,7 @@
                                  ChConfig.Def_Cost_GoldInvest, infoDict):
        return
    #红包奖励
    if investGold == deductGold:
    if not (investType in ChConfig.InvestGoldTypeList and investGold != deductGold):
        redPacketID = IpyGameDataPY.GetFuncEvalCfg('InvestRedPackAward', 1, {}).get(investType, 0)
        if redPacketID:
            PlayerFamilyRedPacket.CreatRedPacketByID(curPlayer, redPacketID)
@@ -240,7 +299,11 @@
        PlayerControl.WorldNotify(0, 'VIPInvestmentRadio', [curPlayer.GetName()])
    elif investType in ChConfig.InvestGoldTypeList:
        PlayerControl.WorldNotify(0, 'JadeInvestmentRadio', [curPlayer.GetName(), investGold])
#    elif investType == ChConfig.GoldInvestType_NewMonth:
#        PlayerControl.WorldNotify(0, 'MonthInvestment', [curPlayer.GetName(), __GetTotalGetGold(investType)])
    elif investType == ChConfig.GoldInvestType_Month1:
        PlayerControl.WorldNotify(0, 'WeekInPInvestment', [curPlayer.GetName(), __GetTotalGetGold(investType)])
    # 更新投资时时间,投资金额,重置回报记录
    curTime = GameWorld.GetCurrentTime()
    curTimeNum = GameWorld.ChangeTimeStrToNum(str(curTime)[:10], ChConfig.TYPE_Time_Format_Day)
@@ -264,7 +327,22 @@
    GameWorld.DebugLog("    投资成功!扣除钻石=%s" % deductGold)
    return
def __GetTotalGetGold(investType):
    investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
    newMaxDay = investMaxDayDict.get(str(investType), 0)
    newTotalGold = 0
    for day in xrange(1, newMaxDay+1):
        ipyData = IpyGameDataPY.GetIpyGameData('Invest', investType*100+day)
        if not ipyData:
            continue
        rewardDict = ipyData.GetReward()
        awardData = 1 #__GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % newInvestType, 1)
        if str(awardData) not in rewardDict:
            continue
        rewardList = rewardDict[str(awardData)]
        gold = rewardList[0][1]
        newTotalGold+=gold
    return newTotalGold
#// A5 41 领取投资理财回报 #tagCMGetInvestReward
#
@@ -341,7 +419,7 @@
    GameWorld.DebugLog("    领取投资理财回报 rewardItemList=%s" % (rewardItemList))
    if rewardItemList:
        for itemID, itemCnt, isBind in rewardItemList:
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, isBind, [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere], True, showSysInfo=True)
            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere])
    
    __CheckInvestReset(curPlayer)
    # 记录领取事件