hxp
2 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
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
#!/usr/bin/python
# -*- coding: GBK -*-
#
#
##@package PlayerEquipDecompose.py
#
# @todo:×°±¸·Ö½â
#
# @author xdh
# @date 2016-08-05
# @version 1.0
# @note:
#------------------------------------------------------------------------------ 
#"""Version = 2017-05-24 14:51"""
#------------------------------------------------------------------------------ 
import IpyGameDataPY
import IPY_GameWorld
import GameWorld
import ItemCommon
import ChPyNetSendPack
import ShareDefine
import NetPackCommon
import PlayerControl
import ChConfig
import FormulaControl
import DataRecordPack
import PlayerSuccess
import GameFuncComm
import PlayerVip
import ItemControler
import random
import json
 
import math
#---------------------------------------------------------------------
 
 
##µÇ¼´¦Àí
# @param curPlayer Íæ¼Ò
# @return None
def PlayerLogin(curPlayer):
    Sync_EDLVInfo(curPlayer)
    return
 
def DoEquipDecomposeOpen(curPlayer):
    #¹¦ÄÜ¿ªÆô
    RefreshEDAttr(curPlayer) # ÊôÐÔË¢ÐÂ
    return
 
#//A3 2C ×°±¸·Ö½â #tagCMEquipDecompose
#
#struct    tagCMEquipDecompose
#{
#    tagHead        Head;
#    BYTE        Count;        //²ÄÁÏËùÔÚ±³°üË÷ÒýµÄÊýÁ¿
#    WORD        IndexList[Count];    //²ÄÁÏËùÔÚ±³°üË÷ÒýÁбí
#    DWORD        ItemIDList[Count];    //²ÄÁÏËùÔÚ±³°üÎïÆ·IDÁбí
#    BYTE        IsAuto;        //ÊÇ·ñ×Ô¶¯·Ö½â
#};
## Íæ¼Ò·Ö½â×°±¸·â°ü A5 08
#  @param playerIndex Íæ¼ÒË÷Òý  
#  @param clientData ¿Í»§¶Ë·â°ü  
#  @param tick Ê±¼ä
#  @return None
def OnDoEquipDecompose(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    if not clientData.Count:
        return
    eatIndexList = clientData.IndexList
    eatItemIDList = clientData.ItemIDList
    isAuto = clientData.IsAuto
    EatItems(curPlayer, eatIndexList, eatItemIDList, isAuto)
    return
 
# ÍÌÊÉÎïÆ·, ·µ»Ø±»ÍÌÊýÁ¿
def EatItems(curPlayer, eatIndexList, eatItemIDList, isAuto=False):
    if len(eatIndexList) != len(eatItemIDList):
        return 0, 0
    drDelItemList, totalAddExp, delAllCnt, giveItemIDDict = __GetCanEatItemInfo(curPlayer, eatIndexList, eatItemIDList)
    if not totalAddExp:
        GameWorld.DebugLog("    ×°±¸ÎüÊՠûÓпÉÍÌÊÉÎïÆ·£¡")
        return 0, 0
    LV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeLV)
    Exp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeExp)
    reduceTotalExp, updLV, updExp = __GetEatItemResult(curPlayer, LV, Exp, totalAddExp)
   
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeExp, updExp)
    if LV != updLV:
        PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeLV, updLV)
        
        #Ë¢ÊôÐÔ
        RefreshEDAttr(curPlayer) # ÊôÐÔË¢ÐÂ
        PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    #¸øÁ¶µ¤²ÄÁÏ
    curDecomposeCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeCnt)
    updDecomposeCnt = curDecomposeCnt + delAllCnt
    perDecomposeCnt = IpyGameDataPY.GetFuncCfg('EquipDecomposeAward')
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeCnt, updDecomposeCnt%perDecomposeCnt)
    jsonItemList = []
    giveCnt = 0
    if perDecomposeCnt and updDecomposeCnt >= perDecomposeCnt:
        awardRateList = IpyGameDataPY.GetFuncEvalCfg('EquipDecomposeAward', 2)
        resetItemIDList = IpyGameDataPY.GetFuncEvalCfg('EquipDecomposeAward', 3)
        giveCnt = updDecomposeCnt/perDecomposeCnt
        minCnt, minItemID = 0, 0
        for itemid in resetItemIDList:
            cnt = ItemControler.FindPlayerItemCountByItemID(curPlayer, IPY_GameWorld.rptItem, itemid)
            cnt += ItemControler.FindPlayerItemCountByItemID(curPlayer, IPY_GameWorld.rptWarehouse, itemid)
            if not minItemID or cnt < minCnt:
                minCnt = cnt
                minItemID = itemid
        
        #giveItemIDDict = {}
        for _ in xrange(giveCnt):
            itmeID = GameWorld.GetResultByRandomList(awardRateList)
            if not itmeID:
                continue
            if itmeID in resetItemIDList and minItemID: #¸øÍæ¼ÒÓµÓÐ×îÉٵIJÄÁÏ
                itmeID = minItemID
                
            giveItemIDDict[itmeID] = giveItemIDDict.get(itmeID, 0) + 1
            
    if giveItemIDDict:
        for giveItemID, itemCnt in giveItemIDDict.items(): 
            jsonItemList.append(ItemCommon.GetJsonItem([giveItemID,itemCnt,1]))
        needSpace = len(giveItemIDDict)
        packSpace = ItemCommon.GetItemPackSpace(curPlayer, IPY_GameWorld.rptItem, needSpace)
        if packSpace < needSpace:
            prizeItemList = [[giveItemID, itemCnt, 1] for giveItemID, itemCnt in giveItemIDDict.items()]
            PlayerControl.SendMailByKey("DefaultLackSpace", [curPlayer.GetPlayerID()], prizeItemList)
        else:
            for giveItemID, itemCnt in giveItemIDDict.items():
                ItemControler.GivePlayerItem(curPlayer, giveItemID, itemCnt, 0, [IPY_GameWorld.rptItem])
    
    #ͬ²½¿Í»§¶Ë
    Sync_EDLVInfo(curPlayer, jsonItemList)
    # Á÷Ïò
    #saveDataDict = {"ExpBefore":Exp, "AddTotalExp":reduceTotalExp, "ExpAfter":updExp,
    #                "DelItemList(ItemID,delCnt,baseExp,addExp)":drDelItemList, 'isAuto':isAuto}
    #DataRecordPack.DR_ClassUpSystem(curPlayer, "EquipDecomposeUp", updLV, saveDataDict)
    
    #EventReport.WriteEvent__lv(curPlayer, LV, updLV, Exp, updExp)
    # ÕûÀí±³°ü
    tick = GameWorld.GetGameWorld().GetTick()
    ItemControler.ResetItem(curPlayer, IPY_GameWorld.rptItem, 0, 0, tick)
    return len(drDelItemList), giveCnt
 
##»ñÈ¡¿ÉÒÔÍÌÊɵÄÎïÆ·ÐÅÏ¢
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return [¿ÉÍÌÊɵÄÎïÆ·Áбí], ×î´ó¿ÉÌṩµÄ¾­Ñé
def __GetCanEatItemInfo(curPlayer, expIndexList, eatItemIDList):
    eatItemList = []
    totalAddExp = 0
    allitemCnt = 0
    awardItemDict = {}
    eatEquipAwardExDict = IpyGameDataPY.GetFuncEvalCfg("EquipDecomposeAward2", 1, {})
    eatEquipAwardItemID = IpyGameDataPY.GetFuncCfg("EquipDecomposeAward", 4)
    petEatItemAddExpPer = PlayerVip.GetPrivilegeValue(curPlayer, ChConfig.VIPPrivilege_EatItem)
    itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)
    for i, index in enumerate(expIndexList):
        eatItem = itemPack.GetAt(index)
        
        if not eatItem or eatItem.IsEmpty():
            continue
 
        eatItemID = eatItem.GetItemTypeID()
        if eatItemIDList[i] != eatItemID:
            GameWorld.ErrLog('    ×°±¸·Ö½â¿Í»§¶Ë·¢µÄÎïÆ·Ë÷ÒýÓëʵ¼ÊÎïÆ·ID²»¶ÔÓ¦  index=%s,eatItemID=%s,wantEatItemID=%s'%(index, eatItemID, eatItemIDList[i]))
            continue
        if eatItem.GetType() == ChConfig.Def_ItemType_EquipDecomposeExp:
            curEff = eatItem.GetEffectByIndex(0)
            baseExp = curEff.GetEffectValue(0)
        elif ItemCommon.CheckItemIsEquip(eatItem):
            itemColor = eatItem.GetItemColor()
            itemClass = eatItem.GetLV()
            isSuite = 1 if eatItem.GetSuiteID() else 0
            ipyData = IpyGameDataPY.GetIpyGameData("PetEatEquip", itemColor, itemClass)
            if not ipyData:
                GameWorld.DebugLog("    tagPetEatEquip.txt,δÅäÖøÃÎïÆ·£¡ eatItemID=%s, EquipColor=%s,EquipClass=%s" % (eatItemID, itemColor, itemClass))
                continue
            baseExp = ipyData.GetExp()
            
            if itemColor >= ChConfig.Def_Quality_Orange:
                awardCount = eval(IpyGameDataPY.GetFuncCompileCfg("EquipDecomposeAward", 5))
                awardItemDict[eatEquipAwardItemID] = awardItemDict.get(eatEquipAwardItemID, 0) + awardCount
                GameWorld.DebugLog("·Ö½â³È×°ÒÔÉ϶îÍâ½±Àø: eatEquip=%s,itemClass=%s,itemColor=%s,isSuite=%s,awardCount=%s total:%s" 
                                   % (eatItem.GetItemTypeID(), itemClass, itemColor, isSuite, awardCount, awardItemDict))
                
            # ¸ßÆ·ÖʶîÍâ½±Àø
            for exAwardColor, exAwardInfo in eatEquipAwardExDict.items():
                if itemColor < int(exAwardColor):
                    continue
                exItemID, exItemCountFormat = exAwardInfo
                exAwardCount = eval(FormulaControl.GetCompileFormula("EquipDecomposeAwardEx%s" % exAwardColor, exItemCountFormat))
                if not exItemID or exAwardCount <= 0:
                    continue
                awardItemDict[exItemID] = awardItemDict.get(exItemID, 0) + exAwardCount
                GameWorld.DebugLog("·Ö½â¸ß¼¶Æ·ÖʶîÍâ½±Àø: eatEquip=%s,itemClass=%s,itemColor=%s,isSuite=%s,exAwardColor=%s,exItemID=%s,exAwardCount=%s total:%s" 
                                   % (eatItem.GetItemTypeID(), itemClass, itemColor, isSuite, exAwardColor, exItemID, exAwardCount, awardItemDict))
                
        else:
            GameWorld.ErrLog('    ²»¿É·Ö½âµÄµÀ¾ßindex=%s eatItemID=%s'%(index, eatItemID))
            continue
        itemCnt = eatItem.GetCount() # ×°±¸Ò»°ãĬÈÏ1£¬ÈçÊǾ­ÑéµÀ¾ßÔòÒ»°ã¿Éµþ¼Ó
        addExp = baseExp * itemCnt
        
        totalAddExp += addExp
        allitemCnt += itemCnt
        ItemCommon.DelItem(curPlayer, eatItem, itemCnt, True, ChConfig.ItemDel_EquipDecompose)
        
        
        GameWorld.DebugLog("    ÎüÊՠɾ³ýÎïÆ· i=%s,baseExp=%s,itemCnt=%s,addExp=%s,totalAddExp=%s" 
                           % (index, baseExp, itemCnt, addExp, totalAddExp))
        # ÏȼìË÷¿É³ÔÁÐ±í£¬·ÀÖ¹Éý¼¶¹ý³ÌÖгԵôÔ­À´²»¿É³ÔµÄ[index, ÎïÆ·ÊµÀý, »ù´¡¾­Ñé]
        eatItemList.append([eatItemID, itemCnt, baseExp, addExp])
    if petEatItemAddExpPer:
        totalAddExp += totalAddExp * petEatItemAddExpPer / ChConfig.Def_MaxRateValue
            
    PlayerSuccess.DoAddSuccessProgress(curPlayer, ShareDefine.SuccType_DecomposeEquip, allitemCnt)
    return eatItemList, totalAddExp, allitemCnt, awardItemDict
 
 
##»ñÈ¡ÍÌÊɽá¹û
#  @param curPlayer: Íæ¼ÒʵÀý
#  @return Êµ¼ÊÐèÒª¿Û³ýµÄ¾­Ñé, ×îÖÕÄ¿±êÎïÆ·, ×îÖÕ¾­ÑéÖµ
def __GetEatItemResult(curPlayer, LV, Exp, totalAddExp):
    remainExp = totalAddExp # Ê£Óà¿ÉÓþ­Ñé
    reduceTotalExp = 0 # ÕæÕýÐèÒª¿Û³ýµÄ¾­Ñé
    ipyMgr = IpyGameDataPY.IPY_Data()
    maxLV = ipyMgr.GetEquipDecomposeByIndex(ipyMgr.GetEquipDecomposeCount()-1).GetLV()
    # ¾­Ñé¼ì²é
    while remainExp > 0:
        if LV +1 >= maxLV:
            break
        maxExp = __GetLvUpNeedExp(LV)
        
        if not maxExp:
            break
        
        needExp = max(0, maxExp - Exp)
        if remainExp >= needExp:
            Exp = 0
            reduceTotalExp += needExp
            remainExp -= needExp
            LV += 1
        else:
            Exp += remainExp
            reduceTotalExp += remainExp
            remainExp = 0
            
    #µÈ¼¶ÂúºóÒ²¿ÉÒÔ·Ö½â¼Ó¾­Ñ飬¹ÊËùÓÐ×°±¸¶¼·Ö½â
    Exp += remainExp
    reduceTotalExp = totalAddExp
    GameWorld.DebugLog("×ܿɼӾ­Ñé=%s,ʵ¼Ê×ܿ۳ý¾­Ñé=%s,newLV=%s,×îÖÕ¾­Ñé=%s" % 
                       (totalAddExp, reduceTotalExp, LV, Exp))
    return reduceTotalExp, LV, Exp
 
 
 
def __GetLvUpNeedExp(lv):
    """»ñȡװ±¸·Ö½âÉý¼¶ÐèÒª¾­Ñé"""
    #ÅäÖõĵȼ¶´Ó1¿ªÊ¼
    ipyData = IpyGameDataPY.GetIpyGameData("EquipDecompose", lv+1)
    if not ipyData:
        return 0
    return ipyData.GetUpNeedExp()
 
 
## Ë¢ÊôÐÔ
def RefreshEDAttr(curPlayer):
    if not GameFuncComm.GetFuncCanUse(curPlayer, ShareDefine.GameFuncID_EquipDecompose):
        return
    allAttrList = [{} for _ in range(4)]
    curLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeLV)
    ipyData = IpyGameDataPY.GetIpyGameData('EquipDecompose', curLV+1)
    if not ipyData:
        return
    for attrID, attrValue in ipyData.GetAttr().items():
        PlayerControl.CalcAttrDict_Type(int(attrID), attrValue, allAttrList)
    
        
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_EquipDecompose, allAttrList)
    return
 
 
 
#// A3 2D ×°±¸·Ö½âÉèÖà#tagCMDecomposeSeting
#
#struct    tagCMDecomposeSeting
#{
#    tagHead        Head;
#    DWORD        Seting;
#};
def OnDecomposeSetingSave(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_EquipDecomposeSeting, clientData.Seting)
    return
 
## ·Ö½âµÈ¼¶Ïà¹ØÐÅÏ¢
def Sync_EDLVInfo(curPlayer, getItemInfo=[]):
    getItemInfo = json.dumps(getItemInfo, ensure_ascii=False)
    PackData = ChPyNetSendPack.tagMCEquipDecomposeInfo()
    PackData.Clear()
    PackData.LV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeLV)
    PackData.Exp = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeExp)
    PackData.Seting = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeSeting)
    PackData.DecomposeCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_EquipDecomposeCnt)
    PackData.GetItemData = str(getItemInfo)
    PackData.GetItemLen = len(PackData.GetItemData)
    NetPackCommon.SendFakePack(curPlayer, PackData)
    return