;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[@GuildWarEventSystem]
{
#SAY
What do you want to do?\\
<Join Team War/@JoinTeamWarEventSystem>\
<Start Team War/@StartTeamWarEventSystem>\\
<Leave/@Exit>\

;--------------------------------------------------------

[@StartTeamWarEventSystem]
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_USER,FLD_FARE,FLD_STEP,FLD_MAXUSER1,FLD_MAXUSER2" @StartTeamWarEventSystem_Check

[@StartTeamWarEventSystem_Check()]
#ACT
Mov A0 %ARG(1)
Mov D0 %ARG(2)
Mov A1 %ARG(3)
Mov D2 %ARG(4)
Mov D3 %ARG(5)

;--------------------

#IF
Equal A1 "OpenGate"
#ELSEACT
break

;--------------------

#ELSESAY
Event is activity unable to apply for another event.\ \
<Leave/@exit>

;--------------------------------------------------------

#IF
CheckTeamCount [1] "E004" 0
#ACT
Mov D2 %P9

;--------------------

#IF
CheckTeamCount [2] "E004" 0
#ACT
Mov D3 %P9

;--------------------

#IF
ELarge D2 %D0
or ELarge D3 %D1
#SAY
<$USERNAME> something wrong... \ \
<Leave/@exit>

#ACT
break

;--------------------

#IF
Equal A1 "StartOpen"
#SAY
Are you sure you want to <Join Team War Game/@JoinChallengeTestSurviveGame>>\\
<Leave/@Exit>
#ELSESAY
现在不能参加组队战游戏。\ \
<Leave/@exit>

;--------------------------------------------------------

[@JoinChallengeTestSurviveGame]
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP" @JoinChallengeTestSurviveGame_Next

;--------------------------------------------------------

[@JoinChallengeTestSurviveGame_Next()]
#IF
#ACT
Mov A1 %ARG(1)

;--------------------

#IF
Equal A1 "StartOpen"
Equal A0 %USERNAME
#ACT
Map E004
break

;--------------------

#IF
Equal A1 "StartOpen"
CheckGold %D0
#ELSEACT
break

;--------------------

#ELSESAY
如果钱不够的话是不能参加游戏的。\ \
<Leave/@exit>

;--------------------------------------------------------

#IF
ELarge D2 %D3
#ACT
Take Gold %D0
TeamMakeTeam 2
Killslave
Map E004
break

;--------------------

#IF
Small D2 %D3
#ACT
Take Gold %D0
TeamMakeTeam 1
Killslave
Map E004
break

;--------------------------------------------------------


[@JoinTeamWarEventSystem]
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP" @JoinTeamWarEventSystem_Next

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next()]
#ACT
mov A9 %ARG(1)

#IF
Equal A9 "Ready"
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP" @JoinTeamWarEventSystem_Next1
#ELSESAY
现在活动正在进行，所以不能进行申请。\ \
<Leave/@exit>

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next1()]
#ACT
mov A9 %ARG(1)

#IF
!Checkitem ProtectionRing 1
#SAY
<$USERNAME> You do not have the item... \ \
<Leave/@exit>
#ACT
break

;--------------------------------------------------------

#IF
Equal A9 "Ready"
Checkitem ProtectionRing 1

#SAY
Please Wait...\\
<Leave/@exit>

#ACT
MapTing E004 5 240 129
ChangeMapAttr "E004" "TEAMFIGHT"
FormatStr "FLD_USER='%s',FLD_STEP='StartClose'" %USERNAME
UpdateValueSQL "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" %A9
UpdateValueSQL "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_POINT1=10000,FLD_POINT2=10000"
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg0]
LineMsg [Grobal] %A7
Delaygoto [Grobal] 300 @JoinTeamWarEventSystem_Next2
break
#SAY
Please Wait...\\
<Leave/@exit>

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next2]
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg1]
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP='OpenGate'"
Delaygoto [Grobal] 1200 @JoinTeamWarEventSystem_Next3

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next3]
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg2]
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP='CloseGate'"
Delaygoto [Grobal] 600 @JoinTeamWarEventSystem_Next4

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next4]
#ACT
ReadValueSQL "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_POINT1,FLD_POINT2" @JoinTeamWarEventSystem_Next5

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next5()]
#ACT
Mov D0 %ARG(1)
Mov D1 %ARG(2)
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP='End'"

;--------------------------------------------------------

#IF
Equal D0 %D1
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg3]
LineMsg [Grobal] %A7
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_REWORD1,FLD_REWORN1COUNT,FLD_MAPEXP" @JoinTeamWarEventSystem_Next6
break

;--------------------------------------------------------

#IF
Large D0 %D1
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg4]
LineMsg [Grobal] %A7
TeamTing E401 2 "E401 40 40 40"
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_REWORD1,FLD_REWORN1COUNT,FLD_MAPEXP" @JoinTeamWarEventSystem_Next6
break

;--------------------------------------------------------

#IF
Large D1 %D0
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg5]
LineMsg [Grobal] %A7
TeamTing E401 1 "E401 40 40 40"
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_REWORD1,FLD_REWORN1COUNT,FLD_MAPEXP" @JoinTeamWarEventSystem_Next6
break

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next6()]
#ACT
mov A9 %ARG(1)
mov D9 %ARG(2)
Mov D8 %ARG(3)
GiveExpMap E004 %D8
DropItemMap "E004,40,40,20" %A9 1 %D9
Delaygoto [Grobal] 300 @JoinTeamWarEventSystem_Next7

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next7]
#ACT
MapTing E002 5 240 129
Delaygoto [Grobal] 300 @JoinTeamWarEventSystem_Next8

;--------------------------------------------------------

[@JoinTeamWarEventSystem_Next8]
#ACT
LoadValue A7 [Convert_Def\QuestDiary\EventSystem\TeamWar\TeamWarNPC.txt] [Convert] [Msg6]
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TeamWar'" "FLD_STEP='Ready'"
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP='Ready'"
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;