| #!/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 = IpyGameDataPY.GetFuncCfg("PlayerMaxLV") # µ±Ç°ÒÑ¿ª·ÅµÄ×î´óµÈ¼¶²»Ò»¶¨´óÓÚÏÂÒ»´ÎתÉúµÈ¼¶  | 
|         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 False  | 
|           | 
|         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)  | 
|   |