-------------------------------------------------------------------------------
Ayleid Arcane Archer (AAA)
Version: 2.7
By: Alek (mitchalek@yahoo.com)
Latest version and updates: http://www.tesnexus.com/downloads/file.php?id=39808
Requires OBSE v0020: http://www.tesnexus.com/downloads/file.php?id=37952
Requires Pluggy v125 for HUD elements (optional): http://tesnexus.com/downloads/file.php?id=23979
Video preview (v2.4): http://youtu.be/i3vEdK_VO44
Video preview (v2.0): http://youtu.be/ZLUUcXY5B7w
Video preview (v2.0) by dAb: http://youtu.be/vFIwWpphq3g
-------------------------------------------------------------------------------

Introduction
------------
You search for an ancient artifact that will give you powers of the old Ayleid Arcane Archers. Buy the book "The Arcane Archery" from bookseller Phintias in Imperial City Market District - First Edition to learn about the history of arcane archers and discover the location of the artifact.

Description
-----------
Finding the arcane stone artifact shouldn't be hard but before being able to reach it an Ancient Guardian has to be defeated. He is designed to be difficult but is 100% killable even with level one character by knowing the right strategy.

As long as you carry the arcane stone with you, with exception to bound arrows, you will have access to following abilities:
- Rapid Shots
- Arcane Shots
- Electrogravitic Shots
- Shock Wave
- Auto Aiming
- Quick Arrow Recovery
- Bound Arrows

You can activate the stone from the inventory or bind it to a regular hotkey to bring up the ability selection and configuration menu. There are three distinct shot types and only one can be active at a time. Each has its own niche and gives a specific passive bonus as long as it remains active. Marksman skill is a major factor and almost everything scales with it, including the shock wave and passive bonuses.

Rapid Shots 
-----------
Passive Bonus: Increased movement speed.
While using rapid shots any equipped bow will be automatically replaced by unique rapid bow which is an exact clone except the weapon speed. Furthermore, unequipping rapid bow or switching off rapid shots will give back the original bow with updated conditions so it is perfectly safe to recharge or repair the rapid bow. Some bows cannot be cloned which includes any bow marked as a quest item or having script attached, excluding conjured bow. While holding rapid bow 70% of max magicka will be reserved and therefore not usable. Reserved magicka will be restored as soon as rapid bow is sheathed, any other weapon equipped or rapid shots switched off. Bow and arrow speeds are scaled with marksman skill and the faster it gets the skill xp gain is reduced by same percentage. All knockdown, expert and master marksman perks are disabled while using rapid shots but instead there is additional chance to stagger the target. Arrows will fly at their full speed and power so there is no need to keep them nocked, just aim and shoot. Damage will be the same as using mundane shots but the rate of fire is what makes a huge difference. You will need to carry a lot more arrows than usual because they are wasted pretty quickly.

Arcane Shots
------------
Passive Bonus: Increased magicka.
With these shots your arrows will deal additional damage as a special arcane damage to a single target. Unlike other elemental and magical damage types, arcane damage is affected by target's weakness to magic but not by the resistances. You also have chance to push the target away and chance is increased with higher marksman skill and higher amount of magicka spent. Arcane shots can either be instant or charged for more damage.

Electrogravitic Shots
---------------------
Passive Bonus: Improved acrobatics and reduced encumbrance.
This is AoE damage and crowd control mode. You create short lasting gravitic fields by shooting someone. Primary target will be lifted off the ground and every foe caught in radius will be pulled by force toward that target. Upon contact an electric discharge will hit them, dealing damage and repelling them slightly. Primary target will not suffer any additional damage. Electrogravitic shot can also be used to control a single melee attacker because of the lift effect. Electrogravitic shots can also be either instant or charged for extended duration, larger area of effect and more discharge damage.

Magicka Usage: Instant vs. Charged
----------------------------------
Shots that use magicka as resource, in this case arcane and electrogravitic shots can either be instant or charged. In instant mode every shot will use a small percentage of max magicka which can be configured to fit personal needs. Instant mode is best used when already in combat and there is no time to use charged mode. Charged mode will drain magicka over time while keeping the arrow nocked. One charge is equal to one point of magicka spent and charge rate will scale with marksman skill ranging from 2% to 12% of max magicka per second. Charged mode is best used to initiate combat when not being detected by the enemy.
Backfire might happen if charged for too long or if taking damage while charging. Backfire will bring your health to its minimum so be careful and try avoiding it.

Shock Wave
----------
This is a defensive ability used to repel all enemies around the player. It does not inflict damage so it is best used to gain some range when being swarmed by melee attackers. It will cost 25% of max magicka to activate and is used by pressing jump button while blocking with a bow. Area of effect and force are scaled with marksman skill.

Auto Aiming
-----------
You lock on the target by holding designated key while aiming and your crosshair should follow the target as long as you keep the key pressed. It takes into account target movement to predict where the arrow will meet the target. This works well most of the time but there are times when it will fail. If target changes velocity rapidly it is probably that you will miss if you fire at the wrong moment. Due to technical limitations it is not possible to find the correct size of a collision box so you will not be able to correctly auto aim knocked down targets or targets being deformed by other special animations. Parabola angle will be calculated using ballistic formula but due to the way arrows are affected by gravity precision will vary with the distance. It has been made to work with a lot of trial and error and extra tweaking but should give satisfying result overall.

Quick Arrow Recovery
--------------------
Enabling this feature allows you to recover your own arrows more quickly. When you pick up an arrow or loot the dead body, script will detect the presence of all ammunition in current cell and recover them automatically. No arrows will be added to target inventory on hit while using quick arrow recovery because they can now be recovered by taking them directly from pierced actor 3D models. Note that this is made to work only on arrows that were shot by the player. To supplement the feature maximum number of arrow references kept in the cell has been increased from default 15 to 100 and time before arrows are removed from game world from 1.5 to 5 minutes.

Bound Arrows
------------
This feature is a supplement to existing bound bow spell. By conjuring a bow, stack of bound arrows will also be added and equipped. Bound arrows are equal to vanilla glass arrows in terms of damage but have zero weight and are removed from inventory and game world when bound bow effect ends. You're still permitted to use regular arrows but will have to equip them manually. This feature cannot be turned off and is in effect as long as you're using this mod.

Compatibility
-------------
Following game settings are exclusively managed from within the scripts: fJumpHeightMin, fJumpHeightMax, fJumpFallTimeMin, fJumpFallTimeMult, fArrowGravityBase, fArrowGravityMult, fArrowBowTimerBase, fKnockdownChance, fKnockdownDamageMult, iPerkMarksmanKnockdownChance, iPerkMarksmanParalyzeChance, iArrowInventoryChance and marksman skill use XP increment. So if you are using any other mod that change some of these settings, AAA will take precedence managing them and restoring to backed-up values when they are not used by specific shots. The two settings iArrowMaxRefCount and fArrowAgeMax are changed but are not dynamically managed so they can be overridden by other mods depending on load order. Changes made on marksman skill leveling speed when using rapid shots are derived from currently active settings so it is fully compatible with overhaul mods that change skill leveling rates. Arrow velocities are changed only on arrows in flight fired by specific shots and are also being derived from currently active settings so custom arrow speeds will be unchanged.
It IS recommended to put AAA late in your load order or use BOSS to do it for you. That way any settings changed by other mods can be picked up, otherwise it might break functionality of some mods (known issue with Oblivion XP having marksman skill continue to increase in the old fashion).
It is NOT recommended to use this mod along with other archery overhaul mods that use scripting to change behavior of archery and arrow physics, such as "Duke Patrick's Combat Archery" because unpredictable results might occur when two scripts try to operate on dynamically changed data.

Installation
------------
If you are installing for the first time then skip to step 3.
1. Save the game with mundane shots active.
2. Make a clean save if upgrading from v1.0, v2.0 BETA, v2.0 or v2.1.
3. Extract the archive to your Oblivion Data folder, replace any existing files and activate the "Ayleid Arcane Archer.esp".
4. Use BOSS to set the load order or manually put "Ayleid Arcane Archer.esp" near the bottom of the list to load after your other mods.
5. Rebuild Bashed Patch if you are using Wrye Bash.

To perform a clean save make sure you save the game with mundane shots active then uninstall or disable the mod. Disable or rebuild bashed patch if you are using one and then re-save the game. Always backup your saves!

Make sure that you are using Oblivion Script Extender v0020 or greater because it is mandatory.
If you want additional HUD icon functionality then you must install OBSE add-on Pluggy v125 or greater and enable Pluggy HUD extension by renaming "OBSE_Elys_Pluggy.dll" to "OBSE_Elys_Pluggy_HUD.dll". See readme that comes with Pluggy for more information.

Uninstallation
--------------
Before uninstalling make sure to save the game with mundane shots active. 

Change Log
----------
V2.7
- Ancient Guardian boss encounter and AI has been improved with nearly the same difficulty regardless of player level and running speed. Boss will now always be 10 levels above, will no longer appear to be immortal and auto regenerate, will reflect spells and have movement speed dynamically changed to match the player. Boss damage output will scale with player level and base endurance stat, will swing the weapon much less if player is out of range so he will use pull spell more often trying to close that distance. Time required to activate all of the stone chargers is scaled with player run speed and should be equal to running shortest distance between two chargers five times. Once stone core has been charged boss will desperately try to escape and damage done by discharge is a percentage based on a max health, where player has a chance to protect himself by increasing resist shock and resist magic stats. Discharge will fire at much slower rate for full 30 seconds, will cover whole cell area, will ignore line of sight and will definitely kill the boss.
- New feature: Bound Arrows. Using Bound Bow spell will also grant stack of bound arrows. This feature is available even if arcane stone has not been obtained and cannot be turned off.
- Quick arrow recovery has been improved. Picking up any arrow or looting a dead body will trigger the recovery. Arrows will no longer be removed from pierced 3D models; they will be available for recovery with zero chance of arrows being added to target's inventory on hit. What you see is what you get.
- Arrow litter count has been further increased from 50 to 100.
- Added couple of new HUD icons and most game messages produced by this mod will now display custom icons.
- Use of ability hotkeys can now be optionally toggled off. Arcane stone can still be bound to a regular hotkey and when used menu will popup where desired shot mode can be selected by a single mouse click.
- Rapid shots stagger effect can no longer be reflected back to the player if target has spell reflect ability.
- Fixed a bug related to a new rapid bow script where copy of cloned bow would be placed somewhere near the player if saved game is loaded and cell being loaded is already in memory cache with player in it. (Fixed in 2.6.R2).
- Various small non game breaking fixes.

V2.6:
- Auto aiming projectile interception calculation can now be toggled using configuration menu.
- Auto aiming will not attempt to lock on followers and their followers anymore.
- Bound bow will now work with rapid shots.
- Targets will no longer have chance to be knocked down while using rapid shots.
- Rapid bow can now be dropped, moved to containers or sold to vendors.
- Fixed a bug that would cause player to permanently lose the bow if having rapid bow equipped when going to jail or having all items temporary removed by other means.
- Electrogravitic pull and shock wave will now also ignore second tier of followers (followers of player followers) including summons, except ones that are attacking the player.

V2.5:
- Rapid shots will no longer drain all magicka. Instead, 70% of max magicka will be reserved only while rapid bow is being held. This allows using spells that do not cost more than 30% of max magicka during combat and have full access to magicka while rapid bow is sheathed or any other weapon being used without the need to switch off rapid shots.
- All shot types now have passive bonuses that scale with marksman skill: Rapid shots (increased movement speed), Arcane shots (increased magicka) and Electrogravitic shots (improved acrobatics and reduced encumbrance).
- Shock wave can now only be used while not using movement keys. This is to keep shock wave from being activated while using acrobatics perk dodge ability.
- Auto aiming will now ignore invisible targets.
- Fixed possible CTD caused when picking up the arrow using Quick Arrow Recovery. Crash was caused by trying to update 3D model of actors that exist in the cell but are disabled and haven't been loaded yet.

V2.4:
- New defensive ability: Shock Wave.
- New feature: HUD status icon displaying currently selected shot type (requires Pluggy v125 with HUD functions enabled).
- Friendly targets killed with arcane shots or electrogravitic discharge will now properly count as a murder. This also fixes compatibility issue with Oblivion XP not giving experience points.
- Electrogravitic defense has been removed. It was much easier to hold block than to use shots for the same effect.
- Electrogravitic shots have been improved. Primary target will defy gravity; slowly being lifted off the ground as long as new shots come one after another, still pulling anyone nearby. Discharged targets will not be in knocked state anymore, they will still be repelled but stay in range for next shot. With these changes electrogravitic shots can be used in a rapid succession to inflict damage every time rather than use it once to scatter the enemies.
- Electrogravitic discharge is now considered a player magic projectile even though it is fired from an activator so it is no longer possible to abuse friendly NPCs without it being noted as a crime. Unfortunately I discovered a bug with OBSE function used to achieve this where if more than 5 projectiles were attended all actors would stop using ranged spells for the rest of game session and stay idle most of the combat. So in order to preserve a bit of that functionality it will be used only 5 times per game session and only in situations where player would otherwise escape the crime system.
- Electrogravitic pull, discharge and shock wave will completely ignore any of player's followers and summoned creatures where shock wave is a bit pickier and will not work on friendly NPCs unless they are attacking the player.
- Quick arrow recovery would give more arrows than intended by collecting arrows that are stuck on actor bodies. Because it is impossible to detect which arrow has penetrated the body it has been fixed by refreshing 3D models of all actors in the cell when picking up the arrow which might disable AI processing for a second but will successfully remove any of these arrows before attempting to pick them up.

V2.3:
- New feature: Quick Arrow Recovery.
- As a part of the new feature arrow clutter limit has been increased from 15 to 50 and lifetime from 90 to 300 seconds. It can still be overridden by putting this mod load before any other mod that changes these settings.
- Arcane shots can now be instant. Damage rebalanced by lowering default base cost from 10 to 8, making arcane shots does a bit more damage.
- Electrogravitic shots can now be charged for greater area of effect, pull duration and higher discharge damage.
- Electrogravitic pull mechanics have been improved and greatly increased chance of discharge to hit the target. Actors will now only get pushed if they actually take damage from discharge.
- Magicka consummation is now percentage of total magicka instead of fixed values. This gives better scaling and encourages player to invest in intellect attribute and increase magicka pool for more damage.
- Charging rate scaling has been tweaked from fixed 1 to 20 magicka per second to percentage ranging from 2% to 12% of total magicka per second scaling with marksman skill.
- Charging rate is now steady and fully related to real time, not affected by FPS changes anymore.
- Backfire has been reworked. There are now two ways to trigger the backfire, charging bit longer than it would take to charge from 0% to 100% of max magicka or by a random chance if taking damage while charging. Being hit by backfire will remove all but one health point.
- Disabled expert and master marksman perks while using rapid shots. Instead of small chance to knockdown or paralyze the target there is now fairly high chance to stagger. There is still chance to knockdown the target if marksman skill is high but that has nothing to do with a perk.
- Mundane shots now have separate hotkey, allowing arcane and electrogravitic shots to toggle between instant and charged state via same hotkey.
- Shooting from point-blank range would cause script error because event handler script is executed after the arrow hit the target and projectile reference being removed from the game world. There is no good way to get around the problem so script will now check for arrow reference and restore any magicka spent if projectile cannot be found.
- Ancient guardian boss corpse will not be removed after cell reset anymore. Also fixed a possible issue with stairs not staying raised after the boss has been killed.
- Improved compatibility. Instead of using hardcoded vanilla settings scripts will now operate on current game settings as they are changed by other mods and restore back to backed-up values when they are not being used, including rapid shots marksman skill xp rate reduction which is now fully compatible with overhaul mods that change skill leveling rates.
- Improved event handling and game settings control. Event handlers and changed game settings are now properly reset when loading a saved game.
- Added OBSE version detection routine which automatically locks the door of interior cell where artifact is being held to avoid script malfunctions in case one tries to enter without OBSE installed.

V2.2:
- No more OBSE save game data bloating. Every time rapid shots have been activated a new set of string and array variables were stored and later saved to .obse file. To remove existing bloat a clean save has to be made without this mod in which case ancient guardian will have to be killed and arcane stone looted again. Sorry about that one folks. ;)
- Fixed arcane stone loop sound start playing on game load even if it is in player's inventory.
- Normalized some sound levels.
- Push force of arcane shot procs and electrogravitic discharges is no longer reduced by target's agility, which is normal and has been caused by Oblivion engine itself.
- New tweakable option - body region aiming.

V2.1:
- Fixed possible CTD by undeleting and disabling previously deleted reference.
- Added more console text info: Rapid shots - will print bow and arrow speeds and skill xp gain percentage. Electrogravitic shots - will print maximum pull velocity and shock damage from discharge.
- Electrogravitic discharge push force was originally proportional to discharged shock damage but if damage was resisted or increased due to weakness force was still the same. It should now take that into account and if shock damage is to be fully resisted then no push will occur.
- Arcane shot charging has new visual and sound effects.
- Arcane Stone cannot be given away to vendors anymore.
- Last used shot type and auto aiming on/off state will now be restored when picking up a dropped stone.
- New tweakable option - auto aiming smoothing.

V2.0:
- Arcane Archery is no more an auto obtainable spell. Power is now gained through an ancient artifact hidden in one of Ayleid ruins. Added background story, free quest and new interior cell with unique boss guarding the artifact.
- Removed custom race added in V1.0 and its dependency.
- Added new visual and sound effects.
- New menu system with user text input.
- Added hotkey support.
- All shots can be now customized via in-game config menu: rapid bow max speed, arcane damage base cost, electrogravitic magicka cost.
- Default hotkeys will now be preserved when automatically switching to rapid bow.
- Removed exploit of having magicka fill to max when leaving rapid shot mode. It will now remember how much magicka player had before activating rapid shots.
- Arcane shots will now exploit the weakness to magic.
- Complete rewrite of auto aiming projectile ballistic trajectory formula, it will now use real physics quadratic equation to find the correct angle. It is more accurate but still problematic due to non-linear gravity acceleration on arrows.
- Improved auto aiming target finding when there are more targets close to a crosshair.
- Arcane and electrogravitic shots can no longer push riding actors or their horses, causing them to be displaced and stuck.
- Fixed a bug in damage calculation if effective marksman skill was too high.
- Fixed auto aiming on actors who are swimming.
- Fixed a bug when auto aiming a summoned creature. It would completely disable the script for the whole game session if summoned creature has been killed or timed out.
- Fixed various bugs where aoe spell scripts were affecting non-actors.

V2.0 BETA:
- Two new shot types: Rapid Shots and Electrogravitic Shots.
- New optional supplement: Auto Aiming.
- Arcane Shots will now fire faster arrows, scaling with magicka spent on charges.

V1.0:
- Initial public release

Credits
-------
Thanks to dAb for testing, debug info and making a cool video.