hch
2019-04-18 68dd06e06c1a4a155884c31403da1155be6f10e8
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerFairyDomain
#
# @todo:çÎç¿ÏÉÓò
# @author xdh
# @date 2019-04-04
# @version 1.0
#
# ÏêϸÃèÊö: çÎç¿ÏÉÓò
#---------------------------------------------------------------------
#"""Version = 2019-04-04"""
#---------------------------------------------------------------------
 
import ChConfig
import ChPyNetSendPack
import NetPackCommon
import ShareDefine
import GameWorld
import GameLogic_CrossGrassland
import PlayerControl
import IpyGameDataPY
import PlayerActivity
import ItemControler
import EventShell
 
import copy
import random
import FBCommon
 
#0-ÆæÓö 1-±¦²Ø 2-Ïɲݠ3-ÑýÍõ 4-Áé²Ý
(
FDEventType0,
FDEventType1,
FDEventType_GrasslandXian,
FDEventType3,
FDEventType_GrasslandLing,
) = range(5)
 
(
FDEventState_No,  #²»¿É°Ý·Ã0
FDEventState_CanVisit,  #¿É°Ý·Ã1
FDEventState_Visiting,  #°Ý·ÃÖÐ2
FDEventState_Visited,  #ÒѰݷÃ3
) = range(4)
 
#1-µÈ¼¶ÆæÓö 2-¾³½çÆæÓö 3-Õ½Á¦ÆæÓö 4-ÆøÔËÆæÓö
AdventuresTypeList = (
AdventuresType1,
AdventuresType2,
AdventuresType3,
AdventuresType4,
) = range(1, 5)
 
 
def OnLogin(curPlayer):
    NotifyVisitFairyDomainInfo(curPlayer)
    NotifyFairyAdventuresInfo(curPlayer)
    return
 
 
#// A5 26 Ñ°·ÃÏÉÓò #tagCMVisitFairyDomain
#
#struct    tagCMVisitFairyDomain
#{
#    tagHead        Head;
#    BYTE        Type;    //0-¿ªÊ¼Ñ°·Ã 1-½áÊøÑ°·Ã
#};
def OnVisitFairyDomain(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    
    otherCntRateList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 2)
    maxEventCnt = max([info[1] for info in otherCntRateList]) + 1  #×î´ó¿É³öÏÖʼþ¸öÊý
    fairyDomainState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainState)  #ÊÇ·ñѰ·ÃÖР 0δѰ·Ã 1Ѱ·ÃÖР2ÈÎÎñ±ê¼Ç¿ÉѰ·Ã
    if clientData.Type == 1:  #½áÊøÑ°·Ã
        if fairyDomainState != 1:
            GameWorld.DebugLog("    Î´¿ªÊ¼Ñ°·ÃÏÉÓò£¬ ÎÞ·¨½áÊø")
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainState, 0)
        
        for i in xrange(maxEventCnt):
            fdEventID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventID % i)
            if fdEventID:
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventID % i, 0)
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState % fdEventID, 0)
                PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyAdventuresData % fdEventID, 0)
                
        NotifyVisitFairyDomainInfo(curPlayer)
        return
    
    dailyID = ShareDefine.DailyActionID_FairyDomain
    hasOpen = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_DailyActionState % dailyID)
    if fairyDomainState != 2 and not hasOpen:
        GameWorld.DebugLog("    Ñ°·ÃÏÉÓò»î¶¯Î´¿ªÆô£¡")
        return
    
    #ÊÇ·ñѰ·ÃÖÐ
    if fairyDomainState == 1:
        GameWorld.DebugLog("    ÕýÔÚѰ·ÃÏÉÓòÖУ¡ÇëÏÈÍ˳öѰ·Ã")
        return
    
    if fairyDomainState != 2 and not PlayerActivity.AddDailyActionFinishCnt(curPlayer, dailyID):
        GameWorld.DebugLog("    Ñ°·ÃÏÉÓò´ÎÊý²»×㣡")
        return
    
    #Ëæ»úʼþ ÖØÖÃʼþ״̬
    visitCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainVisitCnt)
    appointIpyDataList = IpyGameDataPY.GetIpyGameDataListNotLog('FairyDomainAppoint', visitCnt + 1)
    if appointIpyDataList:
        fdEventIDList = []
        for appointIpyData in appointIpyDataList:
            fdEventIDList.append(appointIpyData.GetEventID()) 
    else:
        fdEventTypeDict = {}
        #ÏÈËæ»úÆæÓöʼþ
        fortuitousEventRate = IpyGameDataPY.GetFuncCfg('ImmortalDomain')
        if GameWorld.CanHappen(fortuitousEventRate):
            fdEventTypeDict[FDEventType0] = 1
        
        otherCnt = GameWorld.GetResultByRandomList(otherCntRateList, 0)
        if otherCnt:
            otherEventRateList = copy.deepcopy(IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 3))
            unRepeatTypeList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 4)
            for _ in xrange(otherCnt):
                otherEventType = GameWorld.GetResultByRandomList(otherEventRateList, 0)
                if not otherEventType:
                    continue
                if otherEventType in unRepeatTypeList:
                    for index, info in enumerate(otherEventRateList):
                        if otherEventType == info[1]:
                            otherEventRateList = GameWorld.ResetRiseList(otherEventRateList, index)
                            break
                fdEventTypeDict[otherEventType] = fdEventTypeDict.get(otherEventType, 0) + 1
                    
        fdEventIDList = []
        for eventType, cnt in fdEventTypeDict.items():
            randomList = __RandomFDEventByType(curPlayer, eventType, cnt)
            if not randomList:
                continue                
            fdEventIDList += randomList
    
    #ÆæÓöʼþ Ëæ»úµµÎ»Êý¾Ý
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
    for fdEventID in fdEventIDList:
        if fdEventID not in AdventuresTypeList:
            continue
        ipyData = IpyGameDataPY.InterpolationSearch('FairyAdventures', 'OpenServerDay', openServerDay, {'EventID':fdEventID})
        if not ipyData:
            #GameWorld.ErrLog('Ѱ·ÃÏÉÓò, ÆæÓöʼþûÓÐËæ»ú³ö¶ÔÓ¦µµÎ» randomList=%s,openServerDay=%s' % (randomList, openServerDay))
            continue
        conditionList = ipyData.GetCondition()
        if not conditionList:
            fdEventIDList.remove(fdEventID)
            continue
        condition = random.choice(conditionList)
        index = conditionList.index(condition)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyAdventuresData % fdEventID, ipyData.GetID() * 100 + index)
    
    if not fdEventIDList:
        GameWorld.Log('Ѱ·ÃÏÉÓò, Ã»ÓÐËæ»ú³öʼþ£¡£¡')
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainVisitCnt, min(visitCnt + 1, ChConfig.Def_UpperLimit_DWord))
    #ÉèÖÃʼþ
    for i in xrange(maxEventCnt):
        fdEventID = fdEventIDList[i] if i < len(fdEventIDList) else 0
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventID % i, fdEventID)
        if fdEventID:
            PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState % fdEventID, FDEventState_CanVisit)
    #ÉèÖÃѰ·ÃÖÐ
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainState, 1)
    #ÉèÖóõʼÌåÁ¦
    initEnergy = IpyGameDataPY.GetFuncCfg('ImmortalDomainStrength')
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEnergy, initEnergy)
    GameWorld.DebugLog('Ѱ·ÃÏÉÓò  Ëæ»ú½á¹û fdEventIDList=%s, visitCnt=%s' % (fdEventIDList, visitCnt))
    #֪ͨ
    NotifyVisitFairyDomainInfo(curPlayer, fdEventIDList)
    NotifyFairyAdventuresInfo(curPlayer)
    return
 
 
def __RandomFDEventByType(curPlayer, eventType, cnt):
    ##¸ù¾ÝʼþÀàÐÍËæ»úʼþ
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomain', {'EventType':eventType}, True)
    if not ipyDataList:
        return []
    randomRateList = []
    rate = 0
    curAlchemyLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_AlchemyLV)
    curLV = curPlayer.GetLV()
    for ipyData in ipyDataList:
        needAlchemyLV = ipyData.GetNeedAlchemyLV()
        if curAlchemyLV < needAlchemyLV - 1:
            #µ¤Â¯µÈ¼¶²»×ã
            continue
        lvLimit = ipyData.GetNeedLV()
        if lvLimit and not (lvLimit[0] <= curLV <= lvLimit[1]):
            #µÈ¼¶·¶Î§²»Âú×ã
            continue
        
        rate += ipyData.GetWeight()
        randomRateList.append([rate, ipyData.GetID()])
    if not randomRateList:
        GameWorld.DebugLog('    çÎç¿ÏÉÓòË¢ÐÂ³Ø Ëæ»ú¿â»ñÈ¡´íÎ󠣡eventType=%s' % eventType, curPlayer.GetID())
        return []
    randomResultList = GameWorld.GetResultByRandomListEx(randomRateList, cnt, [])
        
    return randomResultList
 
 
def SetFairyDomainEventState(curPlayer, fdeventID, state):
    ## ÉèÖÃçÎç¿Ê¼þ״̬£¬ return ÊÇ·ñ³É¹¦
    if state not in [FDEventState_Visiting, FDEventState_Visited]:  # 1-δ°Ý·Ã  2-°Ý·ÃÖР3-ÒѰݷÃ
        GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬state=%s' % state)
        return
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventState % fdeventID)
    if not curState:
        #ûÓиÃʼþ
        return
    if curState == state:
        return True
    
    if state == FDEventState_Visiting:
        if curState != FDEventState_CanVisit:
            GameWorld.DebugLog('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬fdeventID=%s, state=%s, curState=%s' % (fdeventID, state, curState))
            return
        ipyData = IpyGameDataPY.GetIpyGameData('FairyDomain', fdeventID)
        if not ipyData:
            return
        costEnergy = ipyData.GetCostEnergy()
        curEnergy = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEnergy)
        if curEnergy < costEnergy:
            GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖÃ,ÌåÁ¦²»×㣡£¬fdeventID=%s, costEnergy=%s, curEnergy=%s' % (fdeventID, costEnergy, curEnergy))
            return
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEnergy, curEnergy - costEnergy)
        
        # ²ÝÔ°ÖØÖÃ
        if ipyData.GetEventType() in [FDEventType_GrasslandXian, FDEventType_GrasslandLing]:
            GameLogic_CrossGrassland.DoResetCrossGrassland(curPlayer, ipyData.GetEventType(), fdeventID)
            
    elif state == FDEventState_Visited:
        if curState != FDEventState_Visiting:
            GameWorld.Log('çÎç¿ÏÉÓòʼþ״̬ÉèÖôíÎó£¬fdeventID=%s, state=%s, curState=%s' % (fdeventID, state, curState))
            return
        EventShell.EventRespons_FairyDomain(curPlayer)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_FairyDomainEventState % fdeventID, state)
    NotifyVisitFairyDomainInfo(curPlayer, [fdeventID], 0)
    return True
 
 
def NotifyVisitFairyDomainInfo(curPlayer, fdEventList=[], isAll=1):
    if not fdEventList:
        syncFDEventList = []
        otherCntRateList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 2)
        maxEventCnt = max([info[1] for info in otherCntRateList]) + 1  #×î´ó¿É³öÏÖʼþ¸öÊý
        for i in xrange(maxEventCnt):
            fdEventID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventID % i)
            if fdEventID:
                syncFDEventList.append(fdEventID)
    else:
        syncFDEventList = fdEventList
 
    packData = ChPyNetSendPack.tagMCFairyDomainInfo()
    packData.IsAll = isAll
    packData.State = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainState)
    packData.Energy = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEnergy)
    packData.VisitCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainVisitCnt)
    packData.InfoList = []
    for fdeventID in syncFDEventList:
        fdeventData = ChPyNetSendPack.tagMCFairyDomainEvent()
        fdeventData.EventID = fdeventID
        fdeventData.EventState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventState % fdeventID)
        packData.InfoList.append(fdeventData)
    packData.Count = len(packData.InfoList)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
 
###=========================ÆæÓö===============================
def NotifyFairyAdventuresInfo(curPlayer):
    ##Í¨ÖªÆæÓöÐÅÏ¢
    visitCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainVisitCnt)
 
    packData = ChPyNetSendPack.tagMCFairyAdventuresInfo()
    packData.InfoList = []
    otherCntRateList = IpyGameDataPY.GetFuncEvalCfg('ImmortalDomain', 2)
    maxEventCnt = max([info[1] for info in otherCntRateList]) + 1  #×î´ó¿É³öÏÖʼþ¸öÊý
    for i in xrange(maxEventCnt):
        fdEventID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainEventID % i)
        if fdEventID not in AdventuresTypeList:
            continue
        adventuresdata = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyAdventuresData % fdEventID)
        if not adventuresdata:
            continue
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog('FairyAdventures', adventuresdata / 100)
        if not ipyData:
            continue
        conditionList = ipyData.GetCondition()
        index = adventuresdata % 100
        if IpyGameDataPY.GetIpyGameDataByCondition('FairyDomainAppoint', {'Cnt':visitCnt, 'EventID':fdEventID}, False, False):
            condition = 0  #¶¨ÖƵÄÌõ¼þΪ0
        else:
            condition = conditionList[index] if index < len(conditionList) else 0
        adventuresdata = ChPyNetSendPack.tagMCFairyAdventuresData()
        adventuresdata.Gear = index + 1
        adventuresdata.Condition = condition
        adventuresdata.EventID = fdEventID
        packData.InfoList.append(adventuresdata)
    if not packData.InfoList:
        return
    packData.Cnt = len(packData.InfoList)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
 
def GetFairyAdventuresAward(curPlayer, fdeventID, state):
    ##ÆæÓöÁìÈ¡½±Àø
    state = GameWorld.ToIntDef(state, 0)
    if state == FDEventState_Visiting:
        SetFairyDomainEventState(curPlayer, fdeventID, state)
    elif state == FDEventState_Visited:
        SetFairyDomainEventState(curPlayer, fdeventID, state)
        #¸ø½±Àø
        adventuresdata = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyAdventuresData % fdeventID)
        ipyData = IpyGameDataPY.GetIpyGameDataNotLog('FairyAdventures', adventuresdata / 100)
        if not ipyData:
            return
        conditionList = ipyData.GetCondition()
        index = adventuresdata % 100
        condition = conditionList[index] if index < len(conditionList) else 0
        if fdeventID != ipyData.GetEventID():
            GameWorld.Log('ÆæÓöÁìÈ¡½±Àø Ê¼þID´íÎó£¡')
            return
        giveItemList = GetFairyAppointAward(curPlayer, fdeventID)
        if not giveItemList:
            #1-µÈ¼¶ÆæÓö 2-¾³½çÆæÓö 3-Õ½Á¦ÆæÓö 4-ÆøÔËÆæÓö
            if fdeventID == AdventuresType1:
                curData = curPlayer.GetLV()
            elif fdeventID == AdventuresType2:
                curData = curPlayer.GetOfficialRank()
            elif fdeventID == AdventuresType3:
                curData = curPlayer.GetFightPower()
            elif fdeventID == AdventuresType4:
                curData = curPlayer.GetLuckValue()
            else:
                return
            if curData >= condition:
                gearAwardList = ipyData.GetGearAward()
                if not gearAwardList:
                    return
                itemRateList = gearAwardList[index] if index < len(gearAwardList) else gearAwardList[-1]
                giveItemList = [GameWorld.GetResultByWeightList(itemRateList)]
            else:
                giveItemList = [ipyData.GetBasicAward()]
                
        ItemControler.GivePlayerItemOrMail(curPlayer, giveItemList)
        msgDict = {FBCommon.Over_itemInfo:FBCommon.GetJsonItemList(giveItemList)}
        FBCommon.Notify_FB_Over(curPlayer, msgDict)
        GameWorld.DebugLog('çÎç¿ÆæÓöÁì½± msgDict=%s, fdeventID=%s' % (msgDict, fdeventID))
    return
 
 
def GetFairyAppointAward(curPlayer, fdEventID):
    ##»ñȡʼþ¶¨Öƽ±Àø, Ã»ÓеĸøÕý³£½±Àø
    visitCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_FairyDomainVisitCnt)
    ipyData = IpyGameDataPY.GetIpyGameDataByCondition('FairyDomainAppoint', {'Cnt':visitCnt, 'EventID':fdEventID}, False, False)
    if not ipyData:
        return
    return ipyData.GetAward()