hxp
2025-06-03 4cdd576855c6e22d986ece4b18f7c80d82cefe38
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerGatherTheSoul
#
# @todo:¾Û»êÐÂ
# @author hxp
# @date 2024-07-12
# @version 1.0
#
# ÏêϸÃèÊö: ¾Û»êÐÂ
#
#-------------------------------------------------------------------------------
#"""Version = 2024-07-12 16:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import ShareDefine
import IpyGameDataPY
import ItemControler
import ChPyNetSendPack
import PassiveBuffEffMng
import PlayerSuccess
import PlayerControl
import NetPackCommon
import ChConfig
 
 
def OnPlayerLogin(curPlayer):
    if Sync_SoulInfo(curPlayer):
        Sync_SoulHoleInfo(curPlayer)
    return
 
#// B2 25 Ð¾ۻê²Ù×÷ #tagCMGatherTheSoulOP
#
#struct    tagCMGatherTheSoulOP
#{
#    tagHead        Head;
#    BYTE        OpType;    // 0-¼¤»îÉý¼¶; 1-´©´÷Ìæ»»; 2-жÏÂ
#    DWORD        SoulID;    // ¾Û»êID£»µ±²Ù×÷Éý¼¶Ê±£¬Èç¹ûΪ0´ú±íÒ»¼üÉý¼¶ËùÓпÉÉý¼¶µÄ
#};
def OnGatherTheSoulOP(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    OpType = clientData.OpType
    soulID = clientData.SoulID
    if OpType == 0:
        OnGatherTheSoulUp(curPlayer, soulID)
    elif OpType == 1:
        OnGatherTheSoulPuton(curPlayer, soulID)
    elif OpType == 2:
        OnGatherTheSoulTakeoff(curPlayer, soulID)
    elif OpType == 3:
        OnGatherTheSoulReset(curPlayer, soulID)
    return
 
def OnGatherTheSoulUp(curPlayer, upSoulID):
    ## ¾Û»ê¼¤»îÉý¼¶
    # @param upSoulID: Ã»ÓÐÖ¸¶¨IDʱÔòÅúÁ¿´¦ÀíÉý¼¶
    if not upSoulID:
        soulIpyDataList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetGatherTheSoulCount()):
            soulIpyDataList.append(ipyDataMgr.GetGatherTheSoulByIndex(index))
    else:
        soulIpyDataList = [IpyGameDataPY.GetIpyGameData("GatherTheSoul", upSoulID)]
        
    holeSoulChange = False
    updSoulIDList = []
    playerID = curPlayer.GetPlayerID()
    for ipyData in soulIpyDataList:
        if not ipyData:
            continue
        soulID = ipyData.GetSoulID()
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        nextLV = soulLV + 1
        nextLVIpyData = IpyGameDataPY.GetIpyGameDataNotLog("GatherTheSoulLV", soulID, nextLV)
        if not nextLVIpyData:
            if soulLV:
                GameWorld.DebugLog("¾Û»êÒÑÂú¼¶! soulID=%s,soulLV=%s" % (soulID, soulLV), playerID)
            continue
        
        pieceItemID = ipyData.GetPieceItemID()
        holeNum = ipyData.GetHoleNum()
        needPieceCount = nextLVIpyData.GetNeedPiece()
        needSoulValue = nextLVIpyData.GetNeedSoulValue()
        playerPieceCount = ItemControler.GetItemCountByID(curPlayer, pieceItemID)
        if playerPieceCount < needPieceCount:
            GameWorld.DebugLog("¾Û»êË鯬²»×㣬ÎÞ·¨Éý¼¶! soulID=%s,nextLV=%s,pieceItemID=%s,playerPieceCount=%s < %s" 
                               % (soulID, nextLV, pieceItemID, playerPieceCount, needPieceCount), playerID)
            continue
        
        if needSoulValue and not PlayerControl.HaveMoney(curPlayer, ShareDefine.TYPE_Price_GatherSoul, needSoulValue, False):
            GameWorld.DebugLog("¾Û»ê¾«»ª²»×㣬ÎÞ·¨Éý¼¶! soulID=%s,nextLV=%s,needSoulValue=%s" % (soulID, nextLV, needSoulValue), playerID)
            continue
        
        GameWorld.DebugLog("¾Û»êÉý¼¶: soulID=%s,nextLV=%s,pieceItemID=%s" % (soulID, nextLV, pieceItemID), playerID)
        ItemControler.SetItemCountByID(curPlayer, pieceItemID, playerPieceCount - needPieceCount)
        if needSoulValue:
            PlayerControl.PayMoney(curPlayer, ShareDefine.TYPE_Price_GatherSoul, needSoulValue, "GatherTheSoulUp", {"soulID":soulID, "nextLV":nextLV})
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GatherTheSoulLV % soulID, nextLV)
        
        # ¼¤»î¶îÍâ´¦Àí
        if nextLV == 1:
            pass
            
        updSoulIDList.append(soulID)
        if soulID == curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum):
            holeSoulChange = True
            
    if not updSoulIDList:
        GameWorld.DebugLog("ûÓпÉÉý¼¶µÄ¾Û»ê!", playerID)
        return
    
    # ³É¾Í
    colorCountDict = {}
    totalSoulLV = 0
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetGatherTheSoulCount()):
        ipyData = ipyDataMgr.GetGatherTheSoulByIndex(index)
        soulID = ipyData.GetSoulID()
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        if not soulLV:
            continue
        totalSoulLV += soulLV
        soulColor = ipyData.GetSoulColor()
        colorCountDict[soulColor] = colorCountDict.get(soulColor, 0) + 1
        
    for soulColor, soulCount in colorCountDict.items():
        PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GatherTheSoulColor, soulCount, [soulColor])
    PlayerSuccess.UptateSuccessProgress(curPlayer, ShareDefine.SuccType_GatherTheSoulLV, totalSoulLV)
    
    Sync_SoulInfo(curPlayer, updSoulIDList)
    RefreshGatherTheSoulAttr(curPlayer, holeSoulChange)
    return
 
def OnGatherTheSoulPuton(curPlayer, soulID):
    ## ¾Û»ê´©´÷Ìæ»»
    playerID = curPlayer.GetPlayerID()
    soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
    if not soulLV:
        GameWorld.DebugLog("δ¼¤»îÎÞ·¨´©´÷! soulID=%s" % soulID, playerID)
        return
    ipyData = IpyGameDataPY.GetIpyGameData("GatherTheSoul", soulID)
    if not ipyData:
        return
    holeNum = ipyData.GetHoleNum()
    holeSoulID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum)
    GameWorld.DebugLog("¾Û»ê´©´÷Ìæ»»! soulID=%s,holeNum=%s,holeSoulID=%s" % (soulID, holeNum, holeSoulID), playerID)
    if holeSoulID == soulID:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum, soulID)
    Sync_SoulHoleInfo(curPlayer)
    RefreshGatherTheSoulAttr(curPlayer, True)
    return
 
def OnGatherTheSoulTakeoff(curPlayer, soulID):
    ## ¾Û»êжÏÂ
    playerID = curPlayer.GetPlayerID()
    ipyData = IpyGameDataPY.GetIpyGameData("GatherTheSoul", soulID)
    if not ipyData:
        return
    holeNum = ipyData.GetHoleNum()
    holeSoulID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum)
    if holeSoulID != soulID:
        GameWorld.DebugLog("¸Ã¿×ûÓд©´÷¸Ã¾Û»ê£¬ÎÞ·¨Ð¶ÏÂ! soulID=%s,holeNum=%s,holeSoulID=%s" % (soulID, holeNum, holeSoulID), playerID)
        return
    GameWorld.DebugLog("¾Û»êжÏÂ! soulID=%s,holeNum=%s" % (soulID, holeNum), playerID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum, 0)
    Sync_SoulHoleInfo(curPlayer)
    RefreshGatherTheSoulAttr(curPlayer, True)
    return
 
def OnGatherTheSoulReset(curPlayer, soulID):
    ## ¾Û»êÖØÖÃ
    ipyData = IpyGameDataPY.GetIpyGameData("GatherTheSoul", soulID)
    if not ipyData:
        return
    holeNum = ipyData.GetHoleNum()
    pieceItemID = ipyData.GetPieceItemID()
    if not pieceItemID:
        return
    soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
    if soulLV <= 1:
        GameWorld.DebugLog("¸Ã¾Û»êµÈ¼¶²»ÐèÒªÖØÖÃ! soulID=%s,soulLV=%s" % (soulID, soulLV))
        return
    
    costMoneyType, costMoneyValue = 0, 0
    costMoneyInfo = IpyGameDataPY.GetFuncEvalCfg("GatherTheSoulHole", 2)
    if costMoneyInfo and len(costMoneyInfo) == 2:
        costMoneyType, costMoneyValue = costMoneyInfo
        if not PlayerControl.HaveMoney(curPlayer, costMoneyType, costMoneyValue):
            return
        
    resetLV = soulLV
    pieceTotal = 0
    soulValueTotal = 0
    for sLV in range(2, 1 + soulLV)[::-1]:
        resetIpyData = IpyGameDataPY.GetIpyGameData("GatherTheSoulLV", soulID, sLV)
        if not resetIpyData:
            continue
        resetLV = sLV
        soulValue = resetIpyData.GetNeedSoulValue()
        if not soulValue:
            # ÖØÖõ½²»ÐèÒª¹«¹²²ÄÁϵĵȼ¶
            break
        pieceTotal += resetIpyData.GetNeedPiece()
        soulValueTotal += soulValue
        
    if resetLV >= soulLV:
        return
    
    GameWorld.DebugLog("ÖØÖþۻê: soulID=%s,soulLV=%s,resetLV=%s,pieceTotal=%s,soulValueTotal=%s" % (soulID, soulLV, resetLV, pieceTotal, soulValueTotal))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_GatherTheSoulLV % soulID, resetLV)
    if costMoneyType and costMoneyValue:
        PlayerControl.PayMoney(curPlayer, costMoneyType, costMoneyValue, "GatherTheSoulReset", {"soulID":soulID})
    ItemControler.GivePlayerItem(curPlayer, pieceItemID, pieceTotal, False, event=["GatherTheSoulReset", False, {"soulID":soulID}])
    PlayerControl.GiveMoney(curPlayer, ShareDefine.TYPE_Price_GatherSoul, soulValueTotal, "GatherTheSoulReset", {"soulID":soulID})
    
    holeSoulChange = (soulID == curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum))
    Sync_SoulInfo(curPlayer, [soulID])
    RefreshGatherTheSoulAttr(curPlayer, holeSoulChange)
    return
 
def GetGatherTheSoulTotalLV(curPlayer):
    totalSoulLV = 0
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetGatherTheSoulCount()):
        ipyData = ipyDataMgr.GetGatherTheSoulByIndex(index)
        soulID = ipyData.GetSoulID()
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        if not soulLV:
            continue
        totalSoulLV += soulLV
    return totalSoulLV
 
def GetHoleSoulColorCount(curPlayer, soulColor, isDownward):
    ## »ñÈ¡ÏâǶ¾Û»êÆ·ÖʸöÊý
    colorCount = 0
    for holeNum in range(1, 1 + IpyGameDataPY.GetFuncCfg("GatherTheSoulHole", 1)):
        soulID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum)
        if not soulID:
            continue
        ipyData = IpyGameDataPY.GetIpyGameData("GatherTheSoul", soulID)
        if not ipyData:
            continue
        # ÏòϼæÈÝÆ·ÖÊ
        if isDownward:
            if ipyData.GetSoulColor() < soulColor:
                continue
        else:
            if ipyData.GetSoulColor() != soulColor:
                continue
        colorCount += 1
        
    return colorCount
    
def RefreshGatherTheSoulSkill(curPlayer):
    ## Ë¢Ð´©´÷µÄ¾Û»ê¼¼ÄÜÐÅÏ¢
    
    playerID = curPlayer.GetPlayerID()
    
    soulSkillLVDict = {}
    for holeNum in range(1, 1 + IpyGameDataPY.GetFuncCfg("GatherTheSoulHole", 1)):
        soulID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum)
        if not soulID:
            continue
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        ipyData = IpyGameDataPY.GetIpyGameData("GatherTheSoul", soulID)
        if not ipyData:
            continue
        skillTypeID = ipyData.GetSoulSkillTypeID()
        if not skillTypeID:
            continue
        skillLVList = ipyData.GetSoulSkillLVList()
        for skillLV, needSoulLV in enumerate(skillLVList, 1):
            if soulLV >= needSoulLV:
                soulSkillLVDict[skillTypeID] = skillLV
            else:
                break
            
    #GameWorld.DebugLog("ˢоۻ꼼ÄÜ: %s" % soulSkillLVDict, playerID)
    skillChange = False  
    playerCtl = PlayerControl.PlayerControl(curPlayer)  
    skillManager = curPlayer.GetSkillManager()
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetGatherTheSoulCount()):
        ipyData = ipyDataMgr.GetGatherTheSoulByIndex(index)
        holeNum = ipyData.GetHoleNum()
        skillTypeID = ipyData.GetSoulSkillTypeID()
        if not skillTypeID:
            continue
        
        delSkill = None
        if skillTypeID in soulSkillLVDict:
            curSkill = skillManager.FindSkillBySkillTypeID(skillTypeID)
            if curSkill:
                if curSkill.GetSkillLV() != soulSkillLVDict[skillTypeID]:
                    delSkill = curSkill
                else:
                    # ¼¼ÄÜÏàͬ²»Óô¦Àí
                    continue
        else:
            delSkill = skillManager.FindSkillBySkillTypeID(skillTypeID)
                            
        # ÏÈɾºó¼Ó
        if delSkill:
            skillChange = True
            skillID = delSkill.GetSkillID()
            GameWorld.DebugLog("ɾ³ý¾Û»ê¼¼ÄÜ: holeNum=%s,skillID=%s" % (holeNum, skillID), playerID)
            skillManager.DeleteSkillBySkillID(skillID)
            playerCtl.RefreshSkillFightPowerByDel(skillID, False)
            
        if skillTypeID in soulSkillLVDict:
            skillLV = soulSkillLVDict[skillTypeID]
            skillData = GameWorld.GetGameData().FindSkillByType(skillTypeID, skillLV)
            if not skillData:
                continue
            skillChange = True
            skillID = skillData.GetSkillID()
            GameWorld.DebugLog("¸üоۻ꼼ÄÜ: holeNum=%s,skillID=%s" % (holeNum, skillID), playerID)
            skillManager.LearnSkillByID(skillID)
            playerCtl.RefreshSkillFightPowerEx(skillID, 0, False)
            
    if skillChange:
        PassiveBuffEffMng.GetPassiveEffManager().RegistPassiveEff(curPlayer)
    return
 
def RefreshGatherTheSoulAttr(curPlayer, refreshSkill=False):
    if refreshSkill:
        RefreshGatherTheSoulSkill(curPlayer)
    CalcSoulAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
def CalcSoulAttr(curPlayer):
    
    allAttrListSoul = [{} for _ in range(4)] # ¼¤»îµÄ¶¼ËãÊôÐÔ
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in range(ipyDataMgr.GetGatherTheSoulCount()):
        ipyData = ipyDataMgr.GetGatherTheSoulByIndex(index)
        soulID = ipyData.GetSoulID()
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        if not soulLV:
            continue
        lvIpyData = IpyGameDataPY.GetIpyGameData("GatherTheSoulLV", soulID, soulLV)
        if not lvIpyData:
            continue
        LVAttrTypeList = lvIpyData.GetLVAttrTypeList()
        LVAttrValueList = lvIpyData.GetLVAttrValueList()
        for i, attrID in enumerate(LVAttrTypeList):
            attrValue = LVAttrValueList[i]
            PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrListSoul)
            
    #GameWorld.DebugLog("¾Û»êÐÂÊôÐÔ: %s" % allAttrListSoul)
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_GatherTheSoul, allAttrListSoul)
    return
 
def Sync_SoulInfo(curPlayer, soulIDList=None):
    if not soulIDList:
        isForce = False
        soulIDList = []
        ipyDataMgr = IpyGameDataPY.IPY_Data()
        for index in range(ipyDataMgr.GetGatherTheSoulCount()):
            ipyData = ipyDataMgr.GetGatherTheSoulByIndex(index)
            soulIDList.append(ipyData.GetSoulID())
    else:
        isForce = True
        
    soulList = []
    for soulID in soulIDList:
        soulLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulLV % soulID)
        if not soulLV and not isForce:
            continue
        soulInfo = ChPyNetSendPack.tagMCGatherTheSoul()
        soulInfo.SoulID = soulID
        soulInfo.LV = soulLV
        soulList.append(soulInfo)
        
    if not soulList:
        return
    
    clientPack = ChPyNetSendPack.tagMCGatherTheSoulInfo()
    clientPack.SoulList = soulList
    clientPack.Count = len(clientPack.SoulList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return True
 
def Sync_SoulHoleInfo(curPlayer):
    holeSoulList = []
    for holeNum in range(1, 1 + IpyGameDataPY.GetFuncCfg("GatherTheSoulHole", 1)):
        soulID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_GatherTheSoulHoleID % holeNum)
        holeSoulList.append(soulID)
    clientPack = ChPyNetSendPack.tagMCGatherTheSoulHoleInfo()
    clientPack.HoleSoulList = holeSoulList
    clientPack.Count = len(clientPack.HoleSoulList)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return