-- GMךÓÿš
local tbGMCard	= Item:GetClass("gmcard");
tbGMCard.MAX_RECENTPLAYER	= 15;
function tbGMCard:OnUse()
	local nIsHide	= GM.tbGMRole:IsHide();
	
	local tbOpt = {
		{(nIsHide == 1 and "Huy an than") or "Bat dau an than", "GM.tbGMRole:SetHide", 1 - nIsHide},
		{"Reload Script",self.Reload,self};	
		{"Xep hang Danh Vong",self.XepHangDanhVong,self},
		{"Test1",self.Test,self},
		{"TBpet", self.itempet, self},	
		{"Mo Khoa",self.mokhoa,self},
		{"Danh Vong",self.Danhvong,self},
		{"Khong Co Gi"},
	};
	
	Dialog:Say("\n  ¿Í·þͬѧÃÇÐÁ¿àÁË£¡<pic=28>\n\n      ¡«¡«ÎªÈËÃñ·þÎñ<pic=98><pic=98><pic=9  8>", tbOpt);
	
	return 0;
end;
--------------------------------
function tbGMCard:Test()
	local szMsg = "Chon di ku";
	local tbOpt = {
		{"TestMini",self.Test1,self};
		{"Roi Khoi"};
	};
	Dialog:Say(szMsg, tbOpt);
end
-----------------
function tbGMCard:Test1()
me.AddItem(18,1,351,1);		 
end
------------
function tbGMCard:itempet()
me.AddItem(21,9,9,1);		 
end
------
function tbGMCard:mokhoa()
	 me.ClearAccountLock()
end
------------------------------------
function tbGMCard

anhvong()
me.AddRepute(1,1,30000);
me.AddRepute(1,2,30000);
me.AddRepute(1,3,30000);
me.AddRepute(2,1,30000);
me.AddRepute(2,2,30000);
me.AddRepute(2,3,30000);
me.AddRepute(3,1,30000);
me.AddRepute(3,2,30000);
me.AddRepute(3,3,30000);
me.AddRepute(3,4,30000);
me.AddRepute(3,5,30000);
me.AddRepute(3,6,30000);
me.AddRepute(3,7,30000);
me.AddRepute(3,8,30000);
me.AddRepute(3,9,30000);
me.AddRepute(3,10,30000);
me.AddRepute(3,11,30000);
me.AddRepute(3,12,30000);
me.AddRepute(4,1,30000);
me.AddRepute(5,1,30000);
me.AddRepute(5,2,30000);
me.AddRepute(5,3,30000);
me.AddRepute(5,4,30000);
me.AddRepute(5,5,30000);
me.AddRepute(5,6,30000);
me.AddRepute(6,1,30000);
me.AddRepute(6,2,30000);
me.AddRepute(6,3,30000);
me.AddRepute(6,4,30000);
me.AddRepute(6,5,30000);
me.AddRepute(7,1,30000);
me.AddRepute(8,1,30000);
me.AddRepute(9,1,30000);
me.AddRepute(9,2,30000);
me.AddRepute(10,1,30000);
me.AddRepute(11,1,30000);
me.AddRepute(12,1,30000);
end
-------------------------------------
function tbGMCard:BanDongHanh()
	me.AddItem(18,1,547,2);
end
---------------------------------------
function tbGMCard:Reload()
	local nRet1 = DoScript("\\script\\item\\class\\gmcard.lua");
	local nRet2 = DoScript("\\script\\misc\\gm_role.lua");
	local nRet3	= DoScript("\\script\\event\\minievent\\newplayergif  t.lua");
	local nRet3	= DoScript("\\script\\misc\\gm.lua");
	GCExcute({"DoScript", "\\script\\misc\\gm_role.lua"});
	DoScript("\\script\\event\\minievent\\daygift.lua"  );
	DoScript("\\script\\factionelect\\factionelect_gs.  lua");
	local szMsg	= "Reloaded!!("..nRet1..","..nRet2..","..nRet3..GetL  ocalDate(") %Y-%m-%d %H:%M:%S");
	me.Msg(szMsg);
	print(szMsg);
end
-----------------------------------------
function tbGMCard:XepHangDanhVong()
    GCExcute({"PlayerHonor:UpdateWuLinHonorLadder"});
    GCExcute({"PlayerHonor:UpdateMoneyHonorLadder"});
    GCExcute({"PlayerHonor:UpdateLeaderHonorLadder"});
    KGblTask.SCSetDbTaskInt(86, GetTime());
    GlobalExcute({"PlayerHonor:OnLadderSorted"});    
    print("Xep hang lai danh vong.");
end
-------------------------------------
function tbGMCard:channguyen()
	me.AddItem(1,1,24,1);
	me.AddItem(1,1,24,2);
	me.AddItem(1,1,24,3);
	me.AddItem(1,1,24,4);
	me.AddItem(1,1,24,5);	
	me.AddItem(1,1,24,6);
	me.AddItem(1,1,24,7);	
end
--------------------------------------
function tbGMCard:SuperQinling()
	me.NewWorld(1536, 1567, 3629);
	me.SetTask(2098, 1, 0);
	me.AddSkillState(1413, 4, 1, 2 * 60 * 60 * Env.GAME_FPS, 1, 1);
end
function tbGMCard:Reload()
	local nRet1	= DoScript("\\script\\item\\class\\gmcard.lua");
	local nRet2	= DoScript("\\script\\misc\\gm_role.lua");
	GCExcute({"DoScript", "\\script\\misc\\gm_role.lua"});
	local szMsg	= "Reloaded!!("..nRet1..","..nRet2..GetLocalDate  (") %Y-%m-%d %H:%M:%S");
	me.Msg(szMsg);
	print(szMsg);
end
function tbGMCard:AskRoleName()
	Dialog:AskString("ÍæŒÒœÇÉ«Ãû", 16, self.OnInputRoleName, self);
end
function tbGMCard:OnInputRoleName(szRoleName)
	local nPlayerId	= KGCPlayer.GetPlayerIdByName(szRoleName);
	if (not nPlayerId) then
		Dialog:Say("ŽËœÇÉ«Ãû²»ŽæÔÚ£¡", {"ÖØÐÂÊäÈë", self.AskRoleName, self}, {"œáÊø¶Ô»°"});
		return;
	end
	
	self:ViewPlayer(nPlayerId);
end
function tbGMCard:ViewPlayer(nPlayerId)
	-- ²åÈë×îœüÍæŒÒÁбí
	local tbRecentPlayerList	= self.tbRecentPlayerList or {};
	self.tbRecentPlayerList		= tbRecentPlayerList;
	for nIndex, nRecentPlayerId in ipairs(tbRecentPlayerList) do
		if (nRecentPlayerId == nPlayerId) then
			table.remove(tbRecentPlayerList, nIndex);
			break;
		end
	end
	if (#tbRecentPlayerList >= self.MAX_RECENTPLAYER) then
		table.remove(tbRecentPlayerList);
	end
	table.insert(tbRecentPlayerList, 1, nPlayerId);
	local szName	= KGCPlayer.GetPlayerName(nPlayerId);
	local tbInfo	= GetPlayerInfoForLadderGC(szName);
	local tbState	= {
		[0]		= "²»ÔÚÏß",
		[-1]	= "ŽŠÀíÖÐ",
		[-2]	= "¹Ò»ú£¿",
	};
	local nState	= KGCPlayer.OptGetTask(nPlayerId, KGCPlayer.TSK_ONLINESERVER);
	local tbText	= {
		{"Ãû×Ö", szName},
		{"Õ˺Å", tbInfo.szAccount},
		{"µÈŒ¶", tbInfo.nLevel},
		{"ÐÔ±ð", (tbInfo.nSex == 1 and "Å®") or "ÄÐ"},
		{"·Ïß", Player:GetFactionRouteName(tbInfo.nFaction, tbInfo.nRoute)},
		{"ŒÒ×å", tbInfo.szKinName},
		{"°ï»á", tbInfo.szTongName},
		{"ÍþÍû", KGCPlayer.GetPlayerPrestige(nPlayerId)},
		{"׎̬", (tbState[nState] or "<color=green>ÔÚÏß<color>") .. "("..nState..")"},
	}
	local szMsg	= "";
	for _, tb in ipairs(tbText) do
		szMsg	= szMsg .. "\n  " .. Lib:StrFillL(tb[1], 6) .. tostring(tb[2]);
	end
	local szButtonColor	= (nState > 0 and "") or "<color=gray>";
	local tbOpt = {
		{szButtonColor.."ÀËû¹ýÀŽ", "GM.tbGMRole:CallHimHere", nPlayerId},
		{szButtonColor.."ËÍÎÒ¹ýÈ¥", "GM.tbGMRole:SendMeThere", nPlayerId},
		{szButtonColor.."ÌßËûÏÂÏß", "GM.tbGMRole:KickHim", nPlayerId},
		{"¹ØÈëÌìÀÎ", "GM.tbGMRole:ArrestHim", nPlayerId},
		{"œâ³ýÌìÀÎ", "GM.tbGMRole:FreeHim", nPlayerId},
		{"·¢ËÍÓÊŒþ", self.SendMail, self, nPlayerId},
		{"œáÊø¶Ô»°"},
	};
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:RecentPlayer()
	local tbOpt	= {};
	for nIndex, nPlayerId in ipairs(self.tbRecentPlayerList or {}) do
		local szName	= KGCPlayer.GetPlayerName(nPlayerId);
		local nState	= KGCPlayer.OptGetTask(nPlayerId, KGCPlayer.TSK_ONLINESERVER);
		tbOpt[#tbOpt+1]	= {((nState > 0 and "<color=green>") or "")..szName, self.ViewPlayer, self, nPlayerId};
	end
	tbOpt[#tbOpt + 1]	= {"œáÊø¶Ô»°"};
	
	Dialog:Say("ÇëÑ¡ÔñÐèÒªµÄÍæŒÒ£º", tbOpt);
end
function tbGMCard:AroundPlayer()
	local tbPlayer	= {};
	local _, nMyMapX, nMyMapY	= me.GetWorldPos();
	for _, pPlayer in ipairs(KPlayer.GetAroundPlayerList(me.nId, 50)) do
		if (pPlayer.szName ~= me.szName) then
			local _, nMapX, nMapY	= pPlayer.GetWorldPos();
			local nDistance	= (nMapX - nMyMapX) ^ 2 + (nMapY - nMyMapY) ^ 2;
			tbPlayer[#tbPlayer+1]	= {nDistance, pPlayer};
		end
	end
	local function fnLess(tb1, tb2)
		return tb1[1] < tb2[1];
	end
	table.sort(tbPlayer, fnLess);
	local tbOpt	= {};
	for _, tb in ipairs(tbPlayer) do
		local pPlayer	= tb[2];
		tbOpt[#tbOpt+1]	= {pPlayer.szName, self.ViewPlayer, self, pPlayer.nId};
		if (#tbOpt >= 8) then
			break;
		end
	end
	tbOpt[#tbOpt + 1]	= {"œáÊø¶Ô»°"};
	
	Dialog:Say("ÇëÑ¡ÔñÐèÒªµÄÍæŒÒ£º", tbOpt);
end
function tbGMCard:AdjustLevel()
	local nMaxLevel	= GM.tbGMRole:GetMaxAdjustLevel();
	Dialog:AskNumber("ÆÚÍûµÈŒ¶(1~"..nMaxLevel.  .")", nMaxLevel, "GM.tbGMRole:AdjustLevel");
end
function tbGMCard:SendMail(nPlayerId)
	Dialog:AskString("ÓÊŒþÄÚÈÝ", 500, "GM.tbGMRole:SendMail", nPlayerId);
end
function tbGMCard:LookGlbBattle()
	if not GLOBAL_AGENT then
		local szMsg = "¿ç·þŸºŒŒŒÇÕßÈë¿Ú<pic=98><pic=98><  pic=98>";
		local tbOpt = {
			{"œøÈëÓ¢ÐÛµº", self.EnterGlobalServer, self},
			{"¿ç·þ°×»¢ÌÃ", self.LookKuaFuBaiHu, self},
			{"ÏȵȵÈ"}};
		Dialog:Say(szMsg, tbOpt);
		return 0;
	end
	local szMsg = "¿ç·þŸºŒŒŒÇÕßÈë¿Ú<pic=98><pic=98><  pic=98>";
	local tbOpt = {
			{"·µ»ØÓ¢ÐÛµº", self.ReturnGlobalServer, self},
			{"·µ»ØÁÙ°²ž®", self.ReturnMyServer, self},
			{"¹Û¿ŽÎäÁÖŽó»áŸöÈü", self.LookWldh, self},
			{"¹Û¿ŽÌúž¡³ÇÕœ", self.LookXkland, self},
			{"¿ç·þ°×»¢ÌÃ", self.LookKuaFuBaiHu, self},
			{"ÏȵȵÈ"},
		};
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:LookWldh()
	local szMsg = "¿ç·þŸºŒŒŒÇÕßÈë¿Ú<pic=98><pic=98><  pic=98>";
	local tbOpt = {
			{"¹Û¿Žµ¥ÈËÈüŸöÈü", self.Wldh_SelectFaction, self},
			{"¹Û¿ŽË«ÈËÈüŸöÈü", self.Wldh_SelectVsState, self, 2, 1},
			{"¹Û¿ŽÈýÈËÈüŸöÈü", self.Wldh_SelectVsState, self, 3, 1},
			{"¹Û¿ŽÎåÈËÈüŸöÈü", self.Wldh_SelectVsState, self, 4, 1},
			{"¹Û¿ŽÍÅÌåÈüŸöÈü", self.Wldh_SelectBattleVsState, self},
			{"ÏȵȵÈ"},
		};
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:ReturnMyServer()
	me.GlobalTransfer(29, 1694, 4037);
end
function tbGMCard:Wldh_SelectBattleVsState()
	local szMsg = "";
	local tbOpt = {
		{"¹ÚŸüÍÅÌåÈü³¡£šœð·œ£©", self.Wldh_EnterBattleMap, self, 1, 1},
		{"¹ÚŸüÍÅÌåÈü³¡£šËηœ£©", self.Wldh_EnterBattleMap, self, 1, 2},
		{"ËÄÇ¿ÍÅÌåÈü³¡£šœðÒ»£©", self.Wldh_EnterBattleMap, self, 1, 1},
		{"ËÄÇ¿ÍÅÌåÈü³¡£šËÎÒ»£©", self.Wldh_EnterBattleMap, self, 1, 2},
		{"ËÄÇ¿ÍÅÌåÈü³¡£šœð¶þ£©", self.Wldh_EnterBattleMap, self, 2, 1},
		{"ËÄÇ¿ÍÅÌåÈü³¡£šËζþ£©", self.Wldh_EnterBattleMap, self, 2, 2},
		{"·µ»ØÉϲã", self.LookWldh, self},
		{"œáÊø¶Ô»°"},		
	};
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:Wldh_EnterBattleMap(nAreaId, nCamp)
	local tbMap = {
		[1] = 1631,
		[2] = 1632,
	};
	local tbPos = {
		[1] = {1767, 2977},
		[2] = {1547, 3512},
	};	
	local nMapId = tbMap[nAreaId];
	
	me.NewWorld(nMapId, unpack(tbPos[nCamp]));
end
function tbGMCard:Wldh_SelectFaction()
	local szMsg = "ÇëÑ¡ÔñÄãÏëÒª¹ÛÕœµÄÃÅÅÉ£¿"  ;
	local tbOpt = {};
	for i=1, 12  do
		table.insert(tbOpt, {Player:GetFactionRouteName(i).."ŸöÈü", self.Wldh_SelectVsState, self, 1, i});
	end
	table.insert(tbOpt, {"·µ»ØÉϲã", self.LookWldh, self});
	table.insert(tbOpt, {"ÎÒÔÙ¿ŒÂÇ¿ŒÂÇ"});
	Dialog:Say(szMsg, tbOpt);	
end
function tbGMCard:Wldh_SelectVsState(nType, nReadyId)
	local szMsg = "ÇëÑ¡ÔñÄãÏëÒª¹ÛÕœµÄÈüÊ£¿"  ;
	local tbOpt = {
		{"¹ÚŸüÈü³¡", self.Wldh_SelectPkMap, self, nType, nReadyId, 1},
		{"ËÄÇ¿Èü³¡", self.Wldh_SelectPkMap, self, nType, nReadyId, 2},
		{"°ËÇ¿Èü³¡", self.Wldh_SelectPkMap, self, nType, nReadyId, 4},
		{"Ê®ÁùÇ¿Èü³¡", self.Wldh_SelectPkMap, self, nType, nReadyId, 8},
		{"ÈýÊ®¶þÇ¿Èü³¡", self.Wldh_SelectPkMap, self, nType, nReadyId, 16},
		{"·µ»ØÉϲã", self.LookWldh, self},
		{"œáÊø¶Ô»°"},
		};
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:Wldh_SelectPkMap(nType, nReadyId, nMapCount)
	local szMsg = "ÇëÑ¡ÔñÄãÏëÒª¹ÛÕœµÄÈü³¡£¿"  ;
	local tbOpt = {};
	for i=1, nMapCount do
		local szSelect = string.format("Èü³¡£š%s£©", i);
		table.insert(tbOpt, {szSelect, self.Wldh_EnterPkMap, self, nType, nReadyId, i});
	end
	table.insert(tbOpt, {"·µ»ØÉϲã", self.LookWldh, self});
	table.insert(tbOpt, {"ÎÒÔÙ¿ŒÂÇ¿ŒÂÇ"});	
	Dialog:Say(szMsg, tbOpt);	
end
function tbGMCard:Wldh_EnterPkMap(nType, nReadyId, nAearId)
	local nMapId = Wldh:GetMapMacthTable(nType)[nReadyId];
	local nPosX, nPosY = unpack(Wldh:GetMapPKPosTable(nType)[nAearId]);
	me.NewWorld(nMapId, nPosX, nPosY);
end
function tbGMCard:EnterGlobalServer()
	Transfer:NewWorld2GlobalMap(me);
end
function tbGMCard:ReturnGlobalServer()
	Transfer:NewWorld2GlobalMap(me);
end
function tbGMCard:LookXkland(nFrom)
	
	if Newland:GetWarState() == Newland.WAR_END then
		Dialog:Say("Ìúž¡³ÇÕù¶áÕœÉÐÎŽ¿ªÊ  Œ£¬ÇëœìʱÔÙÀŽ¡£<enter><color=gold>�  �êÇé°ŽF12-ÏêÏž°ïÖú-¿ç·þ³ÇÕœ²éѯ<color>");
		return 0;
	end
	
	local tbOpt = {};
	local szMsg = "ÇëÑ¡ÔñÒª¹ÛÕœµÄ°ï»á£¿";
	local nCount = 8;
	local nLast = nFrom or 1;
	for i = nLast, #Newland.tbGroupBuffer do
		table.insert(tbOpt, {Newland.tbGroupBuffer[i].szTongName, self.SelectLookTong, self, i});
		nCount = nCount - 1;
		nLast = nLast + 1;
		if nCount <= 0 then
			table.insert(tbOpt, {"ÏÂÒ»Ò³", self.LookXkland, self, nLast});
			break;
		end	
	end
	
	table.insert(tbOpt, {"ÎÒÖªµÀÁË"});
	Dialog:Say(szMsg, tbOpt);
end
function tbGMCard:SelectLookTong(nGroupIndex)
	local nMapId = Newland:GetLevelMapIdByIndex(nGroupIndex, 1);
	local tbTree = Newland:GetMapTreeByIndex(nGroupIndex);
	if nMapId and tbTree then
		local nMapX, nMapY = unpack(Newland.REVIVAL_LIST[tbTree[0]]);
		me.SetTask(Newland.TASK_GID, Newland.TASK_GROUP_INDEX, nGroupIndex);
		me.NewWorld(nMapId, nMapX, nMapY);
	end
end
-------------¿ç·þ°×»¢ŒÇÕß--------------------------
function tbGMCard:LookKuaFuBaiHu()
	local szMsg = "ÇëÑ¡ÔñҪȥµÄ³¡µØ?"
	local tbOpt = {};
	tbOpt[1] = {"œøÈë׌±ž³¡",self.LookKuaFuBaiHuWaitMap  ,self};
	tbOpt[2] = {"œøÈëÕœ¶·³¡",self.LookKuaFuBaiHuFightMa  p,self};
	tbOpt[3] = {"œáÊø¶Ô»°"};
	Dialog:Say(szMsg,tbOpt);
end
function tbGMCard:LookKuaFuBaiHuWaitMap()
	local szMsg = "ÇëÑ¡ÔñҪȥŒžºÅ׌±ž³¡?"
	local tbOpt = {};
	local nIndex = 1;
	for nTbIndex,tbWaitMap in ipairs(KuaFuBaiHu.tbWaitMapIdList) do
		for nMapIndex,nMapId in ipairs(tbWaitMap) do
			local szInfo = string.format("%dºÅ׌±ž³¡",nIndex)
			table.insert(tbOpt,{szInfo,self.TransferBaiHuWaitM  ap,self,nTbIndex,nMapIndex});
			nIndex = nIndex + 1;
		end
	end
	tbOpt[#tbOpt + 1] = {"·µ»ØÉÏÒ»²ã",self.LookKuaFuBaiHu,sel  f}
	tbOpt[#tbOpt + 1] = {"œáÊø¶Ô»°"}
	Dialog:Say(szMsg,tbOpt);
end
function tbGMCard:LookKuaFuBaiHuFightMap()
	local szMsg = "ÇëÑ¡ÔñҪȥŒžºÅÕœ¶·³¡?"
	local tbOpt = {};
	local nIndex = 1;
	for nTbIndex,tbWaitMap in ipairs(KuaFuBaiHu.tbFightMapIdList) do
		for nMapIndex,nMapId in ipairs(tbWaitMap) do
			local szInfo = string.format("%dºÅÕœ¶·³¡",nIndex)
			table.insert(tbOpt,{szInfo,self.TransferBaiHuFight  Map,self,nTbIndex,nMapIndex});
			nIndex = nIndex + 1;
		end
	end
	tbOpt[#tbOpt + 1] = {"·µ»ØÉÏÒ»²ã",self.LookKuaFuBaiHu,sel  f}
	tbOpt[#tbOpt + 1] = {"œáÊø¶Ô»°"}
	Dialog:Say(szMsg,tbOpt);
end
function tbGMCard:TransferBaiHuWaitMap(nTbIndex,nIndex)
	local nMapId = KuaFuBaiHu.tbWaitMapIdList[nTbIndex][nIndex];
	local tbPos = KuaFuBaiHu.tbWaitMapPos[MathRandom(#KuaFuBaiHu.tbWaitMapPos)];
	if not nMapId then
		return 0;
	end
	if GLOBAL_AGENT then	
		local nCanSure = Map:CheckTagServerPlayerCount(nMapId);
		if nCanSure < 0 then
			me.Msg("ǰ·œµÀ·²»Íš¡£","ϵͳÌ�  �ÊŸ");
			return 0;
		end		
		me.NewWorld(nMapId, tbPos.nX/32, tbPos.nY/32);	
	else
		local nCanSure = Map:CheckGlobalPlayerCount(nMapId);
		if nCanSure < 0 then
			me.Msg("ǰ·œµÀ·²»Íš¡£","ϵͳÌ�  �ÊŸ");
			return 0;
		end
		me.GlobalTransfer(nMapId, tbPos.nX / 32, tbPos.nY /32);			
	end
end
function tbGMCard:TransferBaiHuFightMap(nTbIndex,nIndex)
	local nMapId = KuaFuBaiHu.tbFightMapIdList[nTbIndex][nIndex];
	local tbPos = KuaFuBaiHu.tbEnterPos[MathRandom(#KuaFuBaiHu.tbEnterPos)];
	if not nMapId then
		return 0;
	end
	if GLOBAL_AGENT then
		local nCanSure = Map:CheckTagServerPlayerCount(nMapId);
		if nCanSure < 0 then
			me.Msg("ǰ·œµÀ·²»Íš¡£","ϵͳÌ�  �ÊŸ");
			return 0;
		end		
		me.NewWorld(nMapId, tbPos.nX/32, tbPos.nY/32);	
	else
		local nCanSure = Map:CheckGlobalPlayerCount(nMapId);
		if nCanSure < 0 then
			me.Msg("ǰ·œµÀ·²»Íš¡£","ϵͳÌ�  �ÊŸ");
			return 0;
		end
		me.GlobalTransfer(nMapId, tbPos.nX / 32, tbPos.nY /32);			
	end
end