hxp
2018-12-28 edb309f07bd31eb3585d35d15e1150933f261cfb
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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package Player.PlayerBossReborn
#
# @todo:BOSS¸´»î
# @author xdh
# @date 2018-07-12 16:50
# @version 1.0
#
#
# ÏêϸÃèÊö: BOSS¸´»î
#
#---------------------------------------------------------------------
"""Version = 2018-07-12 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
 
 
def OnLogin(curPlayer):
    isReset = __CheckPlayerBossRebornAction(curPlayer)
    if not isReset:
        actCostRebateInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})
        # »î¶¯ÖÐͬ²½»î¶¯ÐÅÏ¢
        if actCostRebateInfo.get(ShareDefine.ActKey_State):
            SyncBossRebornInfo(curPlayer)
            SyncBossRebornPlayerInfo(curPlayer)
    return
 
 
def RefreshOperationAction_BossReborn():
    playerManager = GameWorld.GetPlayerManager()
    for i in xrange(playerManager.GetPlayerCount()):
        curPlayer = playerManager.GetPlayerByIndex(i)
        if curPlayer == None or not curPlayer.GetInitOK():
            continue
        __CheckPlayerBossRebornAction(curPlayer)
    return
 
 
def __CheckPlayerBossRebornAction(curPlayer):
    ## ¼ì²éÍæ¼ÒBOSS¸´»î»î¶¯Êý¾ÝÐÅÏ¢
    playerID = curPlayer.GetPlayerID()
    
    actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})
    bossRebornID = actBossRebornInfo.get(ShareDefine.ActKey_ID, 0)
    state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)
    cfgID = actBossRebornInfo.get(ShareDefine.ActKey_CfgID, 0)
    
    playerBossRebornID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornID)  # Íæ¼ÒÉíÉϵĻID
    
    # »î¶¯ID ÏàͬµÄ»°²»´¦Àí
    if bossRebornID == playerBossRebornID:
        #GameWorld.DebugLog("BOSS¸´»î»î¶¯ID²»±ä£¬²»´¦Àí£¡", curPlayer.GetPlayerID())
        return
    
    templateID = 0
    if cfgID:
        actBossIpyData = IpyGameDataPY.GetIpyGameData("ActBossReborn", cfgID)
        templateID = 0 if not actBossIpyData else actBossIpyData.GetTemplateID()
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)
    
    GameWorld.DebugLog("BOSS¸´»îÖØÖÃ! costRebateID=%s,playerCostRebateID=%s,state=%s,templateID=%s,playerTemplateID=%s" 
                       % (bossRebornID, playerBossRebornID, state, templateID, playerTemplateID), playerID)
    
    # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
    __SendBossRebornMail(curPlayer, playerTemplateID)
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BossRebornID, bossRebornID)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BossRebornTemplateID, templateID)
    for brid in ChConfig.BossRebornActIDList:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionCurTimes % brid, 0)
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionGotTimes % brid, 0)
        
    SyncBossRebornInfo(curPlayer)
    SyncBossRebornPlayerInfo(curPlayer)
    return True
 
 
def __SendBossRebornMail(curPlayer, playerTemplateID):
    # Î´ÁìÈ¡µÄ½±ÀøÓʼþ·¢·Å
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("BossReborn", {'TemplateID':playerTemplateID}, True)
    if not ipyDataList:
        return
    
    totalItemDict = {}
    for ipyData in ipyDataList:
        brid = ipyData.GetID()
        singleTimes = ipyData.GetSingleTimes()
        curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % brid)
        gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % brid)
        canGotCnt = (curTimes - gotTimes) / singleTimes
        if not canGotCnt:
            continue
        itemDict = __GetAwardItem(curPlayer, ipyData, canGotCnt)
        GameWorld.AddDictValue(totalItemDict, itemDict)
    
    #È¥µô¸´»îµãµÀ¾ß
    totalItemDict.pop(ChConfig.Def_ItemID_BossReborn, 0)
    if not totalItemDict:
        return
    totalItemList = [[itemID, itemCnt, 1] for itemID, itemCnt in totalItemDict.items()]
    PlayerControl.SendMailByKey('BossFHUnGetMail', [curPlayer.GetID()], totalItemList)
    return
 
 
def AddBossRebornActionCnt(curPlayer, actionID, addCnt=1):
    '''Ôö¼Óboss¸´»îÏà¹Ø»î¶¯Íê³É´ÎÊý'''
    #ÅжϻÊÇ·ñ¿ªÆô
    actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})
    state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)
    if not state:
        return
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)
    ipyData = IpyGameDataPY.GetIpyGameData('BossReborn', playerTemplateID, actionID)
    if not ipyData:
        return
    totalTimes = ipyData.GetTotalTimes()
    curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actionID)
    addCnt = addCnt if totalTimes == 0 else min(totalTimes - curTimes, addCnt)
    if addCnt <= 0:
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionCurTimes % actionID, curTimes + addCnt)
    
    SyncBossRebornPlayerInfo(curPlayer, actionID)
    return
 
 
def GetBossRebornActionAward(curPlayer, actionID):
    '''ÁìÈ¡boss¸´»î»î¶¯½±Àø'''
    playerTemplateID = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BossRebornTemplateID)
    ipyData = IpyGameDataPY.GetIpyGameData('BossReborn', playerTemplateID, actionID)
    if not ipyData:
        return
    singleTimes = ipyData.GetSingleTimes()
    curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actionID)
    gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % actionID)
    if curTimes - gotTimes < singleTimes:
        return
    
    #¸ø½±Àø
    awardDict = __GetAwardItem(curPlayer, ipyData)
    # ¼ì²é±³°ü
    needSpace = len(awardDict)
    packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
    if needSpace > packSpace:
        PlayerControl.NotifyCode(curPlayer, "GeRen_chenxin_998371")
        return
    #¸üдÎÊý Ã¿´ÎÁì½±Ö»ÁìÒ»´Î
    newGotTimes = gotTimes + singleTimes
    
    #GameWorld.Log('  actionID=%s,curTimes=%s,gotTimes=%s,singleTimes=%s,newGotTimes=%s'%(actionID, curTimes, gotTimes,singleTimes, newGotTimes))
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_BRActionGotTimes % actionID, newGotTimes)
    for itemID, itemCnt in awardDict.items():
        ItemControler.GivePlayerItem(curPlayer, itemID, itemCnt, 1, [IPY_GameWorld.rptItem])
    SyncBossRebornPlayerInfo(curPlayer, actionID)
    return
 
 
def __GetAwardItem(curPlayer, ipyData, times=1):
    awardDict = {}
    for itemID, itemCnt, isbind in ipyData.GetReward():
        if not itemID or not itemCnt:
            continue
        awardDict[itemID] = awardDict.get(itemID, 0) + itemCnt * times
        
    return awardDict
 
 
def SyncBossRebornPlayerInfo(curPlayer, actID=-1):
    #֪ͨµ±Ç°´ÎÊý¡¢ÒÑÁì´ÎÊý 
    packData = ChPyNetSendPack.tagMCBossRebornPlayerInfo()
    packData.DataList = []
    if actID != -1:
        syneActIDList = [actID]
    else:
        syneActIDList = []
        ipyMgr = IpyGameDataPY.IPY_Data()
        for i in xrange(ipyMgr.GetBossRebornCount()):
            ipyData = ipyMgr.GetBossRebornByIndex(i)
            syneActIDList.append(ipyData.GetID())
     
    for actid in syneActIDList:
        curTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionCurTimes % actid)
        gotTimes = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_BRActionGotTimes % actid)
        tiemInfo = ChPyNetSendPack.tagMCBossRebornData()
        tiemInfo.ActID = actid
        tiemInfo.CurTimes = curTimes
        tiemInfo.GotTimes = gotTimes
        packData.DataList.append(tiemInfo)
    
    packData.Count = len(packData.DataList)
    NetPackCommon.SendFakePack(curPlayer, packData)
    return
 
 
def SyncBossRebornInfo(curPlayer):
    actBossRebornInfo = PyGameData.g_operationActionDict.get(ShareDefine.OperationActionName_BossReborn, {})
    state = actBossRebornInfo.get(ShareDefine.ActKey_State, 0)
    cfgID = actBossRebornInfo.get(ShareDefine.ActKey_CfgID, 0)
    if not state or not cfgID:
        return
    actBossIpyData = IpyGameDataPY.GetIpyGameData("ActBossReborn", cfgID)
    if not actBossIpyData:
        return
    templateID = actBossIpyData.GetTemplateID()
    if not templateID:
        return
    ipyDataList = IpyGameDataPY.GetIpyGameDataByCondition("BossReborn", {'TemplateID':templateID}, True)
    if not ipyDataList:
        return
    openServerDay = GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ServerDay) + 1
    actInfo = ChPyNetSendPack.tagMCBossRebornInfo()
    actInfo.Clear()
    actInfo.StartDate = GameWorld.GetOperationActionDateStr(actBossIpyData.GetStartDate(), openServerDay)
    actInfo.EndtDate = GameWorld.GetOperationActionDateStr(actBossIpyData.GetEndDate(), openServerDay)
    actInfo.ResetType = actBossIpyData.GetResetType()
    actInfo.LimitLV = actBossIpyData.GetLVLimit()
    actInfo.TaskInfo = []
    for ipyData in ipyDataList:
        taskInfo = ChPyNetSendPack.tagMCBossRebornTaskInfo()
        taskInfo.TaskID = ipyData.GetID()
        taskInfo.TotalTimes = ipyData.GetTotalTimes()
        taskInfo.SingleTimes = ipyData.GetSingleTimes()
        taskInfo.AwardItem = []
        for itemID, itemCnt, isBind in ipyData.GetReward():
            awardItem = ChPyNetSendPack.tagMCBossRebornAwardItem()
            awardItem.ItemID = itemID
            awardItem.ItemCount = itemCnt
            awardItem.IsBind = isBind
            taskInfo.AwardItem.append(awardItem)
        taskInfo.AwardItemCount = len(taskInfo.AwardItem)
        actInfo.TaskInfo.append(taskInfo)
    actInfo.TaskCnt = len(actInfo.TaskInfo)
    NetPackCommon.SendFakePack(curPlayer, actInfo)
    return