| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package PlayerAutoCheckOnline  | 
| #  | 
| # @todo: Íæ¼ÒÔö¼Ó±³°üµÄÏà¹ØÅäÖÃÐÅÏ¢¹ÜÀíÆ÷£¬¸÷ÖÖ±³°üµÄÅäÖÃ×Ö¶ÎÐÅÏ¢Ðè±£³ÖÒ»Ö  | 
| # @author xcc  | 
| # @date 2014-04-24 22:05  | 
| # @version 1.5  | 
| #  | 
| # ÏêϸÃèÊö: Íæ¼ÒÔö¼Ó±³°üµÄÏà¹ØÅäÖÃÐÅÏ¢¹ÜÀíÆ÷  | 
|   | 
| # @change: "2014-04-22 17:50" xcc Ôö¼ÓÊ×°æ±¾  | 
| # @change: "2014-04-24 22:05" cbw ÔÚÏß¿ªÆô¸ÄΪһ´ÎÒ»¸ñ  | 
| # @change: "2014-06-24 21:00" Alee È¥³ýÒì³£Å׳öÏêϸÊä³ö³ö´íÐÅÏ¢  | 
| # @change: "2015-01-10 23:00" hxp ÆÁ±Î²Ö¿âË¢ÊôÐÔ  | 
| # @change: "2015-08-12 16:00" zqx ¿ª²Ö¿âË¢ÊôÐÔ  | 
| #---------------------------------------------------------------------  | 
| """Version = 2015-08-12 16:00"""  | 
| #------------------------------------------------------------------------------  | 
| import ReadChConfig  | 
| import GameWorld  | 
| import IPY_GameWorld  | 
| import PlayerControl  | 
| import ChConfig  | 
| import copy  | 
|   | 
| ##±³°üµÄÅäÖÃÐÅÏ¢£¬Ö»ÒªÓÃÓÚ¿ÉÀ©³äµÄ±³°üÀàÐÍ£¬ÈçÎïÆ·±³°ü£¬²Ö¿â±³°ü£¬Ê¹ÓõÄÅäÖøñʽÐèͳһ  | 
| class  ExpandPackCfg(object):  | 
|     ##¹¹Ô캯Êý  | 
|     #@param cfgName ÅäÖÃÎļþÃû  | 
|     #@param defCount ³õʼ±³°ü¸ñ×ÓÊý  | 
|     #@param maxCount ×î´ó±³°ü¸ñ×ÓÊý  | 
|     #@return ÎÞ  | 
|     #@remarks ¶ÁÈ¡ÅäÖÃÎļþ  | 
|     def __init__(self, cfgName, defCount, maxCount):  | 
|         self.__cfgInfo = {}   #ÅäÖÃÐÅÏ¢{1:[5,10,2000], ...}  | 
|         self.__totalAddAttrInfoWithCount = {}  #Ôö¼ÓµÄ×ÜÊôÐÔ£¬°´¸ñ×ÓÊý¼ÆË㣬Èç¸ñ×ÓÊýÊÇ3£¬Ôò»áÀÛ¼Ó1£¬2£¬3¸ñµÄÐÅÏ¢  | 
|         self.__defCount = defCount  | 
|         self.__maxCount = maxCount   #×ܵĿÉÔö¼ÓµÄ¸ñ×ÓÊý  | 
|         self.__canAddCount = maxCount - defCount  | 
|         self.__cfgName = cfgName  | 
|         self.__LoadCfg()  | 
|       | 
|     ##¶ÁÈ¡ÅäÖÃÎļþ  | 
|     #@param None  | 
|     #@return ÎÞ  | 
|     #@remarks ¶ÁÈ¡ÅäÖÃÎļþ  | 
|     def __LoadCfg(self):  | 
|         cfgInfo = ReadChConfig.GetEvalChConfig(self.__cfgName)  | 
|         #ûÓжÁÈ¡µ½ÅäÖÃÎļþ  | 
|         if None == cfgInfo:  | 
|             return  | 
|           | 
|         self.__cfgInfo = cfgInfo  | 
|         cfgCount = len(self.__cfgInfo)  #»ñÈ¡¹²ÅäÖÃÁ˼¸¸öÅäÖÃÐÅÏ¢  | 
|         #Exp²ÎÊýÌØÊâ´¦Àí£¬ÒÔΪÊÇÓй«Ê½µÄ  | 
|         totalDict = {"Exp":[]}  | 
|         for i in range(0, self.__canAddCount):  | 
|             count = index = i + 1  | 
|             #Èç¹ûÖ»ÅäÖÃÁËǰ¼¸¸ö¸ñ×ÓµÄÊý¾Ý£¬ÔòºóÃæµÄ¸ñ×ÓÐÅÏ¢ÒÔ×îºóÒ»¸ö¸ñ×ÓµÄÐÅϢΪ׼  | 
|             if index > cfgCount:  | 
|                 index = cfgCount  | 
|             gridCfgInfo = self.__cfgInfo.get(index, {})  | 
|             for key in gridCfgInfo.iterkeys():  | 
|                 if key == "Exp":  | 
|                     totalDict[key].append(gridCfgInfo.get(key, "0"))     | 
|                 else:  | 
|                     totalDict[key] = totalDict.get(key, 0) + gridCfgInfo.get(key, 0)  | 
|               | 
|             #¼ÆËãÌí¼ÓµÄ¸ñ×ÓÊý¶ÔÓ¦µÄ¸½¼ÓÊôÐÔµÄ×ÜÖµ  | 
|             if not self.__totalAddAttrInfoWithCount.has_key(count):  | 
|                 self.__totalAddAttrInfoWithCount[count] = copy.deepcopy(totalDict)  | 
|                   | 
|     ##»ñÈ¡¿ÉÒÔÔö¼ÓµÄ±³°üÊý£¬¼´×î´ó±³°üÊý¼õÈ¥»ù´¡±³°üÊý  | 
|     #@param None  | 
|     #@return ¿ÉÒÔÔö¼ÓµÄ±³°üÊý  | 
|     #@remarks »ñÈ¡¿ÉÒÔÔö¼ÓµÄ±³°üÊý£¬¼´×î´ó±³°üÊý¼õÈ¥»ù´¡±³°üÊý  | 
|     def GetCanAddCount(self):  | 
|         return self.__canAddCount  | 
|       | 
|     def GetAttrInfoByInex(self, buyIndex):  | 
|         cfgCount = len(self.__cfgInfo)  | 
|         if buyIndex > cfgCount:  | 
|             buyIndex = cfgCount  | 
|         return self.__cfgInfo.get(buyIndex, None)  | 
|       | 
|     ##¸ù¾ÝÒѹºÂòµÄ¸ñ×ÓÊý£¬»ñÈ¡×ܵĸ½¼ÓÊôÐÔÐÅÏ¢  | 
|     #@param buyCount ÒѹºÂòµÄ¸ñ×ÓÊý  | 
|     #@return ¸½¼ÓµÄÊôÐÔÐÅÏ¢  | 
|     #@remarks ¸ù¾Ýµ±Ç°¸ñ×ÓÊý£¬»ñÈ¡×ܵĸ½¼ÓÊôÐÔÐÅÏ¢  | 
|     def GetTotalAddAttrInfoByCount(self, buyCount):  | 
|         return self.__totalAddAttrInfoWithCount.get(buyCount, None)  | 
|       | 
|     ##¸ù¾ÝÆðʼ¸ñ×Ó±àºÅ£¬ºÍ½áÊø¸ñ×Ó±àºÅ£¬»ñÈ¡×ܵĿɸ½¼ÓµÄÊôÐÔÐÅÏ¢£¬±àºÅ´Ó1¿ªÊ¼  | 
|     #Èç¹ûµ±Ç°Íæ¼ÒÓÐ50¸ö¸ñ×Ó£¬Òª¿ªÆô51£¬52ÕâÁ½¸ö¸ñ×Ó£¬ÔòfromIndexΪ1£¬ toIndexΪ2£¬Èç¹ûÖ»ÓÐ51£¬ÔòfromIndexºÍtoIndex¾ùΪ1  | 
|     #@param fromIndex Æðʼ¸ñ×Ó±àºÅ  | 
|     #@param toIndex ½áÊø¸ñ×Ó±àºÅ  | 
|     #@param attrList Òª»ñÈ¡µÄÊôÐÔÁÐ±í£¬Èç¹ûÐèÒªËùÓеÄÊôÐԵϰ£¬ÇëÌîд["all"]  | 
|     #@return ¸½¼ÓµÄÊôÐÔÐÅÏ¢  | 
|     #@remarks »ñÈ¡×ܵĿɸ½¼ÓµÄÊôÐÔÐÅÏ¢  | 
|     def GetTotalCanAddAttrInfo(self, curPlayer, fromIndex, toIndex, attrList=["Exp"]):  | 
|         #Ë÷ÒýÓÐÎó   | 
|         if fromIndex <= 0 or toIndex <= 0:  | 
|             GameWorld.ErrLog('GetTotalCanAddAttrInfo fromIndex <= 0 or toIndex <= 0')  | 
|             return None  | 
|         #Ë÷ÒýÓÐÎó    | 
|         if toIndex > self.__canAddCount:  | 
|             GameWorld.ErrLog('GetTotalCanAddAttrInfo toIndex > self.__canAddCount')  | 
|             return None  | 
|           | 
|         #ÆðʼλÖò»ÄÜ´óÓÚ½áÊøÎ»Öà  | 
|         if fromIndex > toIndex:  | 
|             GameWorld.ErrLog('GetTotalCanAddAttrInfo fromIndex > toIndex')  | 
|             return None  | 
|           | 
|         #λÖÃÏàͬ,Ö±½ÓÈ¡ÅäÖÃÐÅÏ¢  | 
|         if fromIndex == toIndex:  | 
|             cfgCount = len(self.__cfgInfo)  #»ñÈ¡¹²ÅäÖÃÁ˼¸¸öÅäÖÃÐÅÏ¢  | 
|             if toIndex > cfgCount:  | 
|                 toIndex = cfgCount  | 
| #            GameWorld.Log("index=%s cfgInfo=%s"%(toIndex, self.__cfgInfo))  | 
| #            GameWorld.Log("get = %s"%self.__cfgInfo.get(toIndex, None))  | 
|             findInfo = self.__cfgInfo.get(toIndex, {})  | 
|             retInfo = {}  | 
|             for attr in attrList:  | 
|                 if attr == "Exp":  | 
|                     ReExp = PlayerControl.GetPlayerReExp(curPlayer)  | 
| #                    GameWorld.Log("ReExp=%s"%ReExp)  | 
|                     addExp = eval(findInfo[attr])  | 
| #                    GameWorld.Log("addExp=%s type=%s"%(addExp, type(addExp)))  | 
|                     retInfo[attr] = addExp  | 
|                 else:  | 
|                     retInfo[attr] = findInfo[attr]  | 
|             return retInfo  | 
|           | 
|         #λÖò»Í¬£¬½øÐмÆËã  | 
|         toInfo = self.GetTotalAddAttrInfoByCount(toIndex)  | 
|         fromInfo = self.GetTotalAddAttrInfoByCount(fromIndex - 1)  | 
|         if toInfo == None or fromInfo == None:  | 
|             GameWorld.ErrLog('GetTotalCanAddAttrInfo NoData %s'%([fromIndex, toIndex]))  | 
|             return None  | 
|           | 
|   | 
|         #Èç¹ûÓÐallÊôÐÔ£¬ËµÃ÷ÊÇҪȡȫ²¿µÄÊôÐÔÐÅÏ¢  | 
|         if "all" in attrList:  | 
|             attrList = toInfo.keys()  | 
|         #È¡³öÐèÒªµÄÊôÐÔ  | 
|         retInfo = {}  | 
|         for attr in attrList:  | 
|             if attr == "Exp":  | 
| #                GameWorld.Log("toIndex=%s fromIndex=%s"%(toIndex, fromIndex))  | 
|                 ReExp = PlayerControl.GetPlayerReExp(curPlayer)  | 
| #                GameWorld.Log("toInfo[attr]=%s"%toInfo[attr])  | 
|                 expFormulaList = toInfo[attr][fromIndex - 1:]  | 
| #                GameWorld.Log("expFormulaList=%s"%expFormulaList)  | 
|                 addExp = 0  | 
|                 for formula in expFormulaList:  | 
|                     addExp += eval(formula)  | 
| #                GameWorld.Log("addExp=%s"%addExp)  | 
|                 retInfo[attr] = addExp  | 
|             else:  | 
|                 retInfo[attr] = toInfo[attr] - fromInfo[attr]  | 
|         return retInfo  | 
|       | 
| #    def __str__(self):  | 
| #        return """CfgName = %s\r\ncfgInfo=%s\r\ntotalAddAttrInfo=%s"""%(  | 
| #                        self.__cfgName, self.__cfgInfo, self.__totalAddAttrInfoWithCount)  | 
|       | 
| ##À©³ä±³°üÅäÖÃÐÅÏ¢¹ÜÀíÆ÷  | 
| class ExpandPackCfgMgr():  | 
|     ##¹¹Ô캯Êý  | 
|     #@param None  | 
|     #@return None  | 
|     #@remarks ¹¹Ô캯Êý  | 
|     def __init__(self):  | 
|         self.__expandPackCfgDict = {}  #¸÷ÖÖÀàÐͱ³°üÅäÖÃÎļþÐÅÏ¢¹ÜÀíÆ÷×Öµä  | 
|       | 
|     ##¼ÓÔØÎïÆ·±³°üºÍ²Ö¿âÀ©³ä¸ñ×ÓʱÐèÒªÓõÄÅäÖÃÐÅÏ¢  | 
|     #@param curPlayer Íæ¼Ò¶ÔÏó  | 
|     #@return None  | 
|     #@remarks ¼ÓÔØÎïÆ·±³°üºÍ²Ö¿âÀ©³ä¸ñ×ÓʱÐèÒªÓõÄÅäÖÃÐÅÏ¢  | 
|     def Load(self, curPlayer):  | 
|         #ĬÈÏÎïÆ·±³°ü¸ñ×ÓÊý  | 
|         defItemPackCount = ChConfig.Def_PlayerFirstLoginOpenBackCnt  | 
|         itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|         self.__expandPackCfgDict[IPY_GameWorld.rptItem] = ExpandPackCfg("ExpandItemPack", defItemPackCount,   | 
|                                                                         itemPack.GetMaxCount())  | 
|         #ĬÈϲֿⱳ°ü¸ñ×ÓÊý  | 
|         defItemPackCount = ChConfig.Def_FirstLogin_OpenWareHouseCnt  | 
|         itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptWarehouse)  | 
|         self.__expandPackCfgDict[IPY_GameWorld.rptWarehouse] = ExpandPackCfg("ExpandWareHousePack", defItemPackCount,   | 
|                                                                              itemPack.GetMaxCount())  | 
|           | 
|     ##»ñÈ¡À©³äÖ¸¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
|     #@param packType ±³°üÀàÐÍ  | 
|     #@return À©³äÖ¸¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
|     #@remarks »ñÈ¡À©³äÖ¸¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
|     def GetExpandPackCfg(self, packType):  | 
|         return self.__expandPackCfgDict.get(packType, None)  | 
|       | 
|     ##¼ÆËãÎïÆ·±³°üºÍ²Ö¿â¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     #@param curPlayer Íæ¼Ò¶ÔÏó  | 
|     #@param allAttrList ÊôÐÔÁÐ±í  | 
|     #@return ¼ÆËã±³°ü¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     #@remarks ¼ÆËã±³°ü¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     def CalcAttr(self, curPlayer, allAttrList):  | 
|         #¼ÆËãÎïÆ·±³°üµÄÊôÐÔ  | 
|         self.__CalcPackAttr(curPlayer, allAttrList, IPY_GameWorld.rptItem)  | 
|         #¼ÆËã²Ö¿â±³°üµÄÊôÐÔ  | 
|         self.__CalcPackAttr(curPlayer, allAttrList, IPY_GameWorld.rptWarehouse)  | 
|       | 
|     ##¼ÆËã±³°ü¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     #@param curPlayer Íæ¼Ò¶ÔÏó  | 
|     #@param allAttrList ÊôÐÔÁÐ±í  | 
|     #@param packType ±³°üÀàÐÍ  | 
|     #@return ¼ÆËã±³°ü¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     #@remarks ¼ÆËã±³°ü¸½¼ÓµÄ×ÜÊôÐÔ  | 
|     def __CalcPackAttr(self, curPlayer, allAttrList, packType):  | 
|         packCfg = self.GetExpandPackCfg(packType)  | 
|         if not packCfg:  | 
|             return  | 
|         #ÒѹºÂò»ò×Ô¶¯¿ªÆôµÄ¸ñ×ÓÊý  | 
|         keyName = ChConfig.Def_Type_CanBuyPack_PlayerDict[packType][ChConfig.Def_PlayerPackDict_Index_Key]  | 
|         curCount = curPlayer.NomalDictGetProperty(keyName)  | 
|         if curCount == 0:  | 
|             return  | 
|         attrInfo = packCfg.GetTotalAddAttrInfoByCount(curCount)  | 
|         expandPackAddAttr = ReadChConfig.GetEvalChConfig("ExpandPackAddAttr")  | 
|         for attrName in expandPackAddAttr:  | 
|             addValue = attrInfo[attrName]  | 
|             #ÎïÀí¹¥»÷  | 
|             PlayerControl.CalcAttrDict_Type(attrName, addValue, allAttrList)  | 
|           | 
|       | 
| #    def __str__(self):  | 
| #        return "ItemPackInfo = %s\r\nWareHousePackInfo = %s"%(self.GetExpandPackCfg(IPY_GameWorld.rptItem),  | 
| #                                                              self.GetExpandPackCfg(IPY_GameWorld.rptWarehouse))  | 
|           | 
| g_expandPackCfgMgr = None  | 
| #»ñÈ¡±³°üÅäÖÃÐÅÏ¢¹ÜÀíÆ÷  | 
| #@param curPlayer Íæ¼ÒʵÀý£¬ÐèÒªÕâ¸öʵÀýÀ´»ñÈ¡¸÷ÖÖ±³°üÀàÐ͵Ä×î´ó±³°üÊý  | 
| #@return ±³°üÅäÖÃÐÅÏ¢¹ÜÀíÆ÷  | 
| #@remarks »ñÈ¡ËùÓб³°üÅäÖÃÐÅÏ¢¹ÜÀíÆ÷  | 
| def GetExpandPackCfgMgr(curPlayer):  | 
|     global g_expandPackCfgMgr  | 
|     if not g_expandPackCfgMgr:  | 
|         g_expandPackCfgMgr = ExpandPackCfgMgr()  | 
|         g_expandPackCfgMgr.Load(curPlayer)  | 
|     return g_expandPackCfgMgr  | 
|   | 
| #»ñÈ¡»ñȡָ¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
| #@param curPlayer Íæ¼ÒʵÀý£¬ÐèÒªÕâ¸öʵÀýÀ´»ñÈ¡¸÷ÖÖ±³°üÀàÐ͵Ä×î´ó±³°üÊý  | 
| #@param packType ±³°üÀàÐÍ  | 
| #@return Ö¸¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
| #@remarks »ñÈ¡»ñȡָ¶¨ÀàÐ͵ı³°üµÄÅäÖÃÐÅÏ¢  | 
| def GetExpandPackCfg(curPlayer, packType):  | 
|     return GetExpandPackCfgMgr(curPlayer).GetExpandPackCfg(packType) |