#!/usr/bin/python # -*- coding: GBK -*- #--------------------------------------------------------------------- # #--------------------------------------------------------------------- ##@package PlayerFamilyRedPacket # @todo: Íæ¼Ò¼Ò×åºì°ü # # @author: xdh # @date 2017-08-31 # @version 1.0 # #--------------------------------------------------------------------- #"""Version = 2017-08-31 16:00""" #--------------------------------------------------------------------- import GameWorld import PlayerControl import ChConfig import IpyGameDataPY import IPY_GameWorld import ChPyNetSendPack import NetPackCommon import PlayerVip import ShareDefine import time #--------------------------------------------------------------------- Def_GoldPacket = 0 #Ö÷¶¯·¢×êʯºì°ü ( State_NoSend, #δ·¢ State_NoGot, #δÁìÈ¡ State_HasGot, #ÒÑÁìÈ¡ State_HasAllGot, #È«²¿ÁìÍê ) = range(4) ## Íæ¼ÒµÇ¼ def OnPlayerLogin(curPlayer): __NotifyGoldLimt(curPlayer) NotifyOSRedPacket(curPlayer) return ## OnDay´¦Àí # @param curPlayer # @return None def RedPacketOnDay(curPlayer, onEventType): if onEventType == ShareDefine.Def_OnEventType: #·¢×êʯºì°ü¶î¶ÈÖØÖà PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0) __NotifyGoldLimt(curPlayer) elif onEventType == ShareDefine.Def_OnEventTypeEx: oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg') openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) if openServerDay < oscDay: grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0) sendCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 5) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, grabCnt+sendCnt) NotifyOSRedPacket(curPlayer) return def CreatCacheRedPacktet(curPlayer): #¼ÓÈëÏÉÃ˺󣬷¢·Å´ý·¢µÄºì°ü ipyMgr = IpyGameDataPY.IPY_Data() for i in xrange(ipyMgr.GetFamilyRedPackCount()): ipyData = ipyMgr.GetFamilyRedPackByIndex(i) redPacketID = ipyData.GetID() if GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID): CreatRedPacketByID(curPlayer, redPacketID) GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID, 0) return def CreatRedPacketByID(curPlayer, redPacketID, state=State_NoSend, data=0): #¸ù¾Ýºì°üIDÉú³Éºì°ü ipyData = IpyGameDataPY.GetIpyGameData('FamilyRedPack', redPacketID) if not ipyData: return getType = ipyData.GetGetType() if getType == IpyGameDataPY.GetFuncCfg('OpenServerRedPacketType'): oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg') openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) if openServerDay >= oscDay: GameWorld.DebugLog(' ·¢¿ª·þºì°ü,»î¶¯Òѹý£¬²»¿É·¢ËÍ£¡') return else: if not curPlayer.GetFamilyID(): #û¼Ò×å ÏÈ´æÆðÀ´£¬µÈ½øÏÉÃËʱÔÙ²¹·¢ GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_PDict_FamilyRedPacketCache, redPacketID, 1) return DoCreatFamilyRedPacket(curPlayer, getType, ipyData.GetMoneyType(), ipyData.GetMoneyNum(), ipyData.GetPacketCnt(), state, '', data) return ## Éú³Éºì°ü def DoCreatFamilyRedPacket(curPlayer, getType, moneyType=2, awardNum=100, packetCnt=10, state=State_NoSend, wishInfo='', data=0): playerID = curPlayer.GetPlayerID() packetCnt = min(packetCnt, awardNum) if getType == Def_GoldPacket: goldLimit = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0) familyRedPacketGoldLimit = IpyGameDataPY.GetFuncCfg('FamilyRedPacketGoldLimit') if awardNum + goldLimit > familyRedPacketGoldLimit: GameWorld.DebugLog(' Ö÷¶¯·¢ÏÉÃË×êʯºì°ü£¬¶î¶ÈÒѳ¬%s,²»¿É·¢ËÍ£¡' % familyRedPacketGoldLimit, playerID) return if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney, awardNum): curBourseMoney = PlayerControl.GetMoney(curPlayer, ShareDefine.TYPE_Price_BourseMoney) GameWorld.Log(" ²»ÄÜ·¢×êʯºì°ü no enough bourse money! priceCount=%s,curBourseMoney=%s" % (awardNum, curBourseMoney), playerID) return if not PlayerControl.PayMoney(curPlayer, moneyType, awardNum, ChConfig.Def_Cost_FamilyRedPacket): return PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FamilyRedPacketGoldLimit, goldLimit + awardNum) #֪ͨ __NotifyGoldLimt(curPlayer) # else: # commonCntLimit = IpyGameDataPY.GetFuncCfg('FamilyRedPacketCnt') # if packetCnt < commonCntLimit: # GameWorld.DebugLog(' ·¢ÆÕͨÏÉÃ˺ì°ü£¬ÊýÁ¿²»ÄÜÉÙÓÚ%s£¡' % commonCntLimit, playerID) # return #֪ͨGameserverÉú³Éºì°ü msg = str([playerID, getType, packetCnt, moneyType, awardNum, wishInfo, state, data]) GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "CreatFamilyRedPacket", msg, len(msg)) GameWorld.DebugLog(' DoCreatFamilyRedPacket ֪ͨGameserverÉú³Éºì°ü msg=%s' % msg) return #// A6 08 ·¢¼Ò×åºì°ü #tagCMSendFamilyRedPacket # #struct tagCMSendFamilyRedPacket #{ # tagHead Head; # DWORD RedPacketID; // ºì°üID,ûÓз¢0 # WORD PacketCnt; // ºì°üÊýÁ¿ # WORD MoneyNum; //½ðÇ®ÊýÁ¿ # WORD WishLen; //×£¸£Óﳤ¶È # char Wish[NameLen]; //size=WishLen #}; ## ·¢¼Ò×åºì°ü def OnSendFamilyRedPacket(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) redPacketID = clientData.RedPacketID packetCnt = clientData.PacketCnt moneyNum = clientData.MoneyNum wishInfo = clientData.Wish if not redPacketID: #Ö÷¶¯·¢µÄ×êʯºì°ü vipÏÞÖÆ if not PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_FamilyGoldPack): GameWorld.DebugLog("Ö÷¶¯·¢µÄ×êʯºì°ü VIPȨÏÞ²»×ã") return DoCreatFamilyRedPacket(curPlayer, Def_GoldPacket, IPY_GameWorld.TYPE_Price_Gold_Money, moneyNum, packetCnt, State_NoGot, wishInfo) else: msg = str([curPlayer.GetPlayerID(), redPacketID, packetCnt]) GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "SendFamilyRedPacket", msg, len(msg)) return ## ֪ͨÇÀºì°ü×êʯ¶î¶È def __NotifyGoldLimt(curPlayer): packData = ChPyNetSendPack.tagMCFamilyRedPacketGoldLimit() packData.Clear() packData.HasSendGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FamilyRedPacketGoldLimit, 0) NetPackCommon.SendFakePack(curPlayer, packData) return ## ֪ͨÇÀºì°ü´ÎÊý def NotifyOSRedPacket(curPlayer): packData = ChPyNetSendPack.tagMCOpenServerRedPacketInfo() packData.Clear() packData.MoneyNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketGrabMoney, 0) packData.GrabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0) startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketStartTime, 0) if not startTime: createRoleTime = curPlayer.GetCreateRoleTime() startTime = GameWorld.ChangeTimeStrToNum(createRoleTime) packData.StartTime = startTime NetPackCommon.SendFakePack(curPlayer, packData) return #// A4 04 ÇÀ¼Ò×åºì°ü #tagCGGrabFamilyRedPacket # #struct tagCGGrabFamilyRedPacket #{ # tagHead Head; # DWORD RedPaketID; // ºì°üID #}; ## ÇÀºì°ü def OnGrabFamilyRedPacket(index, clientData, tick): curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index) redPacketID = clientData.RedPaketID OSCanGrabCnt = GetOSCanGrabCnt(curPlayer) msg = str([redPacketID, OSCanGrabCnt]) GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(curPlayer.GetID(), 0, 0, "GrabFamilyRedPacket", msg, len(msg)) GameWorld.DebugLog(' ÇÀºì°ü OSCanGrabCnt=%s'%OSCanGrabCnt) return def GetOSCanGrabCnt(curPlayer): #»ñÈ¡¿ª·þºì°ü¿ÉÇÀ´ÎÊý # oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg') # openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) # if openServerDay >= oscDay: # return 0 #curGrabCnt = return curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0) # createRoleTime = curPlayer.GetCreateRoleTime() # createRoleTimeNum = GameWorld.ChangeTimeStrToNum(createRoleTime) # curTime = int(time.time()) # rangeTime = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 3) # initCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 2) # return (curTime - createRoleTimeNum)/rangeTime + initCnt - curGrabCnt def GrabOSRedPacketResult(curPlayer, moneyNum, isSelf): ##ÇÀ¿ª·þºì°ü½á¹û grabNum = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketGrabMoney, 0) newGrabNum = grabNum+moneyNum PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketGrabMoney, newGrabNum) #¹ã²¥ needSysOSRAllMoneyList = IpyGameDataPY.GetFuncEvalCfg('OSRAllMoneySys') lastIndex = -1 newIndex = -1 for i, num in enumerate(needSysOSRAllMoneyList): if grabNum >= num: lastIndex = i if newGrabNum >= num: newIndex = i if newIndex != -1 and newIndex > lastIndex: PlayerControl.WorldNotify(0, 'OpenRedBag1', [curPlayer.GetName(), newGrabNum]) if not isSelf: #ÇÀ×Ô¼ºµÄºì°ü²»¿Û´ÎÊý grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, max(0, grabCnt-1)) # if grabCnt == IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 4): # PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketStartTime, int(time.time())) #֪ͨ NotifyOSRedPacket(curPlayer) return def ProcessOSRedPacket(curPlayer, tick): return #¿ª·þºì°ü»Ö¸´´ÎÊý if not GameWorld.SetPlayerTickTime(curPlayer, ChConfig.TYPE_Player_Tick_OSRedPacket, tick): return oscDay = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg') openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) if openServerDay >= oscDay: return grabCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketCanGrabCnt, 0) limitCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 4) if grabCnt >= limitCnt: return startTime = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_OSRedPacketStartTime, 0) if not startTime: newCnt = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 2) createRoleTime = curPlayer.GetCreateRoleTime() curTime = GameWorld.ChangeTimeStrToNum(createRoleTime) else: curTime = int(time.time()) passTime = curTime - startTime rangeTime = IpyGameDataPY.GetFuncCfg('OpenServerRedPacketCfg', 3) addCnt = passTime / rangeTime if addCnt <= 0:#·ÀÖ¹²âÊÔµ÷ʱ¼äµ¼ÖÂÒì³£ return newCnt = min(limitCnt, grabCnt+addCnt) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketCanGrabCnt, newCnt) PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_OSRedPacketStartTime, curTime) NotifyOSRedPacket(curPlayer) return