Here's how it works:
-A perk listens for ranged OnHit events
-The events apply an intermediate ActiveMagicEffect.
-The intermediate ActiveMagicEffect sets the magnitude for the area lightning damage and applies it to its recipient.
So the fundamental problem is: Figuring out what bow/crossbow and what arrow/bolt caused the intermediate ActiveMagicEffect to be applied.
Preferences:
-I would like the effect to scale with bow damage and arrow damage, but the biggest problem is getting arrow damage.
-I have already posted an open question about getting a character's currently equipped arrows/bolts.
I see 3 ways to implement arrow damage, none of which are foolproof:
#1: Use OnObjectEquipped event on the player. Whenever the player equips a bow, log its damage. Whenever the player equips arrows/bolts, log their damage. Use SetEffectMagnitude to update the lightning effect's damage in the OnObjectEquipped event. The problem with this is that players could cheat by launching an arrow from a weak bow and then switching to a much heavier crossbow immediately after, or use a weak arrow and then immediate switch to stronger arrows. The immediate switch would update the area lightning effect's damage, causing it to do way more damage than intended.
#2: Use the OnPlayerBowShot event to update damage, or a "get last projectile launched" function. This is a better solution than #1 because gear switching can't fool it. However, the problem persists if the player is using incredibly fast/modded bows or an "automatic crossbows" mod. This problem could also occur at very long range. For example, suppose the player launches a weak arrow from a weak bow. While the arrow is traveling, the player pulls out an incredibly fast modded crossbow and instantly launches a super bolt that does over 9000 base damage. The area lightning effect's damage is now over 9000. The weak arrow hits, doing an unintended 9000+ damage, and every other NPC in the area starts booing at the player character for cheating.
#3: Get character's currently equipped arrows/bolts (if such a function exists) in the actual area lightning effect instead of pre-setting the effect damage using events. 2 problems with this: It breaks if the special attack is applied on the last arrow of its type. For example, suppose the player is using a premium bow with 1 expensive (and damaging) ebony arrow. Player launches arrow, arrow applies lightning damage effect, and the "get currently equipped arrows" function returns null. The player has just been shortchanged of 20 base damage. Furthermore, it has the same problem as using OnObjectEquipped because the player can just switch arrows after launching an arrow. Note that the "last equipped arrow" problem can be mitigated using OnObjectEquipped as a backup, but it doesn't prevent gear switching.
Currently I'm thinking of implementing option #2, because it's the most reliable. With default ranged choices in Skyrim (no mods), the player will rarely have multiple active arrows at any time because the standard bows/crossbows are so slow. Also: between mods and in-game functions/commands, if the player really wants to cheat that badly, the player will figure out a way to.
Alternately, anyone have any ideas on a foolproof way to implement this?