600000 constant time_end_reg		\ время регистрации на ивент в мс
30000 constant time_for_prep		\ время подготовки к ивенту в мс
180 constant time_for_award		\ время ожидания приза в сек

{ /events/masterxl/TTTspawnlist } value TTT-spawnlist
{ } value TTT_list
{ } value TTT-spawned-list

false value TTT-started
false  value TTT-reg
false value TTT-take
true value TTT-priz
true value TTT-life

: npcspawn
  TTT-spawnlist npc-list-spawn to TTT-spawned-list
;

: npcunspawn  
  TTT-spawned-list npc-list-unspawn
;

: run? 
    TTT-started not if rdrop exit then
;
: reg? 
    TTT-reg not if rdrop exit then
;

: ots 
   0 10 do  I announce 1000 sleep -1 +loop
   "Lets go to fight!" announce
   s0
;



\ добавляем диалог к ивент менеджеру
: npc-12260-dialog-append
    run?
    reg?
   '<br><a action="bypass -h jbf_TTT">REGISTRATION TO EVENT TRY-TO-TAKE.</a><br>' .
;

\ регистрация игроков на ивент
: bypass_TTT
   player@ "Name" p@ TTT_list in-list? if			\ был уже зарегистрирован
   "You are already registred!" show
   exit 
  then
  player@ "Name" p@ TTT_list list+							\ регистрируем имя игрока
  "You are registered for fighting!" show 
   "Registred players:" .
   TTT_list ['] . do-list
  "The player was registred:" player@ "Name" p@ s+  announce
  s1
;

: ttt_teleport_to
\	'149229 46779 0' to event-coordinates
	player@ 'Name' p@ TTT_list in-list? if   					\ игрок принадлежит списку?
		event-coordinates s>coords drop                          	\ преобразуем координаты и дропаем флаг
		500 coords-randomize jump "You moved to event" show exit 	\ телепортируем, показываем сообщение
	then
;
: jte
	"ttt_teleport_to"	do-players 
;

: ttt_teleport_back
	'82800 148700 100' to back-coordinates
	player@ 'Name' p@ TTT_list in-list? if   					\ игрок принадлежит списку?
		back-coordinates s>coords drop                          	\ преобразуем координаты и дропаем флаг
		100 coords-randomize jump 						\ телепортируем, показываем сообщение
	then
;
: jtb
	"ttt_teleport_back"	do-players 
;


: TTT_start
	'149229 46779 0' to event-coordinates
	true to TTT-started
	true to TTT-reg
	true to TTT-take
	true to TTT-priz
	coliseum-doors-close
	"RMT evet TRY-TO-TAKE is starting!" announce
 	"'jbforth\events\masterxl\TTT\TTT_reg.htm' show" do-players
	s4
	time_end_reg sleep 							\ ждем пока все зарегистрируются
	false to TTT-reg								\ false, чтобы не регились после
   	"Registration is finished!" announce
   	"'jbforth\events\masterxl\TTT\TTT_info.htm' show" do-players
	time_for_prep sleep
	"Attantion! You have 10 sec before teleporting." announce 
	sb							
	ots
	npcspawn
	jte
;

: TTT_end 
    	"RMT event TRY-TO-TAKE is finished. Thanks for all. To be continued." announce
	npcunspawn
  	false to TTT-started
	false to TTT-reg
	false to TTT-take
  	{ } to TTT_list
  	s7
;

: ll 
	"list:" .   
	TTT_list ['] . do-list
;

: npc-12751-dialog-append		
    run?
    TTT-take if
    '<br><a action="bypass -h jbf_TTT_priz">Try to take award during 20 sec.</a><br>' .
    else
    '<br>Try to kill player who waiting your award!<br>' .
    then
     "Registered players:" .
      TTT_list ['] . do-list
;

: check_life				
	player@ "CurrentHp" p@ 1 < if 				 
      	false to TTT-priz
	      false to TTT-life
		exit
	else
		True to TTT-life
	then
		" check_life " 1000 do-timer
;

: priz
    TTT-life if
	TTT-priz if 
		3 955 items_add 
		3 951 items_add 
		3 947 items_add 
\    		player@ 5128 30 enchant-level!
  		"Win event and had take award:" player@ "Name" p@ s+  announce
    		s2
   		"jbforth\events\masterxl\TTT\TTT_priz.htm" show
		10000 sleep
		jtb
   		TTT_end
    	else
		true to TTT-take
		true to TTT-priz
		sb
		"Try to take award again" announce
	then
    else
		true to TTT-take
		true to TTT-priz
		sb
		"Try to take award again" announce
    then
;

: bypass_TTT_priz
   	player@ "Name" p@ TTT_list in-list? not if		\ проверяем был ли зарегистрирован
   	 "Sorry, you must be registered!" show
   	 exit 
   	else
    	 false to TTT-take
   	then
   	 "Wow! KILL him! This player try to take your award: " player@ "Name" p@ s+  announce
   	sb
	0 time_for_award do
	  check_life
	-1 +loop
	" priz " time_for_award 1000 * 100 + do-timer
;


