-- ================================================================================================
-- V E D H A 
-- ================================================================================================

dofile("scripts/entities/entityinclude.lua")

notes = 0

-- ================================================================================================
-- FUNCTIONS
-- ================================================================================================

function init(me)
	setupConversationEntity(me, "Vedha", "Vedha")
	entity_setCollideRadius(me, 64)
	--entity_setCollideRadius(me, 64)
	-- type, cursorRadius, playerRange
	entity_setActivation(me, AT_CLICK, 80, 256)
	entity_initPart(me, "CloakFront", "vedha-cloak-front", 0, 0, 1)
	entity_partSetSegs(me, "CloakFront", 2, 60, 0.1, 0.1, -0.018, 0, 2.5, 1)
	entity_initPart(me, "CloakBack", "vedha-cloak-back", 0, 0, 0)
	entity_partSetSegs(me, "CloakBack", 2, 60, 0.1, 0.1, -0.018, 0, 2.5, 1)
end

function update(me, dt)
	entity_touchAvatarDamage(me, 64, 0, 200)
end

function doSingingHint()
	setControlHint("Hold Right on Naija to Sing", 0, 1)
end

running = false

function activate(me)	
	if running then 
		return
	end
	running = true
	
	vedha = me
	naija = getNaija()
	
	entity_watchSwimToEntitySide(getNaija(), me)
	
	if isStory(0) then
		wnd(1)
		txt("Vedha: This is just a textbox test... to see if all is well in textbox land. Do you understand?")
		txt("Naija: WTF? U tink I wudn't 'stand that sh1t bish?")
		wnd(0)
	elseif isStory(1) then
		wnd(1)
		txt("Vedha: Naija, there are you are... at last.")
		txt("Naija: I came as soon as I could...")
		txt("Vedha: You are a passionate student, Naija. Certainly, I do not doubt your abilities or your ambitions.")
		txt("Vedha: However, the Song you possess is beyond any I have ever seen. It is important that it remains contained until we fully comprehend it.")
		txt("Vedha: Do you understand this?")
		txt("Naija: I understand, Grandmother.")
		txt("Vedha: Good, Child. Now listen closely, I have heard a Voice calling throughout the Verse, warning of dangers yet unseen.")
		txt("Vedha: To the west there stands a large gate, carved many ages ago from pure stone. Perhaps you’ve seen it before.")
		txt("Vedha: Beyond this gate, lies a dark and ancient secret. It is forbidden that you enter there.")
		txt("Naija: How would I be able to open this gate anyways?")
		txt("Vedha: I forbid you to think such thoughts, Child. Stay within my teachings, and you will live a long and happy life, the Old Father willing.")
		txt("Naija: Always the Old Father...")
		txt("Vedha: One day you may have to confront that which you deny, Naija. It would serve you better to heed wisdom, than to spite it.")
		txt("Vedha: Now, Child, show me what you’ve practiced. Call upon the Verse, and sing for me your song.")
		wnd(0)
		KM(4)
		KM(5)
		setStory(1.2)
		--voice("naija_singing")
		doSingingHint()
	elseif isStory(1.2) then
		wnd(1)
		txt("Vedha: Show me what you’ve practiced, Child. Call upon the Verse, and sing for me your song.")
		wnd(0)
		doSingingHint()
	elseif getStory() < 10 then -- isStory(1.3) 
		wnd(1)
		txt("Vedha: Swim along, and remember, the Old Father is watching over you, always.")
		wnd(0)
		setStory(2)
	elseif isStory(10) then
		wnd(1)
		txt("Vedha: At long last, you return dear Child.")
		txt("Naija: ...")
		setSceneColor(0.75, 0.75, 0.75, 3)
		txt("Vedha: Perhaps now you understand why you must be studied. You are simply not –")
		wnd(0)
		--display
		fadeOutMusic(2)
		changeForm(FORM_ENERGY)
		watch(2)
		--txt("NAIJA CONVERTS TO ENERGY FORM")
		wnd(1)
		txt("Vedha: ...")
		playMusic("Bond")
		txt("Naija: I have seen things beyond what you will ever experience, old woman. I am no longer an object of your study. I possess the power to be free.")
		txt("Vedha: So... it will begin with this.")
		txt("Naija: I will not tolerate your riddles. I will be free of you and your limits.")
		txt("Vedha: Foolish Child, do you not see the dark passion burning in your soul as you utter these contemptuous words?")
		txt("Vedha: That which would consume you, you embrace with open arms!")
		txt("Naija: ...")
		txt("Vedha: Heed my warnings, Naija. Greater dangers lie within you than in all of - ")
		txt("Naija: Be Silent!")
		wnd(0)
		
		--display
		--txt("NAIJA BLASTS VEDHA")
		playVisualEffect(VFX_SHOCK, entity_getPosition(naija))
		entity_moveToNode(vedha, getNode("VEDHAKNOCKEDBACK"))
		cam_toNode(getNode("VEDHAHURTCAM"))
		overrideZoom(0.5, 0.5)
		watch(1)
		fadeOutMusic(1)
		setSceneColor(1, 1, 1, 4)
		watch(4)
		overrideZoom(1, 3)
		--display
		changeForm(FORM_NORMAL)
		--txt("NAIJA REVERTS")
		wnd(1)
		txt("Naija: ...")
		txt("Naija: Grandmother...")
		txt("Vedha: Is this how you would treat those you meet on your journeys? Is this how you intend to live your life?")
		txt("Naija: No... I...")
		txt("Vedha: You have passed a barrier, Naija. You can no longer be my student.")
		txt("Naija: ...")
		wnd(0)
		cam_toEntity(naija)
		overrideZoom(0)
		setStory(10.1)
	else
		wnd(1)
		txt("Vedha: You have passed a barrier, Naija. You can no longer be my student.")
		wnd(0)
	end
	running = false
end

function songNote(me, note)
	if isStory(1.2) then
		notes = notes + 1
		if notes == 13 then
			notes = 0
			watch(1)
			wnd(1)
			txt("Vedha: Well done, Child.")
			txt("Vedha: Now swim along, and remember, the Old Father is watching over you, always.")
			wnd(0)
			setStory(1.3)
		end
	end
end

function song(me, songType)
end

function enterState(me)
end

function exitState(me)
end