//:://////////////////////////////////////////////////
//:: shaz_lover_ondeath
//::   based on NW_C2_DEFAULT7
/*
  the dying lover cries out for his love
*/

#include "x2_inc_compon"
#include "x0_i0_spawncond"
#include "shaz_inc_love"

void main()
{
	string sDeathScript = GetLocalString(OBJECT_SELF, "DeathScript");
	if (sDeathScript != "")
		ExecuteScript(sDeathScript, OBJECT_SELF);

	object oLove = GetLocalObject(OBJECT_SELF, "ShazLoved");
	
	if(CanISpeakIntelligently()) {
		int iRandom = Random(4);
		if(iRandom == 0) {
			SpeakString("I give my life for you, my love!", TALKVOLUME_SHOUT);
		} else if(iRandom == 1) {
			SpeakString("Goodbye... my love...");
		} else if(iRandom == 2) {
			SpeakString(GetFirstName(oLove) + "... I cannot hang on... farewell...");
		} else if(iRandom == 3) {
			SpeakString("May we meet again, " + GetName(oLove) + ", in the afterlife...");
		} else if(iRandom == 4) {
			SpeakString("Avenge me, my love! Ahhh...", TALKVOLUME_SHOUT);
		}
	} else if(CanISpeakAtAll()) {
		int iRandom = Random(2);
		if(iRandom == 0) {
			SpeakString("Arrgg! Nooo...", TALKVOLUME_SHOUT);
		} else if(iRandom == 1) {
			SpeakString("Goodbye, friend...");
		} else if(iRandom == 2) {
			SpeakString("I die for you, " + GetFirstName(oLove) + "...");
		}
	}
	
	if(GetIsOwnedByPlayer(OBJECT_SELF) || GetIsRosterMember(OBJECT_SELF)) {
		// restore faction settings... attacking people while under the influence of love might have changed them
		SetStandardFactionReputation(STANDARD_FACTION_COMMONER, 100);
		SetStandardFactionReputation(STANDARD_FACTION_MERCHANT, 100);
		SetStandardFactionReputation(STANDARD_FACTION_DEFENDER, 100);
		SetStandardFactionReputation(STANDARD_FACTION_HOSTILE, 0);
	}
	
    //int nClass = GetLevelByClass(CLASS_TYPE_COMMONER);
    //int nAlign = GetAlignmentGoodEvil(OBJECT_SELF);
    object oKiller = GetLastKiller();

    // If we're a good/neutral commoner,
    // adjust the killer's alignment evil
    //if(nClass > 0 && (nAlign == ALIGNMENT_GOOD || nAlign == ALIGNMENT_NEUTRAL))
    //{
    //    AdjustAlignment(oKiller, ALIGNMENT_EVIL, 5);
    //}

    // Call to allies to let them know we're dead
    //SpeakString("NW_I_AM_DEAD", TALKVOLUME_SILENT_TALK);

    //Shout Attack my target, only works with the On Spawn In setup
    //SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);

	if (!GetIsSpirit(OBJECT_SELF))
    	craft_drop_items(oKiller);
	
	// Call the script used to identify items detected by the spell Analyze Dweomer
	ExecuteScript("jx_evcr_spfmwk_ondeath", OBJECT_SELF);
}