-
Notifications
You must be signed in to change notification settings - Fork 0
/
INEQ_MagickaSiphon.psc
785 lines (687 loc) · 26.6 KB
/
INEQ_MagickaSiphon.psc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
Scriptname INEQ_MagickaSiphon extends INEQ_RechargeBase
{Diverts a portion of MP regen to registered abilities through events}
; Abilities should have a MP requirement and a priority. Abilities with the same priority are charged simultaneously.
; This means that passive wards with high priority will be charged first, ignoring all else while other abilities that may have other charging
; mechanics like the auriel's shield or the bloodskal blade can use it when somehting like the ward isn't depending on it.
;=========================================== Properties ===========================================================================>
GlobalVariable Property TimeScale Auto
float Property DrainPercentage Auto Hidden
;========================================== Autoreadonly ==========================================================================>
float Property SecondsInDay = 86400.0 Autoreadonly
float Property CombatCheck = 10.0 Autoreadonly ; checks at most CombatCheck seconds after last update
float Property MPResetDelay = 1.0 Autoreadonly ; Limits rapid checking when mp is close to full
float Property DEFDrainPercentage = 1.0 Autoreadonly
bool Property bDebugTrace = True Autoreadonly
bool Property bDebugMessage = True Autoreadonly
String Property CastStop = "CastStop" Autoreadonly
;=========================================== Variables ============================================================================>
float previousTime
float TotalMagicka
float MagickaRateMult
float MagickaRateMag
float DrainMult
float DrainMag
INEQ_EventListenerBase[] RegisteredAB
float[] RegisteredMP
int [] RegisteredPR
INEQ_EventListenerBase[] BufferAB
float[] BufferMP
int [] BufferPR
INEQ_EventListenerBase[] UnregisterAB
bool bSiphonBelowMax
int numRegistered
int numBuffered
int numPriority
int numUnregistered
;===============================================================================================================================
;==================================== Maintenance ================================================
;================================================================================================
Event OnPlayerLoadGame()
parent.PlayerLoadGame()
; Restores player's MagickaRateMult if the Active state was left in an unexpected way
if DrainMult
String currentState = GetState()
if currentState == "ActiveFull" || currentState == "Off"
RestoreMagickaDrain()
endif
endif
EndEvent
Function RestoreDefaultFields()
parent.RestoreDefaultFields()
DrainPercentage = DEFDrainPercentage
bSiphonBelowMax = False
RestoreMagickaDrain()
EndFunction
Function FullReset()
parent.FullReset()
RegisteredAB = new INEQ_EventListenerBase[32]
RegisteredMP = new float[32]
RegisteredPR = new int[32]
BufferAB = new INEQ_EventListenerBase[16]
BufferMP = new float[16]
BufferPR = new int[16]
UnregisterAB = new INEQ_EventListenerBase[16]
numRegistered = 0
numBuffered = 0
numPriority = 0
numUnregistered = 0
EndFunction
;===============================================================================================================================
;==================================== Listening Events ================================================
;================================================================================================
Event OnAnimationEvent(ObjectReference akSource, string EventName)
ListenerCheckForUpdate()
EndEvent
Event OnSpellCast(Form akSpell)
ListenerCheckForUpdate()
EndEvent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
ListenerCheckForUpdate()
EndEvent
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
ListenerCheckForUpdate()
EndEvent
; Reigster for immediate update if MagickaRateMult or TotalMagicka has changed (If TotalMagicka is at 0, check anyway)
Function ListenerCheckForUpdate()
if MagickaRateMult != SelfRef.GetAV("MagickaRateMult") || ! ( SelfRef.getAVPercentage("Magicka") && ( TotalMagicka == SelfRef.getAV("Magicka") / SelfRef.getAVPercentage("Magicka") ) )
RegisterForSingleUpdate(0)
endif
EndFunction
;===============================================================================================================================
;==================================== States ================================================
;================================================================================================
; Waits for a new register
Auto State Off
Event OnBeginState()
UnregisterForUpdate()
UnregisterForAnimationEvent(SelfRef, CastStop)
;DEBUGTEXT("\t\t{{{Entering Off}}}")
EndEvent
; Empty overrides for listeners
Event OnSpellCast(Form akSpell)
EndEvent
Event OnAnimationEvent(ObjectReference akSource, string EventName)
EndEvent
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
EndEvent
Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
EndEvent
; Override to initialize Register
bool function RegisterForEvent(INEQ_EventListenerBase akAsker, float akMagicka, int akPriority)
SetRegisterElement(0, akAsker, akMagicka, akPriority)
numRegistered = 1
numPriority = 1
RegisterForMPUpdate()
return true
endfunction
; Attempts to change state
Function UpdateState()
if numRegistered > 0
if SelfRef.GetActorValuePercentage("Magicka") == 1.0
GoToState("ActiveFull")
else
GoToState("Active")
endif
endif
EndFunction
Event OnEndState()
RegisterForAnimationEvent(SelfRef, CastStop)
;DEBUGTEXT("\t\t{{{Leaving Off}}}")
EndEvent
EndState
;___________________________________________________________________________________________________________________________
State Active
; Override accounting for concentration spells to recalculate time until MP is full
Event OnAnimationEvent(ObjectReference akSource, string EventName)
RegisterForSingleUpdate(0)
EndEvent
Event OnUpdate()
;DEBUGTEXT("OnUpdate Start")
if bSiphonBelowMax
sendEvent(calculateModifier())
endif
RegisterForMPUpdate()
;DEBUGTEXT("OnUpdate End")
EndEvent
; Calculates what the drian should be and and modifies the Actor's magickaratemult to that value
function UpdateMagickaDrain()
float preDrainMult = DrainMult
DrainMult = (MagickaRateMult + DrainMult) * DrainPercentage
SelfRef.ModActorValue("MagickaRateMult", preDrainMult - DrainMult)
MagickaRateMult = SelfRef.GetActorValue("MagickaRateMult")
endFunction
; Returns the time in seconds until the soonest event or MP restored to full depending on which is most imminent
float function GetUpdateTime()
float MPResetTime = 0.0
if MagickaRateMag
MPResetTime = fMax((TotalMagicka - SelfRef.GetActorValue("Magicka")) / MagickaRateMag, MPResetDelay)
if DrainMag
MPResetTime = fMin(fMax(RegisteredMP[numRegistered - 1] * numPriority / DrainMag, 0.0), MPResetTime)
else
;return MPResetTime
endif
elseif DrainMag
MPResetTime = fMax(RegisteredMP[numRegistered - 1] * numPriority / DrainMag, 0.0)
endif
if SelfRef.isInCombat()
return fMin(MPResetTime, CombatCheck)
else
return MPResetTime
endif
EndFunction
; Calculates the MP siphoned since last update using amount drained (convert to use parameter)
float function calculateModifier()
;DEBUGTEXT("calculateModifier start", 0, False, False)
float timedif = ((Utility.GetCurrentGameTime() - previousTime) / TimeScale.Value) * SecondsInDay
return fMax(DrainMag * timedif / numPriority, 0.0)
endFunction
; Attempts to change state
Function UpdateState()
if numRegistered == 0
RestoreMagickaDrain()
GoToState("Off")
elseif SelfRef.GetActorValuePercentage("Magicka") == 1.0
RestoreMagickaDrain()
GoToState("ActiveFull")
endif
endFunction
EndState
;___________________________________________________________________________________________________________________________
; Player has full MP,
State ActiveFull
Event OnUpdate()
;DEBUGTEXT("OnUpdate Start")
sendEvent(calculateModifier())
RegisterForMPUpdate()
;DEBUGTEXT("OnUpdate End")
EndEvent
; Returns the time in seconds until the soonest update
float function GetUpdateTime()
return fMin(fMax(RegisteredMP[numRegistered - 1] * numPriority / MagickaRateMag, 0.0), CombatCheck)
EndFunction
; Calculates the MP siiphoned since last update using regular MagickaRateMult (convert to use parameter)
float function calculateModifier()
;DEBUGTEXT("calculateModifier start", 0, False, False)
if numPriority
float timedif = ((Utility.GetCurrentGameTime() - previousTime) / TimeScale.Value) * SecondsInDay
return fMax(MagickaRateMag * timedif / numPriority, 0.0)
else
;DEBUGTEXT("calculateModifer: numPriority = 0", 0, True, True)
return 0.0
endif
endFunction
; Attempts to change state
Function UpdateState()
if numRegistered == 0
GoToState("Off")
elseif SelfRef.GetActorValuePercentage("Magicka") < 1.0
GoToState("Active")
endif
endFunction
EndState
;___________________________________________________________________________________________________________________________
State RegisterBusy
Event OnBeginState()
UnregisterForUpdate()
RegisterForSingleUpdate(10.0) ; Exits RegisterBusy after 10 seconds since state is probably stuck
EndEvent
Event OnUpdate()
;DEBUGTEXT(">>> OnUpdate override")
GoToState("Active") ; Ensures Magicka drain is properly removed
UpdateState()
EndEvent
; Calling too many registers will call RgisterForMPUpdate() in this state, this might be solution
function RegisterForMPUpdate()
;DEBUGTEXT(">>> RegisterForMPUpdate override")
RegisterForSingleUpdate(10.0)
endfunction
;___________________________________________________________________________________________________________________________
; Removes current MP magnitude from current priority and sends events if Listener's value falls below 0
function sendEvent(float akModifier)
;DEBUGTEXT("SendEvent Override start", 0, True, True)
int index = numRegistered - numPriority
int max = numRegistered
while index < max
RegisteredMP[index] = RegisteredMP[index] - akModifier
if RegisteredMP[index] <= 0.0
RegisteredAB[index].bRegisteredMS = False
RegisteredAB[index].OnMagickaSiphonEvent()
DeleteRegisterElement(index)
numRegistered -= 1
numPriority -= 1
endif
index += 1
endwhile
;DEBUGTEXT("SendEvent Override end\t", 0, True, True)
endFunction
;___________________________________________________________________________________________________________________________
; Stores registration requests in a temporary array and deletes matches from the Unregiser buffer
bool function RegisterForEvent(INEQ_EventListenerBase akListener, float akMagicka, int akPriority)
;DEBUGTEXT("Register Override start", 0, True, True)
int index = UnregisterAB.find(akListener)
if index != -1
UnregisterAB[index] = none
numUnregistered -= 1
endif
if numBuffered == BufferAB.length
Debug.Trace(self+ ": Number of registers exceeded buffer or main array on adding " +akListener)
return false
elseif numBuffered + numRegistered >= RegisteredAB.length
Debug.Trace(self+ ": Number of registers exceeded main array length on adding " +akListener)
return false
else
index = getFirstNone(BufferAB)
if index < 0
Debug.MessageBox("GetFirstNone returned < 0")
Debug.Trace("GetFirstNone returned < 0")
endif
SetBufferElement(index , akListener, akMagicka, akPriority)
numBuffered += 1
;DEBUGTEXT("Register Override end\t", 0, True, True)
return true
endif
endfunction
;___________________________________________________________________________________________________________________________
; Stores unregistration requests in a temporary array and deletes matches Registration buffer
Function UnregisterForEvent(INEQ_EventListenerBase akListener)
;DEBUGTEXT("Unregister Override start", 0, True, True)
int index = BufferAB.find(akListener)
if index != -1
DeleteBufferElement(index)
numBuffered -= 1
endif
index = RegisteredAB.find(akListener)
if index != -1
if numUnregistered < UnregisterAB.length
UnregisterAB[getFirstNone(BufferAB)] = akListener
numUnregistered += 1
else
Debug.Notification(self+ ": Number of unregisters exceeded buffer on adding " +akListener)
endif
endif
;DEBUGTEXT("Unregister Override end", 0, True, True)
EndFunction
;___________________________________________________________________________________________________________________________
Event OnEndState()
;DEBUGTEXT("Endstate start\t\t\t", 0, True, True)
; Removes all elements uregistered while sending events, then shifts down
if numUnregistered
;DEBUGTEXT("Unregister EndState start", 0, True, True)
ShiftListenerDown(UnregisterAB)
int i = numUnregistered
while i > 0
i -= 1
int index = RegisteredAB.find(UnregisterAB[i])
if index != -1
DeleteRegisterElement(index)
numRegistered -= 1
endif
UnregisterAB[i] = None
endwhile
ShiftElementsDown(RegisteredAB, RegisteredMP, RegisteredPR)
;DEBUGTEXT("Unregister Endstate end", 0, True, True)
endif
; Adds all elements registered while sending events
if numBuffered
;DEBUGTEXT("Register Endstate start", 0, True, True)
ShiftElementsDown(BufferAB, BufferMP, BufferPR)
int i = numBuffered
while i > 0
i -= 1
int index = RegisteredAB.find(BufferAB[i])
if index == -1
index = numRegistered ; add to the end
numRegistered += 1
endif
SetRegisterElement(index, BufferAB[i], BufferMP[i], BufferPR[i])
DeleteBufferElement(i)
endWhile
;DEBUGTEXT("Register Endstate end\t", 0, True, True)
endif
; If any chages were made to the Register, sort it
if numbuffered || numUnregistered
numUnregistered = 0
numBuffered = 0
sortAscending()
endif
UpdatePriorityCount()
;DEBUGTEXT("Endstate end\t\t\t", 0, True, True)
EndEvent
EndState
;===============================================================================================================================
;==================================== Main Functions ================================================
;================================================================================================
; Assumes array sorted from low to high priority. Decrease current phase mp's and sends recharge if mp < 0
function sendEvent(float akModifier)
;DEBUGTEXT("{SendEvent Start} Modifier: " +akModifier, MBox=True)
UnregisterForupdate()
String preState = GetState()
GoToState("RegisterBusy")
SendEvent(akModifier)
GoToState(preState)
;DEBUGTEXT("{SendEvent End}", MBox=True)
endfunction
;___________________________________________________________________________________________________________________________
; Assumes array sorted. If passed reference is registered, shift the elements down and remove the last one [NEEDS TESTING]
function UnregisterForEvent(INEQ_EventListenerBase akListener)
;DEBUGTEXT("{Unregister Start}", MBox=True)
String preState = GetState()
GoToState("RegisterBusy")
UnregisterForEvent(akListener)
GoToState(preState)
if numRegistered > 0
sendEvent(calculateModifier())
endif
RegisterForMPUpdate()
;DEBUGTEXT("{Unregister End}", MBox=True)
EndFunction
;___________________________________________________________________________________________________________________________
; Registers an item and a distance by adding it to an array, then sorts the items by descending distance
bool function RegisterForEvent(INEQ_EventListenerBase akListener, float akMagicka, int akPriority)
;DEBUGTEXT("{Register Start}", MBox=True)
float modifier = calculateModifier()
String preState = GetState()
GoToState("RegisterBusy")
sendEvent(modifier)
bool registered = RegisterForEvent(akListener, akMagicka, akPriority)
GoToState(preState)
RegisterForMPUpdate()
;DEBUGTEXT("{Register End}", MBox=True)
return registered
endFunction
;___________________________________________________________________________________________________________________________
; Updates fields/states and registers for an update at the calculated time
function RegisterForMPUpdate()
;DEBUGTEXT("RegisterForMPUpdate() Start")
UpdateState()
UpdateFields()
if numRegistered > 0 && (MagickaRateMult > 0.0 || DrainMag > 0.0)
if GetState() != "RegisterBusy"
float updateTime = getUpdateTime()
RegisterForSingleUpdate(updateTime)
endif
endif
EndFunction
;___________________________________________________________________________________________________________________________
; Updates the fields used to calculate MP recharged
Function UpdateFields()
if SelfRef
UpdateTotalMagicka()
previousTime = Utility.GetCurrentGameTime()
MagickaRateMult = SelfRef.GetActorValue("MagickaRateMult")
if bSiphonBelowMax
UpdateMagickaDrain()
endif
float multiplier = (SelfRef.GetActorValue("MagickaRate")/100.0) * TotalMagicka / 100.0
DrainMag = DrainMult * multiplier
MagickaRateMag = MagickaRateMult * multiplier
if SelfRef.isInCombat()
MagickaRateMag /= 3.0
DrainMag /= 3.0
endif
endif
EndFunction
;___________________________________________________________________________________________________________________________
; Updates the calculated Total MP including buffs from ModAV
Function UpdateTotalMagicka()
if SelfRef.getActorValuePercentage("Magicka")
TotalMagicka = SelfRef.getActorValue("Magicka") / SelfRef.getActorValuePercentage("Magicka")
else
SelfRef.RestoreActorValue("Magicka", 1.0)
TotalMagicka = SelfRef.getActorValue("Magicka") / SelfRef.getActorValuePercentage("Magicka")
SelfRef.DamageActorValue("Magicka", 1.0)
endif
EndFunction
;___________________________________________________________________________________________________________________________
; Returns the number of elements at the highest priority
Function UpdatePriorityCount()
if numRegistered > 0
int index = numRegistered - 1
int currentPriority = RegisteredPR[numRegistered - 1]
while index && RegisteredPR[index - 1] == currentPriority
index -= 1
endwhile
numPriority = numRegistered - index
else
numPriority = 0
endif
EndFunction
;___________________________________________________________________________________________________________________________
; Restores net MagickaRateMult to the player from DrainMult and and clears the drain values
function RestoreMagickaDrain()
if DrainMult
SelfRef.ModActorValue("MagickaRateMult", DrainMult)
MagickaRateMult = SelfRef.GetActorValue("MagickaRateMult")
DrainMult = 0.0
DrainMag = 0.0
endif
endFunction
;===============================================================================================================================
;==================================== Helper Functions ================================================
;================================================================================================
; Takes arrays of Listeners, magicka and priorities then shifts all elements towards 0 but could unsort the elements
function ShiftElementsDown(INEQ_EventListenerBase[] listener, float[] magicka, int[] priority)
int firstNone = getFirstNone(listener)
int lastElement = getLastElement(listener)
if firstNone == -1 || lastElement == -1
return
endif
while firstNone < lastElement
listener[firstNone] = listener[lastElement]
listener[LastElement] = none
magicka[firstNone] = magicka[lastElement]
magicka[lastElement] = 0.0
priority[firstNone] = priority[lastElement]
priority[lastElement] = 0
firstNone = getFirstNone(listener, firstNone)
lastElement = getLastElement(listener, lastElement)
endwhile
endFunction
;___________________________________________________________________________________________________________________________
; Takes an array of Listeners and shifts all elements towards 0 but could unsort the elements
function ShiftListenerDown(INEQ_EventListenerBase[] listener)
int firstNone = getFirstNone(listener)
int lastElement = getLastElement(listener)
if firstNone != -1 || lastElement != -1
return
endif
while firstNone < lastElement
listener[firstNone] = listener[lastElement]
listener[lastElement] = none
firstNone = getFirstNone(listener, firstNone)
lastElement = getLastElement(listener, lastElement)
endwhile
endFunction
;___________________________________________________________________________________________________________________________
; Returns the last None element of the array from "ending" or -1 if not found
int function getLastElement(INEQ_EventListenerBase[] arr, int ending = -1)
if ending == -1
ending = arr.length
endif
while ending > 0
ending -= 1
if arr[ending] != none
return ending
endif
endwhile
return -1
endfunction
;___________________________________________________________________________________________________________________________
; Returns the last non-None element of the array from "starting" or -1 if not found
int function getFirstNone(INEQ_EventListenerBase[] arr, int starting = 0)
while starting < arr.length
if arr[starting] == none
return starting
endif
starting += 1
endwhile
return -1
endfunction
;___________________________________________________________________________________________________________________________
; Replace with better sorting algorithm later if many items are registered at any one time
function sortAscending()
int index1 = 0
while index1 < numRegistered - 1
int index2 = index1 + 1
while index2 < numRegistered
if RegisteredPR[index1] == RegisteredPR[index2] && RegisteredMP[index1] < RegisteredMP[index2]
swap(index1, index2)
elseif RegisteredPR[index1] > RegisteredPR[index2]
swap(index1, index2)
endif
index2 += 1
endwhile
index1 +=1
endwhile
endfunction
;___________________________________________________________________________________________________________________________
; Takes two indexes and swaps their contents in the ability and distance arrays
function swap(int a, int b)
INEQ_EventListenerBase tempAB = RegisteredAB[a]
float tempMP = RegisteredMP[a]
int tempPR = RegisteredPR[a]
SetRegisterElement(a, RegisteredAB[b], RegisteredMP[b], RegisteredPR[b])
SetRegisterElement(b, tempAB, tempMP, tempPR)
endfunction
;___________________________________________________________________________________________________________________________
; Various functions to handle manipulating the arrays
function SetRegisterElement(int index, INEQ_EventListenerBase akListener, float akMagicka, int akPriority)
if index != -1
RegisteredAB[index] = akListener
RegisteredMP[index] = akMagicka
RegisteredPR[index] = akPriority
endif
Endfunction
function DeleteRegisterElement(int index)
SetRegisterElement(index, none, 0.0, 0)
endfunction
function SetBufferElement(int index, INEQ_EventListenerBase akListener, float akMagicka, int akPriority)
if index != -1
BufferAB[index] = akListener
BufferMP[index] = akMagicka
BufferPR[index] = akPriority
endif
endFunction
function DeleteBufferElement(int index)
SetBufferElement(index, none, 0.0, 0)
endfunction
;___________________________________________________________________________________________________________________________
; Returns the smaller of two floats
float Function fMin(float a, float b)
if a < b
return a
else
return b
endif
endFunction
; Returns the smaller of two ints
int Function iMin(int a, int b)
if a < b
return a
else
return b
endif
endFunction
; Returns the larger of two floats
float function fMax(float a, float b)
if a > b
return a
else
return b
endif
endfunction
;___________________________________________________________________________________________________________________________
; Debugging Function for testing using trace and/or messageboxes
function DEBUGTEXT(String text, int type = -1, bool mp = false, bool listener = false, bool MBox = False)
if bDebugTrace
String s = "" + GetState() + ":\t" +text
if type != -1
if mp || listener
s += ":\tR:" +numRegistered+ "P:" +numPriority+ "\t"
if type == 0
s += "Register"
elseif type == 1
s += " Buffer "
elseif type == 2
s += "Unregstr"
endif
endif
if mp
if type == 0
s += "[" +RegisteredMP[0]+ ", " +RegisteredMP[1]+ ", " +RegisteredMP[2]+ "]"
elseif type == 1
s += "[" +BufferMP[0]+ ", " +BufferMP[1]+ ", " +BufferMP[2]+ "]"
elseif type == 2
s += "[" +UnregisterAB[0]+ ", " +UnregisterAB[1]+ ", " +UnregisterAB[2]+ "]"
endif
endif
if listener
if type == 0
s += "\t[" +RegisteredAB[0]+ ", " +RegisteredAB[1]+ ", " +RegisteredAB[2]+ "]"
elseif type == 1
s += "\t[" +BufferAB[0]+ ", " +BufferAB[1]+ ", " +BufferAB[2]+ "]"
endif
endif
endif
Debug.Trace(s)
endif
if bDebugMessage
if MBox
Debug.Messagebox(text+ ":\tnumPriority=" +numPriority+ "\n0) Priority:" +RegisteredPR[0]+ " MP:" +RegisteredMP[0]+ "\n1) Priority:" +RegisteredPR[1]+ " MP:" +RegisteredMP[1]+"\n2) Priority:" +RegisteredPR[2]+ " MP:" +RegisteredMP[2])
endif
endif
endFunction
;___________________________________________________________________________________________________________________________
; Placeholder fucntions for overrides in the States
function UpdateState()
Debug.Trace(self+ ": UpdateState() called in state \"" +GetState()+"\"")
EndFunction
float function calculateModifier()
Debug.Trace(self+ ": calculateModifier() called in state \"" +GetState()+"\"")
return 0.0
EndFunction
float Function getUpdateTime()
Debug.Trace(self+ ": getUpdateTime() called in state \"" +GetState()+"\"")
return 0.1
EndFunction
; Intentionally not overridden in non-Active states
function UpdateMagickaDrain()
;Debug.Trace(self+ ": UpdateMagickaDrain() called in state \"" +GetState()+"\"")
endFunction
;===============================================================================================================================
;==================================== Menus ================================================
;================================================================================================
Function ChargeMenu(INEQ_MenuButtonConditional Button, INEQ_ListenerMenu ListenerMenu, GlobalVariable MenuActive)
bool abMenu = True
int aiButton
while abMenu && MenuActive.Value
SetButtonMain(Button)
aiButton = MainMenu.Show()
if aiButton == 0
abMenu = False
elseif aiButton == 9 ; Cancel menu
MenuActive.SetValue(0)
elseif aiButton == 1 ; Siphon Below Max MP -> On
bSiphonBelowMax = True
elseif aiButton == 2 ; Siphon Below Max MP -> Off
RestoreDefaultFields()
elseif aiButton == 3 ; Set Siphon Percentage
DrainPercentage = ListenerMenu.SetPercentage(DrainPercentage, DEFDrainPercentage)
endif
endwhile
if GetState() != "RegisterBusy"
RegisterForSingleUpdate(0)
else
Debug.Notification("Menu changed in RegisterBusy")
endif
EndFunction
Function SetButtonMain(INEQ_MenuButtonConditional Button)
Button.clear()
if bSiphonBelowMax
Button.set(2)
Button.set(3)
else
Button.set(1)
endif
Button.set(9)
EndFunction