//Fire Reaver Hatchling, from Fire Reaver by Thothie (quick and sloppy)

{
	const DMG_BURST 30.0
	const DOT_BURN 10.0

	const FREQ_FIRE_BURST $randf(10.0,20.0)

	setvard NPC_GIVE_EXP 250

	//volcano bits
	const ROCK_START_HEIGHT 96
	setvard DMG_VOLCANO 200
	setvard DMG_VOLCANO_DOT 1
	const DMG_VOLCANO_DART 25
	const FREQ_VOLC_SOUND 7.0 //check this
	const FREQ_VOLCANO 0.25
	const FREQ_SMASH 10.0

	const SOUND_WALK1 common/npc_step1.wav
	const SOUND_WALK2 common/npc_step2.wav
	const SOUND_WALK3 common/npc_step3.wav
	const SOUND_WALK4 common/npc_step4.wav
	const SOUND_RUN1 gonarch/gon_step1.wav
	const SOUND_RUN2 gonarch/gon_step2.wav
	const SOUND_RUN3 gonarch/gon_step3.wav //optional
	const SOUND_DEATH gonarch/gon_die1.wav
	const SOUND_WARCRY gonarch/gon_alert1.wav //check
	const SOUND_STRUCK1 gonarch/gon_sack1.wav //check
	const SOUND_STRUCK2 gonarch/gon_sack2.wav //check
	const SOUND_PAIN_STRONG gonarch/gon_pain2.wav
	const SOUND_PAIN_WEAK gonarch/gon_pain4.wav
	const SOUND_PAIN_NEAR_DEATH gonarch/gon_pain5.wav
	const SOUND_SLASHHIT zombie/claw_strike1.wav //overused, look for alternates
	const SOUND_SMASHHIT zombie/claw_strike2.wav //overused, look for alternates
	const SOUND_SLASHMISS zombie/claw_miss1.wav //overused, look for alternates
	const SOUND_SMASHMISS zombie/claw_miss2.wav //overused, look for alternates
	const SOUND_SEARCH1 gonarch/gon_childdie3.wav
	const SOUND_SEARCH2 gonarch/gon_childdie2.wav
	const SOUND_SEARCH3 gonarch/gon_childdie1.wav
	setvard SOUND_ATTACKHIT unset
	setvard SOUND_ATTACKMISS unset

	//called indirectly, so need precache
	precache SOUND_SLASHMISS
	precache SOUND_SLASHHIT
	precache SOUND_SMASHMISS
	precache SOUND_SMASHHIT
	precache SOUND_PAIN_STRONG 
	precache SOUND_PAIN_WEAK
	precache SOUND_PAIN_NEAR_DEATH

	//defaults are a little too far, prob cuz of large model
	setvard ATTACK_RANGE 125
	setvard ATTACK_HITRANGE 150
	setvard ATTACK_MOVERANGE 50
	setvard MOVE_RANGE 50

	const STRONG_THRESHOLD 2500
	const WEAK_THRESHOLD 2000
	const NEAR_DEATH_THRESHOLD 750

	const SLASH_DAMAGE '$rand(100,200)'
	const SMASH_DAMAGE 500
	const SLASH_HITCHANCE 90%

	const FREQ_MISSILE 20.0
	const DMG_MISSILE 600
	const FREQ_VOLC 1.0

	setvar ANIM_WALK walk
	setvar ANIM_RUN run
	setvar ANIM_IDLE idle1
	const ANIM_SEARCH idle2
	setvard ANIM_FLINCH turnl
	const ANIM_SMASH mattack3
	const ANIM_SLASH mattack2
	const ANIM_PROJECTILE distanceattack
	const ANIM_ALERT distanceattack
	setvard ANIM_DEATH1 dieforward
	setvard ANIM_DEATH2 diesimple
	setvard ANIM_DEATH3 diesideways
	const ANIM_VICTORY1 victoryeat
	const ANIM_VICTORY2 victorysniff
	setvard ANIM_VICTORY victoryeat
	setvard ANIM_DEATH dieforward
	setvard ANIM_ATTACK mattack3

	setvard CAN_FLINCH 1
	setvard FLINCH_HEALTH 1000
	setvard FLINCH_CHANCE 30

	const DOSMASH_CHANCE 30

	precache SOUND_DEATH //handled by base_npc
}

#include monsters/base_monster_new

{ npc_spawn

	name an|Fire Reaver Hatchling
	hp 800
	roam 1
	takedmg cold 1.0 //just that hot
	takedmg fire 0.0
	takedmg holy 0.5 //some magic involved in creation
	width 32
	height 48

	race demon
	hearingsensitivity 3
	setmodel monsters/firereaver_mini.mdl
	setmoveanim ANIM_WALK

	dbg game.monster.moveprox
}

{ npcatk_validatetarget //first spot

	if $get(PARAM1,isplayer)
	if !DID_WARCRY

	////dbg temp Spotted Target $get(NPCATK_TARGET,name)

	playsound 0 10 SOUND_WARCRY
	setvard DID_WARCRY 1	
	setvard FIRST_ATTACK 1
}

{ my_target_died

	if !$cansee(enemy)

	local RAND_VICT $rand(1,2)
	if ( RAND_VICT == 1 ) setvard ANIM_VICTORY ANIM_VICTORY1
	if ( RAND_VICT == 2 ) setvard ANIM_VICTORY ANIM_VICTORY2
	playanim critical ANIM_VICTORY
	playrandomsound 0 10 SOUND_SEARCH1 SOUND_SEARCH2 SOUND_SEARCH3
}

{ npcatk_hunt

	if NPCATK_TARGET isnot unset
	if $get(NPCATK_TARGET,isplayer)
	//if ( !VOLCANO_ON ) callevent start_volcano

	//throw some projectiles here via ANIM_PROJECTILE
}

{ npc_targetsighted
	if ( $get(NPCATK_TARGET,range) < 256 )
	{
		if game.time > NEXT_FIRE_BURST
		setvard NEXT_FIRE_BURST game.time
		add NEXT_FIRE_BURST FREQ_FIRE_BURST
		callevent do_fire_burst
	}
}

{ reset_smash_delay
	setvard SMASH_DELAY 0
}

//slash (right hook)
{ attack_mele1 //called from model ANIM_SLASH (mattack2) @ frame 30

	local RANDOM_PUSH $rand(90,150)
	setvard PUSH_VEL $relvel(-100,RANDOM_PUSH,110)
	setvard SOUND_ATTACKHIT SOUND_SLASHHIT
	setvard SOUND_ATTACKMISS SOUND_SLASHMISS
	callevent npcatk_dodamage NPCATK_TARGET ATTACK_HITRANGE SLASH_DAMAGE SLASH_HITCHANCE
	setvard PUSH_ATTACK 1

	if $rand(1,5) == 1
	setvard ANIM_ATTACK ANIM_SMASH
}

//smash (overhead strike)
{ attack_mele2 //called from model ANIM_SMASH (mattack3) @ frame 30

	setvard SOUND_ATTACKHIT SOUND_SMASHHIT
	setvard SOUND_ATTACKMISS SOUND_SMASHMISS
	setvard ANIM_ATTACK ANIM_SLASH

	local L_SLASH_DAMAGE SLASH_DAMAGE
	multiply L_SLASH_DAMAGE 3.0

	callevent npcatk_dodamage NPCATK_TARGET ATTACK_HITRANGE L_SLASH_DAMAGE SLASH_HITCHANCE
	//applyeffect NPCATK_TARGET effects/effect_stun 3 1 1
	setvard ANIM_ATTACK ANIM_SLASH
}

{ npcatk_search_init_advanced

	if !SEARCH_ANIM_DELAY
	setvard NPC_DELAYING_UNSTUCK 10.0
	playanim critical ANIM_SEARCH
	playrandomsound 0 10 SOUND_SEARCH1 SOUND_SEARCH2 SOUND_SEARCH3
	setvard SEARCH_ANIM_DELAY 1
	callevent 5.0 reset_search_anim
}

{ reset_search_anim
	setvard SEARCH_ANIM_DELAY 0
}

{ game_dodamage //1: Attack Hit (1/0)  2: Entity Attack hit  3:  Start Position  4:  End Position

	if ( !PARAM1 )
	{
		if ( SOUND_ATTACKMISS isnot unset ) playsound 0 10 SOUND_ATTACKMISS
	}

	if ( PARAM1 )
	{
		if ( SOUND_ATTACKHIT isnot unset )
		{
			playsound 0 10 SOUND_ATTACKHIT
			if PUSH_ATTACK
			addvelocity PARAM2 PUSH_VEL
		}

		if $get(PARAM2,relationship,ent_me) equals enemy
		applyeffect PARAM2 effects/effect_burn 5.0 $get(ent_me,id) DOT_BURN

	}
	setvard PUSH_ATTACK 0
}

{ game_struck

	setvard HP_STORAGE game.monster.hp //anti-heal

	if ( game.monster.hp >= 1500 ) local PAIN_SOUND SOUND_PAIN_STRONG
	if ( game.monster.hp < 1500 ) local PAIN_SOUND SOUND_PAIN_WEAK
	if ( game.monster.hp < 500 ) local PAIN_SOUND SOUND_PAIN_NEAR_DEATH
	playrandomsound 0 10 SOUND_STRUCK1 SOUND_STRUCK2 SOUND_STRUCK1 SOUND_STRUCK2 PAIN_SOUND
}

{ monster_walk_step //called from model anim walk at various frames

	playrandomsound 0 5 SOUND_WALK1 SOUND_WALK2 SOUND_WALK3 SOUND_WALK4
}

{ monster_run_step //called from model anim run at various frames

	playrandomsound 0 5 SOUND_WALK1 SOUND_WALK2 SOUND_WALK3 SOUND_WALK4
}

{ npc_death //called from base_npc

	//death anims
	local RAND_DEATH $rand(2,3)
	//if ( RAND_DEATH == 1 ) setvard ANIM_DEATH ANIM_DEATH1 //use for volcano anim instead
	if ( RAND_DEATH == 2 ) setvard ANIM_DEATH ANIM_DEATH2
	if ( RAND_DEATH == 3 ) setvard ANIM_DEATH ANIM_DEATH3

	setvard SUSPEND_AI 1
	setmovedest none
	setmoveanim ANIM_DEATH
}

{ game_reached_destination

	//idle anims
	if NPCATK_TARGET equals unset
	if NPC_LOST_TARGET equals unset
	if !$cansee(enemy)
	local RAND_VICT $rand(1,2)
	if ( RAND_VICT == 1 ) setvard ANIM_VICTORY ANIM_VICTORY1
	if ( RAND_VICT == 2 ) setvard ANIM_VICTORY ANIM_VICTORY2
	playanim critical ANIM_VICTORY
}

//{ cycle_up
//	//if ( G_DEVELOPER_MODE ) messageall green firereaver: cycle_up ( VOLCANO_ID )
//	//callevent volcano_shoot
//}

//{ start_volcano
//	if ( VOLCANO_ID equals 'VOLCANO_ID' )
//	{
//		clientevent new all monsters/fire_reaver_cl $get(ent_me,origin) $get(ent_me,index)
//		setvard VOLCANO_ID game.script.last_sent_id
//	}
//	if !VOLCANO_ON
//	setvard VOLCANO_ON 1
//	callevent 0.1 volcano_shoot
//}

{ game_death
	//clientevent remove all VOLCANO_ID
	//playsound 2 0 magic/volcano_loop.wav
}

{ npcatk_clear_targets
	setvard VOLCANO_ON 0
	////playsound 2 0 magic/volcano_loop.wav
}


{ do_fire_burst
	setvard AS_ATTACKING game.time
	add AS_ATTACKING 2.0
	playanim critical ANIM_PROJECTILE
}

{ attack_ranged //called from model ANIM_PROJECTILE ("distanceattack") @ frame 40

	playsound 0 10 ambience/steamburst1.wav
	clientevent new all monsters/summon/flame_burst_cl $get(ent_me,index)
	dodamage $get(ent_me,origin) 384 DMG_BURST 100% 0 reflective fire
}
