//::///////////////////////////////////////////////
//:: shaz_lover_spellcastat
//::   based on NW_C2_DEFAULTB


//#include "nw_i0_generic"
//#include "x2_i0_spells"
#include "ginc_behavior"
#include "shaz_inc_love"


void main()
{
    object oCaster = GetLastSpellCaster();
	int nSpellID = GetLastSpell();

	effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1);
	// the ToM states the "caster falls in love" is only removable by Remove Curse,
	//   but the "target falls in love" is removable by dispel magic. 
	//   Since this is a COMPUTER rpg, I'm gona let both apply for both
	switch(nSpellID) {
		case SPELL_DISPEL_MAGIC:
		case SPELL_GREATER_DISPELLING:
		case SPELL_GREATER_WALL_DISPEL_MAGIC:
		case SPELL_LESSER_DISPEL:
		case SPELL_WALL_DISPEL_MAGIC:
		case SPELL_I_VORACIOUS_DISPELLING:
		case SPELL_MORDENKAINENS_DISJUNCTION:
		case SPELL_REMOVE_CURSE:
			if(CanISpeakAtAll()) {
				SpeakString("Huh? What happened?", TALKVOLUME_SHOUT);
			}
			SetLocalObject(OBJECT_SELF, "ShazLoved", OBJECT_INVALID);
			SafeRestoreEventHandlers(OBJECT_SELF);
			ClearAllActions(TRUE);
			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);
			}
			ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(OBJECT_SELF));
			break;
		default:
			break;
	}
    

    // Send the user-defined event as appropriate
    if(GetSpawnInCondition(NW_FLAG_SPELL_CAST_AT_EVENT))
    {
        SignalEvent(OBJECT_SELF, EventUserDefined(EVENT_SPELL_CAST_AT));
    }


}