new const NINTENDOMOD_LUIGI_PLUGIN[] = "Nintendo Mod - Luigi"
new const NINTENDOMOD_LUIGI_VERSION[] = "1.1"
new const NINTENDOMOD_LUIGI_AUTHOR[] = "Soloist"

/*
	Passive: Silent Walking
		* Footsteps are silent.
	Skill 1: Fire Uppercut
		* On knife attack the enemy is lauched upwards and backwards.
	Skill 2: Long Jump
		* Press duck+jump you will be lauched forward.
	Skill 3: Speed
		* Runs Faster.
	PowerUp: Vacuum
		* Vacuum the enemies weapon (Make enemy drop their weapons).

	Future Plans
		Add CVARS for values

	Written By Soloist
	Version 1.1
	Last Updated On 08/26/06

	*************************************************************************************

	Changelog
		Version 1.1
			* Fixed speed bug
		Version 1.0
			* Release of the plugin
*/

#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <nintendomod>

new const LUIGI_FOOTSTEPSOUND[11] = {100, 105, 110, 115, 120, 125, 150, 175, 200, 225, 999};
new const LUIGI_FIREUPPERCUTDMG[3] = {20, 30, 40};
new const Float:LUIGI_FIREUPPERCUTPROB[3] = {0.333, 0.666, 0.75};
new const Float:LUIGI_SPEEDNUM[3] = {300.0, 325.0, 350.0};

new charName[] = "Luigi";
new passiveName[] = "Silent Walking";
new skill1Name[] = "Fire Uppercut";
new skill2Name[] = "Long Jump";
new skill3Name[] = "Speed";
new powerupName[] = "Vacuum";
new initName[] = "Luigi_Init";
new keyDownName[] = "Luigi_Vacuum";

new passiveHelp[] = "Footsteps are silent.";
new skill1Help[] = "On knife attack the enemy is lauched upwards and backwards.";
new skill2Help[] = "Press duck+jump you will be lauched forward.";
new skill3Help[] = "Runs Faster.";
new powerupHelp[] = "Vacuum the enemies weapon (Make enemy drop their weapons).";

new PlayerLevel[33];
new PlayerSkill1[33];
new PlayerSkill2[33];
new PlayerSkill3[33];
new PlayerPowerUp[33];

new bool:BetweenRounds;

new fireUpperCut;

public plugin_init()
{
	if(is_plugin_loaded("Nintendo Mod") == -1)
	{
		server_print("**********************************");
		server_print("*** Nintendo Mod is not loaded ***");
		server_print("**********************************");
		pause("ae");
		return;
	}

	register_plugin(NINTENDOMOD_LUIGI_PLUGIN, NINTENDOMOD_LUIGI_VERSION, NINTENDOMOD_LUIGI_AUTHOR);

	register_cvar("NintendoMod_Luigi_Version", NINTENDOMOD_LUIGI_VERSION, FCVAR_SERVER|FCVAR_SPONLY);

	register_event("ResetHUD", "ResetHUD", "b");
	register_logevent("RoundStart", 2, "1=Round_Start");
	register_logevent("RoundEnd", 2, "1=Round_End");

	register_forward(FM_PlayerPreThink, "Luigi_SilentWalking");

	register_event("Damage", "Luigi_FireUpperCut", "b", "2!0");
	register_event("CurWeapon", "Luigi_Speed", "be");

	Nintendo_RegisterChar(charName, passiveName, skill1Name, skill2Name, skill3Name, powerupName, initName);
	Nintendo_RegisterHelp(charName, passiveHelp, skill1Help, skill2Help, skill3Help, powerupHelp);
	Nintendo_RegisterKeyDown(charName, keyDownName);

	register_srvcmd(initName, initName);
	register_srvcmd(keyDownName, keyDownName);
}

public plugin_precache()
{
	fireUpperCut = engfunc(EngFunc_PrecacheModel, "sprites/nintendomod/luigi_flame.spr");
}

public client_connect(id)
{
	if(!Nintendo_Active() || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	InitPlayer(id);

	return PLUGIN_CONTINUE;
}

public client_disconnect(id)
{
	if(!Nintendo_Active() || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	InitPlayer(id);
	remove_task(id);

	return PLUGIN_CONTINUE;
}

public InitPlayer(id)
{
	if(!Nintendo_Active() || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	PlayerLevel[id] = 0;
	PlayerSkill1[id] = 0;
	PlayerSkill2[id] = 0;
	PlayerSkill3[id] = 0;
	PlayerPowerUp[id] = 0;

	return PLUGIN_CONTINUE;
}

public Luigi_Init()
{
	new temp[33];
	read_argv(1, temp, 32);
	new id = str_to_num(temp);

	if(!Nintendo_Active() || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	read_argv(2, temp, 32);
	new index  = str_to_num(temp);

	if(index == 0)
	{
		read_argv(3, temp, 32);
		new level = str_to_num(temp);
		read_argv(4, temp, 32);
		new skill1 = str_to_num(temp);
		read_argv(5, temp, 32);
		new skill2 = str_to_num(temp);
		read_argv(6, temp, 32);
		new skill3 = str_to_num(temp);
		read_argv(7, temp, 32);
		new powerup = str_to_num(temp);

		PlayerLevel[id] = level;
		PlayerSkill1[id] = skill1;
		PlayerSkill2[id] = skill2;
		PlayerSkill3[id] = skill3;
		PlayerPowerUp[id] = powerup;
	}
	else
	{
		read_argv(3, temp, 32);
		new value = str_to_num(temp);

		switch(index)
		{
			case 1: PlayerLevel[id] = value;
			case 2: PlayerSkill1[id] = value;
			case 3: PlayerSkill2[id] = value;
			case 4: PlayerSkill3[id] = value;
			case 5: PlayerPowerUp[id] = value;
		}
	}

	ResetHUD(id);

	return PLUGIN_CONTINUE;
}

public RoundStart()
{
	if(!Nintendo_Active())
		return PLUGIN_HANDLED;

	BetweenRounds = false;

	return PLUGIN_CONTINUE;
}

public RoundEnd()
{
	if(!Nintendo_Active())
		return PLUGIN_HANDLED;

	BetweenRounds = true;

	return PLUGIN_CONTINUE;
}

public ResetHUD(id)
{
	if(!Nintendo_Active() || !Nintendo_HasChar(id, charName) || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	Luigi_LongJump(id);
	set_task(get_cvar_float("mp_freezetime"), "Luigi_Speed", id);

	return PLUGIN_CONTINUE;
}

public Luigi_SilentWalking(id) // Passive
{
	if(!Nintendo_Active() || !Nintendo_HasChar(id, charName) || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	set_pev(id, pev_flTimeStepSound, LUIGI_FOOTSTEPSOUND[PlayerLevel[id]]);

	return PLUGIN_CONTINUE;
}

public Luigi_FireUpperCut(id) // Skill 1
{
	if(!Nintendo_Active() || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)
	new headshot = bodypart == 1 ? 1 : 0

	if(!Nintendo_HasChar(attacker, charName) || !Nintendo_IsValidPlayer(attacker))
		return PLUGIN_HANDLED;

	if(PlayerSkill1[attacker] > 0)
	{
		if(weapon == CSW_KNIFE)
		{
			if(Nintendo_TeamKill(id, attacker))
			{
				new Float:randomnumber = random_float(0.0, 1.0);
				if(randomnumber <= LUIGI_FIREUPPERCUTPROB[PlayerSkill1[attacker] - 1])
				{
					new idVelocity[3], vicVelocity[3];

					pev(attacker, pev_velocity, idVelocity);
					pev(id, pev_velocity, vicVelocity);

					new Float:velocity[3];
					velocity[0] = (vicVelocity[0] - idVelocity[0]) * 5.0;
					velocity[1] = (vicVelocity[1] - idVelocity[1]) * 5.0;
					velocity[2] = 300.0;

					set_pev(id, pev_velocity, {0.0, 0.0, 0.0});
					set_pev(id, pev_velocity, velocity);

					Luigi_FireUpperCutSprite(id, attacker);
					Nintendo_ExtraDamage(attacker, id, LUIGI_FIREUPPERCUTDMG[PlayerSkill1[attacker] - 1], "Fire Uppercut", headshot);
				}
			}
		}
	}

	return PLUGIN_CONTINUE;
}

public Luigi_FireUpperCutSprite(victim, attacker) // Skill 1
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
	write_byte(TE_BEAMENTS)
	write_short(attacker);
	write_short(victim);
	write_short(fireUpperCut);
	write_byte(0);
	write_byte(15);
	write_byte(10);
	write_byte(80);
	write_byte(10);
	write_byte(255);
	write_byte(0);
	write_byte(0);
	write_byte(255);
	write_byte(0);
	message_end();

	new origin[3]
	pev(victim, pev_origin, origin)

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
	write_byte(TE_ELIGHT);
	write_short(victim);
	write_coord(origin[0]);
	write_coord(origin[1]);
	write_coord(origin[2]);
	write_coord(100);
	write_byte(255);
	write_byte(0);
	write_byte(0);
	write_byte(15);
	write_coord(0);
	message_end();
}

public Luigi_LongJump(id) // Skill 2
{
	if(!Nintendo_Active() || !Nintendo_HasChar(id, charName) || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	if(PlayerSkill2[id] > 0)
		give_item(id, "item_longjump");

	return PLUGIN_CONTINUE;
}

public Luigi_Speed(id) // Skill 3
{
	if(!Nintendo_Active() || !Nintendo_HasChar(id, charName) || !Nintendo_IsValidPlayer(id) || BetweenRounds)
		return PLUGIN_HANDLED;

	if(PlayerSkill3[id] > 0)
		Nintendo_SetSpeed(id, LUIGI_SPEEDNUM[PlayerSkill3[id]-1]);

	return PLUGIN_CONTINUE;
}

public Luigi_Vacuum()
{
	new temp[6]
	read_argv(1, temp, 5)
	new id = str_to_num(temp)

	if(!Nintendo_Active() || !Nintendo_HasChar(id, charName) || !Nintendo_IsValidPlayer(id))
		return PLUGIN_HANDLED;

	if(PlayerPowerUp[id] == 1)
	{
		new victim, body;
		get_user_aiming(id, victim, body)
		if(Nintendo_IsValidPlayer(victim))
		{
			if(Nintendo_TeamKill(id, victim))
			{
				Nintendo_PowerUpUsed(id, 1, 30);
				new weapons[32], num, weapname[24]
				get_user_weapons(victim, weapons, num)

				for(new i = 0; i < num; i++)
				{
					if(weapons[i] == CSW_C4 || weapons[i] == CSW_KNIFE || weapons[i] == CSW_HEGRENADE || weapons[i] == CSW_SMOKEGRENADE || weapons[i] == CSW_FLASHBANG)
						continue;

					get_weaponname(weapons[i], weapname, 23);
					engclient_cmd(victim, "drop", weapname);
				}

				engclient_cmd(victim, "weapon_knife");

				new name[33], tmp[54];
				get_user_name(id, name, 32);
				format(tmp, 53, "[Luigi] %s vacuumed your weapons", name);
				Nintendo_StatusHUD(victim, tmp);
			}
		}
		else
			Nintendo_PowerUpDeny(id, "Not a valid target.");
	}

	return PLUGIN_CONTINUE;
}
