Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. -- Melee primary ability
  2. SpearCombo = WeaponAbility:new()
  3.  
  4. function SpearCombo:init()
  5. self.damageConfig.baseDamage = self.baseDps * self.fireTime
  6.  
  7. self.holdDamageConfig = sb.jsonMerge(self.damageConfig, self.holdDamageConfig)
  8. self.holdDamageConfig.baseDamage = self.holdDamageMultiplier * self.damageConfig.baseDamage
  9.  
  10. self.comboStep = 1
  11.  
  12. self.energyUsage = self.energyUsage or 0
  13.  
  14. self:computeDamageAndCooldowns()
  15.  
  16. self.weapon:setStance(self.stances.idle)
  17.  
  18. self.edgeTriggerTimer = 0
  19. self.flashTimer = 0
  20. self.cooldownTimer = self.cooldowns[1]
  21.  
  22. self.animKeyPrefix = self.animKeyPrefix or ""
  23.  
  24. self.weapon.onLeaveAbility = function()
  25. self.weapon:setStance(self.stances.idle)
  26. end
  27. end
  28.  
  29. -- Ticks on every update regardless if this is the active ability
  30. function SpearCombo:update(dt, fireMode, shiftHeld)
  31. WeaponAbility.update(self, dt, fireMode, shiftHeld)
  32.  
  33. if self.cooldownTimer > 0 then
  34. self.cooldownTimer = math.max(0, self.cooldownTimer - self.dt)
  35. if self.cooldownTimer == 0 then
  36. self:readyFlash()
  37. end
  38. end
  39.  
  40. if self.flashTimer > 0 then
  41. self.flashTimer = math.max(0, self.flashTimer - self.dt)
  42. if self.flashTimer == 0 then
  43. animator.setGlobalTag("bladeDirectives", "")
  44. end
  45. end
  46.  
  47. self.edgeTriggerTimer = math.max(0, self.edgeTriggerTimer - dt)
  48. if self.lastFireMode ~= (self.activatingFireMode or self.abilitySlot) and fireMode == (self.activatingFireMode or self.abilitySlot) then
  49. self.edgeTriggerTimer = self.edgeTriggerGrace
  50. end
  51. self.lastFireMode = fireMode
  52.  
  53. if not self.weapon.currentAbility and self:shouldActivate() then
  54. self:setState(self.windup)
  55. end
  56. end
  57.  
  58. -- State: windup
  59. function SpearCombo:windup()
  60. local stance = self.stances["windup"..self.comboStep]
  61.  
  62. self.weapon:setStance(stance)
  63.  
  64. self.edgeTriggerTimer = 0
  65.  
  66. if stance.hold then
  67. while self.fireMode == (self.activatingFireMode or self.abilitySlot) do
  68. coroutine.yield()
  69. end
  70. else
  71. util.wait(stance.duration)
  72. end
  73.  
  74. if self.energyUsage then
  75. status.overConsumeResource("energy", self.energyUsage)
  76. end
  77.  
  78. if self.stances["preslash"..self.comboStep] then
  79. self:setState(self.preslash)
  80. else
  81. self:setState(self.fire)
  82. end
  83. end
  84.  
  85. -- State: wait
  86. -- waiting for next combo input
  87. function SpearCombo:wait()
  88. local stance = self.stances["wait"..(self.comboStep - 1)]
  89.  
  90. self.weapon:setStance(stance)
  91.  
  92. util.wait(stance.duration, function()
  93. if self:shouldActivate() then
  94. self:setState(self.windup)
  95. return
  96. end
  97. end)
  98.  
  99. self.cooldownTimer = math.max(0, self.cooldowns[self.comboStep - 1] - stance.duration)
  100. self.comboStep = 1
  101. end
  102.  
  103. -- State: preslash
  104. -- brief frame in between windup and fire
  105. function SpearCombo:preslash()
  106. local stance = self.stances["preslash"..self.comboStep]
  107.  
  108. self.weapon:setStance(stance)
  109. self.weapon:updateAim()
  110.  
  111. util.wait(stance.duration)
  112.  
  113. self:setState(self.fire)
  114. end
  115.  
  116. -- State: fire
  117. function SpearCombo:fire()
  118. sb.logInfo("Fire")
  119. local stance = self.stances["fire"..self.comboStep]
  120.  
  121. self.weapon:setStance(stance)
  122. self.weapon:updateAim()
  123.  
  124. local animStateKey = self.animKeyPrefix .. (self.comboStep > 1 and "fire"..self.comboStep or "fire")
  125. animator.setAnimationState("swoosh", animStateKey)
  126. animator.playSound(animStateKey)
  127.  
  128. local swooshKey = self.animKeyPrefix .. (self.elementalType or self.weapon.elementalType) .. "swoosh"
  129. animator.setParticleEmitterOffsetRegion(swooshKey, self.swooshOffsetRegions[self.comboStep])
  130. animator.burstParticleEmitter(swooshKey)
  131.  
  132. util.wait(stance.duration, function()
  133. local damageArea = partDamageArea("swoosh")
  134. self.weapon:setDamage(self.stepDamageConfig[self.comboStep], damageArea)
  135. end)
  136.  
  137. if self.fireMode == "primary" and self.allowHold ~= false then
  138. self:setState(self.hold)
  139. self.cooldownTimer = self.cooldowns[self.comboStep]
  140. self.comboStep = 1
  141. elseif self.comboStep < self.comboSteps then
  142. self.comboStep = self.comboStep + 1
  143. self:setState(self.wait)
  144. else
  145. self.cooldownTimer = self.cooldowns[self.comboStep]
  146. self.comboStep = 1
  147. end
  148. end
  149.  
  150. function SpearCombo:shouldActivate()
  151. if self.cooldownTimer == 0 and (self.energyUsage == 0 or not status.resourceLocked("energy")) then
  152. if self.comboStep > 1 then
  153. return self.edgeTriggerTimer > 0
  154. else
  155. return self.fireMode == (self.activatingFireMode or self.abilitySlot)
  156. end
  157. end
  158. end
  159.  
  160. function SpearCombo:readyFlash()
  161. animator.setGlobalTag("bladeDirectives", self.flashDirectives)
  162. self.flashTimer = self.flashTime
  163. end
  164.  
  165. function SpearCombo:computeDamageAndCooldowns()
  166. local attackTimes = {}
  167. for i = 1, self.comboSteps do
  168. local attackTime = self.stances["windup"..i].duration + self.stances["fire"..i].duration
  169. if self.stances["preslash"..i] then
  170. attackTime = attackTime + self.stances["preslash"..i].duration
  171. end
  172. table.insert(attackTimes, attackTime)
  173. end
  174.  
  175. self.cooldowns = {}
  176. local totalAttackTime = 0
  177. local totalDamageFactor = 0
  178. for i, attackTime in ipairs(attackTimes) do
  179. self.stepDamageConfig[i] = util.mergeTable(copy(self.damageConfig), self.stepDamageConfig[i])
  180. self.stepDamageConfig[i].timeoutGroup = "primary"..i
  181.  
  182. local damageFactor = self.stepDamageConfig[i].baseDamageFactor
  183. self.stepDamageConfig[i].baseDamage = damageFactor * self.baseDps * self.fireTime
  184.  
  185. totalAttackTime = totalAttackTime + attackTime
  186. totalDamageFactor = totalDamageFactor + damageFactor
  187.  
  188. local targetTime = totalDamageFactor * self.fireTime
  189. local speedFactor = 1.0 * (self.comboSpeedFactor ^ i)
  190. table.insert(self.cooldowns, (targetTime - totalAttackTime) * speedFactor)
  191. end
  192. end
  193.  
  194. function SpearCombo:hold()
  195. self.weapon:setStance(self.stances.hold)
  196. self.weapon:updateAim()
  197.  
  198. while self.fireMode == "primary" do
  199. local damageArea = partDamageArea("blade")
  200. self.weapon:setDamage(self.holdDamageConfig, damageArea)
  201. coroutine.yield()
  202. end
  203.  
  204. self.cooldownTimer = self.cooldowns[self.comboStep]
  205. end
  206.  
  207. function SpearCombo:uninit()
  208. self.weapon:setDamage()
  209. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement