;------------------------------------------------
;Replace physics level system with perm entities
;------------------------------------------------
add:
{
	"classname" "info_target"
	"targetname" "Stage_CounterInit"
	"spawnflags" "0"
	"OnUser1" "Stage_CounterTemplate,ForceSpawn,,0,1"
	"OnUser1" "Stage_Counter,AddOutput,classname info_target,0.03,1"
	"OnUser1" "!self,Kill,,0.06,1"
}

add:
{
	"classname" "point_template"
	"targetname" "Stage_CounterTemplate"
	"Template01" "Stage_Counter"
	"spawnflags" "2"
}

add:
{
	"classname" "math_counter"
	"targetname" "Stage_Counter"
	"startvalue" "7"
	"StartDisabled" "0"
	"min" "1"
	"max" "7"
	"OnGetValue" "Stage_Case,InValue,,0,-1"
}

add:
{
	"classname" "logic_case"
	"targetname" "Stage_Case"
	"Case01" "1"
	"Case02" "2"
	"Case03" "3"
	"Case04" "4"
	"Case05" "5"
	"Case06" "6"
	"Case07" "7"
	"OnCase01" "lvl1_map_relay,Trigger,,0.02,-1"
	"OnCase02" "lvl2_map_relay,Trigger,,0.02,-1"
	"OnCase03" "lvl3_map_relay,Trigger,,0.02,-1"
	"OnCase04" "lvl4_map_relay,Trigger,,0.02,-1"
	"OnCase05" "lvl5_map_relay,Trigger,,0.02,-1"
	"OnCase06" "lvl6_map_relay,Trigger,,0.01,-1"
	"OnCase07" "warmup_map_relay,Trigger,,0.02,-1"
}

modify:
{
	match:
	{
		"classname" "logic_auto"
	}
	insert:
	{
		"OnMapSpawn" "Stage_CounterInit,FireUser1,,0,1"
		"OnMapSpawn" "Stage_Counter,GetValue,,0.02,1"
	}
}

;------------------------------------
;Change stage triggers to new system
;------------------------------------
modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "920292"
	}
	delete:
	{
		"OnPressed" "lvl1_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,1,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "920299"
	}
	delete:
	{
		"OnPressed" "lvl2_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,2,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "920306"
	}
	delete:
	{
		"OnPressed" "lvl3_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,3,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "920453"
	}
	delete:
	{
		"OnPressed" "lvl4_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,4,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "920464"
	}
	delete:
	{
		"OnPressed" "lvl5_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,5,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "func_button"
		"hammerid" "3511208"
	}
	delete:
	{
		"OnPressed" "lvl6_brush,Disable,,0.05,-1"
		"OnPressed" "lvl1_brush,Enable,,0,-1"
		"OnPressed" "lvl2_brush,Enable,,0,-1"
		"OnPressed" "lvl3_brush,Enable,,0,-1"
		"OnPressed" "lvl4_brush,Enable,,0,-1"
		"OnPressed" "lvl5_brush,Enable,,0,-1"
		"OnPressed" "lvl6_brush,Enable,,0,-1"
		"OnPressed" "warmup_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnPressed" "Stage_Counter,SetValue,6,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_once"
		"targetname" "lvl1_win"
	}
	delete:
	{
		"OnStartTouch" "lvl2_brush,Disable,,0.05,-1"
		"OnStartTouch" "lvl1_brush,Enable,,0,-1"
		"OnStartTouch" "lvl2_brush,Enable,,0,-1"
		"OnStartTouch" "lvl3_brush,Enable,,0,-1"
		"OnStartTouch" "lvl4_brush,Enable,,0,-1"
		"OnStartTouch" "lvl5_brush,Enable,,0,-1"
		"OnStartTouch" "lvl6_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnStartTouch" "Stage_Counter,SetValue,2,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_once"
		"targetname" "lvl2_win"
	}
	delete:
	{
		"OnStartTouch" "lvl3_brush,Disable,,0.05,-1"
		"OnStartTouch" "lvl1_brush,Enable,,0,-1"
		"OnStartTouch" "lvl2_brush,Enable,,0,-1"
		"OnStartTouch" "lvl3_brush,Enable,,0,-1"
		"OnStartTouch" "lvl4_brush,Enable,,0,-1"
		"OnStartTouch" "lvl5_brush,Enable,,0,-1"
		"OnStartTouch" "lvl6_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnStartTouch" "Stage_Counter,SetValue,3,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_once"
		"targetname" "lvl3_win"
	}
	delete:
	{
		"OnStartTouch" "lvl4_brush,Disable,,0.05,-1"
		"OnStartTouch" "lvl1_brush,Enable,,0,-1"
		"OnStartTouch" "lvl2_brush,Enable,,0,-1"
		"OnStartTouch" "lvl3_brush,Enable,,0,-1"
		"OnStartTouch" "lvl4_brush,Enable,,0,-1"
		"OnStartTouch" "lvl5_brush,Enable,,0,-1"
		"OnStartTouch" "lvl6_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnStartTouch" "Stage_Counter,SetValue,4,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_once"
		"targetname" "lvl4_win"
	}
	delete:
	{
		"OnStartTouch" "lvl5_brush,Disable,,0.05,-1"
		"OnStartTouch" "lvl1_brush,Enable,,0,-1"
		"OnStartTouch" "lvl2_brush,Enable,,0,-1"
		"OnStartTouch" "lvl3_brush,Enable,,0,-1"
		"OnStartTouch" "lvl4_brush,Enable,,0,-1"
		"OnStartTouch" "lvl5_brush,Enable,,0,-1"
		"OnStartTouch" "lvl6_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnStartTouch" "Stage_Counter,SetValue,5,0,-1"
	}
}

modify:
{
	match:
	{
		"classname" "trigger_once"
		"targetname" "lvl5_win"
	}
	delete:
	{
		"OnStartTouch" "lvl6_brush,Disable,,0.05,-1"
		"OnStartTouch" "lvl1_brush,Enable,,0,-1"
		"OnStartTouch" "lvl2_brush,Enable,,0,-1"
		"OnStartTouch" "lvl3_brush,Enable,,0,-1"
		"OnStartTouch" "lvl4_brush,Enable,,0,-1"
		"OnStartTouch" "lvl5_brush,Enable,,0,-1"
		"OnStartTouch" "lvl6_brush,Enable,,0,-1"
	}
	insert:
	{
		"OnStartTouch" "Stage_Counter,SetValue,6,0,-1"
	}
}

;-------------------------
;Cleanup old level system
;-------------------------
filter:
{
	"classname" "func_brush"
	"targetname" "/^(warmup|lvl[1-6])_brush/"
}

filter:
{
	"classname" "trigger_once"
	"targetname" "/^(warmup|lvl[1-6])_trigger/"
}

filter:
{
	"classname" "func_physbox"
	"targetname" "lvl_phys"
}

modify:
{
	match:
	{
		"classname" "logic_auto"
	}
	delete:
	{
		"OnMapSpawn" "lvl_phys,EnableMotion,,0,-1"
	}
}

;------------------------------------------------------
;Move killer item spawn on stage 5 to after the dragon
;------------------------------------------------------
modify:
{
	match:
	{
		"origin" "7520 -14290 -14"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "killer_itemtemp,AddOutput,origin 4187 8781 4264,0,-1"
	}
	insert:
	{
		"OnTrigger" "killer_itemtemp,AddOutput,origin 12711.66 6144.19 4294.03,0,-1"
	}
}

;------------------------------------------------
;Increase and rework laser balrog health scaling
;------------------------------------------------
modify:
{
	match:
	{
		"classname" "prop_dynamic"
		"origin" "-9.14453 9362 -165.879"
	}
	delete:
	{
		"OnUser1" "bosslvl4_end_case,PickRandom,,18,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,20,1"
		"OnUser1" "bosslvl4_end_model,Enable,,16.4,1"
		"OnUser1" "bosslvl4_end_exp_arrive,Start,,16,1"
		"OnUser1" "bosslvl4_end_bridge,Kill,,15,1"
		"OnUser1" "bosslvl4_end_exp_back_1,Start,,25,1"
		"OnUser1" "bosslvl4_end_exp_back_2,Start,,25,1"
		"OnUser1" "bosslvl4_end_model,Kill,,25.05,1"
		"OnUser1" "bosslvl4_back_exp_sound,PlaySound,,25,1"
		"OnUser1" "boss_sound_arrival,PlaySound,,16,1"
		"OnUser1" "boss_command,Command,say >>> BRIDGE IS BROKEN <<<,15,1"
		"OnUser1" "boss_command,Command,say >>> IT'S BALROG <<<,16.4,1"
		"OnUser1" "boss_command,Command,say >>> BALROG IS ESCAPED <<<,25.05,1"
		"OnUser1" "end_tele_lvl4,Enable,,28,1"
		"OnUser1" "end_tele_lvl4_eff,Start,,27,1"
		"OnUser1" "bridge_exp,Start,,15,1"
		"OnUser1" "cliffexp_sound,PlaySound,,15,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,22,1"
		"OnUser1" "zdrag_screen,StopOverlays,,15,1"
		"OnUser1" "laser_block,Trigger,,15,1"
	}
	insert:
	{
		"OnUser1" "bosslvl4_end_model,Enable,,16.4,1"
		"OnUser1" "bosslvl4_end_exp_arrive,Start,,16,1"
		"OnUser1" "bosslvl4_end_bridge,Kill,,15,1"
		"OnUser1" "bosslvl4_end_exp_back_1,Start,,25,1"
		"OnUser1" "bosslvl4_end_exp_back_2,Start,,25,1"
		"OnUser1" "bosslvl4_end_model,Kill,,25.05,1"
		"OnUser1" "bosslvl4_back_exp_sound,PlaySound,,25,1"
		"OnUser1" "boss_sound_arrival,PlaySound,,16,1"
		"OnUser1" "boss_command,Command,say >>> BRIDGE IS BROKEN <<<,15,1"
		"OnUser1" "boss_command,Command,say >>> IT'S BALROG <<<,16.4,1"
		"OnUser1" "boss_command,Command,say >>> BALROG IS ESCAPED <<<,25.05,1"
		"OnUser1" "end_tele_lvl4,Enable,,28,1"
		"OnUser1" "end_tele_lvl4_eff,Start,,27,1"
		"OnUser1" "bridge_exp,Start,,15,1"
		"OnUser1" "cliffexp_sound,PlaySound,,15,1"
		"OnUser1" "zdrag_screen,StopOverlays,,15,1"
		"OnUser1" "laser_block,Trigger,,15,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,18,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,19,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,20,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,21,1"
		"OnUser1" "bosslvl4_end_case,PickRandom,,22,1"
	}
}

modify:
{
	match:
	{
		"origin" "10087.5 12158 3712.77"
		"classname" "trigger_hurt"
	}
	delete:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,70,2,-1"
	}
	insert:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,0,2,-1"
	}
}

modify:
{
	match:
	{
		"origin" "10087.8 12158 3671"
		"classname" "trigger_hurt"
	}
	delete:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,70,2,-1"
	}
	insert:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,0,2,-1"
	}
}

modify:
{
	match:
	{
		"origin" "10087.6 12158 3692"
		"classname" "trigger_hurt"
	}
	delete:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,70,2,-1"
	}
	insert:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Subtract,0,2,-1"
	}
}

modify:
{
	match:
	{
		"origin" "10077 12945.5 3792"
		"classname" "trigger_multiple"
	}
	delete:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Add,85,0,-1"
	}
	insert:
	{
		"OnStartTouch" "bosslvl5_laser_counter,Add,60,0,-1"
	}
}

;----------------------------------------------------------
;Prevent heal resetting player health at the end of stages
;----------------------------------------------------------
modify:
{
	match:
	{
		"targetname" "endlvl1"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "heal_cure,Kill,,0,-1"
	}
}

modify:
{
	match:
	{
		"targetname" "endlvl2"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "heal_cure,Kill,,0,-1"
	}
}

modify:
{
	match:
	{
		"targetname" "endlvl3"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "heal_cure,Kill,,0,-1"
	}
}

modify:
{
	match:
	{
		"targetname" "endlvl4"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "heal_cure,Kill,,0,-1"
	}
}

modify:
{
	match:
	{
		"targetname" "endlvl5"
		"classname" "trigger_once"
	}
	insert:
	{
		"OnStartTouch" "heal_cure,Kill,,0,-1"
	}
}

;----------------------------------------------------------
;Fix stage 2 ending boss hitbox blocking bullets and items
;----------------------------------------------------------
modify:
{
	match:
	{
		"targetname" "bosslvl2_end_counter3"
		"classname" "math_counter"
	}
	insert:
	{
		"OnHitMin" "bosslvl2_end_hit,Kill,,0,-1"
	}
}

;-----------
;Fix warmup
;-----------
modify:
{
	match:
	{
		"targetname" "warmup_map_relay"
		"classname" "logic_relay"
	}
	delete:
	{
		"OnTrigger" "killall,Enable,,42,-1"
		"OnTrigger" "map_command,Command,say >>> WARMUP ROUND 40 SECONDS REMAINING <<<,0,-1"
		"OnTrigger" "map_command,Command,say >>> WARMUP ROUND 30 SECONDS REMAINING <<<,10,-1"
		"OnTrigger" "map_command,Command,say >>> WARMUP ROUND 20 SECONDS REMAINING <<<,20,-1"
		"OnTrigger" "map_command,Command,say >>> WARMUP ROUND 10 SECONDS REMAINING <<<,30,-1"
		"OnTrigger" "map_command,Command,say >>> WARMUP ROUND END <<<,40,-1"
		"OnTrigger" "warmup_brush,Enable,,40,-1"
		"OnTrigger" "lvl1_brush,Disable,,40.05,-1"
		"OnTrigger" "lvl4_brush,Enable,,40,-1"
		"OnTrigger" "lvl5_brush,Enable,,40,-1"
		"OnTrigger" "lvl1_brush,Enable,,40,-1"
		"OnTrigger" "lvl2_brush,Enable,,40,-1"
		"OnTrigger" "lvl3_brush,Enable,,40,-1"
		"OnTrigger" "warmup_brush,Enable,,40,-1"
	}
	insert:
	{
		"OnTrigger" "Stage_Counter,SetValue,1,1,-1"
	}
}

;------------------------
;Heal staff Immunity Fix
;------------------------
add:
{
	"classname" "filter_activator_class"
	"filterclass" "player"
	"Negated" "1"
	"targetname" "Immunity"
	"origin" "7504 -14386 -14"
}

filter:
{
	"classname" "filter_activator_team"
	"filterteam" "2"
	"Negated" "1"
	"targetname" "immotaly"
	"origin" "7504 -14386 -14"
	"hammerid" "2101605"
}

filter:
{
	"model" "*521"
	"targetname" "heal_cure"
	"StartDisabled" "1"
	"spawnflags" "1"
	"parentname" "heal_elite"
	"origin" "9080.25 -13193.3 -724"
	"nodmgforce" "0"
	"filtername" "filter_human"
	"damagetype" "0"
	"damagemodel" "0"
	"damagecap" "-500"
	"damage" "-500"
	"classname" "trigger_hurt"
	"hammerid" "3855798"
	"OnStartTouch" "!activator,AddOutput,health 250,0,-1"
	"OnStartTouch" "!activator,SetDamageFilter,,7,-1"
	"OnStartTouch" "!activator,SetDamageFilter,immotaly,0,-1"
	"OnEndTouch" "!activator,SetDamageFilter,,0,-1"
}

filter:
{
	"model" "*519"
	"targetname" "heal_cure"
	"StartDisabled" "1"
	"spawnflags" "1"
	"parentname" "heal_elite"
	"origin" "8893.25 -13380.8 -724"
	"nodmgforce" "0"
	"filtername" "filter_human"
	"damagetype" "0"
	"damagemodel" "0"
	"damagecap" "-500"
	"damage" "-500"
	"classname" "trigger_hurt"
	"hammerid" "3855771"
	"OnStartTouch" "!activator,AddOutput,health 250,0,-1"
	"OnStartTouch" "!activator,SetDamageFilter,,7,-1"
	"OnStartTouch" "!activator,SetDamageFilter,immotaly,0,-1"
	"OnEndTouch" "!activator,SetDamageFilter,,0,-1"
}

filter:
{
	"model" "*520"
	"targetname" "heal_cure"
	"StartDisabled" "1"
	"spawnflags" "1"
	"parentname" "heal_elite"
	"origin" "8892.75 -13193.3 -723.8"
	"nodmgforce" "0"
	"filtername" "filter_human"
	"damagetype" "0"
	"damagemodel" "0"
	"damagecap" "-500"
	"damage" "-500"
	"classname" "trigger_hurt"
	"hammerid" "3855795"
	"OnStartTouch" "!activator,AddOutput,health 250,0,-1"
	"OnStartTouch" "!activator,SetDamageFilter,,7,-1"
	"OnStartTouch" "!activator,SetDamageFilter,immotaly,0,-1"
	"OnEndTouch" "!activator,SetDamageFilter,,0,-1"
}

filter:
{
	"model" "*79"
	"targetname" "heal_cure"
	"StartDisabled" "1"
	"spawnflags" "1"
	"parentname" "heal_elite"
	"origin" "9080.75 -13380.8 -724.2"
	"nodmgforce" "0"
	"filtername" "filter_human"
	"damagetype" "0"
	"damagemodel" "0"
	"damagecap" "-500"
	"damage" "-500"
	"classname" "trigger_hurt"
	"hammerid" "566197"
	"OnStartTouch" "!activator,AddOutput,health 250,0,-1"
	"OnStartTouch" "!activator,SetDamageFilter,,7,-1"
	"OnStartTouch" "!activator,SetDamageFilter,immotaly,0,-1"
	"OnEndTouch" "!activator,SetDamageFilter,,0,-1"
}

add:
{
	"model" "*65"
	"targetname" "heal_cure"
	"StartDisabled" "1"
	"spawnflags" "1"
	"parentname" "heal_elite"
	"origin" "8986.75 -13287 -724"
	"nodmgforce" "0"
	"filtername" "filter_human"
	"damagetype" "0"
	"damagemodel" "0"
	"damagecap" "-500"
	"damage" "-500"
	"classname" "trigger_hurt"
	"hammerid" "566197"
	"OnStartTouch" "!activator,AddOutput,health 250,0,-1"
	"OnStartTouch" "!activator,SetDamageFilter,,7,-1"
	"OnStartTouch" "!activator,SetDamageFilter,Immunity,0,-1"
	"OnEndTouch" "!activator,SetDamageFilter,,0,-1"
}