1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GM.Commands.GMT_GetFamilyByServerID
#
# @todo:²éѯÏÉÃË
# @author hxp
# @date 2025-04-09
# @version 1.0
#
# ÏêϸÃèÊö: ²éѯÏÉÃË - ¸ù¾ÝËùÊôÇø·þIDÌõ¼þ
#
#-------------------------------------------------------------------------------
#"""Version = 2025-04-09 16:00"""
#-------------------------------------------------------------------------------
 
import GMCommon
import GameWorld
import PlayerFamily
import ChPlayer
 
def OnExec(orderId, gmCmdDict):
    serverIDList = eval(gmCmdDict.get("serverIDList", '[]')) 
    queryCnt = GameWorld.ToIntDef(gmCmdDict.get("queryCnt", '0')  , 100)
    page = GameWorld.ToIntDef(gmCmdDict.get("page", '0')  , 1)
    queryCnt = min(queryCnt, 100)
    GameWorld.DebugLog("GMT_GetFamilyByServerID queryCnt=%s,page=%s, %s, %s" % (queryCnt, page, serverIDList, gmCmdDict))
    
    isCrossServer = GameWorld.IsCrossServer()
    familyMgr = GameWorld.GetFamilyManager()
    if isCrossServer:
        sortFamilyIDList, totalCnt = PlayerFamily.SortCrossFamily(serverIDList, queryCnt, page)
    else:
        sortFamilyIDList = PlayerFamily.GetSortFamilyIDList()
        totalCnt = len(sortFamilyIDList)
        startIndex = (page - 1) * queryCnt
        sortFamilyIDList = sortFamilyIDList[startIndex:startIndex + queryCnt], totalCnt
        
    retCnt = 0
    familyList = []
    for familyID in sortFamilyIDList:
        if isCrossServer:
            curFamily = familyID
            familyID = curFamily.GetID()
        else:
            curFamily = familyMgr.FindFamily(familyID)
        if not curFamily:
            continue
        familyList.append(GetQueryFamilyInfo(curFamily, isCrossServer))
        retCnt += 1
        if retCnt >= queryCnt:
            break
        
    #Ö´Ðгɹ¦
    retMsg = {"familyList":familyList, "totalCnt":totalCnt}
    GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, retMsg)        
    return
 
def GetQueryFamilyInfo(curFamily, isCrossServer):
    if curFamily == None:
        return {}
    
    onlineCnt = 0
    memberCnt = curFamily.GetCount()
    onlineMgr = ChPlayer.GetOnlinePlayerMgr()
    for index in range(memberCnt):
        curMember = curFamily.GetAt(index)
        playerID = curMember.GetPlayerID()
        if onlineMgr.IsOnline(playerID):
            onlineCnt += 1
            
    familyInfo = {
                  'ID':curFamily.GetID(),
                  'Name':curFamily.GetName(),
                  'FightPower':PlayerFamily.GetFamilyTotalFightPower(curFamily), # ×ÜÕ½Á¦
                  'LeaderID':curFamily.GetLeaderID(),
                  'LeaderName':curFamily.GetLeaderName(),
                  'LV':curFamily.GetLV(),
                  'MemberCnt':memberCnt,
                  'OnLineCnt':onlineCnt,
                  'ServerID':curFamily.GetServerID(),
                  }
    
    return familyInfo