public void OnSpellCastAt(uint CasterObjectId, int SpellId)
{
if (!IsAIControlled)
return;
int nSpell = Script.GetLastSpell();
int nHostile = Script.StringToInt(Script.Get2DAString("spells","HostileSetting", nSpell));
//===================================================================================================================================
//======================= Handling for harmful spells ==============================================================================
//===================================================================================================================================
if (nHostile == 1)
{
// As this is a harmful spell, the target is probably going to be unhappy about it.
bool bAngry = true;
uint CasterId = Script.GetLastSpellCaster();
int nReputation = Script.GetReputation(this.ObjectId, CasterId);
// If the creature is -already- hostile, we don't need to make it any -more- angry.
if (nReputation <= 10)
bAngry = false;
// If this is the caster hitting him or herself, no doubt that's angering, but we don't need to change behavior because of it.
if (CasterId == this.ObjectId)
bAngry = false;
// Maybe mind-controlling magic is in play?
if (bAngry)
{
if (_IsMindMagiced(this.ObjectId)) bAngry = false;
if (_IsMindMagiced(CasterId)) bAngry = false;
}
// If mind magics didn't motivate the spell, we check to see if it's plausibly friendly fire.
if (bAngry)
{
int nTargetArea = Script.StringToInt(Script.Get2DAString("spells", "TargetingUI", nSpell));
if (_IsFriendlyFire(nTargetArea)) bAngry = false;
}
// Is the target a friend to the caster?
if (bAngry)
{
CreatureObject Caster = Server.ObjectManager.GetCreatureObject(CasterId, true);
AIParty Party = this.Party;
// This is the fault of a bug in the AI; best not to compound it.
if (Party.PartyMembers.Contains(Caster))
{
bAngry = false;
}
// These two creatures are friends.
else if (nReputation > 89)
{
Script.SetLocalInt(this.ObjectId, "FRIENDLY_FIRED", Script.GetLocalInt(this.ObjectId, "FRIENDLY_FIRED") + 1);
}
// Neutral creatures take direct attacks personally. Your friends try to trust you, but will snap if abused too much.
else if (nReputation > 10 || Script.GetLocalInt(this.ObjectId, "FRIENDLY_FIRED") > Script.d4(3))
{
// And all of them are going to get angry.
foreach (CreatureObject CurrentPartyMember in this.Party.PartyMembers)
{
_SetMutualEnemies(CurrentPartyMember.ObjectId, CasterId);
if (!CurrentPartyMember.HasCombatRoundProcess)
CurrentPartyMember.SelectCombatRoundAction(false);
}
this.Party.AddPartyEnemy(Caster);
this.Party.EnemySpellcasters.Add(Caster);
HasCombatRoundProcess = true;
if (!UsingEndCombatRound)
{
SelectCombatRoundAction(false);
}
}
}
}
//===================================================================================================================================
//======================= Handling for non-harmful spells ==========================================================================
//===================================================================================================================================
else
{
}
}