| | |
| | | import PlayerControl
|
| | | import ChPyNetSendPack
|
| | | import NetPackCommon
|
| | | import ItemControler
|
| | | import IPY_GameWorld
|
| | | import ShareDefine
|
| | | import ChConfig
|
| | | import random
|
| | | import time
|
| | |
|
| | | PrizeType_Gold = 1 # 金币 = 10万铜钱
|
| | | PrizeType_Xianyu = 2 # 仙玉币 = 10仙玉
|
| | | PrizeType_Redpack = 3 # 红包
|
| | | PrizeType_Super = 4 # 超级奖励
|
| | |
|
| | | PrizeMoneyTypeList = [1, 2, 3] # 本功能可产出的货币类型
|
| | |
|
| | | Sign_NewVerPlayer = 1 # 新版本后端处理玩家 |
| | | Sign_OldVerPlayer = 2 # 老版本前端处理玩家 |
| | |
|
| | | def __InitOldPlayerTjb(curPlayer):
|
| | | ## 老玩家推金币默认奖池处理
|
| | | if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign):
|
| | | #GameWorld.DebugLog("推金币玩家标记已处理: %s" % curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign), curPlayer.GetPlayerID())
|
| | | return
|
| | | sign = Sign_NewVerPlayer
|
| | | for moneyType in PrizeMoneyTypeList:
|
| | | if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType):
|
| | | sign = Sign_OldVerPlayer # 有实际获得过奖励视为老玩家
|
| | | break
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiSign, sign)
|
| | | if sign != Sign_OldVerPlayer:
|
| | | return
|
| | | # 给老玩家初始台面
|
| | | initPrizeList = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 5)
|
| | | for prizeType, prizeCount in initPrizeList:
|
| | | if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType):
|
| | | continue
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, prizeCount)
|
| | | GameWorld.Log("推金币老玩家设置初始台面数据: %s" % str(initPrizeList), curPlayer.GetPlayerID())
|
| | | return
|
| | |
|
| | | def OnPlayerLogin(curPlayer):
|
| | | __InitOldPlayerTjb(curPlayer)
|
| | | SyncTuijinbiInfo(curPlayer)
|
| | | return
|
| | |
|
| | |
| | | #struct tagCMTuijinbi
|
| | | #{
|
| | | # tagHead Head;
|
| | | # BYTE OpType; // 操作类型: 0-抽奖;1-获得金币;2-激活至尊卡
|
| | | # DWORD Value1; // 类型1时为货币类型
|
| | | # DWORD Value2; // 类型1时为货币数值
|
| | | # BYTE OpType; // 操作类型: 0-抽奖;1-获得奖励;2-激活至尊卡
|
| | | # DWORD Value1; // 类型1时为奖励类型
|
| | | # DWORD Value2; // 类型1时为奖励数值
|
| | | #};
|
| | | def OnTuijinbi(index, clientData, tick):
|
| | | curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
|
| | | playerID = curPlayer.GetPlayerID()
|
| | | opType = clientData.OpType
|
| | | value1 = clientData.Value1
|
| | | value2 = clientData.Value2
|
| | |
|
| | | if opType == 0:
|
| | | # 直接扣除次数,仅作为记录用,抽奖逻辑前端自己控制
|
| | | PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, 1, isNotify=False)
|
| | | __DoDraw(curPlayer)
|
| | |
|
| | | elif opType == 1:
|
| | | moneyType = value1
|
| | | moneyValue = value2
|
| | | moneyUpperLimitDict = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 3, {})
|
| | | if moneyType not in moneyUpperLimitDict:
|
| | | GameWorld.DebugLog("推金币没有配置获得该货币奖励上限! moneyType=%s" % moneyType, playerID)
|
| | | return
|
| | | moneyUpperLimit = moneyUpperLimitDict[moneyType]
|
| | | moneyTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType)
|
| | | updMoneyTotal = min(moneyTotal + moneyValue, moneyUpperLimit, ChConfig.Def_UpperLimit_DWord)
|
| | | giveMoney = updMoneyTotal - moneyTotal
|
| | | if giveMoney <= 0:
|
| | | GameWorld.ErrLog("推金币已达奖励上限! moneyType=%s,moneyTotal=%s" % (moneyType, moneyTotal), playerID)
|
| | | return
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiMoney % moneyType, updMoneyTotal)
|
| | | GameWorld.DebugLog("更新推金币奖励: moneyType=%s,moneyValue=%s,giveMoney=%s,updMoneyTotal=%s" |
| | | % (moneyType, moneyValue, giveMoney, updMoneyTotal), playerID)
|
| | | PlayerControl.GiveMoney(curPlayer, moneyType, giveMoney, "Tuijinbi")
|
| | | SyncTuijinbiInfo(curPlayer)
|
| | | __DoGivePrize(curPlayer, value1, value2)
|
| | |
|
| | | elif opType == 2:
|
| | | __DoActiveSuperDiscount(curPlayer)
|
| | |
|
| | | return
|
| | |
|
| | | def SyncTuijinbiInfo(curPlayer):
|
| | | awardMoneyList = []
|
| | | moneyUpperLimitDict = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 3, {})
|
| | | for moneyType in moneyUpperLimitDict.keys():
|
| | | moneyTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType)
|
| | | if not moneyTotal:
|
| | | continue
|
| | | moneyInfo = ChPyNetSendPack.tagMCTuijinbiMoney()
|
| | | moneyInfo.MoneyType = moneyType
|
| | | moneyInfo.MoneyValue = moneyTotal
|
| | | awardMoneyList.append(moneyInfo)
|
| | | if not awardMoneyList:
|
| | | def __DoDraw(curPlayer):
|
| | | ## 抽奖
|
| | | |
| | | if not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, 1):
|
| | | return
|
| | | |
| | | playerID = curPlayer.GetPlayerID()
|
| | | prizeSetList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 1) # 奖池 [[类型, 概率, 数量], ...]
|
| | | prizeRateList = []
|
| | | for setInfo in prizeSetList:
|
| | | prizeRateList.append([setInfo[1], [setInfo[0], setInfo[2]]])
|
| | | playerSign = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiSign)
|
| | | tuijinbiCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiCnt)
|
| | | GameWorld.DebugLog("推金币抽奖: playerSign=%s,tuijinbiCnt=%s,prizeRateList=%s" % (playerSign, tuijinbiCnt, prizeRateList), playerID)
|
| | | |
| | | addPoolPrizeInfo = {} # 增加台面奖池信息
|
| | | drawInfo = GameWorld.GetResultByRandomList(prizeRateList)
|
| | | if playerSign == Sign_NewVerPlayer and not tuijinbiCnt: # 新版本玩家首次推
|
| | | for _ in range(100):
|
| | | if drawInfo and drawInfo[0] in [PrizeType_Gold, PrizeType_Xianyu]: # 首次只能产出金币或仙玉币
|
| | | break
|
| | | drawInfo = GameWorld.GetResultByRandomList(prizeRateList)
|
| | | |
| | | # 首次附加默认初始奖励
|
| | | initPrizeList = IpyGameDataPY.GetFuncEvalCfg("EnSuperDiscount", 5)
|
| | | for prizeType, prizeCnt in initPrizeList:
|
| | | addPoolPrizeInfo[prizeType] = prizeCnt
|
| | | GameWorld.DebugLog("新手首次推额外奖励: %s" % addPoolPrizeInfo, playerID)
|
| | | |
| | | if not drawInfo or len(drawInfo) != 2:
|
| | | return
|
| | | drawType, drawCount = drawInfo
|
| | | PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_Tuijinbi, 1, isNotify=False) |
| | | |
| | | # 红包,直接给奖励
|
| | | if drawType == PrizeType_Redpack:
|
| | | randMoneyList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 3)
|
| | | randMoney = random.choice(randMoneyList)
|
| | | GameWorld.DebugLog("抽到红包直接给: %s" % str(randMoney), playerID)
|
| | | if randMoney and len(randMoney) == 2:
|
| | | __GiveMoney(curPlayer, randMoney[0], randMoney[1], True)
|
| | | |
| | | # 超级奖励
|
| | | elif drawType == PrizeType_Super:
|
| | | randPrizeList = IpyGameDataPY.GetFuncEvalCfg("PushCoin", 2)
|
| | | randPrize = random.choice(randPrizeList)
|
| | | GameWorld.DebugLog("抽到超级奖励: %s" % str(randPrize), playerID)
|
| | | if randPrize and len(randPrize) == 2:
|
| | | randPrizeType, randValue = randPrize
|
| | | addPoolPrizeInfo[randPrizeType] = addPoolPrizeInfo.get(randPrizeType, 0) + randValue
|
| | | else:
|
| | | GameWorld.DebugLog("抽到: drawType=%s,drawCount=%s" % (drawType, drawCount), playerID)
|
| | | addPoolPrizeInfo[drawType] = addPoolPrizeInfo.get(drawType, 0) + drawCount
|
| | | |
| | | for prizeType, addCnt in addPoolPrizeInfo.items():
|
| | | curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
|
| | | updCnt = curCnt + addCnt
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, updCnt)
|
| | | GameWorld.DebugLog("推金币更新台面: prizeType=%s,curCnt=%s,addCnt=%s,updCnt=%s" % (prizeType, curCnt, addCnt, updCnt), playerID)
|
| | | |
| | | tuijinbiCnt += 1
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiCnt, tuijinbiCnt)
|
| | | GameWorld.DebugLog("更新累计推金币次数: %s" % (tuijinbiCnt), playerID)
|
| | | SyncTuijinbiInfo(curPlayer, drawType, drawCount)
|
| | | return
|
| | |
|
| | | def __DoGivePrize(curPlayer, prizeType, prizeCount):
|
| | | if prizeType not in [PrizeType_Gold, PrizeType_Xianyu]:
|
| | | return
|
| | | curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
|
| | | giveCnt = min(prizeCount, curCnt)
|
| | | if not giveCnt:
|
| | | return
|
| | | updCnt = curCnt - giveCnt
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiPool % prizeType, updCnt)
|
| | | GameWorld.DebugLog("掉落更新台面: prizeType=%s,prizeCount=%s,curCnt=%s,giveCnt=%s,updCnt=%s" |
| | | % (prizeType, prizeCount, curCnt, giveCnt, updCnt), curPlayer.GetPlayerID())
|
| | | if prizeType == PrizeType_Gold:
|
| | | __GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Silver_Money, 100000 * giveCnt)
|
| | | elif prizeType == PrizeType_Xianyu:
|
| | | __GiveMoney(curPlayer, IPY_GameWorld.TYPE_Price_Gold_Money, 10 * giveCnt)
|
| | | SyncTuijinbiInfo(curPlayer)
|
| | | return
|
| | |
|
| | | def __GiveMoney(curPlayer, moneyType, moneyValue, notifyAward=False):
|
| | | moneyTotal = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiMoney % moneyType)
|
| | | updMoneyTotal = min(moneyTotal + moneyValue, ChConfig.Def_UpperLimit_DWord)
|
| | | PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_TuiJinbiMoney % moneyType, updMoneyTotal)
|
| | | GameWorld.DebugLog("更新推金币累计奖励货币: moneyType=%s,moneyValue=%s,updMoneyTotal=%s" |
| | | % (moneyType, moneyValue, updMoneyTotal), curPlayer.GetPlayerID())
|
| | | PlayerControl.GiveMoney(curPlayer, moneyType, moneyValue, "Tuijinbi")
|
| | | if notifyAward:
|
| | | ItemControler.NotifyGiveAwardInfo(curPlayer, [], "Tuijinbi", moneyInfo={moneyType:moneyValue})
|
| | | return
|
| | |
|
| | | def SyncTuijinbiInfo(curPlayer, drawType=0, drawCount=0):
|
| | | poolPrizeList = [] # 台面信息
|
| | | for prizeType in [PrizeType_Gold, PrizeType_Xianyu]:
|
| | | prizeCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_TuiJinbiPool % prizeType)
|
| | | if not prizeCount:
|
| | | continue
|
| | | poolInfo = ChPyNetSendPack.tagMCTuijinbiPool()
|
| | | poolInfo.PrizeType = prizeType
|
| | | poolInfo.PrizeCount = prizeCount
|
| | | poolPrizeList.append(poolInfo)
|
| | | |
| | | clientPack = ChPyNetSendPack.tagMCTuijinbiInfo()
|
| | | clientPack.AwardMoneyList = awardMoneyList
|
| | | clientPack.AwardMoneyCount = len(clientPack.AwardMoneyList)
|
| | | clientPack.DrawType = drawType
|
| | | clientPack.DrawCount = drawCount
|
| | | clientPack.PoolPrizeList = poolPrizeList
|
| | | clientPack.PoolPrizeCnt = len(clientPack.PoolPrizeList)
|
| | | NetPackCommon.SendFakePack(curPlayer, clientPack)
|
| | | return
|
| | |
|