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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerNewFairyCeremony
#
# @todo:ÐÂÏɽçÊ¢µä
# @author xdh
# @date 2018-07-23 16:50
# @version 1.0
#
#
# ÏêϸÃèÊö: ÐÂÏɽçÊ¢µä
#
#---------------------------------------------------------------------
"""Version = 2018-07-23 16:50"""
#---------------------------------------------------------------------
import IPY_GameWorld
import GameWorld
import ChConfig
import IpyGameDataPY
import PlayerControl
import ItemControler
import ChPyNetSendPack
import NetPackCommon
import ShareDefine
import PyGameData
import ItemCommon
import PlayerBillboard
 
(
Def_FC_Recharge, #³äÖµ´óÀñ
Def_FC_Fireworks, #ÑÌ»¨
Def_FC_Party, #È«ÃñÀ´àË
Def_FC_RechargeRank, #¾ø°æ½µÁÙ
) = range(1, 5)
 
 
def OnLogin(curPlayer):
    isReset = __CheckPlayerNewFairyCeremonyAction(curPlayer)
    if not isReset:
        actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_NewFairyCeremony, {})
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if actCostRebateInfo.get(ShareDefine.ActKey_State):
            SyncFCRechargeInfo(curPlayer)
            SyncFCPartyInfo(curPlayer)
    return
 
def RefreshOperationAction_NewFairyCeremony():
    playerManager = GameWorld.GetPlayerManager()
    for i in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(i)
        if not GameWorld.IsNormalPlayer(curPlayer):
            continue
        __CheckPlayerNewFairyCeremonyAction(curPlayer)
    return
 
 
def __CheckPlayerNewFairyCeremonyAction(curPlayer):
    ## ¼ì²éÍæ¼ÒÐÂÏɽçÊ¢µä»î¶¯Êý¾ÝÐÅÏ¢
    playerID = curPlayer.GetPlayerID()
    
    actNewFairyCeremonyInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_NewFairyCeremony, {})
    NewFairyCeremonyID = actNewFairyCeremonyInfo.get(ShareDefine.ActKey_ID, 0)
    state = actNewFairyCeremonyInfo.get(ShareDefine.ActKey_State, 0)
    
    playerNewFairyCeremonyID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFairyCeremonyID) # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if NewFairyCeremonyID == playerNewFairyCeremonyID:
        #GameWorld.DebugLog("ÐÂÏɽçÊ¢µä»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())
        return
    actWorldLV = actNewFairyCeremonyInfo.get(ShareDefine.ActKey_WorldLV, 0)
    playerFCWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCActionWorldLV)
    GameWorld.DebugLog("ÐÂÏɽçÊ¢µäÖØÖÃ! NewFairyCeremonyID=%s,playerCostRebateID=%s,state=%s,ActWorldLV=%s,playerFCWorldLV=%s" 
                       % (NewFairyCeremonyID, playerNewFairyCeremonyID, state, actWorldLV, playerFCWorldLV), playerID)
    
    # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
    __SendNewFairyCeremonyMail(curPlayer, playerFCWorldLV)
    
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFairyCeremonyID, NewFairyCeremonyID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCActionWorldLV, actWorldLV)
    #ÖØÖóäÖµ´óÀñ¼Ç¼
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCRechargeState, 0)
    SyncFCRechargeInfo(curPlayer)
    #ÖØÖÃÈ«ÃñÀ´àË
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyCurPoint, 0)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyAwardRecord, 0)
    for actid in ChConfig.PeoplePartyActIDList:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyCurCnt % actid, 0)
    SyncFCPartyInfo(curPlayer)
    #ÖØÖÃÏû·Ñ
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCCostGold, 0)
    return True
 
def __SendNewFairyCeremonyMail(curPlayer, playerFCWorldLV):
    # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
    #³äÖµ´óÀñ
    playerID = curPlayer.GetID()
    playerName = curPlayer.GetName()
    if curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCRechargeState) == 1:
        worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Recharge)
        awardInfoDict = IpyGameDataPY.GetFuncEvalCfg('NewCeremonyRecharge', 1, {})
        if str(worldLvNum) not in awardInfoDict:
            GameWorld.ErrLog('    Óʼþ·¢·Å³äÖµ´óÀñ½±Àø CeremonyRecharge Î´ÅäÖý±Àø worldLvNum=%s' % worldLvNum)
        else:
            awardList = awardInfoDict[str(worldLvNum)]
            PlayerControl.SendMailByKey('NewCeremonyPayPack', [playerID], awardList, [playerName])
    #È«ÃñÀ´àË
    worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Party)
    curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurPoint)
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyAwardRecord)
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition('NewAllPeoplePartyAward', {'WorldLvNum':worldLvNum}, True)
    if not ipyDataList:
        GameWorld.ErrLog('    Óʼþ·¢·ÅÈ«ÃñÀ´à˽±Àø AllPeoplePartyAward Î´ÅäÖÃÊÀ½çµÈ¼¶µµ WorldLvNum=%s' % worldLvNum)
        return
    
    partyAwardList = []
    for ipyData in ipyDataList:
        index = ipyData.GetIndex()
        if awardRecord & pow(2, index):
            continue
        needPoint = ipyData.GetNeedPoint()
        if curPoint < needPoint:
            continue
        awardInfoDict = ipyData.GetAward()
        job = curPlayer.GetJob()
        if str(job) not in awardInfoDict:
            GameWorld.ErrLog('    Óʼþ·¢·ÅÈ«ÃñÀ´à˽±Àø AllPeoplePartyAward Î´ÅäÖÃÖ°Òµ½±Àø job=%s' % job)
            continue
        awardList = awardInfoDict[str(job)]
        partyAwardList += awardList
    if partyAwardList:
        PlayerControl.SendMailByKey('NewCeremonyHaiPoint', [playerID], partyAwardList, [playerName])
    return
 
def __IsAtFCAction():
    ##ÊÇ·ñÔÚÐÂÏɽçÊ¢µä»î¶¯ÖÐ
    actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_NewFairyCeremony, {})
    state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)
    return state == 1
 
def __GetFCWorldLVIndex(curPlayer, fcType):
    #»ñÈ¡»î¶¯ÊÀ½çµÈ¼¶µµ
    playerFCWorldLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCActionWorldLV)
    fcWorldlvDict = IpyGameDataPY.GetFuncEvalCfg('NewCeremonyWorldLv', 1, {})
    if str(fcType) not in fcWorldlvDict:
        return 0
    worldLVIndex = 0
    worldlvList = fcWorldlvDict[str(fcType)]
    for index, lvinfo in enumerate(worldlvList):
        minlv, maxlv = lvinfo
        if minlv <= playerFCWorldLV <= maxlv:
            worldLVIndex = index
            break
    return worldLVIndex
 
#################³äÖµ´óÀñ##############################
def OnFCRecharge(curPlayer):
    if not __IsAtFCAction():
        return
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCRechargeState)
    if curState != 0:
        return
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCRechargeState, 1)
    SyncFCRechargeInfo(curPlayer)
    return
 
def GetFCRechargeAward(curPlayer):
    ## ÁìÈ¡³äÖµ´óÀñ½±Àø
    curState = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCRechargeState)
    if curState != 1:
        return
    worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Recharge)
    awardInfoDict = IpyGameDataPY.GetFuncEvalCfg('NewCeremonyRecharge', 1, {})
    if str(worldLvNum) not in awardInfoDict:
        GameWorld.ErrLog('    ÁìÈ¡³äÖµ´óÀñ½±Àø CeremonyRecharge Î´ÅäÖý±Àø worldLvNum=%s' % worldLvNum)
        return
    awardList = awardInfoDict[str(worldLvNum)]
    # ¼ì²é±³°ü
    needSpace = len(awardList)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCRechargeState, 2)
    for itemID, itemCnt, isBind in awardList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem])
    
    SyncFCRechargeInfo(curPlayer)
    
    PlayerControl.WorldNotify(0, 'NewCeremonyRecharge', [curPlayer.GetName()])
    return
 
 
def SyncFCRechargeInfo(curPlayer):
    ## Í¨Öª³äÖµ´óÀñ»î¶¯×´Ì¬
    packData = ChPyNetSendPack.tagMCNewXJSDRecharge()
    packData.State = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCRechargeState)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
#################È«ÃñÀ´àË##############################
def AddFCPartyActionCnt(curPlayer, actionID, addCnt=1):
    ##Ôö¼ÓÈ«ÃñÀ´àËÍê³É´ÎÊý
    if not __IsAtFCAction():
        return
    ipyData = IpyGameDataPY.GetIpyGameData('NewAllPeopleParty', actionID)
    if not ipyData:
        return
    maxCnt = ipyData.GetTotalTimes()
    curCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurCnt % actionID)
    if curCnt >= maxCnt:
        return
    newCnt = min(maxCnt, curCnt + addCnt)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyCurCnt % actionID, newCnt)
    singlePoint = ipyData.GetAddPoint()
    addPoint = (newCnt - curCnt) * singlePoint
    curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurPoint)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyCurPoint, curPoint + addPoint)
    SyncFCPartyInfo(curPlayer, [actionID])
    return
 
def GetFCPartyAward(curPlayer, index):
    ## È«ÃñÀ´àËÁì½±
    worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Party)
    
    ipyData = IpyGameDataPY.GetIpyGameData('NewAllPeoplePartyAward', worldLvNum, index)
    if not ipyData:
        return
    
    curPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurPoint)
    if curPoint < ipyData.GetNeedPoint():
        GameWorld.DebugLog('    È«ÃñÀ´àËÁì½±, µãÊý²»×ã%s,  worldLvNum=%s, index=%s' % (ipyData.GetNeedPoint(), worldLvNum, index), curPlayer.GetID())
        return
    awardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyAwardRecord)
    awardMark = pow(2, index)
    if awardRecord & awardMark:
        GameWorld.DebugLog('    È«ÃñÀ´àËÁì½±, ÒÑÁì½±,  worldLvNum=%s, index=%s' % (worldLvNum, index), curPlayer.GetID())
        return
    awardInfoDict = ipyData.GetAward()
    job = curPlayer.GetJob()
    if str(job) not in awardInfoDict:
        return
    awardList = awardInfoDict[str(job)]
    # ¼ì²é±³°ü
    needSpace = len(awardList)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    #¸üмǼ
    awardRecord |= awardMark
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCPartyAwardRecord, awardRecord)
    for itemID, itemCnt, isBind in awardList:
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 0, [IPY_GameWorld.rptItem])
    #֪ͨ
    SyncFCPartyInfo(curPlayer, isGetAward=True)
    return
 
 
def SyncFCPartyInfo(curPlayer, actIDList=[], isGetAward=False):
    ##֪ͨȫÃñÀ´àËÐÅÏ¢
    packData = ChPyNetSendPack.tagMCNewAllPeoplePartyInfo()
    packData.Clear()
    packData.CurPoint = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurPoint)
    packData.AwardRecord = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyAwardRecord)
    if not isGetAward:
        packData.BuyCountList = []
        for actID in ChConfig.PeoplePartyActIDList:
            if actIDList and actID not in actIDList:
                continue
            finishInfo = ChPyNetSendPack.tagMCNewAllPeoplePartyCount()
            finishInfo.ActID = actID
            finishInfo.CurTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCPartyCurCnt % actID)
            packData.BuyCountList.append(finishInfo)
        packData.Count = len(packData.BuyCountList)
    
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
#################¾ø°æ½µÁÙ##############################
def AddFCCostGold(curPlayer, costGold):
    ##³äÖµXÔª
    if costGold <= 0:
        return
#    if costType in ChConfig.CostRebate_DisableType:
#        #GameWorld.DebugLog("²»¼ÆÈë¾ø°æ½µÁÙÏû·ÑµÄÏû·ÑÀàÐÍ!costType=%s" % costType, curPlayer.GetPlayerID())
#        return
    if not __IsAtFCAction():
        return
    curCostGold = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_NewFCCostGold)
    updCostGold = curCostGold + costGold
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_NewFCCostGold, updCostGold)
    
    if updCostGold < IpyGameDataPY.GetFuncCfg('NewCeremonyRankLimit'):
        return
    
    #¸üÐÂÅÅÐаñ
    PlayerBillboard.UpdatePlayerBillboard(curPlayer, ShareDefine.Def_BT_NewFCCostGold, updCostGold)
    
    GameWorld.DebugLog("Íæ¼Ò¾ø°æ½µÁÙÏû·Ñ»î¶¯: curCostGold=%s,costGold=%s,updCostGold=%s" 
                       % (curCostGold, costGold, updCostGold), curPlayer.GetPlayerID())
    return
 
#################ÑÌ»¨¿ñ»¶##############################
def IsCanBuyFireworks(curPlayer, itemIndex):
    ##µ±Ç°ÊÇ·ñ¿ÉÒÔÂòÑÌ»¨
    if not __IsAtFCAction():
        GameWorld.Log('    ÑÌ»¨¿ñ»¶ÂòÑÌ»¨ »î¶¯Î´¿ªÆô, ÎÞ·¨¹ºÂò')
        return False
    fireworksDict = IpyGameDataPY.GetFuncEvalCfg('NewCeremonyFireParty', 1, {})
    worldLvNum = __GetFCWorldLVIndex(curPlayer, Def_FC_Fireworks)
    canBuyID = fireworksDict.get(str(worldLvNum), 0)
    if canBuyID != itemIndex:
        GameWorld.Log('    ÑÌ»¨¿ñ»¶ÂòÑÌ»¨ µ±Ç°¿ÉÒÔÂòÑÌ»¨Îª %s, ÎÞ·¨¹ºÂò %s,worldLvNum=%s'%(canBuyID, itemIndex,worldLvNum), curPlayer.GetID())
        return False
    return True