#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerGoldGift # # @todo:³äÖµÀñ°ü # @author hxp # @date 2025-09-28 # @version 1.0 # # ÏêϸÃèÊö: ³äÖµÀñ°ü£¬Ö÷ҪһЩ³£Óá¢Í¨ÓÃµÄ # #------------------------------------------------------------------------------- #"""Version = 2025-09-28 14:30""" #------------------------------------------------------------------------------- import ChConfig import GameWorld import IPY_GameWorld import ItemControler import PlayerControl import DataRecordPack import ChPyNetSendPack import NetPackCommon import IpyGameDataPY import ShareDefine import CommFunc import ObjPool import time def OnDay(curPlayer): DoDailyPackBuyGiftOnDay(curPlayer) return def OnLogin(curPlayer): Sync_FirstChargeInfo(curPlayer) Sync_HistoryChargeAwardGetRecordInfo(curPlayer) Sync_DailyPackBuyGiftInfo(curPlayer) return def OnGiftByCTGID(curPlayer, ctgID): OnActFirstCharge(curPlayer, ctgID) OnActiviteDailyPackBuyGift(curPlayer, ctgID) return ##------------------------------------------------------------------------------ def ClearFirstCharge(curPlayer): ## ÖØÖÃÊ׳ä - Ò»°ãÊÇGMÓà resetCTGIDList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetFirstChargeCount()): ipyData = ipyDataMgr.GetFirstChargeByIndex(index) firstID = ipyData.GetFirstID() ctgID = ipyData.GetNeedCTGID() PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstChargeTime % firstID, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstChargeRecord % firstID, 0) resetCTGIDList.append(ctgID) Sync_FirstChargeInfo(curPlayer) return def OnActFirstCharge(curPlayer, ctgID): ## ¼¤»îÊ׳䵵λ firstIpyData = None ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetFirstChargeCount()): ipyData = ipyDataMgr.GetFirstChargeByIndex(index) if ipyData.GetNeedCTGID() == ctgID: firstIpyData = ipyData break if not firstIpyData: return firstID = firstIpyData.GetFirstID() chargeTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstChargeTime % firstID) if chargeTime: GameWorld.DebugLog("¸ÃÊ׳䵵λÒѾ­¼¤»î¹ýÁË£¬²»Öظ´¼¤»î: ctgID=%s,chargeTime=%s" % (ctgID, chargeTime)) return PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstChargeTime % firstID, int(time.time())) GameWorld.DebugLog("¼Ç¼Ê׳䵵λ³äֵʱ¼ä´Á: ctgID=%s" % ctgID) Sync_FirstChargeInfo(curPlayer) return def GetPlayerFirstCharge(curPlayer, giftDay, firstIDStr): '''ÁìÈ¡Íæ¼ÒÊ׳佱Àø @param dayIndex: Ê׳äµÚ¼¸Ìì½±Àø ''' firstID = GameWorld.ToIntDef(firstIDStr) if not firstID or not giftDay: return playerID = curPlayer.GetPlayerID() chargeTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstChargeTime % firstID) if not chargeTime: GameWorld.DebugLog("¸ÃµµÎ»Î´Ê׳ä! firstID=%s" % firstID, playerID) return canGetMaxDay = GameWorld.GetDiff_Day(int(time.time()), chargeTime) + 1 if giftDay > canGetMaxDay: GameWorld.DebugLog("»¹Î´µ½¿ÉÁìÈ¡µÄÊ׳äÌ죬ÎÞ·¨ÁìÈ¡!chargeTime=%s,giftDay=%s > %s" % (GameWorld.ChangeTimeNumToStr(chargeTime), giftDay, canGetMaxDay), playerID) return getRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstChargeRecord % firstID) if getRecord & pow(2, giftDay): GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ýÊ׳佱Àø£¡firstID=%s,giftDay=%s,getRecord=%s" % (firstID, giftDay, getRecord), playerID) return ipyData = IpyGameDataPY.GetIpyGameData("FirstCharge", firstID) if not ipyData: return if not hasattr(ipyData, "GetAwardListDay%s" % giftDay): return awardList = getattr(ipyData, "GetAwardListDay%s" % giftDay)() if not ItemControler.CheckPackSpaceEnough(curPlayer, [itemInfo[:2] for itemInfo in awardList]): return # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç updGetRecord = getRecord | pow(2, giftDay) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FirstChargeRecord % firstID, updGetRecord) GameWorld.DebugLog("ÁìÈ¡Ê׳佱Àø: firstID=%s,giftDay=%s,getRecord=%s,updGetRecord=%s, %s" % (firstID, giftDay, getRecord, updGetRecord, awardList)) Sync_FirstChargeInfo(curPlayer) isAuctionItem = 0 notifyAwardList = [] for itemID, itemCount, appointID in awardList: setAttrDict = {ShareDefine.Def_CItemKey_AppointID:appointID} if appointID else {} if not ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, event=["FirstCharge", False, {}], setAttrDict=setAttrDict): continue notifyAwardList.append([itemID, itemCount, isAuctionItem]) ItemControler.NotifyGiveAwardInfo(curPlayer, notifyAwardList, "FirstCharge") return def Sync_FirstChargeInfo(curPlayer): ## ֪ͨÊ׳äÐÅÏ¢ clientPack = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCFirstChargeInfo) clientPack.FirstChargeList = [] ipyDataMgr = IpyGameDataPY.IPY_Data() for index in range(ipyDataMgr.GetFirstChargeCount()): ipyData = ipyDataMgr.GetFirstChargeByIndex(index) firstID = ipyData.GetFirstID() firstCharge = ObjPool.GetPoolMgr().acquire(ChPyNetSendPack.tagSCFirstCharge) firstCharge.ChargeTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstChargeTime % firstID) firstCharge.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FirstChargeRecord % firstID) clientPack.FirstChargeList.append(firstCharge) clientPack.Count = len(clientPack.FirstChargeList) NetPackCommon.SendFakePack(curPlayer, clientPack) return ################################ ÿÈÕ´ò°üÖ±¹ºÀñ°ü ################################### def OnActiviteDailyPackBuyGift(curPlayer, ctgID): ## ¼¤»îÿÈÕ´ò°üÖ±¹ºÀñ°ü isActivite = False packCTGIDList = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 3) # ´ò°ü¹ºÂò¶ÔÓ¦³äÖµIDÁбí if ctgID in packCTGIDList: isActivite = True # Èç¹ûÊÇ´ò°ü¹ºÂòµÄ£¬²»¹Üʲô״̬£¬Ö±½ÓÈ«²¿ÖØÖà PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftPackTime, int(time.time())) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftBuy, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftRecord, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftOnDayTime, 0) GameWorld.Log("¼¤»î´ò°üÖ±¹ºÀñ°ü: ctgID=%s" % ctgID, curPlayer.GetID()) else: actCTGIDDict = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 2, {}) # Àñ°üË÷Òý¶ÔÓ¦³äÖµIDÁÐ±í£¬Ã»ÓÐÅäÖõĴú±í¿ÉÃâ·ÑÁìÈ¡ for awardIndexStr, ctgIDList in actCTGIDDict.items(): if ctgID not in ctgIDList: continue isActivite = True awardIndex = int(awardIndexStr) buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftBuy) updBuyState = buyState|pow(2, awardIndex) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftBuy, updBuyState) GameWorld.Log("µ¥¶À¼¤»î´ò°üÖ±¹ºÀñ°ü: awardIndex=%s,ctgID=%s" % (awardIndex, ctgID), curPlayer.GetID()) break if isActivite: Sync_DailyPackBuyGiftInfo(curPlayer) return isActivite def GetDailyPackBuyGift(curPlayer, awardIndex): ## ÁìȡÿÈÕ´ò°üÖ±¹ºÀñ°ü playerID = curPlayer.GetPlayerID() giftItemDict = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 1, {}) # Àñ°üË÷Òý¶ÔÓ¦Àñ°üÎïÆ·Áбí if str(awardIndex) not in giftItemDict: GameWorld.DebugLog("²»´æÔÚ¸ÃÿÈÕ´ò°üÖ±¹ºÀñ°ü! awardIndex=%s" % awardIndex, playerID) return itemList = giftItemDict[str(awardIndex)] getRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftRecord) # ÁìÈ¡¼Ç¼ if getRecord&pow(2, int(awardIndex)): GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ý¸ÃÿÈÕ´ò°üÖ±¹ºÀñ°ü! awardIndex=%s,getRecord=%s" % (awardIndex, getRecord), playerID) return packBuyTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftPackTime) # ´ò°ü¹ºÂòʱ¼ä´Á # ´ò°ü¹ºÂòµÄ if packBuyTime: curTime = int(time.time()) maxDays = IpyGameDataPY.GetFuncCfg("DailyPackBuyGift", 4) curDays = GameWorld.GetDiff_Day(curTime, packBuyTime) + 1 # ´ò°ü¹ºÂòµÚxÌ죬¹ºÂòµ±ÌìΪµÚ1Ìì if curDays > maxDays: GameWorld.DebugLog("´ò°üÖ±¹ºÀñ°ü³¬¹ý¿ÉÁìÈ¡×î´óÌì: curDays=%s > %s" % (curDays, maxDays), playerID) return GameWorld.DebugLog("ÒÑ´ò°ü¹ºÂò: packBuyTime=%s(%s),curDays=%s" % (packBuyTime, GameWorld.ChangeTimeNumToStr(packBuyTime), curDays), playerID) else: actCTGIDDict = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 2, {}) # Àñ°üË÷Òý¶ÔÓ¦³äÖµIDÁÐ±í£¬Ã»ÓÐÅäÖõĴú±í¿ÉÃâ·ÑÁìÈ¡ buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftBuy) # µ¥¶À¹ºÂò״̬ if str(awardIndex) in actCTGIDDict and not buyState&pow(2, awardIndex): GameWorld.DebugLog("½ñÈոôò°üÖ±¹ºÀñ°üδ¹ºÂò£¬ÎÞ·¨ÁìÈ¡: awardIndex=%s,buyState=%s" % (awardIndex, buyState), playerID) return GameWorld.DebugLog("Òѵ¥¶À¹ºÂò: awardIndex=%s,buyState=%s" % (awardIndex, buyState), playerID) # ¼ì²é±³°ü if not ItemControler.CheckPackSpaceEnough(curPlayer, itemList): return # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç updRecord = getRecord|pow(2, awardIndex) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftRecord, updRecord) Sync_DailyPackBuyGiftInfo(curPlayer) GameWorld.DebugLog("ÁìÈ¡´ò°üÖ±¹ºÀñ°ü: awardIndex=%s,updRecord=%s" % (awardIndex, updRecord), playerID) # ¸øÎïÆ· for itemID, itemCount, isAuctionItem in itemList: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isAuctionItem, [IPY_GameWorld.rptItem]) return def DoDailyPackBuyGiftOnDay(curPlayer): ## ÿÈÕ´ò°üÖ±¹ºÀñ°ü¹ýÌì playerID = curPlayer.GetPlayerID() curTime = int(time.time()) # ²¹·¢Î´ÁìÈ¡µÄÌìÊý½±Àø lastOnDayTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftOnDayTime) # Éϴδ¦ÀíµÄ¹ýÌìʱ¼ä packBuyTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftPackTime) # ´ò°ü¹ºÂòʱ¼ä´Á getRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftRecord) # ÁìÈ¡¼Ç¼ buyState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftBuy) # µ¥¶À¹ºÂò״̬ GameWorld.DebugLog("ÿÈÕ´ò°üÖ±¹ºÀñ°ü¹ýÌì: packBuyTime=%s(%s),lastOnDayTime=%s(%s),getRecord=%s,buyState=%s" % (packBuyTime, GameWorld.ChangeTimeNumToStr(packBuyTime), lastOnDayTime, GameWorld.ChangeTimeNumToStr(lastOnDayTime), getRecord, buyState), playerID) giftItemDict = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 1, {}) # Àñ°üË÷Òý¶ÔÓ¦Àñ°üÎïÆ·Áбí actCTGIDDict = IpyGameDataPY.GetFuncEvalCfg("DailyPackBuyGift", 2, {}) # Àñ°üË÷Òý¶ÔÓ¦³äÖµIDÁÐ±í£¬Ã»ÓÐÅäÖõĴú±í¿ÉÃâ·ÑÁìÈ¡ # ´ò°ü¹ºÂòµÄ if packBuyTime: maxDays = IpyGameDataPY.GetFuncCfg("DailyPackBuyGift", 4) curDays = GameWorld.GetDiff_Day(curTime, packBuyTime) + 1 # ´ò°ü¹ºÂòµÚxÌ죬¹ºÂòµ±ÌìΪµÚ1Ìì alreadyAwardDays = GameWorld.GetDiff_Day(lastOnDayTime, packBuyTime) if lastOnDayTime else 0 # ÒѾ­½±Àø¹ýµÄÌìÊý GameWorld.DebugLog(" alreadyAwardDays=%s,curDays=%s" % (alreadyAwardDays, curDays), playerID) # ²¹·¢ÉÏ´ÎÀëÏßÌìµÄ awardDays = alreadyAwardDays + 1 for awardIndexStr, addItemList in giftItemDict.items(): if awardIndexStr not in actCTGIDDict: GameWorld.DebugLog(" ´ò°ü¹ºÂòÃâ·ÑµÄ²»²¹·¢! awardIndex=%s" % (awardIndexStr), playerID) continue if getRecord&pow(2, int(awardIndexStr)): GameWorld.DebugLog(" ÒѾ­ÁìÈ¡¹ý¸Ã½±ÀøÁË£¬²»²¹·¢! awardIndex=%s,getRecord=%s" % (awardIndexStr, getRecord), playerID) continue GameWorld.DebugLog(" ²¹·¢ÀëÏßÌì! awardDays=%s,awardIndex=%s" % (awardDays, awardIndexStr), playerID) paramList = [awardDays] PlayerControl.SendMailByKey("DailyPackBuyGift1", [playerID], addItemList, paramList) # ²¹·¢Î´µÇ¼ÍêÕûÌìµÄ for day in range(awardDays + 1, curDays): if day > maxDays: break paramList = [day] GameWorld.DebugLog(" ²¹·¢ÍêÕûÌì! day=%s" % (day), playerID) for awardIndexStr, addItemList in giftItemDict.items(): if awardIndexStr not in actCTGIDDict: GameWorld.DebugLog(" Ãâ·ÑµÄ²»²¹·¢! awardIndex=%s" % (awardIndexStr), playerID) continue PlayerControl.SendMailByKey("DailyPackBuyGift1", [playerID], addItemList, paramList) # ³¬¹ý×î´óÌìÁË£¬ÖØÖÃËùÓÐ if curDays > maxDays: GameWorld.DebugLog(" ³¬¹ý×î´óÌìÁË£¬ÖØÖÃËùÓÐ! curDays=%s" % (curDays), playerID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftPackTime, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftOnDayTime, 0) else: GameWorld.DebugLog(" 䳬¹ý×î´óÌ죬¹ýÌìÖØÖÃ! curDays=%s" % (curDays), playerID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftOnDayTime, curTime) else: # µ¥Ìì²¹·¢µÄ for awardIndexStr, addItemList in giftItemDict.items(): if awardIndexStr in actCTGIDDict: if not buyState&pow(2, int(awardIndexStr)): GameWorld.DebugLog("ûÓдò°ü¹ºÂòÇÒûÓе¥¶À¹ºÂò£¬²»²¹·¢! awardIndex=%s,packBuyTime=%s,buyState=%s" % (awardIndexStr, packBuyTime, buyState), playerID) continue else: GameWorld.DebugLog("ûÓдò°ü¹ºÂòÇÒÃâ·ÑµÄ²»²¹·¢! awardIndex=%s" % (awardIndexStr), playerID) continue if getRecord&pow(2, int(awardIndexStr)): GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ý¸Ã½±ÀøÁË£¬²»²¹·¢! awardIndex=%s,getRecord=%s" % (awardIndexStr, getRecord), playerID) continue GameWorld.DebugLog(" ²¹·¢ÀëÏßÌì! awardIndex=%s" % (awardIndexStr), playerID) paramList = [] PlayerControl.SendMailByKey("DailyPackBuyGift2", [playerID], addItemList, paramList) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftBuy, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_DailyPackBuyGiftRecord, 0) Sync_DailyPackBuyGiftInfo(curPlayer) return def Sync_DailyPackBuyGiftInfo(curPlayer): clientPack = ChPyNetSendPack.tagMCDailyPackBuyGiftInfo() clientPack.Clear() clientPack.PackBuyTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftPackTime) clientPack.BuyStateToday = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftBuy) clientPack.AwardState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_DailyPackBuyGiftRecord) NetPackCommon.SendFakePack(curPlayer, clientPack) return ################################################################### def OnGetHistoryRechargeAward(curPlayer, awardID): # ÁìÈ¡ÀúÊ·³äÖµ½±Àø ipyData = IpyGameDataPY.GetIpyGameData('HistoryRechargeAward', awardID) if not ipyData: return needCoin = CommFunc.RMBToCoin(ipyData.GetNeedRMB()) # ¼ì²é¿É·ñÁìÈ¡ # Íæ¼Ò³äֵСÓÚÁìÈ¡³äÖµ if curPlayer.GetChangeCoinPointTotal() < needCoin: GameWorld.ErrLog("OnGetHistoryRechargeAward error£ºneedCoin=%s greater than ChangeCoinPointTotal=%s" % (needCoin, curPlayer.GetChangeCoinPointTotal())) return awardInfo = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HistoryChargeAwardGetRecord, 0) awardMark = pow(2, awardID) if awardInfo & awardMark: #ÒÑÁìÈ¡ GameWorld.DebugLog("ÒÑÁìÈ¡ÀúÊ·³äÖµ½±Àø£¡awardID=%s,needCoin=%s" % (awardID, needCoin)) return job = curPlayer.GetJob() awardDict = ipyData.GetReward() if str(job) not in awardDict: return itemList = awardDict[str(job)] if not itemList: return # ¼ì²é±³°ü if not ItemControler.CheckPackSpaceEnough(curPlayer, itemList): return # ¸øÎïÆ· for itemInfo in itemList: itemID, itemCount = itemInfo[:2] ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, 0, [IPY_GameWorld.rptItem]) ItemControler.NotifyGiveAwardInfo(curPlayer, itemList, "HistoryRecharge") # ¸üÐÂÒÑÁìÈ¡³É¹¦±ê¼Ç awardMark = pow(2, awardID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_HistoryChargeAwardGetRecord, awardInfo | awardMark) # ֪ͨ¿Í»§¶Ë Sync_HistoryChargeAwardGetRecordInfo(curPlayer) # ¼Ç¼Áìȡʼþ DataRecordPack.SendEventPack("HistoryRechargeAward", {'awardID':awardID, 'needCoin':needCoin}, curPlayer) return ## ֪ͨµÈ¼¶½±ÀøÁìÈ¡¼Ç¼ÐÅÏ¢ # @param None # @return None def Sync_HistoryChargeAwardGetRecordInfo(curPlayer): sendPack = ChPyNetSendPack.tagMCHistoryReChargeAwardRecord() sendPack.Clear() sendPack.AwardGetRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_HistoryChargeAwardGetRecord, 0) NetPackCommon.SendFakePack(curPlayer, sendPack) return