This originally started as a simple extension of an existing mod I've created. As I've been asking questions, it has grown into a fairely complicated standalone project.
There are a few points left I'm hoping for help/pointers on. The kind folks at the QQ thread have directed me to making me own thread so I can stop polluting over there ^^.
The following is a detailed overview of what I'm trying to do, what I've accomplished so far and what I still need to learn/achieve.
Spoiler
The end goal:
Spoiler
I want a way of keeping track of what I'm going to call "Essence" on an actor that wields an "Essence Enchanted" weapon. Multiple (read potentially infinite) actors should be able to utilize this.
The actor (here on known as the 'wielder') gains Essence by killing/defeating enemies and by dealing damage with their weapon. Kills grant more essence than doing damage and the essence gained by doing damage is based around the base weapon damage up to a maximum. So powerful weapons will net more Essence gain per hit than weaker ones, but still net less than performing a kill.
As the Wielder gains more Essence, they benefit in one of several configurable ways: (I'll call them stat mods)
-increased maximum health
-increased maximum magicka
-slightly increased size and increased physical damage
More Essence means the above will have greater effect.
When the wielder takes damage, if their health drops below 50%, the accumulated essence is used to restore health back to 50%. One Essence point will be worth so much health. The stats mods will decrease in effectiveness because some essence has been consumed. But it can of course be regained.
When the wielders magicka levels drop below 50%, the accumulated essence is used to restore magicka levels back above 50%. One Essence point will be worth so much magicka. The stats mods will decrease in effectiveness because some essence has been consumed. But it can of course be regained.
Only one of the above "restoration effects" will occur at one time. They are dependant on the type of "Essence Enchantment" the Wielders weapon has equipped.
When the Wielder unequips the Essence Enchanted weapon, they do not lose Essence, but can no longer gain any more Essence either.
What I've achieved so far using what:
Spoiler
I'm using Faction ranking to keep track of accumulated Essence.
I'm using a Faction ranking to keep track of accumulated damage (eg. 1000 damage = 1 essence point, so every point in this "damage faction" equals to 20 damage)
I'm using an Ability that is added via the Weapon Enchantment to the wielder to manage restoring health/magicka on the actor and tracking hits/use of magicka (currently only have the "health" tracking part implemented).
I'm using a Weapon Enchantment to manage giving the actor the ability and to detect when the weapon does damage or kills an actor.
I'm using a Quest script to store some common properties:
-Faction
-functions used for updating stats when Faction ranking changes
-constants used for determining things like how much essence weapon damage is worth, how many faction points a kill is worth, how stat mods scale per faction point gained/lost.
-accessor/mutator functions for the above constants
I'm also using the Damage faction to determine when the weapon with the Essence Enchantment is unequipped. The actor will be removed from the damage tracking faction but not the essence faction so accumulated Essence is never lost. That way when the actor gets loaded into a new cell, the script can check if the actor is a part of the damage faction. If they are, then the Ability stays on because that means the weapon wasn't unequipped.
If they aren't part of the damage faction, the ability does not get removed because that means the weapon wasn't unequipped.
Since I can't prevent the ActiveMagicEffect of the ability from terminating (the OnEffectFinish event fires), I re-add the ability if the proper conditions are met.
What I'm still working on/having problems with:
Spoiler
How to keep stat changes (base health, base magicka, size) persistent across different sessions. There's two ways I can think of accomplishing this:
1. Have some kind of a spell on the player so I can call the "OnPlayerLoadGame" Event. But I'd like to avoid adding things to the player.
2. The OnInit event.
But I'd like to tackle the ReferenceAlias part first.
How to work with and manage ReferenceAliases if it is necessary for me to use them.
Right now, the biggest question I have is: do I need to use ReferenceAliases?
Thank you all.