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
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package Item_AddExp
# @todo: ÎïÆ·¸ø¾­Ñé
#
# @author: panwei
# @date 2010-07-28
# @version 1.0
#
#------------------------------------------------------------------------------ 
"""Version = 2015-12-11 18:30"""
#---------------------------------------------------------------------
#µ¼Èë
import GameWorld
import ChConfig
import PlayerControl
import ItemCommon
 
import math
#---------------------------------------------------------------------
#È«¾Ö±äÁ¿
#---------------------------------------------------------------------
 
#---------------------------------------------------------------------
##ÅúÁ¿Ê¹ÓÃÎïÆ·
# @param curPlayer: Íæ¼ÒʵÀý
# @param curRoleItem: ÎïÆ·ÊµÀý
# @param tick: Ê±¼ä´Á
# @param useCnt: Ê¹ÓøöÊý
# @return: 
def BatchUseItem(curPlayer, curRoleItem, tick, useCnt, exData):
    itemTypeID = curRoleItem.GetItemTypeID()
    curLV = curPlayer.GetLV()
    
    GameWorld.DebugLog("Item_AddExp.BatchUseItem itemID=%s,useCnt=%s" % (itemTypeID, useCnt))
    
    giveExp = 0
    curEff = curRoleItem.GetEffectByIndex(0)
    curEffID = curEff.GetEffectID()
    # °´¹Ì¶¨¾­Ñ鏸¾­Ñé
    if curEffID == ChConfig.Def_Effect_ItemAddExp:
        giveExp = curEff.GetEffectValue(0)
        
    elif curEffID == ChConfig.Def_Effect_ItemAddExpByLV:
        expPer = curEff.GetEffectValue(0)#ËùÌáÉý¾­ÑéµÄЧÂÊÖµ
        confLV = curEff.GetEffectValue(1) #µÈ¼¶ÏÞÖÆµ±=0Ϊ²»ÏÞÖÆµÈ¼¶
        reLV = min(confLV, curLV) if confLV else curLV
        
        lvIpyData = PlayerControl.GetPlayerLVIpyData(reLV)
        if not lvIpyData:
            return
        giveExp = int(lvIpyData.GetReExp() * expPer)
    
        
    if giveExp <= 0:
        GameWorld.ErrLog('²ß»®Ìî±í´íÎó£¬ÎïÆ· = %s,¸ø¾­ÑéÒì³£giveExp=%s!'%(itemTypeID, giveExp))
        return False
 
    beforeLV = curPlayer.GetLV()
    beforeTotalExp = PlayerControl.GetPlayerTotalExp(curPlayer)
    
    playerControl = PlayerControl.PlayerControl(curPlayer)
 
    addExpTotal = useCnt * giveExp
    actualAddExp = playerControl.AddExp(addExpTotal)
    GameWorld.DebugLog("    beforeTotalExp=%s,addExpTotal=%s(%s*%s),actualAddExp=%s" 
                       % (beforeTotalExp, addExpTotal, giveExp, useCnt, actualAddExp))
    
    #¸øÍæ¼Ò¾­Ñé
    if actualAddExp <= 0:
        return False
    
    actualUseCnt = int(math.ceil(actualAddExp / float(giveExp)))
 
    afterLV = curPlayer.GetLV()
    afterTotalExp = PlayerControl.GetPlayerTotalExp(curPlayer)
    
    #ÎïÆ·¼õÉÙ
    saveDataDict = {"BeforeLV":beforeLV, "BeforeTotalExp":beforeTotalExp,
                    "AfterLV":afterLV, "AfterTotalExp":afterTotalExp, 
                    "AddExp":actualAddExp}
    
    GameWorld.DebugLog("Item_AddExp saveDataDict=%s" % saveDataDict, curPlayer.GetPlayerID())
    ItemCommon.DelItem(curPlayer, curRoleItem, actualUseCnt, True, ChConfig.ItemDel_AddExp, saveDataDict)
    PlayerControl.NotifyCode(curPlayer, 'UseElixirHint', [itemTypeID, actualAddExp])
    
    return True, actualUseCnt
 
##ʹÓÃÎïÆ·,´¥·¢ÎïÆ·¸½¼Ó¼¼ÄÜ
# @param curPlayer Íæ¼ÒʵÀý
# @param curRoleItem ÎïÆ·ÊµÀý
# @param tick Ê±¼ä´Á
# @return ÊÇ·ñʹÓÃÎïÆ·³É¹¦
# @remarks giveExp = reExp * curEff.GetEffectValue(0) + curEff.GetEffectValue(1)
def UseItem(curPlayer, curRoleItem, tick):
    return BatchUseItem(curPlayer, curRoleItem, tick, 1, 0)