#include "Define.h"
#include "GossipDef.h"
#include "Item.h"
#include "Player.h"
#include "ScriptedGossip.h"
#include "ScriptMgr.h"
#include "Spell.h"

class teleportation_key : public ItemScript
{
public:
	teleportation_key() : ItemScript("teleportation_key") { }

	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
	{
		if (player->IsInCombat())
		{
			player->GetSession()->SendNotification("Vous êtes en combat !");
			return false;
		}

		player->PlayerTalkClass->ClearMenus(); // Clears old options
		if (player->getFaction() == 469) {
			player->ADD_GOSSIP_ITEM(0, "Hurlevent", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
			player->ADD_GOSSIP_ITEM(0, "Darnassus", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
			player->ADD_GOSSIP_ITEM(0, "Forgefer", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3);
			player->ADD_GOSSIP_ITEM(0, "L'Exodar", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4);
			player->ADD_GOSSIP_ITEM(0, "Shattrath", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5);
			player->ADD_GOSSIP_ITEM(0, "Dalaran", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6);
			player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, item->GetGUID());
		}
		else {
			player->ADD_GOSSIP_ITEM(0, "Orgrimmar", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7);
			player->ADD_GOSSIP_ITEM(0, "Les Pitons-du-Tonnerre", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
			player->ADD_GOSSIP_ITEM(0, "Lune d'argent", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 9);
			player->ADD_GOSSIP_ITEM(0, "Fossoyeuse", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 10);
			player->ADD_GOSSIP_ITEM(0, "Shattrath", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5);
			player->ADD_GOSSIP_ITEM(0, "Dalaran", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6);
			player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, item->GetGUID());
		}
		return false; // Cast the spell on use normally
	}

	void OnGossipSelect(Player* player, Item* item, uint32 sender, uint32 action) override
	{
		player->PlayerTalkClass->ClearMenus();

		switch (action)
		{
		case GOSSIP_ACTION_INFO_DEF + 1:
			player->TeleportTo(0, -8971.455078f, 507.174713f, 96.354309f, 0.686878f); // hurlevent
			break;
		case GOSSIP_ACTION_INFO_DEF + 2:
			player->TeleportTo(1, 9950.881836f, 2318.748047f, 1336.552124f, 1.611140f); // Darnassus
			break;
		case GOSSIP_ACTION_INFO_DEF + 3:
			player->TeleportTo(0, -4982.091309f, -881.414978f, 501.659668f, 5.425827f); // Forgefer
			break;
		case GOSSIP_ACTION_INFO_DEF + 4:
			player->TeleportTo(530, -3965.699951f, -11653.599609f, -138.843994f, 0.852154f); // L'exodar
			break;
		case GOSSIP_ACTION_INFO_DEF + 5:
			player->TeleportTo(530, -1871.349365f, 5420.459473f, -10.463559f, 0.894960f); // Shattrath
			break;
		case GOSSIP_ACTION_INFO_DEF + 6:
			player->TeleportTo(571, 5804.149902f, 624.770996f, 647.757029f, 1.640000f); // Dalaran
			break;
		case GOSSIP_ACTION_INFO_DEF + 7:
			player->TeleportTo(1, 1643.577637f, -4412.415039f, 16.934841f, 2.821898f); // Orgrimmar
			break;
		case GOSSIP_ACTION_INFO_DEF + 8:
			player->TeleportTo(1, -1277.369995f, 124.804001f, 131.287003f, 5.222740f); // pitons du tonnerre
			break;
		case GOSSIP_ACTION_INFO_DEF + 9:
			player->TeleportTo(530, 9965.810547f, -7084.448730f, 47.708740f, 0.920067f); // Lune d'argent
			break;
		case GOSSIP_ACTION_INFO_DEF + 10:
			player->TeleportTo(0, 1560.92762f, 224.335693f, -43.102650f, 0.730324f); // Fossoyeuse
			break;
		}
		player->CLOSE_GOSSIP_MENU();
	}
};

class item_teleportation_icc : public ItemScript
{
public:
	item_teleportation_icc() : ItemScript("item_teleportation_icc") { }

	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
	{
		//player->CastSpell(player, 150000);
		player->TeleportTo(571, 5863.0f, 2105.0f, 636.0f, 3.45f);
		return true; // Cast the spell on use normally
	}
};

class item_teleportation_halion : public ItemScript
{
public:
	item_teleportation_halion() : ItemScript("item_teleportation_halion") { }

	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
	{
		//player->CastSpell(player, 150000);
		player->TeleportTo(571, 3560.0f, 274.0f, -115.0f, 0);
		return true; // Cast the spell on use normally
	}
};

void AddSC_custom_item_scripts()
{
	new teleportation_key();
	new item_teleportation_icc();
	new item_teleportation_halion();
}