/*
* 自定义 Massn 死亡 NPC 实体 / Custom Massn dead NPC entity
* 作者(Author): Ice Box
* Steam: https://steamcommunity.com/id/ibox666/
* 如需使用此脚本请联系作者 / If you need to use this script, please contact the author
*/

namespace MassnDead
{

const int HEAD_GROUP = 1;
const int HEAD_WHT = 0;
const int HEAD_BLK = 1;
const int HEAD_NVG = 2;

const int GUN_GROUP = 2;
const int GUN_M16 = 0;
const int GUN_M40A1 = 1;
const int GUN_NONE = 2;

class CMonsterMassnDead : ScriptBaseMonsterEntity
{
	private int m_iPose = -1;
	private int m_iBody = -1;
	private array<string> m_szPoses = { "deadstomach", "deadside", "deadsitting" };
	
	int ObjectCaps()
	{
		return 0;
	}
	
	int Classify()
	{
		return self.GetClassification( CLASS_HUMAN_MILITARY );
	}
	
	string GetMassnModel()
	{
		return "models/cad/massn.mdl";
	}
	
	bool KeyValue( const string& in szKey, const string& in szValue )
	{
		if( szKey == "pose" )
		{
			m_iPose = atoi( szValue );
		}
		else if( szKey == "body" )
		{
			m_iBody = atoi( szValue );
		}
		
		return BaseClass.KeyValue( szKey, szValue );
	}
	
	void Precache()
	{
		BaseClass.Precache();
		g_Game.PrecacheModel( GetMassnModel() );
	}
	
	void Spawn()
	{
		Precache();
		g_EntityFuncs.SetModel( self, GetMassnModel() );
		self.pev.effects = 0;
		self.pev.sequence = 0;
		self.pev.health = 800.0f;
		self.m_bloodColor = BLOOD_COLOR_RED;
		self.MonsterInitDead();
		
		if( string( self.m_FormattedName ).IsEmpty() )
		{
			self.m_FormattedName = "Dead Massn";
		}
	}
	
	void PostSpawn()
	{
		int finalBody = m_iBody;
		if( m_iBody == -1 && self.pev.body != 0 )
		{
			finalBody = self.pev.body;
		}
		else if( m_iBody == -1 )
		{
			finalBody = 0;
		}
		
		self.pev.body = finalBody;
		SetBodygroups( finalBody );
		
		if( m_iPose >= 0 && m_iPose < int(m_szPoses.length()) )
		{
			self.pev.sequence = self.LookupSequence( m_szPoses[m_iPose] );
		}
		else
		{
			self.pev.sequence = self.LookupSequence( "deadstomach" );
		}
		
		if( self.pev.sequence == -1 )
		{
			self.pev.sequence = 0;
		}
	}
	
	void SetBodygroups( int body )
	{
		int head = 0;
		int gun = 0;
		
		switch( body )
		{
			case 0: head = HEAD_WHT; gun = GUN_NONE; break;
			case 1: head = HEAD_WHT; gun = GUN_M16; break;
			case 2: head = HEAD_WHT; gun = GUN_M40A1; break;
			case 3: head = HEAD_BLK; gun = GUN_NONE; break;
			case 4: head = HEAD_BLK; gun = GUN_M16; break;
			case 5: head = HEAD_BLK; gun = GUN_M40A1; break;
			case 6: head = HEAD_NVG; gun = GUN_NONE; break;
			case 7: head = HEAD_NVG; gun = GUN_M16; break;
			case 8: head = HEAD_NVG; gun = GUN_M40A1; break;
			
			default:
				head = HEAD_WHT;
				gun = GUN_NONE;
				break;
		}
		
		self.SetBodygroup( HEAD_GROUP, head );
		self.SetBodygroup( GUN_GROUP, gun );
	}
	
	void SetYawSpeed()
	{
		self.pev.yaw_speed = 0;
	}
	
	int TakeDamage( entvars_t@ pevInflictor, entvars_t@ pevAttacker, float flDamage, int bitsDamageType)
	{
		return BaseClass.TakeDamage( pevInflictor, pevAttacker, flDamage, bitsDamageType );
	}
	
	void Touch( CBaseEntity@ pOther )
	{
	}
	
	void Use( CBaseEntity@ pActivator, CBaseEntity@ pCaller, USE_TYPE useType, float flValue )
	{
	}
	
	void PainSound() {}
	void DeathSound() {}
	void AlertSound() {}
	void IdleSound() {}
	void AttackSound() {}
	
	Schedule@ GetSchedule()
	{
		return null;
	}
	
	void RunAI()
	{
	}
}

void Register()
{
	g_CustomEntityFuncs.RegisterCustomEntity( "MassnDead::CMonsterMassnDead", "monster_massn_dead" );
}

}