#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerGoldInvest # # @todo:Ͷ×Ê # @author hxp # @date 2020-09-10 # @version 1.0 # # ÏêϸÃèÊö: Ͷ×Ê # #------------------------------------------------------------------------------- #"""Version = 2020-09-10 11:00""" #------------------------------------------------------------------------------- import GameWorld import IpyGameDataPY import NetPackCommon import DataRecordPack import ChPyNetSendPack import PlayerFamilyRedPacket import ItemControler import PlayerControl import IPY_GameWorld import ChConfig import time ## µÇ¼ def OnLogin(curPlayer): for investType in ChConfig.InvestTypeList: if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestTime % investType): continue Sync_InvestInfo(curPlayer, investType) return ## ¹ýÌì def OnDay(curPlayer): 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) # ÖÕÉí¿¨ elif investType == ChConfig.InvestType_Life: __GiveUnGetPerDayReward(curPlayer, investType) for keyNum in range(ChConfig.Def_PDict_InvestKeyCount): PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestReward % (investType, keyNum), 0) Sync_InvestInfo(curPlayer, investType) return def __GiveUnGetPerDayReward(curPlayer, investType): ## ²¹·¢Î´ÁìÈ¡µÄÿÈÕ½±Àø£¬Ò»°ãÓÃÓÚ Ã¿ÈÕ¿ÉÁìÈ¡µÄ¹Ì¶¨½±Àø£¬ÈçÓÀ¾Ã¿¨µÈ playerID = curPlayer.GetPlayerID() curTime = int(time.time()) lastRewardTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_InvestRewardTime % investType) if not lastRewardTime: passDays = __GetInvestPassDays(curPlayer, investType) #GameWorld.DebugLog("²¹·¢½±Àøʱ£¬¾àÀ뿪ͨͶ×ÊÒѹýÌìÊý: %s" % passDays, playerID) else: passDays = GameWorld.GetDiff_Day(curTime, lastRewardTime) #GameWorld.DebugLog("²¹·¢½±Àøʱ£¬¾àÀëÉÏ´ÎÁì½±ÒѹýÌìÊý: %s" % passDays, playerID) rewardDays = passDays - 1 # # ÐèÒª²¹·¢µÄ½±ÀøÌìÊý£¬Ö»²¹µ½×òÌ죬²»Ëãµ±Ìì if rewardDays <= 0: GameWorld.DebugLog("²»Óò¹·¢Í¶×Ê¿¨Ã¿ÈÕ½±Àø: investType=%s,rewardDays=%s" % (investType, rewardDays), playerID) return updRewardTime = curTime - 3600 * 24 # ×îºóÒ»´ÎÁ콱ǿÖÆÉèÖõ½×òÌì rewardIndex = 0 # ÿÈÕ½±ÀøĬÈÏ0Ë÷Òý ipyData = IpyGameDataPY.GetIpyGameData("Invest", investType * 100 + rewardIndex) if not ipyData: return rewardInfo = ipyData.GetReward() rewardKey = "1" # ĬÈÏ1 rewardItemList = rewardInfo.get(str(rewardKey), []) if not rewardItemList: return mailItemList = [] for itemID, itemCount, isAuctionItem in rewardItemList: mailItemList.append([itemID, itemCount * rewardDays, isAuctionItem]) GameWorld.DebugLog("Óʼþ²¹·¢Í¶×Ê¿¨Ã¿ÈÕ½±Àø! investType=%s, rewardDays=%s, updRewardTime=%s, mailItemList=%s" % (investType, rewardDays, updRewardTime, mailItemList), playerID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestRewardTime % investType, updRewardTime) PlayerControl.SendMailByKey("InvestDayReward_%s" % investType, [playerID], mailItemList, [rewardDays]) 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 __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 # #struct tagCMGoldInvest #{ # tagHead Head; # BYTE InvestType; // Ͷ×ÊÀàÐÍ # DWORD InvestGold; // Ͷ×ʶî¶È #}; def OnGoldInvest(index, clientData, tick): ## ÏûºÄÏÉÓñͶ×ʵģ¬ÔÝ·ÏÆú return ## ³äÖµÖ±¹ºÍ¶×Ê def InvestByCTG(curPlayer, ctgID): ctgInvestDict = IpyGameDataPY.GetFuncEvalCfg("InvestCost", 3, {}) for investType, ctgIDList in ctgInvestDict.items(): if ctgID in ctgIDList: __DoLogicInvest(curPlayer, int(investType)) break return ## Ö´ÐÐͶ×ÊÂß¼­ 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) # Ͷ×ʺì°ü redPacketID = IpyGameDataPY.GetFuncEvalCfg("InvestRedPackAward", 1, {}).get(investType, 0) if redPacketID: PlayerFamilyRedPacket.CreatRedPacketByID(curPlayer, redPacketID) # ¹ã²¥ PlayerControl.WorldNotify(0, "BuyInvest_%s" % investType, [curPlayer.GetName(), __GetTotalGetGold(investType)]) GameWorld.DebugLog("Ͷ×ÊÀí²Æ³É¹¦: investType=%s" % (investType)) Sync_InvestInfo(curPlayer, investType) PlayerControl.Sync_ExpRateChange(curPlayer) return def __GetTotalGetGold(investType): ## »ñȡͶ×ÊÔ¤¼Æ×ÜÊÕÒæÏÉÓñ¡¢Áéʯ totalGold = 0 ipyDataMgr = IpyGameDataPY.IPY_Data() for index in xrange(ipyDataMgr.GetInvestCount()): ipyData = ipyDataMgr.GetInvestByIndex(index) if ipyData.GetType() != investType: continue rewardDict = ipyData.GetReward() for rewardInfo in rewardDict.values(): for itemID, itemCount, _ in rewardInfo: if itemID in [20, 30]: # µ¥Î»1µÄÏÉÓñ¡¢Áéʯ totalGold += itemCount return totalGold def GetAddBossCnt(curPlayer, bossFuncIndex): ## »ñÈ¡Ôö¼ÓµÄboss´ÎÊýÉÏÏÞ addBossCnt = 0 if GetInvestState(curPlayer, ChConfig.InvestType_Life): lifeCardAddBossCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 1, {}) lifeCardAddCnt = lifeCardAddBossCntDict.get(str(bossFuncIndex), 0) addBossCnt += lifeCardAddCnt return addBossCnt def GetAddFBCnt(curPlayer, mapID): ## »ñÈ¡Ôö¼ÓµÄ¸±±¾´ÎÊýÉÏÏÞ addFBCnt = 0 if GetInvestState(curPlayer, ChConfig.InvestType_Life): lifeCardAddFBCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 2, {}) lifeCardAddCnt = lifeCardAddFBCntDict.get(str(mapID), 0) addFBCnt += lifeCardAddCnt return addFBCnt def GetAddBossBuyCnt(curPlayer, bossFuncIndex): ## »ñÈ¡Ôö¼ÓµÄboss¹ºÂò´ÎÊýÉÏÏÞ addBossBuyCnt = 0 if GetInvestState(curPlayer, ChConfig.InvestType_Life): lifeCardAddBossCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 4, {}) lifeCardAddCnt = lifeCardAddBossCntDict.get(str(bossFuncIndex), 0) addBossBuyCnt += lifeCardAddCnt return addBossBuyCnt def GetAddFBBuyCnt(curPlayer, mapID): ## »ñÈ¡Ôö¼ÓµÄ¸±±¾¹ºÂò´ÎÊýÉÏÏÞ addFBBuyCnt = 0 if GetInvestState(curPlayer, ChConfig.InvestType_Life): lifeCardAddFBCntDict = IpyGameDataPY.GetFuncEvalCfg("InvestPower", 5, {}) lifeCardAddCnt = lifeCardAddFBCntDict.get(str(mapID), 0) addFBBuyCnt += lifeCardAddCnt return addFBBuyCnt def GetAddFightExpRate(curPlayer): ## ɱ¹Ö¾­Ñé¼Ó³É fightExpRate = 0 if GetInvestState(curPlayer, ChConfig.InvestType_Life): fightExpRate += IpyGameDataPY.GetFuncCfg("InvestPower2", 1) return fightExpRate def CanQuickFinishMissionFree(curPlayer): ## ¿É·ñÃâ·Ñ¿ìËÙÍê³ÉÈÎÎñ for investType in IpyGameDataPY.GetFuncEvalCfg("InvestPower", 3): if GetInvestState(curPlayer, investType): return True return False 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 # #struct tagCMGetInvestReward #{ # tagHead Head; # BYTE InvestType; // Ͷ×ÊÀàÐÍ # BYTE RewardIndex; // »Ø±¨Ë÷Òý #}; def OnGetInvestReward(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) investType = clientData.InvestType rewardIndex = clientData.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 needLV = ipyData.GetNeedLV() 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() rewardInfo = ipyData.GetReward() 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 # µÇ¼ 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 # ÖÕÉí¿¨ elif investType == ChConfig.InvestType_Life: pass else: return 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)) # ¼Ç¼×îºóÒ»´ÎÁ콱ʱ¼ä if investType == ChConfig.InvestType_Life: PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_InvestRewardTime % (investType), int(time.time())) for itemID, itemCount, isAuctionItem in rewardItemList: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem], event=["Invest", False, {}]) ItemControler.NotifyGiveAwardInfo(curPlayer, rewardItemList, "Invest") # ¼Ç¼Áìȡʼþ DataRecordPack.DR_GetGoldInvestReward(curPlayer, investType, rewardIndex, rewardItemList) # ÁìÍêÁË£¬ÖØÖÿÉÖظ´¹ºÂòµÄ·ÇÓÀ¾Ã¿¨ 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 ## ͬ²½Í¶×ÊÀí²ÆÐÅÏ¢ def Sync_InvestInfo(curPlayer, investType): investInfoPack = ChPyNetSendPack.tagMCInvestInfo() investInfoPack.InvestType = investType 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