| #!/usr/bin/python  | 
| # -*- coding: GBK -*-  | 
| #  | 
| #  | 
| ##@package UpdatePlayerName.py  | 
| #  | 
| # @todo:Íæ¼Ò¸ÄÃû  | 
| #  | 
| # @author jiang  | 
| # @date 2013-01-23 13:30  | 
| # @version 1.5  | 
| # @note:  | 
| #  | 
| # @change: "2013-03-13 17:00" wdb É¾³ý·â°ü  | 
| # @change: "2014-05-22 10:20" xcc »Ö¸´¸ÄÃû¹¦ÄÜ  | 
| # @change: "2014-12-23 03:40" Alee ¸ÄÃû×ÖµäÓÃÄÚ´ækey  | 
| # @change: "2016-11-09 14:10" xdh Ð޸ĸÄÃûÏûºÄ  | 
| # @change: "2017-07-04 20:10" xdh Íæ¼ÒºÏ·þÊ״εǼ¸ÄÃû´ÎÊýÖØÖÃΪ0  | 
| #------------------------------------------------------------------------------   | 
| #"""Version = 2017-07-04 20:10"""  | 
| #------------------------------------------------------------------------------   | 
| # µ¼Èë  | 
| import GameWorld  | 
| import ChConfig  | 
| import ReadChConfig  | 
| import PlayerControl  | 
| import IPY_GameWorld  | 
| import ItemCommon  | 
| import ChPyNetSendPack  | 
| import NetPackCommon  | 
| import EventReport  | 
| #------------------------------------------------------------------------------   | 
|   | 
| ## ºÏ·þÊ×µÇ  | 
| def ResetChangeNameCnt(curPlayer):  | 
|     return #ÔÝÆÁ±Î  | 
|     GameWorld.DebugLog('        Íæ¼ÒºÏ·þÊ״εǼ ¸ÄÃû´ÎÊýÖØÖÃΪ0')  | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_UpdatePlayerNameCnt, 0)  | 
|     Sync_UpdatePlayerNameCount(curPlayer)  | 
|     return  | 
|   | 
| #===============================================================================  | 
| #//A1 22 ½ÇÉ«¸ÄÃû #tagUpdatePlayerName  | 
| #  | 
| #struct    tagUpdatePlayerName  | 
| #{  | 
| #    tagHead        Head;  | 
| #    BYTE        NewNameLen;  | 
| #    char        NewName[NewNameLen];  | 
| #    BYTE        ItemIndex;    //¸ÄÃûÎïÆ·ÔÚ±³°üÖеÄλÖà  | 
| #    DWORD       ServerID;  | 
| #};  | 
| #===============================================================================  | 
| ## Íæ¼Ò¸ü¸ÄÃû×Ö  | 
| #  @param index: Íæ¼ÒË÷Òý  | 
| #  @param clientData: ·â°ü½á¹¹Ìå  | 
| #  @param tick: Ê±¼ä´Á  | 
| #  @return: None  | 
| def UpdatePlayerName(index, clientData, tick):  | 
|       | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     if GameWorld.IsCrossServer():  | 
|         #itemuse_lzxkoy_0:²»¿ÉÔÚ¿ç·þ»·¾³ÏÂʹÓøÄÃû¹¦ÄÜ¡£  | 
|         PlayerControl.NotifyCode(curPlayer, "itemuse_lzxkoy_0")  | 
|         return  | 
|       | 
|     if curPlayer.GetDictByKey(ChConfig.Def_Player_Dict_UpdatePlayerName):  | 
|         #ÕýÔÚ¸ÄÃûÖÐ  | 
|         GameWorld.Log("ÒѾÔÚ¸ÄÃûÖÐ...", curPlayer.GetID())  | 
|         return  | 
|       | 
|     #ÐÂÃû×Ö  | 
|     newName = clientData.NewName  | 
|     itemIndex = clientData.ItemIndex - 1 #¿Í»§¶Ë·¢µÄĬÈÏ+ÁË1  | 
|     serverID = clientData.ServerID  | 
|     if itemIndex == -1: #-1ÔòĬÈÏ¿ÛÇ®·ñÔò¿ÛµÀ¾ß  | 
|         return  | 
|         moneyType, moneyCount = GetCostMoney(curPlayer)  | 
|         if not PlayerControl.HaveMoney(curPlayer, moneyType, moneyCount):  | 
|             #½ðÇ®²»×ã  | 
|             return False  | 
|     else:  | 
|         itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|         curItem = itemPack.GetAt(itemIndex)  | 
|         if not __CheckItemUpdatePlayerName(curPlayer, curItem):  | 
|             #ÎïÆ·´íÎó  | 
|             return  | 
|       | 
|         #¸ÄÃûÎïÆ·ÔÚ±³°üµÄλÖÃ, ÒòΪ±³°üÎïÆ·Ë÷Òý´Ó0¿ªÊ¼, ×Öµä×îСֵֻÄÜ0, ËùÒÔ´Ë´ÎË÷Òý+1  | 
|         PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex, itemIndex + 1)  | 
|       | 
|     #ÉèÖÃÕýÔÚ¸ÄÃûÖÐ...  | 
|     curPlayer.SetDict(ChConfig.Def_Player_Dict_UpdatePlayerName, 1)  | 
|       | 
|     #֪ͨGameServerÕýʽ¸ÄÃû  | 
|     newNameMsg = str([newName, serverID])  | 
|     GameWorld.Log("UpdatePlayerName Í¨ÖªGameServerÕýʽ¸ÄÃûΪ:%s"%newNameMsg, curPlayer.GetID())  | 
|     curPlayer.GameServer_QueryPlayerByID(ChConfig.queryType_UpdatePlayerName, 0, '', newNameMsg, len(newNameMsg))  | 
|     return True  | 
|   | 
|   | 
| ## ÑéÖ¤ÎïÆ·ÊÇ·ñΪ¸ÄÃûÌù  | 
| #  @param curPlayer Íæ¼ÒʵÀý  | 
| #  @param curItem ¸ÄÃûÌù  | 
| #  @return ÊÇ·ñΪ¸ÄÃûÌù  | 
| def __CheckItemUpdatePlayerName(curPlayer, curItem):  | 
|       | 
|     if not ItemCommon.CheckItemCanUse(curItem):  | 
|         return False  | 
|       | 
|     return (curItem.GetType() == ChConfig.Def_ItemType_ChangePlayerName)  | 
|   | 
|   | 
| ## »ñÈ¡½ðÇ®ÏûºÄ  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return: ½ðÇ®ÀàÐÍ, ½ðÇ®ÊýÁ¿  | 
| def GetCostMoney(curPlayer):  | 
|     #¸ÄÃû´ÎÊý(¹«Ê½²ÎÊý)  | 
|     updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt)    | 
|     moneyType, moneyCount = ReadChConfig.GetEvalChConfig("UpdatePlayerNameMoney")  | 
|     return moneyType, eval(moneyCount)  | 
|       | 
| #===============================================================================  | 
| #//01 17 ½ÇÉ«Ãûͬ²½#tagMUpdatePlayerName  | 
| #tagMUpdatePlayerName    * GettagMUpdatePlayerName();  | 
| #  | 
| #class IPY_MUpdatePlayerName  | 
| #{  | 
| #public:  | 
| #  | 
| #      | 
| #    unsigned char      GetNewNameLen();  | 
| #      | 
| #    std::string GetNewName();  | 
| #};  | 
| #===============================================================================  | 
| ## ÊÕµ½GameServer֪ͨ¸ÄÃû  | 
| #  @param index: Íæ¼ÒË÷Òý  | 
| #  @param tick: Ê±¼ä´Á  | 
| #  @return  | 
| def GameServer_UpdatePlayerName(index, tick):  | 
|     curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)  | 
|     curPlayerName = curPlayer.GetName()  | 
|       | 
|     sendPack = IPY_GameWorld.IPY_MUpdatePlayerName()  | 
|     newName = sendPack.GetNewName()  | 
|       | 
|     curPlayer.SetPlayerName(newName)  | 
|     GameWorld.GetPlayerManager().UpdatePlayerNameIndex(curPlayerName, newName)  | 
|     GameWorld.GetMapCopyPlayerManager().UpdatePlayerNameIndex(curPlayerName, newName)  | 
|     #EventReport.WriteEvent_change_name(curPlayer, curPlayerName, newName)  | 
|     GameWorld.Log("UpdatePlayerName MapServer¸ÄÃû³É¹¦, newName = %s"%newName, curPlayer.GetID())  | 
|           | 
|     #֪ͨGameServer½á¹û  | 
|     curPlayer.UpdatePlayerNameResult(True)  | 
|     return True  | 
|   | 
|   | 
| ## ¿Û³ý¸ÄÃûÏûºÄ  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return: None  | 
| def PayUpdatePlayerNameCost(curPlayer):   | 
|     itemIndex = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex) - 1  | 
|     if itemIndex == -1: #-1ÔòĬÈÏ¿ÛÇ®·ñÔò¿ÛµÀ¾ß  | 
|         #¿Û³ýÏûºÄ  | 
|         moneyType, moneyCount = GetCostMoney(curPlayer)  | 
|         PlayerControl.PayMoney(curPlayer, moneyType, moneyCount, ChConfig.Def_Cost_Rename)  | 
|     else:  | 
|         #¿Û³ýÎïÆ·  | 
|         itemPack = curPlayer.GetItemManager().GetPack(IPY_GameWorld.rptItem)  | 
|         curItem = itemPack.GetAt(itemIndex)  | 
|         if curItem:  | 
|             ItemCommon.DelItem(curPlayer, curItem, 1, True, 'UpdatePlayerName')  | 
|       | 
|     #¸ÄÃû´ÎÊý+1  | 
|     #updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt)  | 
|     #PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_UpdatePlayerNameCnt, updatePlayerNameCnt + 1)    | 
|       | 
|     PlayerControl.NomalDictSetProperty(curPlayer, ChConfig.Def_Player_Dict_UpdatePlayerNameItemIndex, 0)  | 
|     return  | 
|   | 
|   | 
| ## Í¨Öª¸ÄÃû´ÎÊý  | 
| #  @param curPlayer: Íæ¼ÒʵÀý  | 
| #  @return: None  | 
| def Sync_UpdatePlayerNameCount(curPlayer):  | 
|     return  | 
|     updatePlayerNameCnt = curPlayer.NomalDictGetProperty(ChConfig.Def_Player_UpdatePlayerNameCnt)  | 
|       | 
|     pack = ChPyNetSendPack.tagUpdatePlayerNameCount()  | 
|     pack.Clear()  | 
|     pack.Count = updatePlayerNameCnt  | 
|     NetPackCommon.SendFakePack(curPlayer, pack)  | 
|     return  |