#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # ##@package Player.PlayerCostRebate # # @todo:Ïû·Ñ·µÀû»î¶¯ # @author hxp # @date 2018-7-16 # @version 1.0 # # ÏêϸÃèÊö: Ïû·Ñ·µÀû»î¶¯ # #------------------------------------------------------------------------------- #"""Version = 2018-7-16 12:00""" #------------------------------------------------------------------------------- import PyGameData import ShareDefine import PlayerControl import IpyGameDataPY import ItemControler import ChPyNetSendPack import DataRecordPack import IPY_GameWorld import NetPackCommon import ItemCommon import GameWorld import ChConfig def GetTemplateID(cfgID, dayIndex): if cfgID == None or dayIndex == None: return 0 ipyData = IpyGameDataPY.GetIpyGameData("ActCostRebate", cfgID) if not ipyData: return 0 templateIDList = ipyData.GetTemplateIDList() templateID = templateIDList[-1] if dayIndex >= len(templateIDList) else templateIDList[dayIndex] return templateID def OnPlayerLogin(curPlayer): isReset = __CheckPlayerCostRebateAction(curPlayer) if not isReset: actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_CostRebate, {}) # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢ if actCostRebateInfo.get(ShareDefine.ActKey_State): Sync_CostRebateActionInfo(curPlayer) Sync_CostRebateInfo(curPlayer) return def RefreshCostRebateActionInfo(): ## ÊÕµ½GameServerͬ²½µÄ»î¶¯ÐÅÏ¢£¬Ë¢Ð»ÐÅÏ¢ playerManager = GameWorld.GetPlayerManager() for index in xrange(playerManager.GetPlayerCount()): curPlayer = playerManager.GetPlayerByIndex(index) if curPlayer.GetID() == 0: continue __CheckPlayerCostRebateAction(curPlayer) return def __CheckPlayerCostRebateAction(curPlayer): ## ¼ì²éÍæ¼ÒÏû·Ñ·µÀû»î¶¯Êý¾ÝÐÅÏ¢ playerID = curPlayer.GetPlayerID() actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_CostRebate, {}) costRebateID = actCostRebateInfo.get(ShareDefine.ActKey_ID, 0) state = actCostRebateInfo.get(ShareDefine.ActKey_State, 0) playerCostRebateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateID) # Íæ¼ÒÉíÉϵĻID # »î¶¯ID ÏàͬµÄ»°²»´¦Àí if costRebateID == playerCostRebateID: #GameWorld.DebugLog("Ïû·Ñ·µÀû»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID()) return templateID = GetTemplateID(actCostRebateInfo.get(ShareDefine.ActKey_CfgID, 0), actCostRebateInfo.get(ShareDefine.ActKey_DayIndex, 0)) playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateTemplateID) GameWorld.DebugLog("Ïû·Ñ·µÀûÖØÖÃ! costRebateID=%s,playerCostRebateID=%s,state=%s,templateID=%s,playerTemplateID=%s" % (costRebateID, playerCostRebateID, state, templateID, playerTemplateID), playerID) # δÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å __SendCostRebateMail(curPlayer, playerTemplateID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateID, costRebateID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateTemplateID, templateID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateGold, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateAwardRecord, 0) Sync_CostRebateActionInfo(curPlayer) Sync_CostRebateInfo(curPlayer) return True def __SendCostRebateMail(curPlayer, playerTemplateID): # δÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å if not playerTemplateID: return costGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateGold) if not costGold: return ipyDataList = IpyGameDataPY.GetIpyGameDataList("CostRebateTemplate", playerTemplateID) if not ipyDataList: return playerID = curPlayer.GetPlayerID() batchPlayerIDList, batchAddItemList, batchParamList = [], [], [] awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateAwardRecord) for ipyData in ipyDataList: awardIndex = ipyData.GetAwardIndex() if awardRecord & pow(2, awardIndex): continue needCostGold = ipyData.GetNeedCostGold() if costGold < needCostGold: continue awardRecord |= pow(2, awardIndex) awardItemList = ipyData.GetAwardItemList() batchPlayerIDList.append([playerID]) batchAddItemList.append(awardItemList) batchParamList.append([needCostGold]) if batchPlayerIDList: PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateAwardRecord, awardRecord) PlayerControl.SendMailBatch("ConsumptionRebateMail", batchPlayerIDList, batchAddItemList, batchParamList) return def AddCostRebateGold(curPlayer, costType, costGold, infoDict): if costGold <= 0: return if costType in ChConfig.CostRebate_DisableType: GameWorld.DebugLog("²»¼ÆÈëÏû·Ñ·µÀûµÄÏû·ÑÀàÐÍ!costType=%s" % costType, curPlayer.GetPlayerID()) return actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_CostRebate, {}) if not actCostRebateInfo.get(ShareDefine.ActKey_State): GameWorld.DebugLog("Ïû·Ñ·µÀû»î¶¯µ±Ç°Î´¿ªÆô!") return actID = actCostRebateInfo.get(ShareDefine.ActKey_ID) templateID = GetTemplateID(actCostRebateInfo.get(ShareDefine.ActKey_CfgID, 0), actCostRebateInfo.get(ShareDefine.ActKey_DayIndex, 0)) if not actID or not templateID: GameWorld.ErrLog("Ïû·Ñ·µÀû»î¶¯Êý¾ÝÒì³£!actID=%s,templateID=%s" % (actID, templateID), curPlayer.GetPlayerID()) return PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateID, actID) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateTemplateID, templateID) curCostGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateGold) updCostGold = curCostGold + costGold PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateGold, updCostGold) Sync_CostRebateInfo(curPlayer) GameWorld.DebugLog("Íæ¼ÒÏû·Ñ·µÀû»î¶¯: actID=%s,templateID=%s,curCostGold=%s,costGold=%s,updCostGold=%s" % (actID, templateID, curCostGold, costGold, updCostGold), curPlayer.GetPlayerID()) return def OnGetCostRebateAward(curPlayer, awardIndex): ## ÁìÈ¡Ïû·Ñ·µÀû½±Àø playerID = curPlayer.GetPlayerID() actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_CostRebate, {}) costRebateID = actCostRebateInfo.get(ShareDefine.ActKey_ID, 0) state = actCostRebateInfo.get(ShareDefine.ActKey_State, 0) templateID = GetTemplateID(actCostRebateInfo.get(ShareDefine.ActKey_CfgID, 0), actCostRebateInfo.get(ShareDefine.ActKey_DayIndex, 0)) if not state or not templateID: GameWorld.DebugLog("ûÓÐÏû·Ñ·µÀû»î¶¯£¬ÎÞ·¨Áì½±£¡state=%s,templateID=%s" % (state, templateID), playerID) return playerCostRebateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateID) # Íæ¼ÒÉíÉϵĻID if costRebateID != playerCostRebateID: return awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateAwardRecord) if awardRecord & pow(2, awardIndex): GameWorld.DebugLog("ÒѾ­ÁìÈ¡¹ý¸ÃÏû·Ñ·µÀû»î¶¯½±Àø!awardIndex=%s" % awardIndex, playerID) return ipyDataList = IpyGameDataPY.GetIpyGameDataList("CostRebateTemplate", templateID) if not ipyDataList: return awardIpyData = None for ipyData in ipyDataList: if ipyData.GetAwardIndex() == awardIndex: awardIpyData = ipyData break if not awardIpyData: GameWorld.DebugLog("ÕÒ²»µ½¸Ã·µÀû»î¶¯µµÎ»Ë÷Òý½±Àø!templateID=%s,awardIndex=%s" % (templateID, awardIndex), playerID) return needCostGold = awardIpyData.GetNeedCostGold() awardItemList = awardIpyData.GetAwardItemList() curCostGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateGold) if curCostGold < needCostGold: GameWorld.DebugLog("ËùÐèÏû·ÑÏÉÓñÊý²»×㣬ÎÞ·¨ÁìÈ¡!templateID=%s,awardIndex=%s,needCostGold=%s,curCostGold=%s" % (templateID, awardIndex, needCostGold, curCostGold), playerID) return needSpace = len(awardItemList) packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace) if packSpace < needSpace: return awardRecord |= pow(2, awardIndex) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_CostRebateAwardRecord, awardRecord) Sync_CostRebateInfo(curPlayer) notifyKey = awardIpyData.GetNotifyKey() if notifyKey: PlayerControl.WorldNotify(0, notifyKey, [curPlayer.GetPlayerName(), needCostGold]) for itemID, itemCount, isBind in awardItemList: ItemControler.GivePlayerItem(curPlayer, itemID, itemCount, isBind, [IPY_GameWorld.rptItem]) addDataDict = {"TemplateID":templateID, "NeedCostGold":needCostGold, "AwardIndex":awardIndex, "ItemList":str(awardItemList)} DataRecordPack.DR_FuncGiveItem(curPlayer, "CostRebateAward", addDataDict) return def Sync_CostRebateInfo(curPlayer): ## ֪ͨÏû·Ñ·µÀûÍæ¼ÒÊý¾ÝÐÅÏ¢ playerActInfo = ChPyNetSendPack.tagMCCostRebatePlayerInfo() playerActInfo.CostGoldTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateGold) playerActInfo.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_CostRebateAwardRecord) NetPackCommon.SendFakePack(curPlayer, playerActInfo) return def Sync_CostRebateActionInfo(curPlayer): ## ֪ͨÏû·Ñ·µÀû»î¶¯ÐÅÏ¢ actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_CostRebate, {}) if not actCostRebateInfo: return if not actCostRebateInfo.get(ShareDefine.ActKey_State): return cfgID = actCostRebateInfo.get(ShareDefine.ActKey_CfgID) ipyData = IpyGameDataPY.GetIpyGameData("ActCostRebate", cfgID) if not ipyData: return templateIDList = ipyData.GetTemplateIDList() if not templateIDList: return openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1 actInfo = ChPyNetSendPack.tagMCCostRebateInfo() actInfo.StartDate = GameWorld.GetOperationActionDateStr(ipyData.GetStartDate(), openServerDay) actInfo.EndtDate = GameWorld.GetOperationActionDateStr(ipyData.GetEndDate(), openServerDay) actInfo.LimitLV = ipyData.GetLVLimit() actInfo.IsDayReset = ipyData.GetIsDayReset() actInfo.AwardDayInfo = [] for templateID in templateIDList: ipyDataList = IpyGameDataPY.GetIpyGameDataList("CostRebateTemplate", templateID) if not ipyDataList: continue dayInfo = ChPyNetSendPack.tagMCCostRebateAwardDay() dayInfo.AwardInfo = [] for ipyData in ipyDataList: awardInfo = ChPyNetSendPack.tagMCCostRebateAward() awardInfo.AwardIndex = ipyData.GetAwardIndex() awardInfo.NeedGold = ipyData.GetNeedCostGold() awardInfo.AwardItem = [] for itemID, itemCount, isBind in ipyData.GetAwardItemList(): awardItem = ChPyNetSendPack.tagMCCostRebateAwardItem() awardItem.ItemID = itemID awardItem.ItemCount = itemCount awardItem.IsBind = isBind awardInfo.AwardItem.append(awardItem) awardInfo.AwardItemCount = len(awardInfo.AwardItem) dayInfo.AwardInfo.append(awardInfo) dayInfo.AwardCount = len(dayInfo.AwardInfo) actInfo.AwardDayInfo.append(dayInfo) actInfo.AwardDays = len(actInfo.AwardDayInfo) NetPackCommon.SendFakePack(curPlayer, actInfo) return