From 7d6425827901a98ff9f47b25718542bd81dbbfac Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期一, 08 三月 2021 14:43:41 +0800
Subject: [PATCH] 8807 【BT2】【后端】Part1 14、投资返利送充值券(增加登录投资9、等级投资10、boss投资11;优化永久投资、周卡投资逻辑 同步主干);

---
 ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py |  624 ++++++++++++++++++++++----------------------------------
 1 files changed, 250 insertions(+), 374 deletions(-)

diff --git a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py
index 0fbd2e6..7591379 100644
--- a/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py
+++ b/ServerPython/ZoneServerGroup/map1_8G/MapServer/MapServerData/Script/Player/PlayerGoldInvest.py
@@ -2,175 +2,114 @@
 # -*- coding: GBK -*-
 #-------------------------------------------------------------------------------
 #
-#-------------------------------------------------------------------------------
-#
 ##@package Player.PlayerGoldInvest
 #
-# @todo:理财投资
-# @author xdh
-# @date 2018-04-02
+# @todo:投资
+# @author hxp
+# @date 2020-09-10
 # @version 1.0
 #
+# 详细描述: 投资
 #
-# 详细描述: 理财投资
-#
-#---------------------------------------------------------------------
-#"""Version = 2018-04-02 10:30"""
-#---------------------------------------------------------------------
+#-------------------------------------------------------------------------------
+#"""Version = 2020-09-10 11:00"""
+#-------------------------------------------------------------------------------
 
+import GameWorld
 import IpyGameDataPY
 import NetPackCommon
-import ChPyNetSendPack
-import IPY_GameWorld
-import PlayerControl
-import GameWorld
-import ChConfig
-import ItemControler
 import DataRecordPack
+import ChPyNetSendPack
 import PlayerFamilyRedPacket
+import ItemControler
+import PlayerControl
+import IPY_GameWorld
+import ChConfig
 
 import time
-import re
 
-
-## 获取投资理财玩家数据库字典信息值
-#  @param curPlayer 玩家实例
-#  @param key 字典key
-#  @param defaultValue 默认值
-#  @return
-def __GetPDictValue(curPlayer, key, defaultValue=0):
-    return curPlayer.NomalDictGetProperty(key, defaultValue, ChConfig.Def_PDictType_GoldInvest)
-
-
-## 设置投资理财玩家数据库字典信息值
-#  @param curPlayer 玩家实例
-#  @param key 字典key
-#  @param value 设置的值
-#  @return
-def __SetPDictValue(curPlayer, key, value):
-    PlayerControl.NomalDictSetProperty(curPlayer, key, value, ChConfig.Def_PDictType_GoldInvest)
+def __TransferPlayerInvestDBKey(curPlayer):
+    ## 转换玩家存储字典,换key名
+    
+    # 旧版key
+    # 投资理财 Def_PDictType_GoldInvest
+    Def_PDict_GoldInvest_Time = "Invest_Time_%s"  # 投资时的时间,参数为投资类型
+    #Def_PDict_GoldInvest_Gold = "Invest_Gold_%s"  # 投资的额度,参数为投资类型                                             标记是否已投资,可用投资时间即可,不处理
+    #Def_PDict_GoldInvest_AwardData = "Invest_AwardData_%s"  # 投资时的数据,参数为投资类型                                 默认1,无用,可不管
+    Def_PDict_GoldInvest_GotRewardValue = "Invest_GotRewardValue_%s_%s"  # 等级回报已领取数值,参数为投资类型 索引
+    
+    playerID = curPlayer.GetPlayerID()
+    for investType in [ChConfig.InvestType_NewMonth, ChConfig.InvestType_Month1]:
+        investTimeKeyOld = Def_PDict_GoldInvest_Time % investType
+        investTime = curPlayer.NomalDictGetProperty(investTimeKeyOld, 0, ChConfig.Def_PDictType_GoldInvest)
+        if not investTime:
+            continue
+        
+        investTimeKeyNew = ChConfig.Def_PDict_InvestTime % investType
+        PlayerControl.NomalDictSetProperty(curPlayer, investTimeKeyNew, investTime)
+        PlayerControl.NomalDictSetProperty(curPlayer, investTimeKeyOld, 0, ChConfig.Def_PDictType_GoldInvest)
+        GameWorld.Log("转换投资key: investType=%s,investTimeKeyNew=%s,investTime=%s,investTimeKeyOld=%s" 
+                      % (investType, investTimeKeyNew, investTime, investTimeKeyOld), playerID)
+        
+        maxDay = __GetInvestMaxDays(investType)
+        for i in xrange(1, maxDay + 1):
+            rewardKeyOld = Def_PDict_GoldInvest_GotRewardValue % (investType, i)
+            reward = curPlayer.NomalDictGetProperty(rewardKeyOld, 0, ChConfig.Def_PDictType_GoldInvest)
+            if not reward:
+                continue
+            
+            GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestReward, i, 1, True, [investType])
+            PlayerControl.NomalDictSetProperty(curPlayer, rewardKeyOld, 0, ChConfig.Def_PDictType_GoldInvest)
+            GameWorld.Log("    转换投资已领取记录: i=%s,rewardKeyOld=%s" % (i, rewardKeyOld), playerID)
+            
     return
 
-
-## 投资理财玩家登录处理
-#  @param curPlayer 玩家
-#  @return
+## 登录
 def OnLogin(curPlayer):
-    CheckOldInvestMail(curPlayer)
-    __CheckInvestReset(curPlayer)
-    for iType in ChConfig.GoldInvestTypeList:
-        Sync_GoldInvestInfo(curPlayer, iType)
+    __TransferPlayerInvestDBKey(curPlayer)
+    for investType in ChConfig.InvestTypeList:
+        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType):
+            continue
+        Sync_InvestInfo(curPlayer, investType)
     return
 
-
-## 投资理财玩家过天处理
-#  @param curPlayer 玩家
-#  @return
+## 过天
 def OnDay(curPlayer):
-    CheckOldInvestMail(curPlayer)
-    #vip投资过了整个周期则重置
-    __CheckInvestReset(curPlayer)
-    
-    
-    for iType in ChConfig.GoldInvestTypeList:
-        Sync_GoldInvestInfo(curPlayer, iType)
-    
-    awardData = __GetInvestLVData(curPlayer)
-    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % ChConfig.GoldInvestType_VIP, awardData)
+    for investType in ChConfig.InvestTypeList:
+        if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType):
+            continue
+        
+        # 登录卡
+        if investType == ChConfig.InvestType_Login:
+            progressValue = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestProgress % (investType, 0))
+            maxDays = __GetInvestMaxDays(investType)
+            if maxDays and progressValue < maxDays:
+                progressValue += 1
+                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestProgress % (investType, 0), progressValue)
+                GameWorld.DebugLog("更新登录投资可领奖天数进度: %s" % progressValue)
+                
+        Sync_InvestInfo(curPlayer, investType)
     return
 
-def __CheckInvestReset(curPlayer):
-    ##检查vip投资重置 超过28天或28天奖励已领取可重置
-    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 __GetInvestPassDays(curPlayer, investType):
+    ## 获取投资已过天数,投资当天为第一天,即从 1 开始; 0代表未投资
+    investTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
+    if not investTime:
+        return 0
+    curTime = int(time.time())
+    return max(0, GameWorld.GetDiff_Day(curTime, investTime) + 1)
 
-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
-            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)
-        
-        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
+def __GetInvestMaxDays(investType):
+    ## 获取投资最大天数,0为永久
+    investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg("InvestMaxDay", 1, {})
+    return investMaxDayDict.get(str(investType), 0)
 
+def GetInvestState(curPlayer, investType):
+    ## 获取投资卡状态 0-未投资;1-已投资;
+    investTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType)
+    if not investTime:
+        return 0
+    return 1
 
 #// A5 40 投资理财 #tagCMGoldInvest
 #
@@ -180,169 +119,96 @@
 #    BYTE        InvestType; // 投资类型
 #    DWORD        InvestGold; // 投资额度
 #};
-## 投资理财
-#  @param 
-#  @return
 def OnGoldInvest(index, clientData, tick):
-    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
-    investType = clientData.InvestType
-    investGold = clientData.InvestGold
-    investCostDict = IpyGameDataPY.GetFuncEvalCfg('InvestCost')
-    if str(investType) not in investCostDict:
-        return
-    costList = investCostDict[str(investType)]
-    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)
-    __DoLogicInvest(curPlayer, investType, investGold, awardData)
+    ## 消耗仙玉投资的,暂废弃
     return
 
+## 充值直购投资
 def InvestByCTG(curPlayer, ctgID):
-    ## 充值投资
-    ctgInvestDict = IpyGameDataPY.GetFuncEvalCfg('InvestCost', 3, {})
+    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())
+            __DoLogicInvest(curPlayer, int(investType))
             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))
+## 执行投资逻辑
+def __DoLogicInvest(curPlayer, investType):
+    if GetInvestState(curPlayer, investType) == 1:
+        GameWorld.DebugLog("已投资,无法重复投资! investType=%s" % investType)
         return
     
+    # 可投资,更新重置投资相关数据
+    curTime = int(time.time())
+    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestTime % investType, curTime)
+    for keyNum in range(ChConfig.Def_PDict_InvestKeyCount):
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestReward % (investType, keyNum), 0)
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestProgress % (investType, keyNum), 0)
+    
+    # 登录卡,投资当天可领奖,完成设置为1
+    if investType == ChConfig.InvestType_Login:
+        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestProgress % (investType, 0), 1)
         
-    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)
-        #可循环投资
-        if investType in ChConfig.CanRepeatInvestType:
-            # 已投资过,检查天数是否已结束
-            investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
-            maxDay = investMaxDayDict.get(str(investType), 0)
-            if curDay < maxDay:
-                GameWorld.DebugLog('    还有投资天数未领取!curDay=%s,maxDay=%s'%(curDay,maxDay))
-                return
-            if curDay == maxDay:
-                rewardRecord = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, maxDay))
-                if not rewardRecord:
-                    GameWorld.DebugLog("    还有未领取的投资回报,不可投资!investType=%s,rewardRecord=%s" 
-                                       % (investType, rewardRecord))
-                    return
-                
-                
-        # 不可循环投资,但可追加投资
-        elif investType in ChConfig.InvestGoldTypeList:
-            if investGoldRecord >= investGold:
-                GameWorld.DebugLog("    已投资档次=%s >= 追加投资档次=%s ,不可追加投资!" 
-                                   % (investGoldRecord, investGold))
-                return
-            
-            deductGold = investGold - investGoldRecord # 追加投资需要扣除的钻石
-            GameWorld.DebugLog("    已投资=%s,追加投资需扣除=%s" % (investGoldRecord, deductGold))
-        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
+    # 投资红包
+    redPacketID = IpyGameDataPY.GetFuncEvalCfg("InvestRedPackAward", 1, {}).get(investType, 0)
+    if redPacketID:
+        PlayerFamilyRedPacket.CreatRedPacketByID(curPlayer, redPacketID)
         
-    __DoGoldInvest(curPlayer, investType, investGold, deductGold, awardData)
-    return
-
-def __GetInvestCurDay(curPlayer, investType):
-    ## 获取投资当前第几天
-    investTime = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Time % investType)
-    curTime = GameWorld.ChangeTimeStrToNum(GameWorld.GetCurrentDataTimeStr())
-    passTick = max(0, curTime - investTime)
-    return passTick / 3600 / 24 + 1
-
-def __GetInvestLVData(curPlayer):
-    #vip投资 当前所属等级范围
-    investLVDataDict = IpyGameDataPY.GetFuncEvalCfg('VIPInvest')
-    lv = curPlayer.GetLV()
-    for keyData, lvRange in investLVDataDict.items():
-        if lvRange[0] <=lv <= lvRange[1]:
-            return int(keyData)
-    return 0
-
-## 执行投资理财
-#  @param 
-#  @return
-def __DoGoldInvest(curPlayer, investType, investGold, deductGold, awardData):
-    #扣钻石    
-    infoDict = {"InvestType":investType, "DeductGold":deductGold, "InvestGold":investGold,
-                ChConfig.Def_Cost_Reason_SonKey:investType}
-    if not PlayerControl.PayMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, deductGold,
-                                  ChConfig.Def_Cost_GoldInvest, infoDict):
-        return
-    #红包奖励
-    if not (investType in ChConfig.InvestGoldTypeList and investGold != deductGold):
-        redPacketID = IpyGameDataPY.GetFuncEvalCfg('InvestRedPackAward', 1, {}).get(investType, 0)
-        if redPacketID:
-            PlayerFamilyRedPacket.CreatRedPacketByID(curPlayer, redPacketID)
-    if investType == ChConfig.GoldInvestType_VIP:
-        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)
-    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Time % investType, curTimeNum)
-    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType, investGold)
-    __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % investType, awardData)
+    # 广播
+    PlayerControl.WorldNotify(0, "BuyInvest_%s" % investType, [curPlayer.GetName(), __GetTotalGetGold(investType)])
     
-    if investType in ChConfig.CanRepeatInvestType:
-        investMaxDayDict = IpyGameDataPY.GetFuncEvalCfg('InvestMaxDay')
-        maxDay = investMaxDayDict.get(str(investType), 0)
-        for i in xrange(1, maxDay+1):
-            __SetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, i), 0)
-    
-    
-    #EventShell.EventRespons_OnGoldInvest(curPlayer, investType)
-    # 同步投资信息
-    Sync_GoldInvestInfo(curPlayer, investType)
-    
-    # 投资全服广播
-    
-    GameWorld.DebugLog("    投资成功!扣除钻石=%s" % deductGold)
+    GameWorld.DebugLog("投资理财成功: investType=%s" % (investType))
+    Sync_InvestInfo(curPlayer, investType)
     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:
+    ## 获取投资预计总收益仙玉、灵石
+    totalGold = 0
+    ipyDataMgr = IpyGameDataPY.IPY_Data()
+    for index in xrange(ipyDataMgr.GetInvestCount()):
+        ipyData = ipyDataMgr.GetInvestByIndex(index)
+        if ipyData.GetType() != investType:
             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
+        for rewardInfo in rewardDict.values():
+            for itemID, itemCount, _ in rewardInfo:
+                if itemID in [20, 30]: # 单位1的仙玉、灵石
+                    totalGold += itemCount
+    return totalGold
+
+def OnKillBoss(curPlayer, npcID):
+    ## 参与击杀boss
+    if GetInvestState(curPlayer, ChConfig.InvestType_Boss) != 1:
+        #GameWorld.DebugLog("boss投资未投资!")
+        return
+    key = "BossInvestNPCIDDict"
+    BossInvestNPCIDDict = IpyGameDataPY.GetConfigEx(key)
+    if not BossInvestNPCIDDict:
+        BossInvestNPCIDDict = {}
+        ipyDataMgr = IpyGameDataPY.IPY_Data()
+        for index in xrange(ipyDataMgr.GetInvestCount()):
+            ipyData = ipyDataMgr.GetInvestByIndex(index)
+            if ipyData.GetType() != ChConfig.InvestType_Boss:
+                continue
+            if not ipyData.GetNeedNPCID():
+                continue
+            BossInvestNPCIDDict[ipyData.GetNeedNPCID()] = ipyData.GetID()
+        IpyGameDataPY.SetConfigEx(key, BossInvestNPCIDDict)
+        GameWorld.Log("缓存boss投资对应关系: %s" % BossInvestNPCIDDict)
+        
+    if npcID not in BossInvestNPCIDDict:
+        #GameWorld.DebugLog("    该boss没有投资奖励!")
+        return
+    investID = BossInvestNPCIDDict[npcID]
+    investType, rewardIndex = investID / 100, investID % 100
+    if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestProgress, rewardIndex, True, [investType]):
+        #GameWorld.DebugLog("已设置击杀过该投资boss: npcID=%s,rewardIndex=%s,progressValue=%s" % (npcID, rewardIndex, progressValue))
+        return
+    progressValue, updProgressValue = GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestProgress, rewardIndex, 1, True, [investType])
+    Sync_InvestInfo(curPlayer, investType)
+    GameWorld.DebugLog("设置杀过投资boss: npcID=%s,rewardIndex=%s,progressValue=%s,updProgressValue=%s" 
+                       % (npcID, rewardIndex, progressValue, updProgressValue))
+    return
 
 #// A5 41 领取投资理财回报 #tagCMGetInvestReward
 #
@@ -352,111 +218,121 @@
 #    BYTE        InvestType; // 投资类型
 #    BYTE        RewardIndex; // 回报索引
 #};
-## 领取投资理财回报
-#  @param 
-#  @return
-def OnGetGoldInvestReward(index, clientData, tick):
+def OnGetInvestReward(index, clientData, tick):
     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
     investType = clientData.InvestType
     rewardIndex = clientData.RewardIndex
-    ipyData = IpyGameDataPY.GetIpyGameData('Invest', investType*100+rewardIndex)
+    GameWorld.DebugLog("领取投资理财回报:investType=%s,rewardIndex=%s" % (investType, rewardIndex))
+    
+    if investType not in ChConfig.InvestTypeList:
+        #GameWorld.DebugLog("不存在该投资类型!")
+        return
+    
+    if GetInvestState(curPlayer, investType) != 1:
+        GameWorld.DebugLog("    未投资或已过期,无法领奖!")
+        return
+    
+    ipyData = IpyGameDataPY.GetIpyGameData("Invest", investType * 100 + rewardIndex)
     if not ipyData:
         return
     
-    investGold = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
-    
-    GameWorld.DebugLog("领取投资理财回报:investType=%s,investGold=%s,rewardIndex=%s" 
-                       % (investType, investGold, rewardIndex))
-    
-    if not investGold:
-        GameWorld.DebugLog("    该类型没有投资过,无法领取回报!investType=%s" % investType)
-        return
     needLV = ipyData.GetNeedLV()
-    if curPlayer.GetLV() < needLV:
-        GameWorld.DebugLog("    等级不够%s,无法领取回报!investType=%s" % (needLV, investType))
+    if needLV and curPlayer.GetLV() < needLV:
+        GameWorld.DebugLog("    等级不足,无法领奖! needLV=%s" % needLV)
+        return
+    
+    if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestReward, rewardIndex, True, [investType]):
+        GameWorld.DebugLog("    已领取过该索引奖励! rewardIndex=%s" % rewardIndex)
         return
     
     needDay = ipyData.GetNeedDay()
-    if needDay:
-        curDay = __GetInvestCurDay(curPlayer, investType)
-        if needDay != curDay:
-            GameWorld.DebugLog("    无法领取回报! 只能领取当天的,curDay=%s,needDay=%s" % (curDay, needDay))
-            return
+    rewardInfo = ipyData.GetReward()
     
-    rewardDict = ipyData.GetReward()
-    awardData = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_AwardData % investType, 1)
-    if str(awardData) not in rewardDict:
-        GameWorld.DebugLog('    领取投资理财回报, rewardDict=%s, 没有key=%s'%(rewardDict, awardData))
-        return
-    rewardList = rewardDict[str(awardData)]
-
-    rewardItemList = rewardList # 回报物品列表
-    rewardValueKey = ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, rewardIndex)
-    lastDayGotData = __GetPDictValue(curPlayer, rewardValueKey) # 已领取数据
-
-    if lastDayGotData:
-        if investType in ChConfig.InvestGoldTypeList:
-            if awardData > lastDayGotData:
-                lastGotAwardList = rewardDict[str(lastDayGotData)]
-                rewardItemList = []
-                for itemID, itemCnt, isBind in rewardList:
-                    newCnt = itemCnt
-                    for itemInfo in lastGotAwardList:
-                        if itemID == itemInfo[0]:
-                            newCnt = max(1,itemCnt - itemInfo[1])
-                            break
-                    rewardItemList.append([itemID, newCnt, isBind])
-            else:
-                GameWorld.DebugLog('    11领取投资理财回报, 已领取过! investType=%s, rewardIndex=%s'%(investType, rewardIndex))
-                return
-        else:
-            GameWorld.DebugLog('    领取投资理财回报, 已领取过! investType=%s, rewardIndex=%s'%(investType, rewardIndex))
+    indexProgressState = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestProgress, rewardIndex, True, [investType])
+    
+    # 月卡
+    if investType in [ChConfig.InvestType_NewMonth, ChConfig.InvestType_Month1]:
+        passDays = __GetInvestPassDays(curPlayer, investType) # 按投资时间计算天
+        if needDay > passDays:
+            GameWorld.DebugLog("    投资天数不足,无法领取! needDay=%s > passDays=%s" % (ipyData.GetNeedDay(), passDays))
             return
-            
         
-    __SetPDictValue(curPlayer, rewardValueKey, awardData)
-                
-    GameWorld.DebugLog("    领取投资理财回报 rewardItemList=%s" % (rewardItemList))
-    if rewardItemList:
-        for itemID, itemCnt, isBind in rewardItemList:
-            ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem, IPY_GameWorld.rptAnyWhere])
+    # 登录
+    elif investType == ChConfig.InvestType_Login:
+        loginDays = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestProgress % (investType, 0)) # 按登录天计算天,有登录才算
+        if needDay > loginDays:
+            GameWorld.DebugLog("    登录投资天数不足,无法领取! needDay=%s > loginDays=%s" % (needDay, loginDays))
+            return
+        
+    # 等级
+    elif investType == ChConfig.InvestType_LV:
+        # 公共等级条件已判断
+        pass
+        
+    # Boss
+    elif investType == ChConfig.InvestType_Boss:
+        if not indexProgressState:
+            GameWorld.DebugLog("    Boss投资无参与击杀该boss,无法领取! rewardIndex=%s" % (rewardIndex))
+            return
+        
+    else:
+        return
     
-    __CheckInvestReset(curPlayer)
+    if not ipyData:
+        return
+        
+    rewardKey = "1" # 默认1
+    rewardItemList = rewardInfo.get(str(rewardKey), [])
+    if not rewardItemList:
+        return
+    
+    if not ItemControler.CheckPackSpaceEnough(curPlayer, rewardItemList):
+        return
+    
+    rewardValue, updRewardValue = GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestReward, rewardIndex, 1, True, [investType])
+    Sync_InvestInfo(curPlayer, investType)
+    GameWorld.DebugLog("    rewardValue=%s,updRewardValue=%s,rewardItemList=%s" % (rewardValue, updRewardValue, rewardItemList))
+    
+    for itemID, itemCount, isAuctionItem in rewardItemList:
+        ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem],
+                                     event=["Invest", False, {}])
+        
     # 记录领取事件
     DataRecordPack.DR_GetGoldInvestReward(curPlayer, investType, rewardIndex, rewardItemList)
-        
-    Sync_GoldInvestInfo(curPlayer, investType, rewardIndex)
+    
+    # 领完了,重置可重复购买的非永久卡
+    maxDays = __GetInvestMaxDays(investType)
+    canRepetBuyTypeList = IpyGameDataPY.GetFuncEvalCfg("InvestMaxDay", 2)
+    if maxDays > 1 and investType in canRepetBuyTypeList:
+        isAllDayGet = True
+        for i in range(maxDays, -1, -1):
+            if not IpyGameDataPY.GetIpyGameDataNotLog("Invest", investType * 100 + i):
+                continue
+            if not GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_InvestReward, i, True, [investType]):
+                isAllDayGet = False
+                #GameWorld.DebugLog("    还有未领取: i=%s,isAllDayGet=%s" % (i, isAllDayGet))
+                break
+            
+        if isAllDayGet:
+            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestTime % investType, 0)
+            for keyNum in range(ChConfig.Def_PDict_InvestKeyCount):
+                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestReward % (investType, keyNum), 0)
+                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestProgress % (investType, keyNum), 0)
+            Sync_InvestInfo(curPlayer, investType)
+            GameWorld.DebugLog("    领完奖励了,重置投资! investType=%s" % investType)
+            
     return
 
 ## 同步投资理财信息
-#  @param 
-#  @return
-def Sync_GoldInvestInfo(curPlayer, investType, index=-1, isForce=False):
-    investGold = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_Gold % investType)
-    if not isForce and not investGold:
-        return
-    investInfoPack = ChPyNetSendPack.tagMCGoldInvestInfo()
-    investInfoPack.Clear()
+def Sync_InvestInfo(curPlayer, investType):
+    investInfoPack = ChPyNetSendPack.tagMCInvestInfo()
     investInfoPack.InvestType = investType
-    investInfoPack.CurDay = __GetInvestCurDay(curPlayer, investType)
-    investInfoPack.InvestGold = investGold
-    investInfoPack.InvestRewardList = []
-    ipyGameDataList = IpyGameDataPY.GetIpyGameDataByCondition('Invest', {'Type':investType}, True)
-    
-    if not ipyGameDataList:
-        return
-    for ipyData in ipyGameDataList:
-        rewardIndex = ipyData.GetID() % 100
-        if index !=-1 and rewardIndex != index:
-            continue
-        investReward = ChPyNetSendPack.tagMCInvestReward()
-        investReward.RewardIndex = rewardIndex
-        investReward.RewardValue = __GetPDictValue(curPlayer, ChConfig.Def_PDict_GoldInvest_GotRewardValue % (investType, rewardIndex))
-        investInfoPack.InvestRewardList.append(investReward)
-    investInfoPack.RewardRecordCnt = len(investInfoPack.InvestRewardList)
+    investInfoPack.CurDay = __GetInvestPassDays(curPlayer, investType)
+    for keyNum in range(ChConfig.Def_PDict_InvestKeyCount):
+        investInfoPack.RewardValue.append(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestReward % (investType, keyNum)))
+        investInfoPack.ProgressValue.append(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestProgress % (investType, keyNum)))
+    investInfoPack.ValueCount = len(investInfoPack.RewardValue)
     NetPackCommon.SendFakePack(curPlayer, investInfoPack)
     return
-
-
 
 

--
Gitblit v1.8.0