| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package PlayerTruck  | 
| #  | 
| # @todo: Íæ¼ÒïÚ³µ  | 
| #  | 
| # @author eggxp  | 
| # @date 2010-5-13  | 
| # @version 1.3  | 
| #  | 
| # @change: "2012-08-13 16:30" jiang Ôö¼ÓïÚ³µÂß¼¼ÓÅж¨Èç¹ûÒÑÓÐïÚ³µÉ¾³ý¾ÉµÄ  | 
| # @change: "2016-06-13 10:30" hxp ïÚ³µÐÞ¸ÄΪÏÞʱÍê³É  | 
| # @change: "2017-01-21 15:30" hxp ¿ªÊ¼ÔËïÚʱ¼ä¸ÄΪͬ²½Ê£Óàʱ¼ä£¬Ôö¼Ó³¬Ê±ÇëÇóʱ¼äÑéÖ¤  | 
| #---------------------------------------------------------------------  | 
| #"""Version = 2017-01-21 15:30"""  | 
| #------------------------------------------------------------------------------   | 
|   | 
| import IPY_GameServer  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import ReadChConfig  | 
| import GameWorld  | 
|   | 
| import time  | 
| #---------------------------------------------------------------------  | 
|   | 
| #Íæ¼ÒÉÏÏßµÄʱºòÐèÒª×öµÄ:  | 
| #curPlayer.SetLogoffTick(0)  | 
|   | 
| #Íæ¼Ò״̬´¦ÀíÐèÒª×öµÄ:  | 
| #¸ù¾ÝÍæ¼ÒµÄGetLogoffTick()µÃµ½Íæ¼ÒÏÂÏßʱ¼ä, ¼ÆËãæô³µÊÇ·ñÐèÒªÏûʧ  | 
|   | 
| #·þÎñÆ÷Í£·þÐèÒª×öµÄ:  | 
| #°Ñæô³µÉèÖÃΪÖÐֹ״̬(Õý³£ÖÐÖ¹, »Ù»µÖÐÖ¹)  | 
|   | 
| #class   IPY_GAddTruck  | 
| #{  | 
| #public:  | 
| #    //Íæ¼ÒID  | 
| #    int      GetPlayerID();  | 
| #    //æô³µID  | 
| #    int      GetTruckID();  | 
| #    //µØÍ¼ID  | 
| #    int      GetMapID();  | 
| #};  | 
| ## ÎªÍæ¼ÒÔö¼ÓÒ»¸öïÚ³µ  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºÎªÍæ¼ÒÔö¼ÓÒ»¸öïÚ³µ  | 
| def MapServer_TruckAppear(index, tick):  | 
|     sendPack = IPY_GameServer.IPY_GAddTruck()  | 
|     playerID = sendPack.GetPlayerID()  | 
|     truckID = sendPack.GetTruckID()  | 
|       | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)  | 
|     curTruck = GameWorld.GetTruckMananger().FindTruckByTruckID(truckID)  | 
|     if curPlayer and curTruck:  | 
|         GameWorld.ErrLog("GameServerÒѾ´æÔÚïÚ³µ, MapServer֪ͨÔö¼Ó", sendPack.GetPlayerID())  | 
|           | 
|         #æô³µÏûʧ  | 
|         curTruck.SetTruckState(IPY_GameServer.tusDisappear)  | 
|         curTruck.Disappear()  | 
|           | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|     curTruck = truckMananger.AddTruck(truckID, playerID)  | 
|     curTruck.SetMapID(sendPack.GetMapID())  | 
|     curTruck.SetCountry(sendPack.GetCountry())  | 
|     curTruck.SetName(sendPack.GetName());  | 
|     curTruck.SetTruckState(IPY_GameServer.tusNormal)  | 
|     startTime = int(time.time())  | 
|     curTruck.SetLogoffTick(startTime) # ÓÀºãÏîÄ¿ïÚ³µÖ÷ÈËÀëÏßʱ¼ä×÷Ϊ¿ªÊ¼Ê±¼äÓà  | 
|     SyncPlayerTruckStartTime(curPlayer)  | 
|     GameWorld.Log("%d ¿ªÊ¼æô³µ, startTime=%s" % (playerID, startTime), playerID)  | 
|     return  | 
|   | 
| ## Í¬²½ïÚ³µ¿ªÊ¼Ê±¼ä  | 
| def SyncPlayerTruckStartTime(curPlayer):  | 
|     curTruck = GameWorld.GetTruckMananger().FindTruckByOwner(curPlayer.GetPlayerID())  | 
|     # ÎÞïÚ³µ  | 
|     if curTruck == None:  | 
|         return  | 
|       | 
|     curTime = int(time.time())  | 
|     startTime = curTruck.GetLogoffTick()  | 
|     truckTime = ReadChConfig.GetEvalChConfig("TruckTime") * 60  | 
|     remainTime = max(0, truckTime - (curTime - startTime))  | 
|     truckStartTime = ChPyNetSendPack.tagGCTruckStartTime()  | 
|     truckStartTime.Clear()  | 
|     truckStartTime.StartTime = remainTime  | 
|     NetPackCommon.SendFakePack(curPlayer, truckStartTime)  | 
|     return  | 
|   | 
|   | 
| #// AE 07 ÔËïÚʱ¼äµ¹¼ÆÊ±½áÊø #tagCGTruckTimeEnd  | 
| #  | 
| #struct    tagCGTruckTimeEnd  | 
| #{  | 
| #    tagHead        Head;  | 
| #};  | 
| ### ÓÉÓÚ·þÎñÆ÷¼ìË÷ïÚ³µ³¬Ê±ÆµÂÊΪ1·ÖÖÓ£¬¹Ê¿Í»§¶Ëµ¹¼ÆÊ±½áÊøºóÖ÷¶¯ÇëÇó´¥·¢·þÎñ¶ËÍæ¼Ò¸öÈËÔËïÚ³¬Ê±Âß¼  | 
| def OnTruckTimeEnd(index, clientData, tick):  | 
|       | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     if not curPlayer:  | 
|         return  | 
|       | 
|     curTruck = GameWorld.GetTruckMananger().FindTruckByOwner(curPlayer.GetPlayerID())  | 
|     # ÎÞïÚ³µ  | 
|     if curTruck == None:  | 
|         return  | 
|       | 
|     # GetLogoffTick  | 
|     curTime = int(time.time())  | 
|     startTime = curTruck.GetLogoffTick()  | 
|     # ÓÉÓÚ·þÎñÆ÷¼ìË÷ïÚ³µ³¬Ê±ÆµÂÊΪ1·ÖÖÓ, ÕâÀï×ö¸öÈݲîʱ¼ä1·ÖÖÓ  | 
|     truckTime = (ReadChConfig.GetEvalChConfig("TruckTime") - 1) * 60  | 
|     if curTime - startTime < truckTime:  | 
|         GameWorld.Log("¿Í»§¶ËÇëÇóÔËïÚ³¬Ê±½áËã, Êµ¼Êδ³¬Ê±!: curTime=%s,startTime=%s,truckTime=%s"   | 
|                       % (curTime, startTime, truckTime), curPlayer.GetPlayerID())  | 
|         return  | 
|       | 
|     result = ""  | 
|     curPlayer.MapServer_QueryPlayerResult(0, 0, "TruckTimeOut", result, len(result))  | 
|     return  | 
|   | 
|   | 
| #class   IPY_GTruckRefresh  | 
| #{  | 
| #public:  | 
| #    //æô³µID  | 
| #    int      GetTruckID();  | 
| #    //µØÍ¼ID  | 
| #    int      GetMapID();  | 
| #    //æô³µ×´Ì¬  | 
| #    int      GetTruckState();  | 
| #};  | 
| ## Íæ¼ÒïÚ³µË¢Ð  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºÍæ¼ÒïÚ³µË¢Ð   | 
| def MapServer_TruckRefresh(index, tick):  | 
|     sendPack = IPY_GameServer.IPY_GTruckRefresh()  | 
|     truckID = sendPack.GetTruckID()  | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|     truckState = sendPack.GetTruckState()  | 
|     curTruck = truckMananger.FindTruckByTruckID(truckID)  | 
|       | 
|     if curTruck == None:  | 
|         return  | 
|       | 
|     playerID = curTruck.GetOwnerID()  | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(playerID)  | 
|       | 
|     GameWorld.Log("æô³µÐÅÏ¢ %d -> %d" %(truckID, truckState) , playerID)  | 
|       | 
|     if truckState == IPY_GameServer.tusNull:  | 
|         #ɾ³ýæô³µ  | 
|         curTruck = truckMananger.FindTruckByOwner(curPlayer.GetPlayerID())  | 
|         curTruck.Disappear()  | 
|         return  | 
|       | 
|     curTruck.SetMapID(sendPack.GetMapID())  | 
|     state = sendPack.GetTruckState()  | 
|     curTruck.SetTruckState(sendPack.GetTruckState())  | 
|       | 
|     #֪ͨµØÍ¼·þÎñÆ÷  | 
|       | 
|     if curPlayer == None:  | 
|         GameWorld.Log("ÕÒ²»µ½æô³µÖ÷ÈËÍæ¼Ò: %d"%(playerID) , playerID)  | 
|         return  | 
|       | 
|     curPlayer.MapServer_SetPlayerTruckState(state)  | 
|     return  | 
|   | 
| #class   IPY_GTruckChangeMap  | 
| #{  | 
| #public:  | 
| #    //æô³µID  | 
| #    int      GetTruckID();  | 
| #    //NPCÀàÐÍID  | 
| #    int      GetNPCTypeID();  | 
| #    //ÓµÓÐÕßID  | 
| #    int      GetPlayerID();  | 
| #    //µ±Ç°ÉúÃü  | 
| #    int      GetHP();  | 
| #  | 
| #    int      GetMapID();  | 
| #  | 
| #    int      GetPosX();  | 
| #  | 
| #    int      GetPosY();  | 
| #};  | 
| ## Íæ¼ÒïÚ³µË¢Ð Èç¹ûTruckIdΪ0ÔòÇåµôïÚ³µ ·ñÔòÕÒµ½²¢»»µØÍ¼  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºÍæ¼ÒïÚ³µË¢Ð Èç¹ûTruckIdΪ0ÔòÇåµôïÚ³µ ·ñÔòÕÒµ½²¢»»µØÍ¼  | 
| def MapServer_TruckChangeMap(index, tick):  | 
|     sendPack = IPY_GameServer.IPY_GTruckMapRefresh()  | 
|     truckID = sendPack.GetTruckID()  | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|       | 
|     if truckID == 0:  | 
|         #ɾ³ýæô³µ  | 
|         curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|         curTruck = truckMananger.FindTruckByOwner(curPlayer.GetPlayerID())  | 
|         curTruck.Disappear()  | 
|         return  | 
|       | 
|     GameWorld.Log("æô³µµØÍ¼ÐÅÏ¢ %d -> %d" %(truckID, sendPack.GetMapID()))  | 
|     curTruck = truckMananger.FindTruckByTruckID(truckID)  | 
|     curTruck.SetMapID(sendPack.GetMapID())  | 
|   | 
| #class       IPY_GTruckMsg  | 
| #public:  | 
| #    //get×Ô¶¯Éú³É  | 
| #    int      GetHead();  | 
| #    int      GetMsg();                //1.Êܵ½¹¥»÷  | 
| #    //set×Ô¶¯Éú³É  | 
| #    void                SetHead(int inputHead);  | 
| #    void                SetMsg(int inputMsg);         //1.Êܵ½¹¥»÷  | 
| #};  | 
| ## ïÚ³µÐÅÏ¢ Êܵ½¹¥»÷µÈ  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºïÚ³µÐÅÏ¢ Êܵ½¹¥»÷µÈ  | 
| def MapServer_TruckMsg(index, tick):  | 
|     sendPack = IPY_GameServer.IPY_GTruckMsg()  | 
|     truckID = sendPack.GetTruckID()  | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|     curTruck = truckMananger.FindTruckByTruckID(truckID)  | 
|     curPlayer = GameWorld.GetPlayerManager().FindPlayerByID(curTruck.GetOwnerID())  | 
|       | 
|     GameWorld.Log("æô³µÐÅÏ¢ Msg = %d"%(sendPack.GetMsg()) , curPlayer.GetPlayerID())  | 
|     curPlayer.Sync_TruckMsg(sendPack.GetMsg())  | 
|     return  | 
|   | 
| ## Íæ¼ÒïÚ³µË¢ÐÂÇëÇó´¦Àí  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºÍæ¼ÒïÚ³µË¢ÐÂÇëÇó´¦Àí  | 
| def MapServer_TruckRefreshReq(index, tick):  | 
|     sendPack = IPY_GameServer.IPY_GTruckRefreshReq()  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     truckID = sendPack.GetTruckID()  | 
|     GameWorld.Log("ÒªÇóæô³µË¢Ð id = %d"%(truckID) , curPlayer.GetPlayerID())  | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|     curTruck = truckMananger.FindTruckByTruckID(truckID)  | 
|     if curTruck == None:  | 
|         #ûÓÐæô³µ  | 
|         curPlayer.MapServer_TruckRefreshAnswer(0, 0)  | 
|         return  | 
|     curPlayer.MapServer_TruckRefreshAnswer(truckID, curTruck.GetMapID())  | 
|       | 
|     curState = curTruck.GetTruckState()  | 
|     if curState == IPY_GameServer.tusDestroy:  | 
|         #Íæ¼Òæô³µÒѾËð»µ, Ë¢ÐÂæô³µ×´Ì¬  | 
|         curPlayer.MapServer_SetPlayerTruckState(curState)  | 
|     return  | 
|   | 
|   | 
| ## É¾³ýïÚ³µ  | 
| #  @param curTruck ÄÚ²¿µôÓú¯Êý  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£ºÉ¾³ýïÚ³µ  | 
| def DelTruck( curTruck ):  | 
|     curTruck.SetTruckState(IPY_GameServer.tusDisappear)  | 
|   | 
|     GameWorld.Log("æô³µÏûʧ, ID = %s MapID = %s"%(curTruck.GetTruckID(), curTruck.GetMapID()))  | 
|       | 
|     #֪ͨµØÍ¼·þÎñÆ÷  | 
|     curTruck.SyncMapServer_TruckRefresh()  | 
|       | 
|     #æô³µÏûʧ  | 
|     curTruck.Disappear()  | 
|     return  | 
|   | 
| #//////////////////////////////////////////////////////////////  | 
| #//03 06 æô³µÏûʧ#tagGDelTruck  | 
| #tagGDelTruck       *   GettagGDelTruck();  | 
| #  | 
| #class   IPY_GDelTruck  | 
| #{  | 
| #public:  | 
| #  | 
| #    int      GetTruckID();  | 
| #};  | 
| ## É¾³ýÍæ¼ÒµÄæô³µ  | 
| #  @param index  Íæ¼ÒÔÚGameServerÖеÄindex  | 
| #  @param tick   µ÷ÓÃʱµÄtick  | 
| #  @return ÎÞ·µ»ØÖµ  | 
| #  @remarks º¯ÊýÏêϸ˵Ã÷£º#ɾ³ýÍæ¼ÒµÄæô³µ  | 
| def MapServer_TruckDelete(index, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     pack = IPY_GameServer.IPY_GDelTruck()  | 
|     truckMananger = GameWorld.GetTruckMananger()  | 
|     truckID = pack.GetTruckID()  | 
|     curTruck = truckMananger.FindTruckByTruckID(truckID)  | 
|     if curTruck == None:  | 
|         return  | 
|       | 
|     #2009.2.23  | 
|     #Ò»¶¨ÒªÏÈɾ³ýæô³µ, ÔÙÇå³ýÍæ¼Ò״̬  | 
|     #·ñÔò:  | 
|     #bugʾÀý:  | 
|     #1.Çå³ýÍæ¼Ò״̬  | 
|     #2.Íæ¼Ò½Óæô³µÈÎÎñ      <- ÕâÀï»á¶ÏÑÔ, 2Á¾æô³µ  | 
|     #3.ɾ³ýæô³µ  | 
|     DelTruck(curTruck)  | 
|     curPlayer.MapServer_SetPlayerTruckState(IPY_GameServer.tusNull)  | 
|     return  |