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

[@SurviveGameMainMenu]
{
#IF
IsAdmin
#SAY
{FCOLOR/10}GM Menu{FCOLOR/12} \ \
<[ GM Menu - Challenge Room ]/@InitalSurviveGameMainMenu> \
{FCOLOR/10}User Menu{FCOLOR/12} \\

#IF
#SAY
Are you ready for the Challene Room Event?\\
<[ Start Challenge Room Event ]/@BeginSurviveGameMainMenu>\
<[ Join Challenge Room Event ]/@JoinSurviveGameMainMenu>\\

[@InitalSurviveGameMainMenu]
#CALL [EventSystem\SurviveGame\SurviveGame.txt] @TestSurviveGame_Finish

[@BeginSurviveGameMainMenu]
#CALL [EventSystem\SurviveGame\SurviveGame.txt] @TestSurviveGame_Start

[@JoinSurviveGameMainMenu]
#CALL [EventSystem\SurviveGame\SurviveGame.txt] @TestSurviveGame_Join
}



[@TestSurviveGame_Start]
{
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP" @PreTestSurviveGame_Start

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

#IF
Equal A9 "Ready"
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP" @TestSurviveGame_Start_Next

#ELSESAY
Its already running, call again later\\
<[ Exit ]/@exit>\\\

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

#IF
!Checkitem FreePass 1
#SAY
You don't have a Free Pass!\\
<[ Exit ]/@exit>\\\
#ACT
break

#IF
Equal A9 "Ready"
checkitem FreePass 1
#SAY
Challenge Room Event Started!\\
<[ Exit ]/@exit>\\\

#ACT
Take FreePass 1
FormatStr "FLD_USER='%s',FLD_STEP='StartClose'" %USERNAME
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" %A9
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP='Act'"
Mov  A7  "(!) The Challenge Room Event will start in 5 minutes!"
LineMsg [Grobal] %A7
Delaygoto [Grobal] 300 @TestSurviveGame_Start_Next1 10030
break

#IF
#SAY
Its already running, call again later\\
<[ Exit ]/@exit>\\\
#ACT
break

[@TestSurviveGame_Start_Next1]
#IF
#ACT
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='StartOpen'"
ResetMapAttr "E002"
MonClear E002
Mov   A7 "(!) The Challenge Room Event is Starting, If you want to Join, go to the Event Guy in OldBichon(5 Mins Left)"
LineMsg [Grobal] %A7
mov N5 2
mov N6 4
mov N7 40
mov N8 4
movr P9 6

#IF
Equal P9 0
#ACT
mov B0 "Shocktopus"
mov N0 20
mov B1 "Ichthyo"
mov N1 40
mov B2 "HellHound"
mov N2 40
mov B3 "Venoctopus"
mov N3 40
mov B4 "HwanTrooper"
mov N4 5

#IF
Equal P9 1
#ACT
mov B0 "Shocktopus"
mov N0 20
mov B1 "Ichthyo"
mov N1 40
mov B2 "HellHound"
mov N2 40
mov B3 "Venoctopus"
mov N3 40
mov B4 "HwanTrooper"
mov N4 5

#IF
Equal P9 2
#ACT
mov B0 "IceKing"
mov N0 20
mov B1 "IceMaster"
mov N1 40
mov B2 "IceSoldier"
mov N2 40
mov B3 "IceWarrior"
mov N3 40
mov B4 "IceMaiden"
mov N4 5

#IF
Equal P9 3
#ACT
mov B0 "Shocktopus"
mov N0 20
mov B1 "Ichthyo"
mov N1 40
mov B2 "HellHound"
mov N2 40
mov B3 "Venoctopus"
mov N3 40
mov B4 "HwanTrooper"
mov N4 5
#IF
Equal P9 4
#ACT
mov B0 "IceKing"
mov N0 20
mov B1 "IceMaster"
mov N1 40
mov B2 "IceSoldier"
mov N2 40
mov B3 "IceWarrior"
mov N3 40
mov B4 "IceMaiden"
mov N4 5

#IF
Equal P9 5
#ACT
mov B0 "NecroFireDragon"
mov N0 10
mov B1 "NecroSoldier"
mov N1 20
mov B2 "Deathguard"
mov N2 20
mov B3 "InfernalNecro"
mov N3 20
mov B4 "NecromanticQueen"
mov N4 1

#IF
#ACT
mov A5 ""
Addstr A5 B0
Addstr A5 ","
Addstr A5 B1
Addstr A5 ","
Addstr A5 B2
Addstr A5 ","
Addstr A5 B3
Addstr A5 ","
Addstr A5 B4
Delaygoto [Grobal] 60 @TestSurviveGame_Start_Next3_A 10030

[@TestSurviveGame_Start_Next3_A]
#ACT
Mov   A7 "(!) The Challenge Room Event is Starting, If you want to Join, go to the Event Guy in OldBichon(4 Mins Left)"
LineMsg [Grobal] %A7
Delaygoto [Grobal] 60 @TestSurviveGame_Start_Next3_B 10030

[@TestSurviveGame_Start_Next3_B]
#ACT
Mov   A7 "(!) The Challenge Room Event is Starting, If you want to Join, go to the Event Guy in OldBichon(3 Mins Left)"
LineMsg [Grobal] %A7
Delaygoto [Grobal] 60 @TestSurviveGame_Start_Next3_C 10030

[@TestSurviveGame_Start_Next3_C]
#ACT
Mov   A7 "(!) The Challenge Room Event is Starting, If you want to Join, go to the Event Guy in OldBichon(2 Mins Left)"
LineMsg [Grobal] %A7
Delaygoto [Grobal] 60 @TestSurviveGame_Start_Next3_D 10030

[@TestSurviveGame_Start_Next3_D]
#ACT
Mov   A7 "(!) The Challenge Room Event is Starting, If you want to Join, go to the Event Guy in OldBichon(1 Min Left)"
LineMsg [Grobal] %A7
Delaygoto [Grobal] 60 @TestSurviveGame_Start_Next3 10030


[@TestSurviveGame_Start_Next3]
#ACT
mov N11 1
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='Start'"
Mov A7  "(!) Challenge Room Event has started, you can no longer join!"
LineMsg [Grobal] %A7
goto @TestSurviveGame_Start_Next4

[@TestSurviveGame_Start_Next4]
#IF
Elarge N11 11
#ACT
goto @TestSurviveGame_Start_Result
break
#ELSEACT
Inc N5 5
Inc N6 5
Inc N7 100
Inc N8 4
Mov A7  "Round <$OUTPUT(N11)> - Monsters Entering the Room!!  They are getting harder.. watch out!!!"
EventMsg "E002" %A7
MonGenP "E002,40,40,30" %B0 %N0
MonGenP "E002,40,40,30" %B1 %N1
MonGenP "E002,40,40,30" %B2 %N2
MonGenP "E002,40,40,30" %B3 %N3
MonGenP "E002,40,40,30" %B4 %N4
MonPwr "E002" %A5 [AC] %N5
MonPwr "E002" %A5 [MAC] %N6
MonPwr "E002" %A5 [HP] %N7
MonPwr "E002" %A5 [DC] %N8
Inc N11 1
ChangeMonLevel "E002" %A5 99
Delaygoto [Grobal] 180 @TestSurviveGame_Start_Next4 10031

[@TestSurviveGame_Start_Result]
#IF
CheckMonMap E002 16
#ACT
MapTing E002 5 240 129
MonClear E002
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='End'"
Mov A7  "(!) You survived, but you failed! Sorry....."
LineMsg [Grobal] %A7
Delaygoto [Grobal] 300 @TestSurviveGame_Start_Result_Ready 10033
#ELSEACT
ChangeMapAttr "E002" "SAFE"
MonClear E002
MapTing E002 E002 40 40
Mov A7  "(!) You survived, and you ROCKED!!!"
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='End'"
Delaygoto [Grobal] 300 @TestSurviveGame_Start_Result_PreReady 10033
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_REWORD1,FLD_REWORD1COUNT,FLD_MAPEXP" @TestSurviveGame_Start_Result_Next

[@TestSurviveGame_Start_Result_Next()]
#ACT
mov A9 %ARG(1)
mov D9 %ARG(2)
Mov D8 %ARG(3)
GiveExpMap E002 %D8
DropItemMap "E002,40,40,20" %A9 1 %D9

[@TestSurviveGame_Start_Result_PreReady]
#ACT
MapTing E002 5 240 129
Delaygoto [Grobal] 300 @TestSurviveGame_Start_Result_Ready 10033

[@TestSurviveGame_Start_Result_Ready]
#ACT
Mov  A7  "(!) Event System is now ready to use" 
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='Ready'"
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP='Ready'"
MonClear "E002"
MapTing E002 5 240 129
ClearDelaygoto 10030
ClearDelaygoto 10031
ClearDelaygoto 10032
ClearDelaygoto 10033
Close
}



[@TestSurviveGame_Finish]
{

#SAY
Are you sure you want to cancel the Event?\\
<[ Cancel Challenge Room Event ]/@TestSurviveGame_Finish_ConFirm>\\
<[ Exit ]/@exit>\\\

[@TestSurviveGame_Finish_ConFirm]
#ACT
Mov A7 "(!) The Challenge Room Event has been cancelled"
LineMsg [Grobal] %A7
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_STEP='Ready'"
UpdateValueSql "TBL_EventSystemTotal" "FLD_NAME='TotalControl'" "FLD_STEP='Ready'"
MonClear "E002"
MapTing E002 5 240 129
ClearDelaygoto 10030
ClearDelaygoto 10031
ClearDelaygoto 10032
ClearDelaygoto 10033
Close
}


[@TestSurviveGame_Join]
{
#ACT
ReadValueSql "TBL_EventSystemTotal" "FLD_NAME='Survival'" "FLD_USER,FLD_FARE,FLD_STEP" @ChallengeTestSurviveGame

[@ChallengeTestSurviveGame()]
#ACT
mov A9 %ARG(1)
Mov D9 %ARG(2)
mov A8 %ARG(3)

#IF
Equal A8 "StartOpen"
#SAY
IF there are more than 11 people or 15 Monsters\
left at the end, you lose, sorry\
It will cost you <$OUTPUT(D9)> To Enter\\
<[ Enter Event Room ]/@JoinChallengeTestSurviveGame>\
<[ Exit ]/@exit>\\\
#ELSESAY
You cannot join at this time\\
<[ Exit ]/@exit>\\\

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

[@JoinChallengeTestSurviveGame_Next()]
#IF
#ACT
mov A8 %ARG(1)

#IF
Equal A8 "StartOpen"
Equal A9 %USERNAME
#ACT
Map E002
break

#IF
Equal A8 "StartOpen"
CheckGold %D9
#ACT
Take Gold %D9
Map E002
break

#ELSESAY
You don't have enough Cash!\\
<[ Exit ]/@exit>\\\

}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;