| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #---------------------------------------------------------------------  | 
| #  | 
| #---------------------------------------------------------------------  | 
| ##@package FormulaControl  | 
| # @todo: ¹«Ê½¹ÜÀíÆ÷  | 
| #  | 
| # @author: panwei  | 
| # @date 2010-08-16  | 
| # @version 1.3  | 
| #  | 
| # @note: ÓÃÓÚ»º´æÔ¤±à¼µÄ¹«Ê½, Ìá¸ßevalµÄЧÂÊ  | 
| #  | 
| # @change: "2010-08-19 14:45" panwei Ìí¼Ó²»¿É±àÒëÁбí, Ôà»°ÁÐ±í²»¿É±àÒë  | 
| # @change: "2010-09-01 15:30" panwei ÐÞ¸ÄÈ«¾Ö×ÖµäÍü¼ÇÌí¼Óglobal  | 
| # @change: "2010-10-08 11:05" panwei °Î³ý·þÎñÆ÷°æ±¾¿ØÖÆ´úÂë    | 
| #---------------------------------------------------------------------  | 
| """Version = 2010-10-08 11:05"""  | 
| #---------------------------------------------------------------------  | 
| #===============================================================================  | 
| # Áʽ¼ÆËãÌá¸ß25±¶µÄ·½·¨£º  | 
| # 1.Ô·½·¨   | 
| # expression = "a + b"  | 
| # c = eval(expression)  | 
| #   | 
| # 2.ÏȱàÒ룬ºóeval  | 
| # expression = "a + b"  | 
| # d = compile(expression, "modeName", "eval")  | 
| # c = eval(d)  | 
| #   | 
| # ´óÁ¿ÔËËã²âÊÔ½á¹û£º  | 
| # c = eval(d) ±È  | 
| # c = eval(expression) ¿ì25±¶  | 
| #   | 
| # evalÒ»¸ö×Ö·û´®µÄʱ¼ä = ±àÒëÒ»¸ö×Ö·û´® + evalÒ»¸ö±àÒëºÃµÄÄ£¿é  | 
| #===============================================================================  | 
| #---------------------------------------------------------------------  | 
|   | 
| #---------------------------------------------------------------------  | 
| #¹«Ê½×ÖµäÃû×¢²á  | 
| #×¢²á¹«Ê½×ÖµäÃû·½Ê½ 'Facl_DistKey_ + KeyName' (ǰ׺ÃûÓÃÓÚÇø±ð²ß»®ÅäÖÃtxt¹«Ê½Key)  | 
| #ÀýÈç: Facl_DistKey_KillNPC = 'Facl_DistKey_KillNPC'  | 
|   | 
| #---------------------------------------------------------------------  | 
| #»º´æ·þÎñÆ÷ËùÓеĹ«Ê½×ÖµäÐÅÏ¢{δ±àÒëµÄ¹«Ê½:±àÒëºóµÄ¹«Ê½}  | 
| AllFormulaDist = {}  | 
| #---------------------------------------------------------------------  | 
| #ÌØÊ⹫ʽ²»ÄܱàÒëÁбí(Ôà»°Áбí)  | 
| IgnoreFormulaKeyList = ['DirtyList', 'DirtyName']  | 
| #---------------------------------------------------------------------  | 
| ##»ñÈ¡±àÒëºóµÄ¹«Ê½.  | 
| # @param formulaKey ×ÖµäKeyÃû  | 
| # @param noCompileFormula Î´±àÒëµÄ¹«Ê½  | 
| # @return ±àÒëºóµÄ¹«Ê½  | 
| # @remarks »ñÈ¡±àÒëºóµÄ¹«Ê½.  | 
| def GetCompileFormula(formulaKey, noCompileFormula):  | 
|     global AllFormulaDist  | 
|       | 
|     #±àÒëºóµÄ×Öµä  | 
|     compileFormula = AllFormulaDist.get(formulaKey)  | 
|       | 
|     #---Õâ¸ö¹«Ê½ÒѾ±àÒë¹ýÁË---  | 
|     if compileFormula != None:  | 
|         #GameWorld.Log('Õâ¸ö¹«Ê½ = %s ÒѾ±àÒë¹ý, Ö±½Ó·µ»Ø'%(formulaKey))  | 
|         return compileFormula  | 
|       | 
|     #---Õâ¸ö¹«Ê½Î´±àÒë¹ýÁË---  | 
|     compileFormula = CompileFormula(formulaKey, noCompileFormula)  | 
|     #¸üÐÂ×Öµä  | 
|     AllFormulaDist.update({formulaKey:compileFormula})  | 
|     #GameWorld.Log('Õâ¸ö¹«Ê½ = %s Î´±àÒë¹ý, ¼ÓÈë±àÒë'%(formulaKey))  | 
|     return compileFormula  | 
| #---------------------------------------------------------------------  | 
| ##±àÒ빫ʽ  | 
| # @param formulaName ¹«Ê½Ãû  | 
| # @param noCompileFormula Î´±àÒëµÄ¹«Ê½  | 
| # @return ±àÒëºóµÄ¹«Ê½  | 
| # @remarks ±àÒ빫ʽ  | 
| def CompileFormula(formulaName, noCompileFormula):  | 
|     #ÌØÊâ²»¿É±àÒëµÄ¹«Ê½, Ö±½Ó·µ»Ø  | 
|     if formulaName in IgnoreFormulaKeyList:  | 
|         return noCompileFormula  | 
|       | 
|     #·µ»Ø±àÒëºóµÄ½á¹û  | 
|     return compile(noCompileFormula, 'FormulaControl', 'eval')  | 
| #---------------------------------------------------------------------  | 
| ##Çå¿Õ±àÒëºóµÄ¹«Ê½×Öµä  | 
| # @param ÎÞ²ÎÊý  | 
| # @return ·µ»ØÖµÎÞÒâÒå  | 
| # @remarks Çå¿Õ±àÒëºóµÄ¹«Ê½×Öµä  | 
| def ClearCompileFormulaDist():  | 
|     global AllFormulaDist  | 
|     AllFormulaDist = {}  | 
|     #GameWorld.Log('ClearCompileFormulaDist Sucess AllFormulaDist = %s'%(AllFormulaDist))  | 
|     return  |