spellTimer.qsrc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #spellTimer
  2. ! Run the durational components of a spell.
  3. ! Two parts:
  4. ! 1) "Ticks" - defined things that happen every minute that passes.
  5. ! Examples: HoTs or DoTs type thing - Reneneration might heal some hitpoints every minute.
  6. ! 2) "Completion" - Something that happens when a spells duration completes.
  7. ! Examples: A disguise spell might last for 60 minutes, and the Completion, you set back to normal.
  8. !
  9. ! Arrays involved:
  10. ! 1) spellComplete - this holds the totminut when the spell will end
  11. ! 2) $spellCompExec - this holds some code to run once the spell ends
  12. ! 3) $spellTickExec - this holds some code to be executed every minute the spell is in effect
  13. ! 4) $spellTimeName - hold the name of the spell being run
  14. !
  15. ! If First Parameter is 'add', then we add an entry to the arrays
  16. ! In that case Expected Parameters are:
  17. ! $ARGS[1] = $spellTimeName - hold the name of the spell being run
  18. ! ARGS[2] = Length of spell in minutes
  19. ! $ARGS[3] = $spellCompExec - this holds some code to run once the spell ends
  20. ! $ARGS[4] = $spellTickExec - this holds some code to be executed every minute the spell is in effect
  21. !
  22. ! Else this will process the ticks with these Parameters:
  23. ! ARGS[0] = prevtotmin = Previous Total Minutes
  24. ! ARGS[1] = totminut = current Total Minutes since midnight Jan 1st 2016
  25. if $ARGS[0] = 'add':
  26. ! Call this to instantiate a timed spell.
  27. ! Expected Args:
  28. ! $ARGS[1] = $spellTimeName - hold the name of the spell being run
  29. ! ARGS[2] = Length of spell in minutes
  30. ! $ARGS[3] = $spellCompExec - this holds some code to run once the spell ends
  31. ! $ARGS[4] = $spellTickExec - this holds some code to be executed every minute the spell is in effect
  32. *pl ""
  33. spellCompSize = arrsize('spellComplete')
  34. spellComplete[spellCompSize] = totminut + ARGS[2]
  35. $spellTimeName[spellCompSize] = $ARGS[1]
  36. $spellCompExec[spellCompSize] = $ARGS[3]
  37. $spellTickExec[spellCompSize] = $ARGS[4]
  38. killvar 'spellCompSize'
  39. else
  40. if ARGS[0] = 0:
  41. BeforeTime = prevtotmin
  42. else
  43. BeforeTime = ARGS[0]
  44. end
  45. if ARGS[1] = 0:
  46. AfterTime = totminut
  47. else
  48. AfterTime = ARGS[1]
  49. end
  50. i=0
  51. SpellEnds = 0
  52. :SpellTimerLoop
  53. if i < arrsize('spellComplete'):
  54. NumTicks = AfterTime - BeforeTime
  55. if spellComplete[i] <= AfterTime:
  56. NumTicks -= AfterTime - spellComplete[i]
  57. SpellEnds = 1
  58. else
  59. SpellEnds = 0
  60. end
  61. if NumTicks > 0 and $spellTickExec[i] ! '':
  62. j=0
  63. :SpellTickLoop
  64. if j < NumTicks:
  65. dynamic $spellTickExec[i]
  66. j += 1
  67. jump 'SpellTickLoop'
  68. end
  69. end
  70. if SpellEnds = 1:
  71. if $spellCompExec[i] ! '':
  72. dynamic $spellCompExec[i]
  73. end
  74. killvar 'spellComplete', i
  75. killvar '$spellTickExec', i
  76. killvar '$spellCompExec', i
  77. killvar '$spellTimeName', i
  78. end
  79. i += 1
  80. jump 'SpellTimerLoop'
  81. end
  82. killvar 'i'
  83. killvar 'j'
  84. killvar 'NumTicks'
  85. killvar 'SpellEnds'
  86. killvar 'BeforeTime'
  87. Killvar 'AfterTime'
  88. end
  89. --- spellTimer ---------------------------------