hxp
2025-06-12 96c0ba31f74064e59c746921fcd1386cddf78d42
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package GM.Commands.OpenFunc
#
# @todo:¹¦ÄÜ¿ªÆô
# @author hxp
# @date 2017-12-21
# @version 1.0
#
# ÏêϸÃèÊö: ¹¦ÄÜ¿ªÆô
#
#-------------------------------------------------------------------------------
#"""Version = 2017-12-21 12:00"""
#-------------------------------------------------------------------------------
 
import GameWorld
import PlayerControl
import PlayerPrestigeSys
import PlayerMagicWeapon
import IpyGameDataPY
import GameFuncComm
import ChConfig
import ShareDefine
 
## GMÃüÁîÖ´ÐÐÈë¿Ú
#  @param curPlayer µ±Ç°Íæ¼Ò
#  @param list ²ÎÊýÁбí
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def OnExec(curPlayer, cmdList):
    GameWorld.DebugAnswer(curPlayer, "--------------")
    if not cmdList:
        GameWorld.DebugAnswer(curPlayer, "¿ªÆôËùÓй¦ÄÜ: OpenFunc 1")
        GameWorld.DebugAnswer(curPlayer, "¿ªÆôÖ¸¶¨¹¦ÄÜ: OpenFunc 1 ¹¦ÄÜID")
        GameWorld.DebugAnswer(curPlayer, "¹Ø±ÕËùÓй¦ÄÜ: OpenFunc 0")
        GameWorld.DebugAnswer(curPlayer, "¹Ø±ÕÖ¸¶¨¹¦ÄÜ: OpenFunc 0 ¹¦ÄÜID")
    else:
        state = cmdList[0]
        if not state:
            closeFuncID = cmdList[1] if len(cmdList) > 1 else 0
            DoGMCloseFunc(curPlayer, closeFuncID)
        else:
            openFuncID = cmdList[1] if len(cmdList) > 1 else 0
            DoGMOpenFunc(curPlayer, openFuncID)
            
    PrintFuncOpenState(curPlayer)
    return
 
def PrintFuncOpenState(curPlayer):
    openFuncIDList = []
    unOpenFuncIDList = []
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    funcOpenLVCount = ipyDataMgr.GetFuncOpenLVCount()
    for i in xrange(funcOpenLVCount):
        ipyData = ipyDataMgr.GetFuncOpenLVByIndex(i)
        funcID = ipyData.GetFuncId()
        isOpen = GameWorld.GetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_GameFuncFirstTouch, funcID, True)
        if isOpen:
            openFuncIDList.append(funcID)
        else:
            unOpenFuncIDList.append(funcID)
            
    GameWorld.DebugAnswer(curPlayer, "ÒÑ¿ªÆôµÄ¹¦ÄÜÊý: %s/%s" % (len(openFuncIDList), funcOpenLVCount))
    if len(openFuncIDList) < len(unOpenFuncIDList):
        for i in range((funcOpenLVCount/10) + 1):
            openList = openFuncIDList[i*10:(i+1)*10]
            if not openList:
                break
            GameWorld.DebugAnswer(curPlayer, "%s" % openList)
            
    GameWorld.DebugAnswer(curPlayer, "먦ÆôµÄ¹¦ÄÜ: %s/%s" % (len(unOpenFuncIDList), funcOpenLVCount))
    if len(unOpenFuncIDList) < len(openFuncIDList):
        for i in range((funcOpenLVCount/10) + 1):
            unOpenList = unOpenFuncIDList[i*10:(i+1)*10]
            if not unOpenList:
                break
            GameWorld.DebugAnswer(curPlayer, "%s" % unOpenList)
    return
 
def DoGMOpenFunc(curPlayer, openFuncID=0):
    openFuncIDList = []
    if openFuncID:
        if GameFuncComm.GetFuncCanUse(curPlayer, openFuncID):
            GameWorld.DebugLog("¹¦ÄÜÒÑ¿ªÆô£¬²»ÐèÒªÖØ¸´¼¤»î!openFuncID=%s" % openFuncID, curPlayer.GetPlayerID())
            return
        openFuncIDList = [openFuncID]
        
    if openFuncIDList:
        needLV, needMagicWeaponIDList, needRealmLV, needMissionIDList = __GetOpenFuncLimit(openFuncIDList)
        if needMagicWeaponIDList:
            openFuncIDList.append(ShareDefine.GameFuncID_MagicWeapon)
        if needRealmLV:
            openFuncIDList.append(ShareDefine.GameFuncID_Official)
    needLV, needMagicWeaponIDList, needRealmLV, needMissionIDList = __GetOpenFuncLimit(openFuncIDList)
    
    GameWorld.DebugLog("GM´¦ÀíµÈ¼¶¿ªÆô¹¦ÄÜ: openFuncID=%s,openFuncIDList=%s,needLV=%s" % (openFuncID, openFuncIDList, needLV), curPlayer.GetPlayerID())
    
    # ÓÅÏÈ´¦ÀíÉý¼¶        
    if needLV:
        preLV = needLV - 1
        curPlayer.SetLV(preLV)
        PlayerControl.SetPlayerTotalExp(curPlayer, PlayerControl.GetTotalExpByPlayerLv(preLV))
        PlayerControl.PlayerControl(curPlayer).PlayerLvUp()
            
    GameWorld.DebugLog("GM´¦Àí·¨±¦¿ªÆô¹¦ÄÜ: needMagicWeaponIDList=%s" % needMagicWeaponIDList, curPlayer.GetPlayerID())
    for mwIDKey in needMagicWeaponIDList:
        mwID, mwLV = mwIDKey/100, mwIDKey%100
        for lv in xrange(mwLV+1):
            PlayerMagicWeapon.DoActiveMW(curPlayer, mwID, lv)
        
        
    GameWorld.DebugLog("GM´¦Àí¾³½ç¿ªÆô¹¦ÄÜ: needRealmLV=%s" % needRealmLV, curPlayer.GetPlayerID())
    if needRealmLV:
        curPlayer.SetOfficialRank(max(1, needRealmLV - 1))
        PlayerPrestigeSys.DoRealmLVUpLogic(curPlayer)
        
    GameWorld.DebugLog("GM´¦ÀíÈÎÎñ¿ªÆô¹¦ÄÜ: needMissionIDList=%s" % needMissionIDList, curPlayer.GetPlayerID())
    #×îºóÇ¿ÖÆ´¥·¢Ò»´Î
    #if needMissionIDList:
    GameFuncComm.DoFuncOpenLogic(curPlayer, needMissionIDList)
    return
 
def __GetOpenFuncLimit(openFuncIDList):
    maxLV = IpyGameDataPY.GetFuncCfg("PlayerMaxLV")
    needLV = 0
    needRealmLV = 0
    needMissionIDList = []
    needMagicWeaponIDList = []
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    funcOpenLVCount = ipyDataMgr.GetFuncOpenLVCount()
    for i in xrange(funcOpenLVCount):
        ipyData = ipyDataMgr.GetFuncOpenLVByIndex(i)
        funcID = ipyData.GetFuncId()
        if openFuncIDList and funcID not in openFuncIDList:
            continue
        
        limitLV = ipyData.GetLimitLV()
        if limitLV and limitLV <= maxLV and needLV < limitLV:
            needLV = limitLV
            
        limitMagicWeaponID = ipyData.GetLimitMagicWeapon()
        if limitMagicWeaponID and limitMagicWeaponID not in needMagicWeaponIDList:
            needMagicWeaponIDList.append(limitMagicWeaponID)
            
        limitRealmLV = ipyData.GetLimiRealmLV()
        if limitRealmLV and needRealmLV < limitRealmLV:
            needRealmLV = limitRealmLV
            
        limitMissionID = ipyData.GetLimitMissionID()
        if limitMissionID and limitMissionID not in needMissionIDList:
            needMissionIDList.append(limitMissionID)
    return needLV, needMagicWeaponIDList, needRealmLV, needMissionIDList
 
def DoGMCloseFunc(curPlayer, closeFuncID):
    ## GM¹Ø±Õ¹¦ÄÜ
    if not closeFuncID:
        curPlayer.SetLV(1)
        curPlayer.SetOfficialRank(1)
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyDataMgr.GetTreasureCount()):
            ipyData = ipyDataMgr.GetTreasureByIndex(i)
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponLV % ipyData.GetID(), 0)
            
        for keyNum in xrange(8):
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_GameFuncFirstTouch % keyNum, 0)
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_GameFuncAwardState % keyNum, 0)
            
        needLV, needMagicWeaponIDList, needRealmLV, needMissionIDList = __GetOpenFuncLimit([])
        for missionID in needMissionIDList:
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_MissionFinish % missionID, 0)
        
        GameFuncComm.Sync_FuncOpenState(curPlayer, isSyncUnOpen=True)
        GameWorld.DebugAnswer(curPlayer, "¹Ø±ÕËùÓй¦ÄÜ!")
        return
    
    if not GameFuncComm.GetFuncCanUse(curPlayer, closeFuncID):
        GameWorld.DebugLog("¹¦ÄÜÒѹرգ¬²»ÐèÒªÖØ¸´¹Ø±Õ! closeFuncID=%s" % closeFuncID, curPlayer.GetPlayerID())
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("FuncOpenLV", closeFuncID)
    if not ipyData:
        return
    
    limitLV = ipyData.GetLimitLV()
    if limitLV and curPlayer.GetLV() >= limitLV:
        curPlayer.SetLV(max(1, limitLV - 1))
        PlayerControl.SetPlayerTotalExp(curPlayer, 0)
        
    limitRealmLV = ipyData.GetLimiRealmLV()
    if limitRealmLV and curPlayer.GetOfficialRank() >= limitRealmLV:
        curPlayer.SetOfficialRank(max(1, limitRealmLV - 1))
        
    limitMagicWeaponID = ipyData.GetLimitMagicWeapon()
    if limitMagicWeaponID:
        mwID = limitMagicWeaponID / 100
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_MagicWeaponLV % mwID, 0)
        
    limitMissionID = ipyData.GetLimitMissionID()
    if limitMissionID:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_MissionFinish % limitMissionID, 0)
            
    GameWorld.SetDictValueByBit(curPlayer, ChConfig.Def_Player_Dict_GameFuncFirstTouch, closeFuncID, 0)
    GameFuncComm.Sync_FuncOpenState(curPlayer, isSyncUnOpen=True)
    GameWorld.DebugAnswer(curPlayer, "¹Ø±Õ¹¦ÄÜ: %s" % closeFuncID)
    return