From 818774d25af38005782d7d46914a229e725ea8c7 Mon Sep 17 00:00:00 2001
From: hxp <ale99527@vip.qq.com>
Date: 星期五, 08 十一月 2019 16:50:54 +0800
Subject: [PATCH] 8333 【主干】【后端】boss之家死亡在复活点复活,不退出副本(死亡不退出副本,支持地图内复活,支持地图内传送到其他副本)

---
 ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyParty.py |  274 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 185 insertions(+), 89 deletions(-)

diff --git a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyParty.py b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyParty.py
index 0c297ac..f6b51be 100644
--- a/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyParty.py
+++ b/ServerPython/CoreServerGroup/GameServer/Script/Player/PlayerFamilyParty.py
@@ -26,18 +26,16 @@
 import ChConfig
 import PlayerFamilyRedPacket
 import PlayerTalk
+import PyGameData
 
 import random
 
-FamilyPartyFB_QuestionID = 'FamilyPartyFB_QuestionID%s' #当前题ID
-FamilyPartyFB_AnswerTick = 'FamilyPartyFB_AnswerTick%s' #答对时间
+FamilyPartyFB_HisQuestionID = 'FamParty_HisQuestionID%s' #当前题ID - 不重置, 参数 familyID
+FamilyPartyFB_QuestionID = 'FamParty_QuestionID%s' #当前题ID - 答对会重置, 参数 familyID
+FamilyPartyFB_QuestionTick = 'FamParty_QuestionTick%s' #当前题出题时间, 参数 familyID
+FamilyPartyFB_AnswerTick = 'FamParty_AnswerTick%s' #答对时间, 参数 familyID
 
-
-g_questionIDHistory = {} #出过的题记录 {familyid:[出过的题id,..]}
-g_familyAnswerDict = {} #仙盟答题数量 {familyid:答题数量,..}
-g_heroAnswerDict = {} #个人答题数量 {playerid:答题数量,..}
-
-
+AnswerState = 1 #开始答题活动状态
 ## 玩家登录
 #  @param None
 #  @return None
@@ -45,11 +43,20 @@
     NotifyFamilyPartyQuestion(curPlayer)
     return
 
+def OnPlayerChangeMap(curPlayer, tick):
+    if curPlayer.GetMapID() != ChConfig.Def_FBMapID_FamilyParty:
+        return
+    playerID = curPlayer.GetID()
+    if playerID not in PyGameData.g_partyheroAnswerDict:
+        PyGameData.g_partyheroAnswerDict[playerID] = 0
+    return
+
+
 def NotifyFamilyPartyQuestion(curPlayer):
     #刚登录的或刚进仙盟的补发最近的题目
     gameWorld = GameWorld.GetGameWorld()
-    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_FBFuncState % ChConfig.Def_FBMapID_FamilyParty)
-    if state != 1:
+    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % ShareDefine.DailyActionID_FamilyParty)
+    if state != AnswerState:
         return
     curFamilyid = curPlayer.GetFamilyID()
     if not curFamilyid:
@@ -60,72 +67,97 @@
     PlayerControl.NotifyCode(curPlayer, 'Party_Topic', [questionID])
     return
 
-def FamilyPartyStateChange(state):
+def FamilyPartyStateChange(state, beforeState=0):
     #活动状态变更
-    global g_questionIDHistory
-    global g_familyAnswerDict
-    global g_heroAnswerDict
+    if state == beforeState:
+        return
     
-    if state == 1:
-        g_questionIDHistory = {}
-        g_familyAnswerDict = {}
-        g_heroAnswerDict = {}
+    if state == AnswerState:
+        PyGameData.g_questionIDHistory = {}
+        PyGameData.g_familyAnswerDict = {}
+        PyGameData.g_familyPartyTopInfo = []
+        PyGameData.g_partyheroAnswerDict = {}
+        PyGameData.g_familyAnswerPlayerIDDict = {}
         gameWorld = GameWorld.GetGameWorld()
         familyManager = GameWorld.GetFamilyManager()
         for i in range(0, familyManager.GetCount()):
             family = familyManager.GetAt(i)
             familyID = family.GetID()
             gameWorld.SetDict(FamilyPartyFB_QuestionID % familyID, 0)
+            gameWorld.SetDict(FamilyPartyFB_HisQuestionID % familyID, 0)
             gameWorld.SetDict(FamilyPartyFB_AnswerTick % familyID, 0)
-            
-    
+        GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_FamilyPartyInfo, [])
+        
     if state == 0:
         #活动结算 前3名仙盟、答题王
-        GameWorld.Log(" 仙盟宴会结算 g_familyAnswerDict=%s, g_heroAnswerDict=%s"%(g_familyAnswerDict, g_heroAnswerDict))
+        GameWorld.Log("仙盟宴会结算 g_familyAnswerDict=%s, g_familyPartyTopInfo=%s" % (PyGameData.g_familyAnswerDict, PyGameData.g_familyPartyTopInfo))
         
         noneStr = 'null'
-        topfamilyNameList = [noneStr,noneStr,noneStr]
-        if g_familyAnswerDict:
-            sortFamilyList = g_familyAnswerDict.items()
-            sortFamilyList.sort(cmp=CmpFunc)
-            familyIDList = [familyInfo[0] for familyInfo in sortFamilyList][:3]
-            GameWorld.DebugLog("    宴会结束 familyIDList=%s"%familyIDList)
+        topfamilyNameList = [noneStr, noneStr, noneStr]
+        if PyGameData.g_familyAnswerDict:
+            sortFamilyList = __GetFamilyAnswerRankList()
+            GameWorld.DebugLog("    宴会结束 sortFamilyList=%s" % sortFamilyList)
             redPackID = IpyGameDataPY.GetFuncCfg('PartyReward', 4)
-            for i, familyID in enumerate(familyIDList):
-                familyName = PlayerFamily.GetFamilyName_ByID(familyID)
+            for i, familyInfo in enumerate(sortFamilyList):
+                familyID, familyName = familyInfo[:2]
                 topfamilyNameList[i] = familyName
                 #发红包
                 family = GameWorld.GetFamilyManager().FindFamily(familyID)
                 if not family:
                     continue
                 PlayerFamilyRedPacket.CreatNewFamilyRedPacket(family, family.GetLeaderID(), redPackID)
+                
         PlayerControl.WorldNotify(0, 'Party_TopThree', topfamilyNameList)
         
-        topHeroName = noneStr
-        if g_heroAnswerDict:
+        if PyGameData.g_familyPartyTopInfo:
+            topHeroID, topHeroName = PyGameData.g_familyPartyTopInfo[:2]
             rewardInfo = IpyGameDataPY.GetFuncEvalCfg('PartyReward', 3)
-            sortHeroList = g_heroAnswerDict.items()
-            sortHeroList.sort(cmp=CmpFunc)
-            sortHeroidList = [heroInfo[0] for heroInfo in sortHeroList]
-            GameWorld.DebugLog("    宴会结束 sortHeroidList=%s"%sortHeroidList)
-            playerManager = GameWorld.GetPlayerManager()
-            for playerID in sortHeroidList:
-                curPlayer = playerManager.FindPlayerByID(playerID)
-                if not curPlayer:
-                    continue
-#                if curPlayer.GetMapID() != ChConfig.Def_FBMapID_FamilyParty:
-#                    #不在副本
-#                    continue
-                topHeroName = curPlayer.GetName()
-                #给奖励
-                mailKey, day, itemList = rewardInfo
-                content = ShareDefine.Def_MailFormat % (mailKey, '')
-                GameWorld.DebugLog('发送仙盟宴会答题王邮件   itemList=%s' % (itemList))
-                PlayerCompensation.SendPersonalItemMailEx('', content, day, [playerID], itemList)
-                break
-        if topHeroName != noneStr:
+            #给奖励
+            mailKey, day, itemList = rewardInfo
+            content = ShareDefine.Def_MailFormat % (mailKey, '')
+            GameWorld.DebugLog('发送仙盟宴会答题王邮件   itemList=%s' % (itemList))
+            PlayerCompensation.SendPersonalItemMailEx('', content, day, [topHeroID], itemList)
+                
             PlayerControl.WorldNotify(0, 'Party_TopPlayer', [topHeroName])
+            
+        #给参与奖励
+        joinPlayerIDList = PyGameData.g_partyheroAnswerDict.keys()
+        if joinPlayerIDList:
+            joinReward = IpyGameDataPY.GetFuncEvalCfg('PartyReward')
+            if joinReward:
+                PlayerCompensation.SendMailByKey('FamilyParty', joinPlayerIDList, joinReward)
+        
+        #修改为答完题直接给每题奖励
+#        joinReward = IpyGameDataPY.GetFuncEvalCfg('PartyReward')
+#        answerRWItemReward = IpyGameDataPY.GetFuncEvalCfg('PartyReward2', 1)
+#        for playerID, ansRightCount in PyGameData.g_partyheroAnswerDict.items():
+#            if answerRWItemReward and len(answerRWItemReward) == 2:
+#                ansTotalCount = len(PyGameData.g_familyAnswerPlayerIDDict.get(playerID, []))
+#                ansWrongCount = max(0, ansTotalCount - ansRightCount)
+#                isAuctionItem = False
+#                rightRewardEx, wrongRewardEx = [], []
+#                rightItemID, wrongItemID = answerRWItemReward
+#                if rightItemID and ansRightCount:
+#                    rightRewardEx = [(rightItemID, ansRightCount, isAuctionItem)]
+#                if wrongItemID and ansWrongCount:
+#                    wrongRewardEx = [(wrongItemID, ansWrongCount, isAuctionItem)]
+#                curJoinReward = joinReward + rightRewardEx + wrongRewardEx
+#            else:
+#                curJoinReward = joinReward
+#            if joinReward:
+#                PlayerCompensation.SendMailByKey('FamilyParty', [playerID], curJoinReward)
+                
     return
+
+def __GetFamilyAnswerRankList():
+    if not PyGameData.g_familyAnswerDict:
+        return []
+    sortFamilyList = PyGameData.g_familyAnswerDict.items()
+    sortFamilyList.sort(cmp=CmpFunc)
+    rankList = [] #[[familyID, familyName, 答题数量]]
+    for familyID, info in sortFamilyList[:3]:
+        rankList.append([familyID, info[2], info[0]])
+    return rankList
 
 ## 排序函数
 #  @param elem1 元素1
@@ -139,83 +171,147 @@
     return result
 
 def FamilyParty_Process(tick):
-    global g_questionIDHistory
     #开始出题
     gameWorld = GameWorld.GetGameWorld()
-    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_FBFuncState % ChConfig.Def_FBMapID_FamilyParty)
-    if state != 1:
+    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % ShareDefine.DailyActionID_FamilyParty)
+    if state != AnswerState:
         return
-    
+    allQuestionIDList = IpyGameDataPY.GetConfigEx('AllQuestionID')
+    ipyMgr = IpyGameDataPY.IPY_Data()
+    if not allQuestionIDList:
+        allQuestionIDList = []
+        for i in xrange(ipyMgr.GetQuestionBankCount()):
+            ipyData = ipyMgr.GetQuestionBankByIndex(i)
+            questionID = ipyData.GetID()
+            allQuestionIDList.append(questionID)
+        IpyGameDataPY.SetConfigEx('AllQuestionID', allQuestionIDList)
+    if not allQuestionIDList:
+        GameWorld.ErrLog('仙盟宴会题库没有题目!')
+        return
     familyManager = GameWorld.GetFamilyManager()
     for i in range(0, familyManager.GetCount()):
         family = familyManager.GetAt(i)
         familyID = family.GetID()
-    
-        if gameWorld.GetDictByKey(FamilyPartyFB_QuestionID % familyID):
+        lastQuestionID = gameWorld.GetDictByKey(FamilyPartyFB_QuestionID % familyID)
+        if lastQuestionID:
             #还有题未答
-            continue
+            maxSecond = IpyGameDataPY.GetFuncCfg('FairyCorrectAnswer')
+            if tick - gameWorld.GetDictByKey(FamilyPartyFB_QuestionTick % familyID) > maxSecond * 1000:
+                ipyData = IpyGameDataPY.GetIpyGameData('QuestionBank', lastQuestionID)
+                if ipyData:
+                    answer = ipyData.GetAnswer()
+                    answer = answer.replace('[', '')
+                    answer = answer.replace(']', '')
+                    PlayerControl.FamilyNotify(familyID, 'Party_Correct', [maxSecond, GameWorld.GbkToCode(answer)])
+                    
+                for index in xrange(family.GetCount()):
+                    member = family.GetAt(index)
+                    memPlayer = member.GetPlayer()
+                    if memPlayer and memPlayer.GetMapID() == ChConfig.Def_FBMapID_FamilyParty:
+                        rightPlayerID = 0
+                        answerInfo = str([rightPlayerID])
+                        memPlayer.MapServer_QueryPlayerResult(0, 0, "FamilyPartyAnswer", answerInfo, len(answerInfo))
+                        break
+            else:
+                continue
         answerTick = gameWorld.GetDictByKey(FamilyPartyFB_AnswerTick % familyID)
-        if tick - answerTick < 5000:
+        if not lastQuestionID and tick - answerTick < 5000:
             continue
         
         #随机题目
-        historyQuestionIDList = g_questionIDHistory.get(familyID, [])
-        questionCnt = IpyGameDataPY.IPY_Data().GetQuestionBankCount()
+        historyQuestionIDList = PyGameData.g_questionIDHistory.get(familyID, [])
         for i in xrange(50):
-            questionID = random.randint(1, questionCnt)
+            questionID = random.choice(allQuestionIDList)
             # 随机到不重复的即可
             if questionID not in historyQuestionIDList or i == 49:
-                historyQuestionIDList.append(questionID)
-                g_questionIDHistory[familyID] = historyQuestionIDList
+                if questionID not in historyQuestionIDList:
+                    historyQuestionIDList.append(questionID)
+                    PyGameData.g_questionIDHistory[familyID] = historyQuestionIDList
                 break
         
         gameWorld.SetDict(FamilyPartyFB_QuestionID % familyID, questionID)
+        gameWorld.SetDict(FamilyPartyFB_HisQuestionID % familyID, questionID)
+        gameWorld.SetDict(FamilyPartyFB_QuestionTick % familyID, tick)
+        
         PlayerControl.FamilyNotify(familyID, 'Party_Topic', [questionID])
     return
 
 ## 仙盟频道聊天
 def OnTalkFamily(curPlayer, content, tick):
-    global g_familyAnswerDict
-    global g_heroAnswerDict
-    
+
     gameWorld = GameWorld.GetGameWorld()
-    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_FBFuncState % ChConfig.Def_FBMapID_FamilyParty)
-    if state != 1:
+    state = gameWorld.GetDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % ShareDefine.DailyActionID_FamilyParty)
+    if state != AnswerState:
         return
     
+    playerID = curPlayer.GetID()
     curFamilyid = curPlayer.GetFamilyID()
     if not curFamilyid:
         return
+    
+    ## 添加玩家参与答题的题目ID,只要在本地图答题期间仙盟发送聊天信息就算
+    ## 在每题中间有5秒缓冲,在此期间可能速度慢的玩家还在回答上一题,在缓冲期间题目ID为0,所以添加题目ID需用不重置的历史题目ID
+    if curPlayer.GetMapID() == ChConfig.Def_FBMapID_FamilyParty:
+        if playerID not in PyGameData.g_familyAnswerPlayerIDDict:
+            PyGameData.g_familyAnswerPlayerIDDict[playerID] = []
+        answerQuestionIDList = PyGameData.g_familyAnswerPlayerIDDict[playerID]
+        hisQuestionID = gameWorld.GetDictByKey(FamilyPartyFB_HisQuestionID % curFamilyid)
+        if hisQuestionID and hisQuestionID not in answerQuestionIDList:
+            answerQuestionIDList.append(hisQuestionID)
+            
     questionID = gameWorld.GetDictByKey(FamilyPartyFB_QuestionID % curFamilyid)
     if not questionID:
         return
+    ipyData = IpyGameDataPY.GetIpyGameData('QuestionBank', questionID)
+    if not ipyData:
+        GameWorld.ErrLog('仙盟宴会答题 该题不存在,异常 questionID=%s, 重新出题' % questionID)
+        gameWorld.SetDict(FamilyPartyFB_QuestionID % curFamilyid, 0)
+        gameWorld.SetDict(FamilyPartyFB_QuestionTick % curFamilyid, 0)
+        return
     
-    ipyData = IpyGameDataPY.IPY_Data().GetQuestionBankByIndex(questionID-1)
     answerList = eval(ipyData.GetAnswer())
     ChContent = PlayerTalk.ChangeVoiceChat(content)
-    ChContent = ChContent.decode(GameWorld.GetCharacterEncoding()).encode(ShareDefine.Def_Game_Character_Encoding)
+    ChContent = GameWorld.CodeToGBK(ChContent)
     ChContent = ChContent.strip()
     isRight = ChContent in answerList
-#    if curPlayer.GetMapID() != ChConfig.Def_FBMapID_FamilyParty:
-#        if isRight:
-#            PlayerControl.FamilyNotify(curFamilyid, 'FamilyPleaseIntoParty')
-#            PlayerControl.NotifyCode(curPlayer, 'FamilyNoIntoParty')
-#        return
+    if curPlayer.GetMapID() != ChConfig.Def_FBMapID_FamilyParty:
+        if isRight:
+            PlayerControl.FamilyNotify(curFamilyid, 'FamilyPleaseIntoParty')
+            PlayerControl.NotifyCode(curPlayer, 'FamilyNoIntoParty')
+        return
     
-    playerID = curPlayer.GetID()
-    GameWorld.DebugLog("    answer=%s  ChContent=%s"%(answerList, ChContent), playerID)
-    
+    GameWorld.DebugLog("    answer=%s  ChContent=%s" % (answerList, ChContent), playerID)
     if isRight:
-        GameWorld.DebugLog("    答对了! %s"%playerID)
-        gameWorld.SetDict(FamilyPartyFB_QuestionID%curFamilyid, 0)
-        gameWorld.SetDict(FamilyPartyFB_AnswerTick%curFamilyid, tick)
-        PlayerControl.FamilyNotify(curFamilyid, 'Party_Answer', [curPlayer.GetName()])
+        GameWorld.DebugLog("    答对了! %s" % playerID)
+        playerName = curPlayer.GetName()
+        gameWorld.SetDict(FamilyPartyFB_QuestionID % curFamilyid, 0)
+        gameWorld.SetDict(FamilyPartyFB_AnswerTick % curFamilyid, tick)
+
+        if curFamilyid in PyGameData.g_familyAnswerDict:
+            PyGameData.g_familyAnswerDict[curFamilyid][0] += 1
+            PyGameData.g_familyAnswerDict[curFamilyid][1] = tick
+        else:
+            familyName = PlayerFamily.GetFamilyName_ByID(curFamilyid)
+            PyGameData.g_familyAnswerDict[curFamilyid] = [1, tick, familyName]
+            
+        rightCountAward = IpyGameDataPY.GetFuncEvalCfg("PartyReward", 5)
+        if rightCountAward and len(rightCountAward) == 2:
+            perRightCount, addFamilyActivity = rightCountAward
+            if PyGameData.g_familyAnswerDict[curFamilyid][0] % perRightCount == 0:
+                PlayerControl.FamilyNotify(curFamilyid, "Contribution1", [perRightCount, addFamilyActivity])
+                GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_FamilyPartyAddFamilyActivity, [ChConfig.Def_FBMapID_FamilyParty, curFamilyid, addFamilyActivity])
+                
+        PyGameData.g_partyheroAnswerDict[playerID] = PyGameData.g_partyheroAnswerDict.get(playerID, 0) + 1
         
-        g_familyAnswerDict[curFamilyid] = [g_familyAnswerDict.get(curFamilyid, [0])[0] + 1, tick]
-        g_heroAnswerDict[playerID] = [g_heroAnswerDict.get(playerID, [0])[0] + 1, tick]
-        
-        
-        #通知玩家可获得贡献
-        curPlayer.MapServer_QueryPlayerResult(0, 0, "FamilyPartyAnswer", '', 0)
+        if PyGameData.g_familyPartyTopInfo:
+            if PyGameData.g_partyheroAnswerDict[playerID] > PyGameData.g_partyheroAnswerDict[PyGameData.g_familyPartyTopInfo[0]]:
+                PyGameData.g_familyPartyTopInfo = [playerID, playerName]
+        else:
+            PyGameData.g_familyPartyTopInfo = [playerID, playerName]
+        msgList = [__GetFamilyAnswerRankList(), PyGameData.g_familyPartyTopInfo[1], PyGameData.g_partyheroAnswerDict[PyGameData.g_familyPartyTopInfo[0]]]
+        GameWorld.SendMapServerMsgEx(ShareDefine.Def_Notify_WorldKey_FamilyPartyInfo, msgList)
+        #通知答题结果
+        answerInfo = str([playerID])
+        curPlayer.MapServer_QueryPlayerResult(0, 0, "FamilyPartyAnswer", answerInfo, len(answerInfo))
         
     return

--
Gitblit v1.8.0