| | |
| | | import PlayerUniversalGameRec
|
| | |
|
| | | import random
|
| | | import json
|
| | | import math
|
| | | import json
|
| | |
|
| | | RecType = ShareDefine.Def_UniversalGameRecType_XMZZStageRecord
|
| | | RecType1 = ShareDefine.Def_UniversalGameRecType_XMZZPKInfoRecord
|
| | | #strValue3 {投注索引:结果,..}
|
| | | g_playerPowerDict = {} #玩家战力缓存
|
| | | g_historyPKDict = {} #历史对手ID缓存
|
| | |
|
| | | (
|
| | |
| | |
|
| | | def XMZZOndayEx():
|
| | | #过天
|
| | | global g_playerPowerDict
|
| | | global g_historyPKDict
|
| | | PyDataManager.GetXMZZManager().ResetXMZZ()
|
| | | g_playerPowerDict = {} #玩家战力缓存
|
| | | g_historyPKDict = {} #历史对手ID缓存
|
| | | return
|
| | |
|
| | |
| | | class XMZZManager(object):
|
| | |
|
| | | def __init__(self):
|
| | | self.XMZZPlayerDict = {} # {playerid:data, ...} PyGameDataStruct.tagDBPySealDemonRecord
|
| | | self.XMZZPlayerDict = {} # {playerid:data, ...} PyGameDataStruct.tagDBPyXMZZ
|
| | | self.XMZZFactionDict = {Faction_1:[0, 0], Faction_2:[0, 0]} # {faction:[积分, 人数]}
|
| | | self.XMZZTopScore = 0 #积分王积分
|
| | | self.XMZZTopPlayerName = '' #积分王名
|
| | |
| | | if playerID not in self.vsPlayerIDDict:
|
| | | return
|
| | | pkPlayerID = self.vsPlayerIDDict[playerID]
|
| | | curCache = PlayerViewCache.ViewCacheMgr.FindCache(pkPlayerID)
|
| | | curCache = PlayerViewCache.FindViewCache(pkPlayerID)
|
| | | if not curCache:
|
| | | return
|
| | | PropData, ItemData = curCache.GetPropData(), curCache.GetItemData()
|
| | |
|
| | | packData = ChPyNetSendPack.tagGCXMZZFightInfo()
|
| | | packData.Clear()
|
| | | packData.PlayerID = pkPlayerID
|
| | | packData.PropData = PropData
|
| | | packData.PropData = curCache.PropData
|
| | | packData.PropDataSize = len(packData.PropData)
|
| | | packData.ItemData = ItemData
|
| | | packData.ItemDataSize = len(packData.ItemData)
|
| | | NetPackCommon.SendFakePack(curPlayer, packData)
|
| | | return
|
| | |
|
| | |
| | | #第一积分奖励
|
| | | if topScorePlayerID:
|
| | | topScoreAward = IpyGameDataPY.GetFuncEvalCfg('XMZZAward', 2)
|
| | | PlayerCompensation.SendMailByKey('XMZZTopScore', [topScorePlayerID], topScoreAward, [topScore])
|
| | | SavePKRecord('XMZZ_FirstPlace', [self.XMZZTopPlayerName, self.XMZZTopScore], False)
|
| | | if topScoreAward:
|
| | | PlayerCompensation.SendMailByKey('XMZZTopScore', [topScorePlayerID], topScoreAward, [topScore])
|
| | | SavePKRecord('XMZZ_FirstPlace', [self.XMZZTopPlayerName, self.XMZZTopScore], False)
|
| | |
|
| | | #押注奖励
|
| | | self.BetOverLogic()
|
| | |
| | | #阵营奖励
|
| | | winAward = IpyGameDataPY.GetFuncEvalCfg('XMZZAward', 3)
|
| | | LoseAward = IpyGameDataPY.GetFuncEvalCfg('XMZZAward', 4)
|
| | | dogfallAward = IpyGameDataPY.GetFuncEvalCfg('XMZZAward', 5)
|
| | | dogfallAward = IpyGameDataPY.GetFuncCfg('XMZZAward', 5)
|
| | | result = self.GetXMZZCurResult()
|
| | | if result == Faction_1:
|
| | | SavePKRecord('XMZZ_Victory', [result], True)
|
| | |
| | | faction_2_Score = self.XMZZFactionDict.get(Faction_2, [0, 0])[0]
|
| | | if faction_1_Score + faction_2_Score >= XMZZDogFallLimit:
|
| | | SavePKRecord('XMZZ_Draw', [], True)
|
| | | |
| | | PlayerCompensation.SendMailByKey('XMZZDogfall', Faction_2_IDList + Faction_1_IDList, [], goldPaper=dogfallAward)
|
| | | #PlayerControl.MergeWorldNotify(0, '', [])
|
| | | if dogfallAward:
|
| | | PlayerCompensation.SendMailByKey('XMZZDogfall', Faction_2_IDList + Faction_1_IDList, [], goldPaper=dogfallAward)
|
| | |
|
| | | PlayerDBGSEvent.SetDBGSTrig_ByKey(PlayerDBGSEvent.Def_XMZZIsOver, 1)
|
| | | self.NotifyXMZZInfo()
|
| | |
| | | cnt += 1
|
| | | savaData += XMZZData.getBuffer()
|
| | |
|
| | | GameWorld.Log("SaveXMZZ cnt :%s" % cnt)
|
| | | GameWorld.Log("SaveXMZZ cnt :%s len=%s" % (cnt, len(savaData)))
|
| | | return CommFunc.WriteDWORD(cntData, cnt) + savaData
|
| | |
|
| | | # 从数据库载入数据
|
| | |
| | |
|
| | | def RandomBattler(curPlayer, overInfo=[]):
|
| | | #筛选对手 根据连胜次数一定几率随机到高级机器人,否则每5个的第1个低于自己战力 先从小范围随机,再大范围随机,没有则用NPC
|
| | | global g_playerPowerDict
|
| | | global g_historyPKDict
|
| | | myPlayerID = curPlayer.GetID()
|
| | | GameWorld.DebugLog(' 仙魔之争开始筛选对手', myPlayerID)
|
| | |
| | |
|
| | | pkPlayerID = 0 # 默认低级机器人
|
| | | isRobotNPC = True
|
| | | pkDataDict = {}
|
| | | conWinCnt = XMZZPlayerDict[myPlayerID].ConWinCnt #参数
|
| | | XMZZSpecialNPCRate = eval(IpyGameDataPY.GetFuncCfg('XMZZSpecialNPCRate'))
|
| | | XMZZSpecialNPCRate = eval(IpyGameDataPY.GetFuncCompileCfg('XMZZSpecialNPCRate'))
|
| | | XMZZSuperNPCRate = eval(IpyGameDataPY.GetFuncCompileCfg('XMZZSpecialNPCRate', 2))
|
| | | XMZZNPCByLVPowerList = IpyGameDataPY.GetFuncEvalCfg('XMZZPKPowerRange', 2)
|
| | | isByLVPower = conWinCnt + 1 in XMZZNPCByLVPowerList #是否按等级表战力来随机范围
|
| | | if GameWorld.CanHappen(XMZZSuperNPCRate):
|
| | | GameWorld.DebugLog(' 筛选对手 超级机器人 XMZZSuperNPCRate=%s' % (XMZZSuperNPCRate))
|
| | | pkPlayerID = 2
|
| | |
|
| | | if not isByLVPower and GameWorld.CanHappen(XMZZSpecialNPCRate):
|
| | | elif not isByLVPower and GameWorld.CanHappen(XMZZSpecialNPCRate):
|
| | | GameWorld.DebugLog(' 筛选对手 高级机器人 XMZZSpecialNPCRate=%s' % (XMZZSpecialNPCRate))
|
| | | #机器人ID规则: ID从0~n, n不大于机器人ID列表长度, ID越大机器人越高级,根据策划需求自增
|
| | | #高级机器人
|
| | |
| | | if isByLVPower:
|
| | | worldLv = PlayerDBGSEvent.GetDBGSTrig_ByKey(ShareDefine.Def_Notify_WorldKey_WorldAverageLv)
|
| | | ipyData = IpyGameDataPY.GetIpyGameData('PlayerLV', worldLv)
|
| | | myPower = ipyData.GetReFightPower() if ipyData else curPlayer.GetFightPower() |
| | | myPower = ipyData.GetReFightPower() if ipyData else PlayerControl.GetFightPower(curPlayer) |
| | | else:
|
| | | myPower = curPlayer.GetFightPower()
|
| | | myPower = PlayerControl.GetFightPower(curPlayer)
|
| | | XMZZPKPowerRange = IpyGameDataPY.GetFuncEvalCfg('XMZZPKPowerRange')
|
| | | minPower1, maxPower1 = myPower * (100 - XMZZPKPowerRange[0][0]) / 100, myPower * (100 + XMZZPKPowerRange[0][1]) / 100
|
| | | minPower2, maxPower2 = myPower * (100 - XMZZPKPowerRange[1][0]) / 100, myPower * (100 + XMZZPKPowerRange[1][1]) / 100
|
| | | underList1, aboveList1 = [], [] #小范围
|
| | | underList2, aboveList2 = [], [] #大范围
|
| | |
|
| | | ViewCacheMgr = GameWorld.GameWorldData.GetPlayerViewCacheMgr()
|
| | | for i in xrange(ViewCacheMgr.GetCount()):
|
| | | curCache = ViewCacheMgr.At(i)
|
| | | itemData = PlayerViewCache.GetItemData(curCache)
|
| | | if not itemData:
|
| | | #没有装备信息
|
| | | continue
|
| | | playerID = curCache.GetPlayerID()
|
| | | |
| | | pyViewCacheMgr = PyDataManager.GetPlayerViewCachePyManager()
|
| | | playerViewCachePyDict = pyViewCacheMgr.playerViewCachePyDict
|
| | | for playerID, curCache in playerViewCachePyDict.items():
|
| | | if myPlayerID == playerID:
|
| | | #不和自己pk
|
| | | continue
|
| | |
| | | #已匹配过的跳过
|
| | | continue
|
| | |
|
| | | if playerID in g_playerPowerDict:
|
| | | power = g_playerPowerDict[playerID]
|
| | | else:
|
| | | propDataDict = eval(curCache.GetPropData())
|
| | | power = propDataDict.get('FightPower', 0)
|
| | | g_playerPowerDict[playerID] = power
|
| | | propDataDict = PlayerViewCache.GetCachePropDataDict(curCache)
|
| | | power = propDataDict.get('FightPower', 0)
|
| | |
|
| | | pkDataDict[playerID] = [curCache.GetPropData(), curCache.GetItemData()]
|
| | | #GameWorld.DebugLog(' 筛选对手 playerID=%s,power=%s' % (playerID, power))
|
| | | if minPower1 < power < myPower:
|
| | | underList1.append(playerID)
|
| | |
| | | aboveList2.append(playerID)
|
| | | GameWorld.DebugLog(' 筛选对手 myPower=%s,underList1=%s, aboveList1=%s,underList2=%s, aboveList2=%s' % (myPower, underList1, aboveList1, underList2, aboveList2), myPlayerID)
|
| | |
|
| | | if conWinCnt % 5 == 0: #每5个匹配战力低的对手
|
| | | if conWinCnt % 5 == 0 or conWinCnt <= IpyGameDataPY.GetFuncCfg('XMZZPKPowerRange', 3): #每5个匹配战力低的对手
|
| | | if underList1:
|
| | | pkPlayerID = underList1[0]
|
| | | elif underList2:
|
| | |
| | | if isRobotNPC:
|
| | | #机器人, 职业随机
|
| | | openJob = IpyGameDataPY.GetFuncEvalCfg("OpenJob")
|
| | | PropData = str({"Job":random.choice(openJob), "LV":curPlayer.GetLV()})
|
| | | ItemData = "" # 前端自己根据职业及NPC等级处理
|
| | | pkPlayerPropData = {"Job":random.choice(openJob), "LV":curPlayer.GetLV()}
|
| | | else:
|
| | | if myPlayerID in g_historyPKDict:
|
| | | g_historyPKDict[myPlayerID].append(pkPlayerID)
|
| | | else:
|
| | | g_historyPKDict[myPlayerID] = [pkPlayerID]
|
| | |
|
| | | PropData, ItemData = pkDataDict.get(pkPlayerID, ["", ""])
|
| | | pkPlayerCache = PlayerViewCache.FindViewCache(pkPlayerID)
|
| | | pkPlayerPropData = {} if not pkPlayerCache else PlayerViewCache.GetCachePropDataDict(pkPlayerCache)
|
| | | XMZZManager.vsPlayerIDDict[myPlayerID] = pkPlayerID
|
| | |
|
| | | GameWorld.DebugLog(' 仙魔之争匹配对手信息 pkPlayerID=%s, PropData=%s, overInfo=%s' % (pkPlayerID, PropData, overInfo), myPlayerID)
|
| | | GameWorld.DebugLog(' 仙魔之争匹配对手信息 pkPlayerID=%s, pkPlayerPropData=%s, overInfo=%s' % (pkPlayerID, pkPlayerPropData, overInfo), myPlayerID)
|
| | |
|
| | | #通知前端
|
| | | packData = ChPyNetSendPack.tagGCXMZZFightInfo()
|
| | | packData.Clear()
|
| | | packData.PlayerID = pkPlayerID
|
| | | packData.PropData = PropData
|
| | | packData.PropData = json.dumps(pkPlayerPropData, ensure_ascii=False)
|
| | | packData.PropDataSize = len(packData.PropData)
|
| | | packData.ItemData = ItemData
|
| | | packData.ItemDataSize = len(packData.ItemData)
|
| | | NetPackCommon.SendFakePack(curPlayer, packData)
|
| | |
|
| | | #通知地图
|
| | | pkPlayerPropData = {}
|
| | | if PropData:
|
| | | pkPlayerPropData = eval(PropData)
|
| | | else:
|
| | | GameWorld.ErrLog("仙魔之争没有匹配到对手信息!fightPower=%s" % curPlayer.GetFightPower(), myPlayerID)
|
| | | if not pkPlayerPropData:
|
| | | GameWorld.ErrLog("仙魔之争没有匹配到对手信息!fightPower=%s" % PlayerControl.GetFightPower(curPlayer), myPlayerID)
|
| | | vsPlayerInfo = [pkPlayerID, pkPlayerPropData]
|
| | | XMZZManager.MapServer_XMZZPKInfo(curPlayer, overInfo, vsPlayerInfo)
|
| | | return True
|