BATTLE_GROUND_COLUMN_LIST ={}; BATTLE_GROUND_QUEUE_COUNTER = 0; BATTLE_GROUND_QUEUE_COLUMN_NUM ={}; BATTLE_GROUND_QUEUE_STATUS ={}; IS_ALLOW_JOIN_BG_WITH_TEAM = {}; IS_LEADER_SELF_JOIN_BG = 0; IS_TEAM_JOIN_BG = 0; BG_SELECT_COLUMN_NUM = 0; BATTLE_GROUND_QUEUE_LIST_TYPE = 0; BATTLE_GROUND_QUEUE_Frame_OPEN_FLAG = 0; BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS = {}; BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG = 0; BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER = 11; function QueueChildFrameBattleGroundName_OnShow(this) BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG = 0; BattleGroundGroupJoinQueueButton:Disable(); for i=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do getglobal("BattleGroundQueueFrameChildFrame"..i.."ColumnSelectColumn"):Hide(); BATTLE_GROUND_QUEUE_STATUS[i] = 0; end if(BATTLE_GROUND_QUEUE_COUNTER > 0)then BG_SELECT_COLUMN_NUM = 1; getglobal("BattleGroundQueueFrameChildFrame1ColumnSelectColumn"):Show();--選擇第一列 else BattleGroundPersonalJoinQueueButton:Disable(); end BATTLE_GROUND_QUEUE_Frame_OPEN_FLAG = 1; GetBattleGroundResultType();--要求Zone送出戰場訊息,以便取得戰場列表 BattleGroundQueueScrollFrame:UpdateScrollChildRect(); BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; end function JoinQueueButtonWithPersonal_OnClick(this) --個人加入佇列按鈕 if((BG_SELECT_COLUMN_NUM > 0) and (BATTLE_GROUND_COLUMN_LIST[BG_SELECT_COLUMN_NUM] ~= nil) and (GetBattleGroundType() <= 0) and (BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[BG_SELECT_COLUMN_NUM] >= 4))then JoinBattleGround(BATTLE_GROUND_COLUMN_LIST[BG_SELECT_COLUMN_NUM]); end end function JoinQueueButtonWithTeam_OnClick(this) --團隊加入佇列按鈕 if((GetBattleGroundType() <= 0) and (BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[BG_SELECT_COLUMN_NUM] >= 4)) then if(BATTLE_GROUND_COLUMN_LIST[BG_SELECT_COLUMN_NUM] ~= nil) then JoinBattleGroundWithTeam(BATTLE_GROUND_COLUMN_LIST[BG_SELECT_COLUMN_NUM]); end end end function CloseQueueFrame_OnClick(this) --關閉戰場即時排隊介面按鈕 BattleGroundQueueFrame:Hide(); end function EnterBattleGroundFrame_OnClick(this) --進入戰場按鈕 if(BATTLE_GROUND_COLUMN_LIST[this:GetID()] ~= nil) then EnterBattleGround(BATTLE_GROUND_COLUMN_LIST[this:GetID()]); end if(GetBattleGroundType() <= 0)then BGQueueButtonAndColumnStatus(this:GetID(),1); BATTLE_GROUND_QUEUE_STATUS[this:GetID()] = 0; end end function LeaveQueue_OnClick(this) --離開佇列按鈕 if(BATTLE_GROUND_COLUMN_LIST[this:GetID()] ~= nil) then LeaveBattleGroundWaitQueue(BATTLE_GROUND_COLUMN_LIST[this:GetID()]); BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[this:GetID()] = 0; BGQueueButtonAndColumnStatus(this:GetID(),2); BATTLE_GROUND_QUEUE_STATUS[this:GetID()] = 0; end end function LeaveBattleGround_OnClick(this) --離開戰場按鈕 LeaveBattleGround(); BattleGroundQueueFrame:Hide(); BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[this:GetID()] = 5; BGQueueButtonAndColumnStatus(this:GetID(),2); BATTLE_GROUND_QUEUE_STATUS[this:GetID()] = 0; end function SelectBGQueueList_OnClick(this) --點選戰場列 BG_SELECT_COLUMN_NUM = this:GetID(); for i=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do if(i == this:GetID()) then getglobal("BattleGroundQueueFrameChildFrame"..i.."ColumnSelectColumn"):Show(); else getglobal("BattleGroundQueueFrameChildFrame"..i.."ColumnSelectColumn"):Hide(); end end end function BattleGroundQueueFrame_OnLoad(this) this:RegisterEvent("UPDATE_QUEUE_FRAME_INFO"); this:RegisterEvent("CLEAR_ALL_QUEUE_STATUS"); this:RegisterEvent("GOT_BATTLE_GROUND_QUEUE_RESULT"); this:RegisterEvent( "ZONE_CHANGED" ); this:RegisterEvent( "UNIT_CLASS_CHANGED" ); GetBattleGroundResultType();--要求Zone送出戰場訊息,以便取得戰場列表 for i=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] = 5; end end function BattleGroundQueueUpdate_OnEvent(this,event) --************************************************************************************************************************************************************** if(event == "ZONE_CHANGED") then BattleGroundQueueFrame:Hide(); end --************************************************************************************************************************************************************ if(event == "GOT_BATTLE_GROUND_QUEUE_RESULT") then --取得戰場列表 BattleGroundQueue_GetListResult(); end --**************************************************************************************************************************************************** if(event == "UPDATE_QUEUE_FRAME_INFO") then --接收戰場封包訊息 local iType, iQueueStatus, iTimeExcepted, iTimeToLeaveQueue, iIsLeader = UpdateQueueFrameInfo(); local iqueuecount; local countnum = 0; IS_LEADER_SELF_JOIN_BG = iIsLeader; IS_TEAM_JOIN_BG = iIsTeam; --////////////////////////////////////////////////////////////////////////////////////////// if(BattleGroundQueueFrame:IsVisible()) then BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER + 1; if(BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER == 44) then BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG = 0; GetBattleGroundResultType();--要求Zone送出戰場訊息,以便取得戰場列表 BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; end local doubleBATTLE_GROUND_QUEUE_COUNTER = BATTLE_GROUND_QUEUE_COUNTER + BATTLE_GROUND_QUEUE_COUNTER; if((BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG ~= BATTLE_GROUND_QUEUE_COUNTER) and (BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER == doubleBATTLE_GROUND_QUEUE_COUNTER))then Clear_BattleGroundQueue_List_Info();--清除戰場列表,重新取得戰場列表 end end --/////////////////////////////////////////////////////////////////////////////////////////// if((iType ~= 0) and (BATTLE_GROUND_QUEUE_COLUMN_NUM[iType] ~= nil)) then iqueuecount = BATTLE_GROUND_QUEUE_COLUMN_NUM[iType]; BATTLE_GROUND_QUEUE_STATUS[iqueuecount] = iQueueStatus; iTimeExcepted = iTimeExcepted / 1000; TimeExcepted = iTimeExcepted / 60; if(iTimeExcepted >= 60) then local time = TimeExcepted; else local time = iTimeExcepted; end if(iTimeExcepted == 0) then time = "?"; end childframename="BattleGroundQueueFrameChildFrame"..iqueuecount.."Column"; if(iqueuecount > 0) then if(BATTLE_GROUND_QUEUE_STATUS[iqueuecount] == 1) then--In Queue getglobal(childframename.."BattleGroundQueueState"):SetText(BATTLEGROUNDSTATUS_IN_QUEUE_WAIT_ENTER); getglobal(childframename.."BattleGroundQueueTime"):SetText(EXCEPT_ENTER_BATTLE_GROUND_TIME.." "..time); BGQueueButtonAndColumnStatus(iqueuecount,3); end if(BATTLE_GROUND_QUEUE_STATUS[iqueuecount] == 2 or BATTLE_GROUND_QUEUE_STATUS[iqueuecount] == 3) then--Got Ticket getglobal(childframename.."BattleGroundQueueState"):SetText(BATTLEGROUNDSTATUS_GOT_TICKET_WAIT_ENTER); getglobal(childframename.."BattleGroundQueueTime"):SetText(LEAVE_QUEUE_BATTLE_GROUND_TIME.." "..iTimeToLeaveQueue); BGQueueButtonAndColumnStatus(iqueuecount,4); if(iTimeToLeaveQueue <= 0.5) then BATTLE_GROUND_QUEUE_STATUS[iqueuecount] = 0; end end for i=1,BATTLE_GROUND_QUEUE_COUNTER do if(BATTLE_GROUND_COLUMN_LIST[i] == GetBattleGroundType()) then --正在戰場中,改變成離開戰場的按鈕 BGQueueButtonAndColumnStatus(i,1); BATTLE_GROUND_QUEUE_STATUS[i] = 0; BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; end if(BATTLE_GROUND_COLUMN_LIST[i] ~= GetBattleGroundType()) then --不在戰場或不在本欄位的戰場 if(BATTLE_GROUND_QUEUE_STATUS[i] == 0)then--不在佇列或得到ticket中 BGQueueButtonAndColumnStatus(i,2);--應變成進入佇列按鈕 if(BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] < 4) then BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] = BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] + 1 ;--延遲兩秒才可再加入 end end end end iqueuecount = 0; end end end --***************************************************************************************************************************************************** if(event == "CLEAR_ALL_QUEUE_STATUS") then --無戰場封包訊息時 local iType, iQueueStatus, iTimeExcepted, iTimeToLeaveQueue, iIsLeader = UpdateQueueFrameInfo(); IS_LEADER_SELF_JOIN_BG = iIsLeader; BATTLE_GROUND_INQUEUE_NUMBER = 0; --//////////////////////////////////////////////////////////////////////////// if(BattleGroundQueueFrame:IsVisible()) then BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER + 1; if(BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER == 40) then --20秒再取得列表一次 BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG = 0; GetBattleGroundResultType();--要求Zone送出戰場訊息,以便取得戰場列表 BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; end if((BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG ~= BATTLE_GROUND_QUEUE_COUNTER) and (BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER == 2))then Clear_BattleGroundQueue_List_Info();--清除戰場列表,重新取得戰場列表 end end --////////////////////////////////////////////////////////////////////////////// for i=1,BATTLE_GROUND_QUEUE_COUNTER do if(BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] < 4) then BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] = BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[i] + 1 ;--延遲兩秒才可再加入佇列 end if(BATTLE_GROUND_COLUMN_LIST[i] == GetBattleGroundType()) then --正在戰場中 BGQueueButtonAndColumnStatus(i,1);--改變成離開戰場的按鈕 BATTLE_GROUND_QUEUE_STATUS[i] = 0; BATTLE_GROUND_QUEUE_FRAME_TIME_COUNTER = 0; end if(GetBattleGroundType() == 0) then--不在戰場 BGQueueButtonAndColumnStatus(i,2);--變成加入佇列按鈕 end end if((BATTLE_GROUND_QUEUE_LIST_TYPE == 0) and (BATTLE_GROUND_QUEUE_Frame_OPEN_FLAG == 1)) then StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"] = {}; StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].text = TEXT("BATTLE_GROUND_IS_NOT_OPENED"); StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].button1 = TEXT("OKAY"); StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].OnAccept = OnClick_BattleGroundNOOpen; StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].OnCancel = OnClick_BattleGroundNOOpen; StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].timeout = 0; StaticPopupDialogs["BATTLE_GROUND_NO_OPEN_TIP"].hideOnEscape = 1; StaticPopup_Show( "BATTLE_GROUND_NO_OPEN_TIP" ); BATTLE_GROUND_QUEUE_Frame_OPEN_FLAG = 0; end end if(event == "UNIT_CLASS_CHANGED") then--當改變主副職時 if ( arg1 == "player" ) then local leave = 0; local mainClass, subClass = UnitClass("player"); if( this.mainClass ~= mainClass ) then this.mainClass = mainClass; leave = 1; end if( this.subClass ~= subClass ) then this.subClass = subClass; leave = 1; end if( leave == 1 ) then Leave_All_Battle_Ground_Queue(); end end end end --**********************改變按鍵*********************----------------------------------- function BGQueueButtonAndColumnStatus(col,type) childframename="BattleGroundQueueFrameChildFrame"..col.."Column"; leavequeuebutton = getglobal(childframename.."BattleGroundLeaveQueueButton"); enterBGbutton = getglobal(childframename.."EnterBattleGroundButton"); leaveBGbutton = getglobal(childframename.."LeaveBattleGroundButton"); queuestate = getglobal(childframename.."BattleGroundQueueState"); queuetime = getglobal(childframename.."BattleGroundQueueTime"); if(type == 1) then queuestate:SetText(""); queuetime:SetText(""); end if(type == 2) then queuestate:SetText(""); queuetime:SetText(""); if(GetBattleGroundType() <= 0) then if((BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] == 0) or (BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] == 1))then queuetime:SetText( BATTLE_GROUND_LEAVE_QUEUE.." ".."2" ); end if((BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] == 2) or (BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] == 3)) then queuetime:SetText( BATTLE_GROUND_LEAVE_QUEUE.." ".."1" ); end if(BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] == 4) then queuetime:SetText(""); end end end if(type == 1) then--離開戰場 leavequeuebutton:Hide(); enterBGbutton:Hide(); leaveBGbutton:Show(); if(col == BG_SELECT_COLUMN_NUM) then BattleGroundPersonalJoinQueueButton:Disable(); BattleGroundGroupJoinQueueButton:Disable(); end elseif(type == 2) then--加入佇列 enterBGbutton:Hide(); leaveBGbutton:Hide(); leavequeuebutton:Hide(); if((col == BG_SELECT_COLUMN_NUM) and (GetBattleGroundType() <= 0)) then --延遲兩秒才可再加入佇列 if(BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] >= 4)then BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[col] = 5; BattleGroundPersonalJoinQueueButton:Enable(); --判斷戰場需要團隊加入,而且本身是隊長 if((IS_ALLOW_JOIN_BG_WITH_TEAM[BG_SELECT_COLUMN_NUM] == 1) and (IS_LEADER_SELF_JOIN_BG == 1))then BattleGroundGroupJoinQueueButton:Enable(); else BattleGroundGroupJoinQueueButton:Disable(); end end end elseif(type == 3) then--離開佇列 enterBGbutton:Hide(); leaveBGbutton:Hide(); leavequeuebutton:Show(); if(col == BG_SELECT_COLUMN_NUM) then BattleGroundPersonalJoinQueueButton:Disable(); BattleGroundGroupJoinQueueButton:Disable(); end elseif(type == 4) then--進入戰場 leavequeuebutton:Hide(); leaveBGbutton:Hide(); enterBGbutton:Show(); if(col == BG_SELECT_COLUMN_NUM) then BattleGroundPersonalJoinQueueButton:Disable(); BattleGroundGroupJoinQueueButton:Disable(); end end end function ShowBGQueueListSelect_OnEnter(this) local i; i = this:GetID(); if(i > 0)then getglobal("BattleGroundQueueFrameChildFrame"..i.."ColumnSelectColumn"):Show(); end end function HideBGQueueListSelect_OnLeave(this) for j=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do if(BG_SELECT_COLUMN_NUM ~= j) then getglobal("BattleGroundQueueFrameChildFrame"..j.."ColumnSelectColumn"):Hide(); end end end function OnClick_BattleGroundNOOpen(this) BattleGroundQueueFrame:Hide(); end function BattleGroundQueue_GetListResult() local col,IsAllowJoinWithTeam,IsLeaderSelf = ReturnBattleGroundType(); local isRepeat; if(col > 400) then IS_LEADER_SELF_JOIN_BG = IsLeaderSelf; BATTLE_GROUND_QUEUE_LIST_TYPE = col; isRepeat = 0; if(col ~= 0)then for BGi=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do if(BATTLE_GROUND_COLUMN_LIST[BGi] ~= col) then isRepeat = isRepeat +1; end if( isRepeat == BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER) then BATTLE_GROUND_QUEUE_COUNTER = BATTLE_GROUND_QUEUE_COUNTER+1; BATTLE_GROUND_COLUMN_LIST[BATTLE_GROUND_QUEUE_COUNTER] = col; IS_ALLOW_JOIN_BG_WITH_TEAM[BATTLE_GROUND_QUEUE_COUNTER] = IsAllowJoinWithTeam;--是否團隊加入的戰場 childframename="BattleGroundQueueFrameChildFrame"..BATTLE_GROUND_QUEUE_COUNTER.."Column"; if(GetBattleGroundName(col) ~= nil)then getglobal(childframename.."BattleGroundQueueName"):SetText(GetBattleGroundName(col)); end getglobal(childframename.."LeaveBattleGroundButton"):SetID(BATTLE_GROUND_QUEUE_COUNTER); getglobal(childframename.."BattleGroundLeaveQueueButton"):SetID(BATTLE_GROUND_QUEUE_COUNTER); getglobal(childframename.."EnterBattleGroundButton"):SetID(BATTLE_GROUND_QUEUE_COUNTER); getglobal("BattleGroundQueueFrameChildFrame"..BATTLE_GROUND_QUEUE_COUNTER.."Column"):SetID(BATTLE_GROUND_QUEUE_COUNTER); leavequeuebutton = getglobal(childframename.."BattleGroundLeaveQueueButton"); enterBGbutton = getglobal(childframename.."EnterBattleGroundButton"); leaveBGbutton = getglobal(childframename.."LeaveBattleGroundButton"); BATTLE_GROUND_QUEUE_COLUMN_NUM[col] = BATTLE_GROUND_QUEUE_COUNTER; end end if(BATTLE_GROUND_QUEUE_COUNTER ~= 0)then BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG = BATTLE_GROUND_QUEUE_COLUMN_COUNTER_FLAG + 1; getglobal( "BattleGroundQueueFrameChildFrame"..BATTLE_GROUND_QUEUE_COUNTER.."Column"):Show(); for i=BATTLE_GROUND_QUEUE_COUNTER+1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do getglobal( "BattleGroundQueueFrameChildFrame"..i.."Column"):Hide(); end else BATTLE_GROUND_QUEUE_LIST_TYPE = 0; end if(BATTLE_GROUND_QUEUE_COUNTER > BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER) then BATTLE_GROUND_QUEUE_COUNTER = 0; end end end end function Clear_BattleGroundQueue_List_Info() local type; for BGNUM=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do if(BATTLE_GROUND_COLUMN_LIST[BGNUM] ~= nil)then type = BATTLE_GROUND_COLUMN_LIST[BGNUM]; BATTLE_GROUND_QUEUE_COLUMN_NUM[ type ] = 0; end BATTLE_GROUND_COLUMN_LIST[BGNUM] = nil; BATTLE_GROUND_QUEUE_COUNTER = 0; IS_ALLOW_JOIN_BG_WITH_TEAM[BGNUM] = nil; BATTLE_GROUND_QUEUE_STATUS[BGNUM] = 0; childframename="BattleGroundQueueFrameChildFrame"..BGNUM.."Column"; getglobal(childframename.."BattleGroundQueueName"):SetText(""); getglobal(childframename.."LeaveBattleGroundButton"):SetID(0); getglobal(childframename.."BattleGroundLeaveQueueButton"):SetID(0); getglobal(childframename.."EnterBattleGroundButton"):SetID(0); getglobal("BattleGroundQueueFrameChildFrame"..BGNUM.."Column"):SetID(0); end GetBattleGroundResultType();--要求Zone送出戰場訊息,以便取得戰場列表 if(BATTLE_GROUND_QUEUE_COUNTER == 1)then BG_SELECT_COLUMN_NUM = 1; getglobal("BattleGroundQueueFrameChildFrame1ColumnSelectColumn"):Show(); else for i=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do getglobal("BattleGroundQueueFrameChildFrame"..i.."ColumnSelectColumn"):Hide(); BATTLE_GROUND_QUEUE_STATUS[i] = 0; end end end function Leave_All_Battle_Ground_Queue() local ZoneID = GetBattleGroundType(); for BGNUM=1,BATTLE_GROUND_QUEUE_COLUMN_TOTAL_NUMBER do if((BATTLE_GROUND_QUEUE_STATUS[BGNUM] ~= nil) and (BATTLE_GROUND_QUEUE_STATUS[BGNUM] ~= 0))then if(ZoneID ~= 448)then LeaveBattleGround(); end LeaveBattleGroundWaitQueue(BATTLE_GROUND_COLUMN_LIST[BGNUM]); BATTLE_GROUND_QUEUE_COUNT_TWO_SECONDS[BGNUM] = 0; BGQueueButtonAndColumnStatus(BGNUM,2); BATTLE_GROUND_QUEUE_STATUS[BGNUM] = 0; end end end