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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package Player.PlayerLianTi
#
# @todo:Á¶Ìå
# @author hxp
# @date 2022-22-23
# @version 1.0
#
# ÏêϸÃèÊö: Á¶Ìå
#
#-------------------------------------------------------------------------------
#"""Version = 2022-22-23 15:30"""
#-------------------------------------------------------------------------------
 
import GameWorld
import IpyGameDataPY
import PlayerControl
import FunctionNPCCommon
import ChPyNetSendPack
import NetPackCommon
import ItemCommon
import ChConfig
import SkillCommon
 
def DoLianTiOpen(curPlayer):
    ## ¹¦ÄÜ¿ªÆô
    lianTiLV = 1
    ipyData = IpyGameDataPY.GetIpyGameData("LianTi", lianTiLV)
    if not ipyData:
        return
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LianTiLV, lianTiLV)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LianTiEatItemCount, 0)
    
    GameWorld.DebugLog("Á¶Ì幦ÄÜ¿ªÆô! lianTiLV=%s" % lianTiLV)
    SyncLianTiInfo(curPlayer)
    RefreshLianTiAttr(curPlayer)
    return True
 
def OnPlayerLogin(curPlayer):
    if not curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiLV):
        return
    SyncLianTiInfo(curPlayer)
    return
 
#// A5 33 Á¶ÌåÌáÉý #tagCMLianTiUp
#
#struct    tagCMLianTiUp
#{
#    tagHead        Head;
#    DWORD        UseItemCnt;    //ÏûºÄ²ÄÁϸöÊý
#    BYTE        IsAutoBuy;    //ÊÇ·ñ×Ô¶¯¹ºÂò
#};
def OnLianTiUp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
    costItemCount = clientData.UseItemCnt # ÏûºÄ²ÄÁϸöÊý
    isAutoBuy = clientData.IsAutoBuy # ÊÇ·ñ×Ô¶¯¹ºÂò
    
    lianTiLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiLV)
    curEatItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiEatItemCount)
    
    if not lianTiLV:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("LianTi", lianTiLV)
    if not ipyData:
        return
    
    needEatCount = ipyData.GetNeedEatCount()
    if not needEatCount:
        GameWorld.DebugLog("Á¶ÌåÒÑÂú¼¶£¡ lianTiLV=%s" % lianTiLV)
        return
        
    if curEatItemCount >= needEatCount:
        GameWorld.DebugLog("±¾¼¶ÒѳÔÂú£¡ lianTiLV=%s,curEatItemCount=%s >= %s" % (lianTiLV, curEatItemCount, needEatCount))
        return
    
    costItemID = IpyGameDataPY.GetFuncCfg("LianTiUpItem", 1)
    if not costItemID or not costItemCount:
        return
    
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount)
    lackCnt = costItemCount - bindCnt - unBindCnt
    if lackCnt > 0 and not isAutoBuy:
        GameWorld.DebugLog("µÀ¾ß²»×㣬ÎÞ·¨ÌáÉýÁ¶Ìå! costItemID=%s,costItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s" 
                           % (costItemID, costItemCount, bindCnt, unBindCnt, lackCnt))
        return
    
    delCnt = costItemCount
    if lackCnt > 0:
        autoBuyMoneyType = IpyGameDataPY.GetFuncCfg("LianTiUpItem", 2)
        if not autoBuyMoneyType:
            return
        infoDict = {ChConfig.Def_Cost_Reason_SonKey:costItemID}
        if not FunctionNPCCommon.PayAutoBuyItem(curPlayer, {costItemID:lackCnt}, autoBuyMoneyType, ChConfig.Def_Cost_LianTi, infoDict):
            return
        delCnt -= lackCnt
        
    # ¿Û³ýÏûºÄ
    if delCnt:
        ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, delCnt, ChConfig.ItemDel_LianTi)
        
    updEatItemCount = curEatItemCount + costItemCount
    GameWorld.DebugLog("Á¶ÌåÌáÉý: lianTiLV=%s,curEatItemCount=%s,costItemCount=%s,updEatItemCount=%s,needEatCount=%s" 
                       % (lianTiLV, curEatItemCount, costItemCount, updEatItemCount, needEatCount))
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LianTiEatItemCount, updEatItemCount)
    
    SyncLianTiInfo(curPlayer)
    RefreshLianTiAttr(curPlayer)
    return
 
#// A5 34 Á¶ÌåÍ»ÆÆ #tagCMLianTiLVUp
#
#struct    tagCMLianTiLVUp
#{
#    tagHead        Head;
#};
def OnLianTiLVUp(index, clientData, tick):
    curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
        
    lianTiLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiLV)
    curEatItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiEatItemCount)
    
    if not lianTiLV:
        return
    
    ipyData = IpyGameDataPY.GetIpyGameData("LianTi", lianTiLV)
    if not ipyData:
        return
    
    needEatCount = ipyData.GetNeedEatCount()
    if not needEatCount:
        GameWorld.DebugLog("Á¶ÌåÒÑÂú¼¶£¡ lianTiLV=%s" % lianTiLV)
        return
    
    if curEatItemCount < needEatCount:
        GameWorld.DebugLog("Á¶ÌåÅàÑøÎïÆ·¸öÊý²»×㣬ÎÞ·¨Í»ÆÆ£¡ lianTiLV=%s,curEatItemCount=%s < %s" % (lianTiLV, curEatItemCount, needEatCount))
        return
    
    costItemInfo = ipyData.GetLVUpCostItemInfo()
    if not costItemInfo or len(costItemInfo) != 2:
        return
    costItemID, costItemCount = costItemInfo
    if not costItemID or not costItemCount:
        return
    costItemIndexList, bindCnt, unBindCnt = ItemCommon.GetPackItemBindStateIndexInfo(curPlayer, costItemID, costItemCount)
    lackCnt = costItemCount - bindCnt - unBindCnt
    if lackCnt > 0:
        GameWorld.DebugLog("µÀ¾ß²»×㣬ÎÞ·¨Í»ÆÆÁ¶Ìå! costItemID=%s,costItemCount=%s,bindCnt=%s,unBindCnt=%s,lackCnt=%s" 
                           % (costItemID, costItemCount, bindCnt, unBindCnt, lackCnt))
        return
    
    nextLianTiLv = lianTiLV + 1
    nextIpyData = IpyGameDataPY.GetIpyGameDataNotLog("LianTi", nextLianTiLv)
    if not nextIpyData:
        return
    
    curRealmLV = curPlayer.GetOfficialRank()
    if nextLianTiLv > curRealmLV:
        GameWorld.DebugLog("Á¶ÌåÍ»ÆÆ²»Äܳ¬¹ýµ±Ç°¾³½ç! nextLianTiLv=%s > curRealmLV(%s)" % (nextLianTiLv, curRealmLV))
        return
    
    # ¿Û³ýÏûºÄ
    ItemCommon.DelCostItemByBind(curPlayer, costItemIndexList, bindCnt, unBindCnt, costItemCount, ChConfig.ItemDel_LianTi)
    
    updEatItemCount = curEatItemCount - needEatCount
    activateSkillID = nextIpyData.GetActivateSkillID()
    GameWorld.DebugLog("Á¶ÌåÍ»ÆÆ: lianTiLV=%s,curEatItemCount=%s,needEatCount=%s,updEatItemCount=%s,nextLianTiLv=%s,activateSkillID=%s" 
                       % (lianTiLV, curEatItemCount, needEatCount, updEatItemCount, nextLianTiLv, activateSkillID))
    
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LianTiLV, nextLianTiLv)
    PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_PDict_LianTiEatItemCount, updEatItemCount)
    
    if activateSkillID:
        SkillCommon.GivePlayerSkillByJobSkill(curPlayer, [activateSkillID])
        
    SyncLianTiInfo(curPlayer)
    RefreshLianTiAttr(curPlayer)
    return
 
def RefreshLianTiAttr(curPlayer):
    CalcLianTiAttr(curPlayer)
    PlayerControl.PlayerControl(curPlayer).RefreshPlayerAttrState()
    return
 
def CalcLianTiAttr(curPlayer):
    
    lianTiLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiLV)
    if not lianTiLV:
        return
    
    allAttrList = [{} for _ in range(4)]
    
    ipyDataMgr = IpyGameDataPY.IPY_Data()
    for index in xrange(ipyDataMgr.GetLianTiCount()):
        lvupIpyData = ipyDataMgr.GetLianTiByIndex(index)
        dataLV = lvupIpyData.GetLianTiLV()
        if dataLV > lianTiLV:
            break
        
        upItemCount = lvupIpyData.GetNeedEatCount()
        if dataLV == lianTiLV:
            upItemCount = min(curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiEatItemCount), upItemCount)
        #GameWorld.DebugLog("dataLV=%s,upItemCount=%s" % (dataLV, upItemCount))
        
        # ¹Ì¶¨ÊôÐÔ
        fixedAttrTypeList = lvupIpyData.GetFixedAttrType()
        fixedAttrValueList = lvupIpyData.GetFixedAttrValue()
        for i, attrID in enumerate(fixedAttrTypeList):
            attrValue = fixedAttrValueList[i] if len(fixedAttrValueList) > i else 0
            PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
            #GameWorld.DebugLog("    %s, attrID=%s,attrValue=%s,%s" % (i, attrID, attrValue, allAttrList))
            
        # ÅàÑøµ¤Ôö¼ÓÊôÐÔ
        upItemPerCount = lvupIpyData.GetEatPerCount()
        if upItemCount and upItemPerCount:
            upItemAttrTypeList = lvupIpyData.GetEatItemAttrType()
            upItemAttrValueList = lvupIpyData.GetEatItemAttrValue()
            attrMultiple = upItemCount / upItemPerCount
            #GameWorld.DebugLog("    upItemCount=%s,upItemPerCount=%s,attrMultiple=%s" % (upItemCount, upItemPerCount, attrMultiple))
            for i, attrID in enumerate(upItemAttrTypeList):
                attrValue = upItemAttrValueList[i] if len(upItemAttrValueList) > i else 0
                attrValue *= attrMultiple
                PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
                #GameWorld.DebugLog("    %s, attrID=%s,attrValue=%s,%s" % (i, attrID, attrValue, allAttrList))
                
        # ÔöÇ¿ÊôÐÔÍò·ÖÂÊÀÛ¼Ó
        plusAttrTypeList = lvupIpyData.GetPlusAttrType()
        plusAttrRateList = lvupIpyData.GetPlusAttrRate()
        for i, attrID in enumerate(plusAttrTypeList):
            attrValue = plusAttrRateList[i] if len(plusAttrRateList) > i else 0
            PlayerControl.CalcAttrDict_Type(attrID, attrValue, allAttrList)
            
    #GameWorld.DebugLog("    allAttrList=%s" % allAttrList)
    # ±£´æ¼ÆËãÖµ
    PlayerControl.SetCalcAttrListValue(curPlayer, ChConfig.Def_CalcAttrFunc_LianTi, allAttrList)
    return
 
def SyncLianTiInfo(curPlayer):
    clientPack = ChPyNetSendPack.tagMCLianTiInfo()
    clientPack.LianTiLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiLV)
    clientPack.EatItemCount = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_LianTiEatItemCount)
    NetPackCommon.SendFakePack(curPlayer, clientPack)
    return