hxp
5 天以前 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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
#
##@package UseItem.Item_AddLV
#
# @todo:Ö±½ÓÉý¼¶µÀ¾ß
# @author hxp
# @date 2014-12-11
# @version 1.0
#
#
# ÏêϸÃèÊö: Ö±½ÓÉý¼¶µÀ¾ß
#
#---------------------------------------------------------------------
#"""Version = 2017-03-20 14:20"""
#---------------------------------------------------------------------
 
#µ¼Èë
import ChConfig
import GameWorld
import ItemCommon
import PlayerControl
import IpyGameDataPY
#---------------------------------------------------------------------
#È«¾Ö±äÁ¿
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
##ʹÓÃÎïÆ·,´¥·¢ÎïÆ·¸½¼Ó¼¼ÄÜ
# @param curPlayer Íæ¼ÒʵÀý
# @param curRoleItem ÎïÆ·ÊµÀý
# @param tick Ê±¼ä´Á
# @return ÊÇ·ñʹÓÃÎïÆ·³É¹¦
# @remarks XX¼¶Ç°ÉýÒ»¼¶£¬XX¼¶ºó¼ÓXX¼¶1¼¶¾­Ñ飨AÖµËùÌáÉýµÄµÈ¼¶£¬BֵΪµÈ¼¶ÏÞÖÆ£¬µ±B=0Ϊ²»ÏÞÖÆµÈ¼¶£©
def BatchUseItem(curPlayer, curRoleItem, tick, useCnt, exData):
    itemTypeID = curRoleItem.GetItemTypeID()
    curEff = curRoleItem.GetEffectByIndex(0)
    curEffID = curEff.GetEffectID()
 
    if curEffID != ChConfig.Def_Effect_ItemAddLV:
        GameWorld.ErrLog('²ß»®Ìî±í´íÎó£¬ÎïÆ· = %s,¸øµÈ¼¶Ð§¹û´íÎó = %s' % (itemTypeID, curEffID))
        return False
    
    giveLV = 1 # ÌáÉýµÈ¼¶ Ä¬ÈÏ1¼¶
    isKeepExp = curEff.GetEffectValue(0) # ÊÇ·ñ±£Áôµ±Ç°µÈ¼¶ÏÖÓо­Ñé
    lvLimit = curEff.GetEffectValue(1) # Ð¡Óڴ˵ȼ¶ÔòÖ±½ÓÌáÉý¹Ì¶¨µÈ¼¶£¬·ñÔò¸øÓëÒ»¶¨¾­Ñé Èô´ËֵΪ0ÔòÎÞÂÛ¶àÉÙ¼¶£¬¶¼Ö±½ÓÉý¼¶
 
    if giveLV <= 0:
        GameWorld.ErrLog('²ß»®Ìî±í´íÎó£¬ÎïÆ· = %s,µÈ¼¶ÅäÖôíÎó = %s, effLV=%s' % (itemTypeID, curEffID, giveLV))
        return False
    
    #¼Ç¼ÓÃ
    beforeTotalExp = PlayerControl.GetPlayerTotalExp(curPlayer) # µ±Ç°ÓµÓеľ­Ñé
    beforeLV = curPlayer.GetLV()
    
    realCnt = 0
    addTotalExp = 0
    for _ in xrange(useCnt):
        curLV = curPlayer.GetLV()
        isOnlyLVUp = lvLimit==0 or curLV < lvLimit #ÊÇ·ñÖ±½ÓÌáÉý¹Ì¶¨µÈ¼¶
            
        maxLV = PlayerControl.GetPlayerMaxLV(curPlayer)
        if isOnlyLVUp and curLV >= maxLV:
            PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_607994")
            GameWorld.Log('Éý¼¶¹ûʵÎÞ·¨Ê¹Óã¬ÒÑ´ïµ½µ±Ç°×î´óµÈ¼¶ curLV=%s,maxLV=%s' 
                          % (curLV, maxLV), curPlayer.GetPlayerID())
            break
        
        addExp = DoAddLVEx(curPlayer, giveLV, isKeepExp, isOnlyLVUp, lvLimit)
        if not addExp:
            break
        
        realCnt += 1
        addTotalExp += addExp
        
    if not realCnt:
        return False
    
    #ÎïÆ·¼õÉÙ
    saveDataDict = {"BeforeLV":beforeLV, "AfterLV":curPlayer.GetLV(), "BeforeTotalExp":beforeTotalExp, 
                    "IsKeepExp":isKeepExp, "AfterTotalExp":PlayerControl.GetPlayerTotalExp(curPlayer),
                    "AddExp":addTotalExp}
    
    GameWorld.DebugLog("ʹÓÃÉý¼¶µ¤½á¹û£ºsaveDataDict=%s" % str(saveDataDict))
    ItemCommon.DelItem(curPlayer, curRoleItem, realCnt, True, ChConfig.ItemDel_AddLV, saveDataDict)
    return True, realCnt
 
def UseItem(curPlayer, curRoleItem, tick):
    return BatchUseItem(curPlayer, curRoleItem, tick, 1, 0)
 
##δÂú¼¶Ê±Ôö¼ÓתÉúµÈ¼¶
# @param curPlayer Íæ¼ÒʵÀý
# @param giveLV Ôö¼ÓµÈ¼¶
# @param isKeepExp ÊÇ·ñ±£Áôµ±Ç°¾­Ñé
# @param isOnlyLVUp ÊÇ·ñÖ±½ÓÌáÉý¹Ì¶¨µÈ¼¶
# @param formulaIndex ¸øÓë¾­ÑéµÄ¹«Ê½Ë÷Òý
# @return Ê¹Óýá¹û×ÖµäÐÅÏ¢
def DoAddLVEx(curPlayer, giveLV, isKeepExp, isOnlyLVUp, lvLimit):
        
    curLV = curPlayer.GetLV()
    lvUpNeedExp = PlayerControl.GetTotalExpByPlayerLv(curLV)
    beforeTotalExp = PlayerControl.GetPlayerTotalExp(curPlayer) # µ±Ç°ÓµÓеľ­Ñé
    if isOnlyLVUp:
        # Âú¼¶
        if lvUpNeedExp <= 0:
            PlayerControl.NotifyCode(curPlayer, "GeRen_liubo_607994")
            return 0
        
        giveExp = 0
        for lv in range(curLV, curLV + giveLV):
            curLVNeedExp = PlayerControl.GetTotalExpByPlayerLv(lv)
            
            if curLVNeedExp > 0:
                giveExp += curLVNeedExp
        
        # Èç¹û²»±£Áô¾­Ñ飬Ôò¿Û³ýµ±Ç°ÓµÓеľ­Ñé
        if not isKeepExp:
            giveExp -= beforeTotalExp
    else:
        giveExp = PlayerControl.GetTotalExpByPlayerLv(lvLimit)
        
        
    GameWorld.DebugLog("Item_AddLV isOnlyLVUp=%s, lvLimit=%s, curLV=%s,giveLV=%s,isKeepExp=%s,beforeTotalExp=%s,giveExp=%s" 
                       % (isOnlyLVUp, lvLimit, curLV, giveLV, isKeepExp, beforeTotalExp, giveExp))
    if giveExp <= 0:
        return 0
    
    playerControl = PlayerControl.PlayerControl(curPlayer)
    return playerControl.AddExp(giveExp)