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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GM.Commands.GMT_Worship
#
# @todo:ºǫ́¹ÜÀíĤ°Ý
# @author hxp
# @date 2024-07-02
# @version 1.0
#
# ÏêϸÃèÊö: ºǫ́¹ÜÀíĤ°Ý
#
#-------------------------------------------------------------------------------
#"""Version = 2024-07-02 16:30"""
#-------------------------------------------------------------------------------
 
import GMCommon
import ChConfig
import GameWorship
import PyDataManager
import PlayerViewCache
import IpyGameDataPY
import ShareDefine
import GameWorld
 
 
## Ö´ÐÐÂß¼­
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param gmCmdDict: ÃüÁî×Öµä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnExec(orderId, gmCmdDict):
    GameWorld.Log("GMT_Worship %s" % gmCmdDict)
    queryType = gmCmdDict.get(GMCommon.Def_GMKey_QueryType, '')
    playerFind = gmCmdDict.get(GMCommon.Def_GMKey_PlayerFind, '')
    worshipType = GameWorld.ToIntDef(gmCmdDict.get('worshipType', ''), 0)
    worshipValue = GameWorld.ToIntDef(gmCmdDict.get('worshipValue', ''), 0)
    zoneID = GameWorld.ToIntDef(gmCmdDict.get('zoneID', ''), 0)
    days = GameWorld.ToIntDef(gmCmdDict.get('days', ''), 0)
    
    opType = gmCmdDict.get('opType', '')
    
    if not opType or not worshipType:
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)
        return
    
    if opType == "view":
        worshipList = __GetServerWorshipList()
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, {"WorshipList":worshipList})
        return
    
    if worshipType in ShareDefine.Def_WorshipTypeCross:
        if not GameWorld.IsCrossServer():
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr, "player run in cross server.")
            return
    else:
        if GameWorld.IsCrossServer():
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr, "do not run in cross server.")
            return
        
    ipyData = IpyGameDataPY.GetIpyGameData("Worship", worshipType, worshipValue)
    if not ipyData:
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr, "worshipType value ipyData is not exist.")
        return
    
    playerManager = GameWorld.GetPlayerManager()
    
    if queryType == "playerID":
        tagPlayerID = GameWorld.ToIntDef(playerFind, 0)
    else:
        if queryType == GMCommon.Def_GMKey_PlayerAccID:
            queryType = ChConfig.queryType_sqtPlayerByAccID
            tagPlayer = playerManager.FindPlayerByAccID(str(playerFind))
            
        elif queryType == GMCommon.Def_GMKey_PlayerName:
            queryType = ChConfig.queryType_sqtPlayerByName
            tagPlayer = playerManager.FindPlayerByName(str(playerFind))
            
        else:
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)
            return
        
        if not tagPlayer:
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_PlayerOfLine)
            return
        tagPlayerID = tagPlayer.GetPlayerID()
        
    cacheDict = PlayerViewCache.GetCachePropDataDict(PlayerViewCache.FindViewCache(tagPlayerID))
    if not cacheDict:
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_NoTag, "can not found player view cache")
        return {}
    Name = cacheDict.get("Name", "")
    AccID = cacheDict.get("AccID", "")
    
    if opType == "add":
        if not GameWorship.AddWorshipPlayer(tagPlayerID, worshipType, worshipValue, days, zoneID):
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Unknow, "add error.")
            return
        
    elif opType == "del":
        GameWorship.DelWorshipPlayer(worshipType, worshipValue, tagPlayerID)
        
    else:
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_ParamErr)
        return
    
    worshipList = __GetServerWorshipList()
    GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, {"AccID":AccID, "Name":Name, "PlayerID":tagPlayerID, "WorshipList":worshipList})
    return
 
def __GetServerWorshipList():
    worshipList = []
    playerRecMgr = PyDataManager.GetDBPlayerRecDataManager()
    recDict = playerRecMgr.GetPlayerRecDataDict(ShareDefine.Def_PlayerRecType_WorshipPlayer)
    for recDataList in recDict.values():
        for recData in recDataList:
            playerInfo = GameWorship.GetModelShowInfo(recData)
            worshipList.append({"PlayerID":recData.GetPlayerID(),
                                "AddTime":GameWorld.ChangeTimeNumToStr(recData.GetTime()),
                                "WorshipType":GameWorship.GetWorshipType(recData),
                                "WorshipValue":GameWorship.GetWorshipValue(recData),
                                "Days":GameWorship.GetWorshipDays(recData),
                                "ZoneID":GameWorship.GetWorshipZoneID(recData),
                                "AccID":playerInfo.get("AccID", ""),
                                "Name":playerInfo.get("Name", ""),
                                })
    return worshipList