#!/usr/bin/python  
 | 
# -*- coding: GBK -*-  
 | 
#---------------------------------------------------------------------  
 | 
#  
 | 
#------------------------------------------------------------------------------   
 | 
##@package Item_GiveMoney  
 | 
# @todo: ¸øÈËÎï½ðÇ®  
 | 
#  
 | 
# @author: adaws  
 | 
# @date 2010-08-11 16:00  
 | 
# @version 1.9  
 | 
#  
 | 
# @change: "2011-02-23 17:30" panwei É¾³ýÍâ²ãͳһÁ÷Ïò¼Ç¼, µ¥¸öÎïÆ·µ÷ÓÃͳһÁ÷Ïò¼Ç¼  
 | 
# @change: "2011-04-27 11:00" Alee Íæ¼ÒÊý¾ÝÁ÷Ïò¼Ç¼  
 | 
# @change: "2012-04-09 14:30" jiang Á÷Ïò¼Ç¼  
 | 
# @change: "2012-06-18 18:00" jiang ÐÞ¸ÄItemCommon.DelItemº¯ÊýµÄ²ÎÊýÓÃÓÚOssʼþ¼Ç¼  
 | 
# @change: "2013-12-26 20:20" Alee ¼õÉÙÁ÷Ïò¼Ç¼  
 | 
# @change: "2014-02-19 20:10" Alee ¸øÓû§ÒøÆ±£¨¶ñħ¾«»ª£©  
 | 
# @change: "2015-01-14 00:30" hxp Ôö¼Óʼþ»ã±¨  
 | 
# @change: "2015-05-20 16:00" hxp Ôö¼ÓÅúÁ¿Ê¹ÓÃÂß¼  
 | 
# @change: "2016-07-20 14:30" hxp Í³Ò»º¯Êý  
 | 
#------------------------------------------------------------------------------   
 | 
#"""Version = 2016-07-20 14:30"""  
 | 
#------------------------------------------------------------------------------  
 | 
#µ¼Èë  
 | 
import GameWorld  
 | 
import ChConfig  
 | 
import PlayerControl  
 | 
import IPY_GameWorld  
 | 
import ItemCommon  
 | 
import ShareDefine  
 | 
import PlayerFamily  
 | 
#------------------------------------------------------------------------------   
 | 
  
 | 
  
 | 
#------------------------------------------------------------------------------   
 | 
  
 | 
##ÅúÁ¿Ê¹ÓÃÎïÆ·  
 | 
# @param curPlayer: Íæ¼ÒʵÀý  
 | 
# @param curRoleItem: ÎïÆ·ÊµÀý  
 | 
# @param tick: Ê±¼ä´Á  
 | 
# @param useCnt: Ê¹ÓøöÊý  
 | 
# @return:   
 | 
def BatchUseItem(curPlayer, curRoleItem, tick, useCnt, exData):  
 | 
    itemID = curRoleItem.GetItemTypeID()  
 | 
    #itemName = curRoleItem.GetName()  
 | 
    GameWorld.DebugLog("Item_GiveMoney.BatchUseItem itemID=%s,useCnt=%s" % (itemID, useCnt))  
 | 
      
 | 
    effectCount = curRoleItem.GetEffectCount()  
 | 
    playerLv = curPlayer.GetLV()  
 | 
    reMoney = GameWorld.GetReMoney(playerLv)  
 | 
    itemID = curRoleItem.GetItemTypeID()  
 | 
      
 | 
    # »ã×ܸÃÎïÆ·¿É¸øµÄ»õ±ÒÀàÐÍ  
 | 
    giveMoneyDict = {}  
 | 
    for i in range(effectCount):  
 | 
        curEff = curRoleItem.GetEffectByIndex(i)  
 | 
        curEffID = curEff.GetEffectID()  
 | 
        moneyType = GetAddMoneyType(curEffID)  
 | 
        if moneyType == -1:  
 | 
            continue  
 | 
          
 | 
        #multiValue = curEff.GetEffectValue(0)  
 | 
        #addValue = curEff.GetEffectValue(1)  
 | 
        giveMoney = curEff.GetEffectValue(0)#reMoney*multiValue + addValue  
 | 
        if giveMoney <= 0:  
 | 
            continue  
 | 
          
 | 
        giveMoneyDict[moneyType] = giveMoney  
 | 
          
 | 
    GameWorld.DebugLog("    giveMoneyDict=%s" % giveMoneyDict)  
 | 
    if not giveMoneyDict:  
 | 
        return  
 | 
          
 | 
    # Ô¤¼ì²é¿É³É¹¦Ê¹ÓõÄ×ܸöÊý  
 | 
    successCnt = 0  
 | 
    isBreak = False  
 | 
    for i in range(useCnt):  
 | 
          
 | 
        if isBreak:  
 | 
            break  
 | 
          
 | 
        for moneyType, giveMoney in giveMoneyDict.items():  
 | 
            curTypeTotalMoney = giveMoney * (successCnt + 1)  
 | 
            # Ö»ÒªÓÐÆäÖÐÒ»ÖÖ»õ±ÒÀàÐͲ»ÄܸøÔòÍ£Ö¹ÅúÁ¿Ê¹ÓÃÎïÆ·  
 | 
            if not PlayerControl.CanGiveMoney(curPlayer, moneyType, curTypeTotalMoney):  
 | 
                isBreak = True  
 | 
                break  
 | 
              
 | 
            successCnt += 1  
 | 
              
 | 
    GameWorld.DebugLog("    successCnt=%s" % successCnt)  
 | 
    if successCnt <= 0:  
 | 
        return  
 | 
      
 | 
    #ÎïÆ·¼õÉÙ  
 | 
    ItemCommon.DelItem(curPlayer, curRoleItem, successCnt, True, ChConfig.ItemDel_GiveMoney)  
 | 
              
 | 
    # ¸ø»õ±Ò  
 | 
    for moneyType, giveMoney in giveMoneyDict.items():  
 | 
          
 | 
        giveTotalMoney = giveMoney * successCnt  
 | 
        if moneyType == ShareDefine.TYPE_Price_Family_Contribution:  
 | 
            PlayerFamily.AddPlayerFamilyActiveValue(curPlayer, giveTotalMoney, True, ShareDefine.Def_AddFAVReason_UseItem, True)  
 | 
        else:  
 | 
            addDataDict = {"UseCount":successCnt, ChConfig.Def_Give_Reason_SonKey:itemID}  
 | 
            PlayerControl.GiveMoney(curPlayer, moneyType, giveTotalMoney, ChConfig.Def_GiveMoney_UseItem, addDataDict)  
 | 
              
 | 
    return True, successCnt  
 | 
  
 | 
  
 | 
##ʹÓÃÎïÆ·,´¥·¢ÎïÆ·¸½¼ÓЧ¹û ¸øÈËÎï½ðÇ®  
 | 
# @param curPlayer: Íæ¼ÒʵÀý  
 | 
# @param curRoleItem: ÎïÆ·ÊµÀý  
 | 
# @param tick: Ê±¼ä´Á  
 | 
# @return: ÊÇ·ñʹÓÃÎïÆ·³É¹¦  
 | 
# @remarks: giveMoney = reMoney * curEff.GetEffectValue(1) + curEff.GetEffectValue(2)  
 | 
# AֵΪ½ðÇ®¹«Ê½ÀïµÄÊýÁ¿(³Ë·¨Òò×Ó) BֵΪ½ðÇ®¹«Ê½Àï¶îÍâ¹Ì¶¨ÊýÁ¿(¼Ó·¨Òò×Ó)   
 | 
def UseItem(curPlayer, curRoleItem, tick):  
 | 
    return BatchUseItem(curPlayer, curRoleItem, tick, 1, 0)  
 | 
  
 | 
  
 | 
## ¸ù¾ÝµÀ¾ßµÄЧ¹ûID»ñµÃÐèÒª¸øµÄ½ðÇ®µÄÀàÐÍ  
 | 
#  @param curEffID: µÀ¾ßµÄЧ¹ûID  
 | 
#  @return: ½ðÇ®µÄÀàÐÍ Èç¹û¸ù¾ÝЧ¹ûIDÕÒ²»µ½µÄ»°·µ»Ø-1  
 | 
#  @remarks: ¸ù¾ÝµÀ¾ßµÄЧ¹ûID»ñµÃÐèÒª¸øµÄ½ðÇ®µÄÀàÐÍ DÕÒ²»µ½µÄ»°·µ»Ø-1  
 | 
def GetAddMoneyType(curEffID):  
 | 
    if curEffID == ChConfig.Def_Effect_GivePlayerMoneySilver:  
 | 
        return IPY_GameWorld.TYPE_Price_Silver_Money  
 | 
    elif curEffID == ChConfig.Def_Effect_GivePlayerMoneyGift:  
 | 
        return IPY_GameWorld.TYPE_Price_Gold_Paper  
 | 
    elif curEffID == ChConfig.Def_Effect_GivePlayerMoneyGold:  
 | 
        return IPY_GameWorld.TYPE_Price_Gold_Money  
 | 
    elif curEffID == ChConfig.Def_Effect_GivePlayerSilverPaper:  
 | 
        return IPY_GameWorld.TYPE_Price_Silver_Paper  
 | 
    elif curEffID == ChConfig.Def_Effect_ItemGiveHonorPoint:  
 | 
        return ShareDefine.TYPE_Price_Honor  
 | 
    elif curEffID == ChConfig.Def_Effect_ItemGiveRuneJH:  
 | 
        return ShareDefine.TYPE_Price_Rune  
 | 
    elif curEffID == ChConfig.Def_Effect_ItemGiveRuneSplinters:  
 | 
        return ShareDefine.TYPE_Price_RuneSplinters  
 | 
    elif curEffID == ChConfig.Def_Effect_ItemGiveFamilyActivity:  
 | 
        return ShareDefine.TYPE_Price_FamilyActivity  
 | 
    elif curEffID == ChConfig.Def_Effect_ItemGiveFamilyContribution:  
 | 
        return ShareDefine.TYPE_Price_Family_Contribution  
 | 
    return -1  
 | 
      
 |