| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #-------------------------------------------------------------------------------  | 
| #  | 
| ##@package Player.RemoteQuery.GY_Query_GMTTaskMarket  | 
| #  | 
| # @todo:ÌÚѶÈÎÎñ¼¯ÊÐ  | 
| # @author hxp  | 
| # @date 2016-09-18  | 
| # @version 1.0  | 
| #  | 
| # ÏêϸÃèÊö: ÌÚѶÈÎÎñ¼¯ÊÐ  | 
| #  | 
| #-------------------------------------------------------------------------------  | 
| #"""Version = 2016-09-18 18:00"""  | 
| #-------------------------------------------------------------------------------  | 
|   | 
| import PlayerQQ  | 
| import GameWorld  | 
| import QuestCommon  | 
| import ReadChConfig  | 
| import PlayerControl  | 
| #import PlayerPrestigeSys  | 
| import DataRecordPack  | 
| import ShareDefine  | 
| import PlayerPet  | 
| import ChConfig  | 
| import FBLogic  | 
|   | 
| #---------------------------------------------------------------------  | 
| #È«¾Ö±äÁ¿  | 
| #---------------------------------------------------------------------  | 
|   | 
| #±ê×¼·µ»ØÂëÈçÏ£º  | 
| #0: ²½ÖèÒÑÍê³É »ò ½±Àø·¢·Å³É¹¦  | 
| #1: Óû§ÉÐδÔÚÓ¦ÓÃÄÚ´´½¨½ÇÉ«  | 
| #2£ºÓû§ÉÐδÍê³É±¾²½Öè  | 
| #3£º¸Ã²½Öè½±ÀøÒÑ·¢·Å¹ý  | 
| #100: tokenÒѹýÆÚ  | 
| #101: token²»´æÔÚ  | 
| #102: ½±Àø·¢·Åʧ°Ü  | 
| #103: ÇëÇó²ÎÊý´íÎó  | 
|   | 
| #{"ret":0,"msg":"OK","zoneid":"1"}  | 
| #{"ret":200,"msg":"²ÎÊý´íÎó","zoneid":"1"}  | 
| #×¢£º·µ»ØÂë0-200Ϊƽ̨±£Áô£¬ ¿ª·¢Õß×Ô¶¨Òå·µ»ØÂëÎñ±ØÔÚ200-10000Ö®¼ä¡£·µ»ØÂë±ØÐëÑϸñ×ñÊØ¹æ·¶£¬Èô²»×ñÊØ£¬½«³öÏÖÍâÍø¹ÊÕÏ¡£  | 
|   | 
| Def_Ret_OK = 0  | 
| Def_Ret_NoFinish = 2  | 
| Def_Ret_AwardGot = 3  | 
| Def_Ret_TokenNotExist = 101  | 
| Def_Ret_AwardFail = 102  | 
| Def_Ret_ParamErr = 103  | 
|   | 
| Def_CustomRet_ParamErr = 201 # ×Ô¶¨Òå²ÎÊý´íÎó  | 
| Def_CustomRet_Condition_Nonsupport = 202 # ÈÎÎñÌõ¼þ²»Ö§³Ö  | 
|   | 
| (  | 
| Def_QQTM_MailContent, # ½±ÀøÓʼþÄÚÈÝÄ£°å  | 
| Def_QQTM_MailGetDays, # ½±ÀøÓʼþÓÐЧÌì  | 
| Def_QQTM_InfoDict,  # ÈÎÎñÐÅÏ¢×Öµä  | 
| ) = range(3)  | 
|   | 
| #Â߼ʵÏÖ   | 
| ## ÇëÇóÂß¼    | 
| #  @param query_Type ÇëÇóÀàÐÍ  | 
| #  @param query_ID Íæ¼ÒID  | 
| #  @param packCMDList ·¢°üÃüÁî   | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return "True" or "False" or ""  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoLogic(query_Type, query_ID, packCMDList, tick):  | 
|           | 
|     GameWorld.DebugLog("GY_Query_GMTTaskMarket %s" % packCMDList)  | 
|     orderId, gmCmdDict = packCMDList  | 
|       | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(query_ID)  | 
|     if not curPlayer or curPlayer.IsEmpty():  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_Ret_TokenNotExist,"msg":"token²»´æÔÚ"})  | 
|         return  | 
|       | 
|     #²ÎÊý: cmd    Ö´ÐÐÃüÁî  | 
|     #    check: ¿ª·¢Õß½öÐèÒª²éѯÈÎÎñ²½ÖèÊÇ·ñÍê³É£¬·µ»Ø²½ÖèÍê³É״̬¡£  | 
|     #    check_award: ¿ª·¢ÕßÐèÒª²éѯÈÎÎñ²½ÖèÊÇ·ñÍê³É£¬Èô²½ÖèÒÑÍê³É£¬Ö±½Ó¸øÓû§·¢»õ£¨payitem£©£¬²¢·µ»Ø·¢»õÊÇ·ñ³É¹¦¡£  | 
|     #    award: Æ½Ì¨Í¨Öª¿ª·¢ÕßÖ±½Ó¸ø¸øÓû§·¢»õ£¬¿ª·¢Õß·µ»Ø·¢»õÊÇ·ñ³É¹¦¡£  | 
|     cmd = gmCmdDict.get("cmd", '')  | 
|     if not cmd or cmd not in ["check", "check_award", "award"]:  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_Ret_ParamErr,"msg":"ÇëÇó²ÎÊý´íÎó(cmd)"})  | 
|         return  | 
|       | 
|     #²ÎÊý: contractid    # ÈÎÎñID, ÓɹãµãͨÈÎÎñ´´½¨ºó×Ô¶¯Éú³É  | 
|     contractid = gmCmdDict.get("contractid", '')  | 
|     if not contractid:  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_Ret_ParamErr,"msg":"ÇëÇó²ÎÊý´íÎó(contractid)"})  | 
|         return  | 
|       | 
|     #²ÎÊý: step    ÈÎÎñ²½Öè  | 
|     #    ÈÎÎñµÄ²½Ö裬step´Ó1¿ªÊ¼¼Æ¡£step=1±íʾµÚÒ»²½£¬Ëĸö²½Öè¶¼ÊDZØÑ¡¡£  | 
|     #    µÚÒ»²½ÄÚÈݹ̶¨Îª½øÈëÓ¦Óã¬ÓÉÆ½Ì¨ÅжÏÓû§ÊÇ·ñÍê³É¡£  | 
|     #    µÚËIJ½ÄÚÈÝΪÁ¬ÐøÈýÌìµÇ½£¬ÓÉÆ½Ì¨ÅжÏÓû§ÊÇ·ñÍê³É¡£  | 
|     #    µÚ¶þ²½¡¢µÚÈý²½ÄÚÈݺÍÍê³ÉÅжϾùÓÉ¿ª·¢Õß×ÔÓÉʵÏÖ£¨ÄÚÈݲ»¿ÉΪÁ¬ÐøµÇ½¡¢³äÖµµÈÌõ¼þ£©  | 
|     step = GameWorld.ToIntDef(gmCmdDict.get("step"), 0)  | 
|     if step not in [1, 2, 3, 4]:  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_Ret_ParamErr,"msg":"ÇëÇó²ÎÊý´íÎó(step)"})  | 
|         return  | 
|       | 
|     #²ÎÊý: payitem    µÀ¾ßÀñ°üid  | 
|     #    Èô±¾´Î»Øµ÷ÐèÒª·¢»õ£¨cmd×Ö¶ÎֵΪcheck_award »ò award£©£¬±¾×Ö¶ÎֵΪ¸Ã²½ÖèµÀ¾ßÀñ°üid£¬¿ª·¢ÕßÐèÖ±½Ó¸øÓû§·¢·Å¸ÃidµÄµÀ¾ßÀñ°ü¡£  | 
|     #    ÆäËûÇé¿ö£¬±¾×Ö¶ÎֵΪ¿Õ¡£  | 
|     payitem = GameWorld.ToIntDef(gmCmdDict.get("payitem"), 0)  | 
|     if cmd in ["check_award", "award"] and payitem <= 0:  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_Ret_ParamErr,"msg":"ÇëÇó²ÎÊý´íÎó(payitem)"})  | 
|         return  | 
|       | 
|     #²ÎÊý: billno    # ·¢·Å½±ÀøÁ÷Ë®ºÅ£¬ÓÉÆ½Ì¨Éú³É£¬´«¸øÓ¦Óá£Ó¦ÓÃÐè¼Ç¼¸ÃÁ÷Ë®ºÅ£¬ÓÃÓÚ¿ª·¢ÉÌÓëÆ½Ì¨¶ÔÕÊ¡£  | 
|     billno = gmCmdDict.get("billno", '')  | 
|       | 
|     ##--------------------------- ÌÚѶÇëÇó½Ó¿Ú²ÎÊý¼ì²éÍê±Ï ---------------------------  | 
|   | 
|     qqtmCfg = ReadChConfig.GetEvalChConfig("QQTaskMarket")  | 
|     taskMarketDict = qqtmCfg[Def_QQTM_InfoDict]  | 
|     if contractid not in taskMarketDict:  | 
|         __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, {"ret":Def_CustomRet_ParamErr,"msg":"²ÎÊý´íÎó(contractid)δÅäÖÃ"})  | 
|         return  | 
|     taskNum, conditionDict = taskMarketDict[contractid]  | 
|       | 
|     ##--------------------------- ÒÔϾßÌåÂß¼ ---------------------------  | 
|       | 
|     if cmd == "check":  | 
|         retMsg = __DoQQTM_Check(curPlayer, contractid, step, conditionDict)  | 
|           | 
|     elif cmd == "check_award":  | 
|         retMsg = __DoQQTM_Check_Award(curPlayer, contractid, step, conditionDict, taskNum, payitem, billno, qqtmCfg)  | 
|           | 
|     # ½ø1£¬4 ²½Öè¿ÉÒÔÖ±½Ó·¢·Å½±Àø  | 
|     elif cmd == "award" and step in [1, 4]:  | 
|         retMsg = __DoQQTM_Award(curPlayer, contractid, step, taskNum, payitem, billno, qqtmCfg)  | 
|           | 
|     else:  | 
|         retMsg = {"ret":Def_Ret_ParamErr,"msg":"ÇëÇó²ÎÊý´íÎó(cmd step)"}  | 
|       | 
|     __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, retMsg)  | 
|     return  | 
|   | 
| #---------------------------------------------------------------------  | 
| #Ö´Ðнá¹û  | 
| ## Ö´Ðнá¹û  | 
| #  @param curPlayer ·¢³öÇëÇóµÄÍæ¼Ò  | 
| #  @param callFunName ¹¦ÄÜÃû³Æ  | 
| #  @param funResult ²éѯµÄ½á¹û  | 
| #  @param tick µ±Ç°Ê±¼ä  | 
| #  @return None  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷.  | 
| def DoResult(curPlayer, callFunName, funResult, tick):  | 
|     return  | 
|   | 
| def __DoQQTM_Check(curPlayer, contractid, step, conditionDict):  | 
|     # ÓÐÐèÒª¼ì²éÔòÐèÒªÅäÖÃÌõ¼þ  | 
|     if step not in conditionDict:  | 
|         return {"ret":Def_CustomRet_ParamErr,"msg":"²ÎÊý´íÎó(step)δÅäÖÃ"}  | 
|       | 
|     conditionInfo = conditionDict[step]  | 
|     conditionType = conditionInfo[0] # ÈÎÎñÌõ¼þÀàÐÍ  | 
|       | 
|     ret = Def_Ret_NoFinish  | 
|       | 
|     # µÈ¼¶  | 
|     if conditionType == "LV":  | 
|         if curPlayer.GetLV() >= conditionInfo[1]:  | 
|             ret = Def_Ret_OK  | 
|               | 
|     # ¼Ò×å  | 
|     elif conditionType == "Family":  | 
|         if curPlayer.GetFamilyID() > 0:  | 
|             ret = Def_Ret_OK  | 
|               | 
| #    # ³èÎï  | 
| #    elif conditionType == "Pet":  | 
| #        petNPCID, petLV = conditionInfo[1:]  | 
| #        petItemIndex = PlayerPet.GetPetDataItemIndexByNPCID(curPlayer, petNPCID)  | 
| #        if petItemIndex >= 0:  | 
| #            petDataItem = PlayerPet.GetPetDataItemByIndex(curPlayer, petItemIndex)  | 
| #            if petDataItem and petDataItem.GetUserAttr(ShareDefine.Def_IudetPet_StarLV) >= petLV:  | 
| #                ret = Def_Ret_OK  | 
|               | 
| #    # ¹Ù¾ôÐǼ¶  | 
| #    elif conditionType == "Official":  | 
| #        officialLV, star = conditionInfo[1:]  | 
| #        curOfficialLV = curPlayer.GetOfficialRank()  | 
| #        curStar = PlayerPrestigeSys.GetOfficialStarIndex(curPlayer)  | 
| #        if curOfficialLV > officialLV or (curOfficialLV == officialLV and curStar >= star):  | 
| #            ret = Def_Ret_OK    | 
|               | 
| #    # ×øÆï  | 
| #    elif conditionType == "Horse":  | 
| #        classLV, starLV = conditionInfo[1:]  | 
| #        curClassLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Horser_ClassLV, 0, ChConfig.Def_PDictType_Horse)  | 
| #        curStarLV = curPlayer.NomalDictGetProperty(ChConfig.Def_PDict_Horser_StarLV, 0, ChConfig.Def_PDictType_Horse)  | 
| #        if curClassLV > classLV or (curClassLV == classLV and curStarLV >= starLV):  | 
| #            ret = Def_Ret_OK  | 
|               | 
|     # ²ÎÓ븱±¾  | 
|     elif conditionType == "FBEnter":  | 
|         mapID = conditionInfo[1]  | 
|         if FBLogic.GetHadEnterFB(curPlayer, mapID):  | 
|             ret = Def_Ret_OK  | 
|               | 
|     # Íê³ÉÈÎÎñ  | 
|     elif conditionType == "Mission":  | 
|         missionID = conditionInfo[1]  | 
|         if QuestCommon.GetHadFinishMainMission(curPlayer, missionID):  | 
|             ret = Def_Ret_OK          | 
|       | 
|     # ÆäËûÌõ¼þÖ§³ÖÔÚ´ËÀ©Õ¹  | 
|     else:  | 
|         return {"ret":Def_CustomRet_Condition_Nonsupport,"msg":"²»Ö§³Ö¸ÃÌõ¼þ²éѯ(%s)" % conditionType}  | 
|       | 
|     return {"ret":ret,"msg":"²½ÖèÒÑÍê³É" if ret == Def_Ret_OK else "Óû§ÉÐδÍê³É±¾²½Öè"}  | 
|   | 
| def __DoQQTM_Check_Award(curPlayer, contractid, step, conditionDict, taskNum, payitem, billno, qqtmCfg):  | 
|     retMsg = __DoQQTM_Check(curPlayer, contractid, step, conditionDict)  | 
|     if retMsg.get("ret") == Def_Ret_OK:  | 
|         retMsg = __DoQQTM_Award(curPlayer, contractid, step, taskNum, payitem, billno, qqtmCfg)  | 
|     return retMsg  | 
|   | 
| def __DoQQTM_Award(curPlayer, contractid, step, taskNum, payitem, billno, qqtmCfg):  | 
|     ret = Def_Ret_AwardFail  | 
|     msg = "½±Àø·¢·Åʧ°Ü"  | 
|     tmAwardRecord = PlayerQQ.__GetQQPDictValue(curPlayer, ChConfig.Def_PDict_QQTaskMarketRecord % taskNum)  | 
|     if tmAwardRecord&pow(2, step):  | 
|         ret = Def_Ret_AwardGot  | 
|         msg = "¸Ã²½Öè½±ÀøÒÑ·¢·Å¹ý"  | 
|     else:  | 
|         isOK = PlayerControl.SendMail("", qqtmCfg[Def_QQTM_MailContent], qqtmCfg[Def_QQTM_MailGetDays],   | 
|                                       [curPlayer.GetPlayerID()], [(payitem, 1, 1)])  | 
|         if isOK:  | 
|             PlayerQQ.__SetQQPDictValue(curPlayer, ChConfig.Def_PDict_QQTaskMarketRecord % taskNum, tmAwardRecord|pow(2, step))  | 
|             ret = Def_Ret_OK  | 
|             msg = "½±Àø·¢·Å³É¹¦"  | 
|             addDataDict = {"contractid":contractid, "step":step, "taskNum":taskNum, "payitem":payitem, "billno":billno}  | 
|             DataRecordPack.DR_FuncGiveItem(curPlayer, "QQTaskMarketMail", addDataDict)  | 
|               | 
|     return {"ret":ret,"msg":msg}  | 
|   | 
| def __GameServer_QueryPlayerResult(orderId, query_ID, curPlayer, retMsg):  | 
|     GameWorld.Log("GMT_TaskMarket retMsg=%s" % retMsg)  | 
|       | 
|     playerName = "" if not curPlayer else curPlayer.GetPlayerName()  | 
|     accID = "" if not curPlayer else curPlayer.GetAccID()  | 
|       | 
|     resultMsg = str([orderId, retMsg, 'GMT_TaskMarket'])  | 
|     GameWorld.GetPlayerManager().GameServer_QueryPlayerResult(0, 0, 0, 'GMToolResult', resultMsg, len(resultMsg))  | 
|     DataRecordPack.DR_ToolGMOperate(query_ID, playerName, accID, 'GMT_TaskMarket', resultMsg)  | 
|     return  | 
|   | 
|   | 
|   |