enderalse/scripts/source/_00e_fs_entropy_bonespiritmonitorsc.psc

145 lines
3.0 KiB
Plaintext

Scriptname _00E_FS_Entropy_BoneSpiritMonitorSC extends activemagiceffect
Event OnEffectStart(Actor akTarget, Actor akCaster)
akCheckActor = akTarget
UpdateDamage()
fLastDamageMod = 0.0 ; Force damage updae on next UpdateDamage, just in case
EndEvent
Event OnEffectFinish(Actor akTarget, Actor akCaster)
bEffectFinished = True
; Wait for UpdateDamage to stop meddling with the magnitudes
While bUpdatingDamage
Utility.WaitMenuMode(0.05)
EndWhile
If fLastDamageMod != 1.0
If spell1
spell1.SetNthEffectMagnitude(0, fOriginalDamage1)
EndIf
If spell2
spell2.SetNthEffectMagnitude(0, fOriginalDamage2)
EndIf
EndIf
EndEvent
Event OnPlayerLoadGame()
; Force delayed update after player load game
fLastDamageMod = 0.0
RegisterForSingleUpdate(1.0)
EndEvent
Event OnUpdate()
UpdateDamage()
EndEvent
Function UpdateDamage()
If bEffectFinished
Return
EndIf
bUpdatingDamage = True
Bool bUpdateSpellDamage = False
; Get equipped bone spirits
Spell spellNew1 = None
Spell spellNew2 = None
Spell spellRight = akCheckActor.GetEquippedSpell(1) ; Right hand
If spellRight && ((spellRight == spell1) || (spellRight == spell2) || _00E_FS_Entropy_BoneSpiritSpells.HasForm(spellRight))
spellNew1 = spellRight
EndIf
Spell spellLeft = akCheckActor.GetEquippedSpell(0) ; Left hand
If spellLeft && (spellLeft != spellRight) && ((spellLeft == spell1) || (spellLeft == spell2) || _00E_FS_Entropy_BoneSpiritSpells.HasForm(spellLeft))
If spellNew1 == None
spellNew1 = spellLeft
Else
spellNew2 = spellLeft
EndIf
EndIf
; New spell1?
If spell1 != spellNew1
If spell1 && spell1 != spellNew2
spell1.SetNthEffectMagnitude(0, fOriginalDamage1)
EndIf
spell1 = spellNew1
If spell1
fOriginalDamage1 = ControlQuest.GetOriginalSpellDamage(spell1)
EndIf
bUpdateSpellDamage = True
EndIf
; New spell2?
If spell2 != spellNew2
If spell2 && spell2 != spellNew1
spell2.SetNthEffectMagnitude(0, fOriginalDamage2)
EndIf
spell2 = spellNew2
if spell2
fOriginalDamage2 = ControlQuest.GetOriginalSpellDamage(spell2)
EndIf
bUpdateSpellDamage = True
EndIf
; Calculate damage modifier (+13% of damage for every 10% of health lost)
Float fDamageMod = 1.0
Float fDamageMult = Math.Floor(10.0 - (akCheckActor.GetAVPercentage("Health") * 10.0)) as Float
If fDamageMult > 0.0
fDamageMod += (0.13 * fDamageMult)
EndIf
If fDamageMod != fLastDamageMod
fLastDamageMod = fDamageMod
bUpdateSpellDamage = True
EndIf
; Update spells' damage
If bUpdateSpellDamage
If spell1
spell1.SetNthEffectMagnitude(0, fOriginalDamage1 * fDamageMod)
EndIf
If spell2
spell2.SetNthEffectMagnitude(0, fOriginalDamage2 * fDamageMod)
EndIf
EndIf
bUpdatingDamage = False
If bEffectFinished == False
RegisterForSingleUpdate(1.0)
EndIf
EndFunction
Spell spell1 = None
Spell spell2 = None
Float fOriginalDamage1
Float fOriginalDamage2
Float fLastDamageMod
Actor akCheckActor
Bool bUpdatingDamage
Bool bEffectFinished
Formlist Property _00E_FS_Entropy_BoneSpiritSpells Auto
_00E_BoneSpiritControlScript Property ControlQuest Auto