CombatModule.lua 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. --[[
  2. Script Name : SpawnScripts/Generic/CombatModule.lua
  3. Script Author : LordPazuzu
  4. Script Date : 2023.09.19 08:09:17
  5. Script Purpose : Base Population Combat Common Features
  6. :
  7. --]]
  8. GlobalDmgMod = 1.0 -- Global Damage Multiplier- make global adjustments to all NPC autoattack damage.
  9. globalStatMod = 1.0 -- Global Attribute Multiplier- make global adjustments to NPC attribute scores.
  10. function combatModule(NPC, Spawn)
  11. level = GetLevel(NPC) -- NPC Level
  12. difficulty = GetDifficulty(NPC) -- NPC Difficulty || Function in testing phase, default to 6 if necessary.
  13. levelSwitch(NPC)
  14. regen(NPC)
  15. attributes(NPC)
  16. end
  17. --Determine damage function based on NPC level.
  18. function levelSwitch(NPC, Spawn)
  19. if level <= 3 then
  20. TierOneA(NPC)
  21. elseif level >= 4 and level <= 5 then
  22. TierOneB(NPC)
  23. elseif level >= 6 and level <= 9 then
  24. TierOneC(NPC)
  25. elseif level >= 10 and level <= 15 then
  26. TierTwoA(NPC)
  27. elseif level >= 16 and level <= 19 then
  28. TierTwoB(NPC)
  29. elseif level >= 20 and level <= 24 then
  30. TierThreeA(NPC)
  31. elseif level >= 25 and level <= 29 then
  32. TierThreeB(NPC)
  33. end
  34. end
  35. -- Set attributes based on NPC level and difficulty
  36. function attributes(NPC, Spawn)
  37. -- Calculate attributes
  38. if level <= 4 then
  39. baseStat = 19 else
  40. baseStat = level + 15
  41. end
  42. local low = baseStat - 15 -- Difficulty 1-3 vvv
  43. local four = baseStat - 10 -- Difficulty 4 vv
  44. local five = baseStat - 5 -- Difficulty 5 v
  45. local seven = baseStat + 10 -- Difficulty 7 ^
  46. local eight = baseStat + 15 -- Difficulty 8 ^^
  47. local nine = baseStat + 20 -- Difficulty 9 ^^^
  48. lowStat = math.floor(low * globalStatMod)
  49. fourStat = math.floor(four * globalStatMod)
  50. fiveStat = math.floor(five * globalStatMod)
  51. sixStat = math.floor(baseStat * globalStatMod)
  52. sevenStat = math.floor(seven * globalStatMod)
  53. eightStat = math.floor(eight * globalStatMod)
  54. nineStat = math.floor(nine * globalStatMod)
  55. -- Determine attribute by difficulty
  56. if difficulty <= 3 then
  57. finalStat = lowStat
  58. elseif difficulty == 4 then
  59. finalStat = fourStat
  60. elseif difficulty == 5 then
  61. finalStat = fiveStat
  62. elseif difficulty == 6 then
  63. finalStat = sixStat
  64. elseif difficulty == 7 then
  65. finalStat = sevenStat
  66. elseif difficulty == 8 then
  67. finalStat = eightStat
  68. elseif difficulty == 9 then
  69. finalStat = nineStat
  70. end
  71. SetInfoStructFloat(NPC, "str", finalStat)
  72. SetStrBase(NPC, finalStat)
  73. SetInfoStructFloat(NPC, "agi", finalStat)
  74. SetAgiBase(NPC, finalStat)
  75. SetInfoStructFloat(NPC, "sta", finalStat)
  76. SetStaBase(NPC, finalStat)
  77. SetInfoStructFloat(NPC, "intel", finalStat)
  78. SetIntBase(NPC, finalStat)
  79. SetInfoStructFloat(NPC, "wis", finalStat)
  80. SetWisBase(NPC, finalStat)
  81. end
  82. --Health and power regeneration rates
  83. function regen(NPC, Spawn)
  84. -- In-combat health regeneration
  85. SetInfoStructUInt(NPC, "hp_regen_override", 1) -- Set to 0 to disable and allow the server to set the regen rate.
  86. SetInfoStructSInt(NPC, "hp_regen", 0) -- Set Regen Amount. Default 0
  87. -- In-combat power regeneration
  88. SetInfoStructUInt(NPC, "pw_regen_override", 1) -- Set to 0 to disable and allow the server to set the regen rate.
  89. SetInfoStructSInt(NPC, "pw_regen", 0) -- Set Regen Amount. Default 0
  90. end
  91. --Damage functions based on NPC level range.
  92. --Level 1-3
  93. function TierOneA(NPC, Spawn)
  94. local dmgMod =GetStr(NPC)/10 -- Strength-based damage bonus for autoattack damage.
  95. lowDmg = math.floor(0 * GlobalDmgMod + dmgMod)
  96. highDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  97. SetInfoStructUInt(NPC, "override_primary_weapon", 1) -- Enables override of server autoattack damage. Set to 0 to allow server to set damage.
  98. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  99. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  100. end
  101. --Level 4-5
  102. function TierOneB(NPC, Spawn)
  103. local dmgMod =GetStr(NPC)/10
  104. if difficulty <=4 then --
  105. lowDmg = math.floor(1 * GlobalDmgMod + dmgMod)
  106. highDmg =math.floor(2 * GlobalDmgMod + dmgMod)
  107. elseif difficulty == 5 then
  108. lowDmg = math.floor(1 * GlobalDmgMod + dmgMod)
  109. highDmg = math.floor(3 * GlobalDmgMod + dmgMod)
  110. elseif difficulty >=6 and difficulty <=9 then
  111. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  112. highDmg = math.floor(4 * GlobalDmgMod + dmgMod)
  113. end
  114. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  115. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  116. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  117. end
  118. --Level 6-9
  119. function TierOneC(NPC, Spawn)
  120. local dmgMod =GetStr(NPC)/10
  121. if difficulty <=4 then -- 1-3 dif 1-4
  122. lowDmg = math.floor(1 * GlobalDmgMod + dmgMod)
  123. highDmg =math.floor(3 * GlobalDmgMod + dmgMod)
  124. elseif difficulty == 5 then -- 2-4 dif 5
  125. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  126. highDmg = math.floor(4 * GlobalDmgMod + dmgMod)
  127. elseif difficulty ==6 then -- 2-7 damage- Dif 6
  128. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  129. highDmg = math.floor(7 * GlobalDmgMod + dmgMod)
  130. elseif difficulty >=7 then -- 2-7 damage- Dif 7+
  131. lowDmg = math.floor(5 * GlobalDmgMod + dmgMod)
  132. highDmg = math.floor(10 * GlobalDmgMod + dmgMod)
  133. end
  134. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  135. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  136. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  137. end
  138. --Level 10-15
  139. function TierTwoA(NPC, Spawn)
  140. local dmgMod =GetStr(NPC)/10
  141. if difficulty <=4 then
  142. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  143. highDmg =math.floor(4 * GlobalDmgMod + dmgMod)
  144. elseif difficulty == 5 then
  145. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  146. highDmg = math.floor(7 * GlobalDmgMod + dmgMod)
  147. elseif difficulty ==6 then
  148. lowDmg = math.floor(6 * GlobalDmgMod + dmgMod)
  149. highDmg = math.floor(15 * GlobalDmgMod + dmgMod)
  150. elseif difficulty == 7 then
  151. lowDmg = math.floor(8 * GlobalDmgMod + dmgMod)
  152. highDmg = math.floor(17 * GlobalDmgMod + dmgMod)
  153. elseif difficulty >= 8 then
  154. lowDmg = math.floor(12 * GlobalDmgMod + dmgMod)
  155. highDmg = math.floor(24 * GlobalDmgMod + dmgMod)
  156. end
  157. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  158. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  159. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  160. end
  161. --Level 16-19
  162. function TierTwoB(NPC, Spawn)
  163. local dmgMod =GetStr(NPC)/10
  164. if difficulty <=4 then
  165. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  166. highDmg =math.floor(7 * GlobalDmgMod + dmgMod)
  167. elseif difficulty == 5 then
  168. lowDmg = math.floor(6 * GlobalDmgMod + dmgMod)
  169. highDmg = math.floor(15 * GlobalDmgMod + dmgMod)
  170. elseif difficulty ==6 then
  171. lowDmg = math.floor(12 * GlobalDmgMod + dmgMod)
  172. highDmg = math.floor(24 * GlobalDmgMod + dmgMod)
  173. elseif difficulty == 7 then
  174. lowDmg = math.floor(18 * GlobalDmgMod + dmgMod)
  175. highDmg = math.floor(32 * GlobalDmgMod + dmgMod)
  176. elseif difficulty >= 8 then
  177. lowDmg = math.floor(25 * GlobalDmgMod + dmgMod)
  178. highDmg = math.floor(55 * GlobalDmgMod + dmgMod)
  179. end
  180. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  181. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  182. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  183. end
  184. --Level 20-24
  185. function TierThreeA(NPC, Spawn)
  186. local dmgMod =GetStr(NPC)/10
  187. if difficulty <=4 then
  188. lowDmg = math.floor(2 * GlobalDmgMod + dmgMod)
  189. highDmg =math.floor(7 * GlobalDmgMod + dmgMod)
  190. elseif difficulty == 5 then
  191. lowDmg = math.floor(6 * GlobalDmgMod + dmgMod)
  192. highDmg = math.floor(15 * GlobalDmgMod + dmgMod)
  193. elseif difficulty ==6 then
  194. lowDmg = math.floor(12 * GlobalDmgMod + dmgMod)
  195. highDmg = math.floor(24 * GlobalDmgMod + dmgMod)
  196. elseif difficulty == 7 then
  197. lowDmg = math.floor(18 * GlobalDmgMod + dmgMod)
  198. highDmg = math.floor(32 * GlobalDmgMod + dmgMod)
  199. elseif difficulty >= 8 then
  200. lowDmg = math.floor(25 * GlobalDmgMod + dmgMod)
  201. highDmg = math.floor(55 * GlobalDmgMod + dmgMod)
  202. end
  203. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  204. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  205. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  206. end
  207. --Level 25-29
  208. function TierThreeB(NPC, Spawn)
  209. local dmgMod =GetStr(NPC)/10
  210. if difficulty <=4 then
  211. lowDmg = math.floor(6 * GlobalDmgMod + dmgMod)
  212. highDmg =math.floor(15 * GlobalDmgMod + dmgMod)
  213. elseif difficulty == 5 then
  214. lowDmg = math.floor(12 * GlobalDmgMod + dmgMod)
  215. highDmg = math.floor(24 * GlobalDmgMod + dmgMod)
  216. elseif difficulty ==6 then
  217. lowDmg = math.floor(20 * GlobalDmgMod + dmgMod)
  218. highDmg = math.floor(35 * GlobalDmgMod + dmgMod)
  219. elseif difficulty == 7 then
  220. lowDmg = math.floor(18 * GlobalDmgMod + dmgMod)
  221. highDmg = math.floor(32 * GlobalDmgMod + dmgMod)
  222. elseif difficulty >= 8 then
  223. lowDmg = math.floor(35 * GlobalDmgMod + dmgMod)
  224. highDmg = math.floor(75 * GlobalDmgMod + dmgMod)
  225. end
  226. SetInfoStructUInt(NPC, "override_primary_weapon", 1)
  227. SetInfoStructUInt(NPC, "primary_weapon_damage_low", lowDmg)
  228. SetInfoStructUInt(NPC, "primary_weapon_damage_high", highDmg)
  229. end