//:://////////////////////////////////////////////////
//:: shaz_onattacked_love
/*
  Informs the lover that we've been attacked so they can retaliate, then calls our original script

 */

#include "nw_i0_generic"
 
void main()
{
	object oPC = GetFirstPC(FALSE);
	object oLover = GetLocalObject(OBJECT_SELF, "ShazLover");
	string sLoveOnHeartOriginalScript = GetLocalString(OBJECT_SELF, "ShazLoveOnHeartOriginalScript");
	int iFoundTarget = FALSE;
	int iNth = 1;
	
	//SendMessageToPC(oPC, "love target " + GetName(OBJECT_SELF) + " had heartbeat");
	
	if(!GetIsObjectValid(oLover) || GetIsDead(oLover)) {
		// our lover is either dead or gone, restore our original scripting
		SetEventHandler(OBJECT_SELF, CREATURE_SCRIPT_ON_HEARTBEAT, sLoveOnHeartOriginalScript);
	} else {
		//object oEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, oMaster, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);
		object oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, iNth,CREATURE_TYPE_PERCEPTION , PERCEPTION_SEEN);
		while(GetIsObjectValid(oTarget) && (iFoundTarget == FALSE)) {
			if(oTarget != oLover) {
				iFoundTarget = TRUE;
	//			if(GetStandardFactionReputation(STANDARD_FACTION_HOSTILE, oTarget) > 0) {
	//				ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_DEFENDER);
	//			} else {
	//				ChangeToStandardFaction(OBJECT_SELF, STANDARD_FACTION_HOSTILE);
	//			}
				ClearAllActions(TRUE);
				DetermineCombatRound(oTarget);
			}
			iNth++;
			oTarget = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF, iNth,CREATURE_TYPE_PERCEPTION , PERCEPTION_SEEN);
		}
	}
	
	ExecuteScript(sLoveOnHeartOriginalScript, OBJECT_SELF);
}