Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.36 KB | None | 0 0
  1. library Spells initializer onInit
  2.  
  3. globals
  4. public Battle thisBattle
  5. public Action spellCast
  6. public unit turnUnit
  7. private Action array actions
  8. private integer count = 0
  9. private integer array savedSkills
  10. endglobals
  11.  
  12. private function createSpell takes string name, string behavior, integer id, real cost, integer learn, integer learnCost returns nothing
  13. set actions[count] = Action.create(name,behavior,id,cost,learn,learnCost)
  14. set count = count + 1
  15. endfunction
  16.  
  17. /**
  18. * Gets an ability from an id
  19. */
  20. public function convertAbilityIdToAction takes integer id returns Action
  21. local integer i = 0
  22. local Action returnAbility = 0
  23. local Action temp = 0
  24. loop
  25. exitwhen i>count
  26. set temp = actions[i]
  27. if(temp!=0)then
  28. if(temp.getId()==id)then
  29. set returnAbility = actions[i]
  30. endif
  31. endif
  32. set i = i + 1
  33. endloop
  34. return returnAbility
  35. endfunction
  36.  
  37. /**
  38. * Gets an ability from a name
  39. */
  40. public function convertAbilityNameToAction takes string name returns Action
  41. local integer i = 0
  42. local Action returnAbility = 0
  43. local Action temp = 0
  44. loop
  45. exitwhen i>count
  46. set temp = actions[i]
  47. if(temp!=0)then
  48. if(temp.getName()==name)then
  49. set returnAbility = actions[i]
  50. endif
  51. endif
  52. set i = i + 1
  53. endloop
  54. return returnAbility
  55. endfunction
  56.  
  57. /**
  58. * Gets an ability from an id
  59. */
  60. public function convertAbilityIdToName takes integer id returns string
  61. local integer i = 0
  62. local string name
  63. local Action temp = 0
  64. loop
  65. exitwhen i>count
  66. set temp = actions[i]
  67. if(temp!=0)then
  68. if(temp.getId()==id)then
  69. set name = actions[i].getName()
  70. endif
  71. endif
  72. set i = i + 1
  73. endloop
  74. return name
  75. endfunction
  76.  
  77. /**
  78. * Gets an ability id from a name
  79. */
  80. public function convertAbilityNameToId takes string name returns integer
  81. local integer i = 0
  82. local integer id = 0
  83. local Action temp = 0
  84. loop
  85. exitwhen i>count
  86. set temp = actions[i]
  87. if(temp!=0)then
  88. if(temp.getName()==name)then
  89. set id = actions[i].getId()
  90. endif
  91. endif
  92. set i = i + 1
  93. endloop
  94. return id
  95. endfunction
  96.  
  97. /**
  98. * Gets an ability from a learncode
  99. */
  100. public function convertAbilityLearncodeToAbility takes integer learncode returns Action
  101. local integer i = 0
  102. local Action desired = 0
  103. local Action temp = 0
  104. loop
  105. exitwhen i>count
  106. set temp = actions[i]
  107. if(temp!=0)then
  108. if(temp.getLearn()==learncode)then
  109. set desired = temp
  110. endif
  111. endif
  112. set i = i + 1
  113. endloop
  114. return desired
  115. endfunction
  116.  
  117. /**
  118. * Gets an ability id from a learncode
  119. */
  120. public function convertAbilityLearncodeToAbilityId takes integer learncode returns integer
  121. return convertAbilityLearncodeToAbility(learncode).getId()
  122. endfunction
  123.  
  124. /**
  125. * Transfers abilities from source to u
  126. */
  127. public function giveAbilities takes unit source, unit u returns nothing
  128. local integer i = 0
  129. local integer abil = 0
  130. loop
  131. exitwhen i>count
  132. set abil = actions[i].getId()
  133. if(GetUnitAbilityLevel(source,abil)>0)then
  134. call UnitAddAbility(u,abil)
  135. endif
  136. set i = i + 1
  137. endloop
  138. endfunction
  139.  
  140. public function learnSkill takes integer learncode, unit u returns nothing
  141. local Action toLearn = convertAbilityLearncodeToAbility(learncode)
  142. local integer apRequired
  143. local item apOfHero
  144. if(toLearn!=0)then
  145. set apRequired = toLearn.getLearnCost()
  146. set apOfHero = GetItemOfTypeFromUnitBJ(u,'I006')
  147. if(GetItemCharges(apOfHero)>=apRequired)then
  148. call SetItemCharges(apOfHero,GetItemCharges(apOfHero)-apRequired)
  149. call UnitAddAbility(u,toLearn.getId())
  150. call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl",u,"origin"))
  151. else
  152. call DisplayTextToPlayer(GetOwningPlayer(u),0,0,"|cFF0080FFYou do not have enough AP!|r")
  153. endif
  154. endif
  155. endfunction
  156.  
  157. /**
  158. * Removes the specified ability from the unit.
  159. */
  160. public function parseRemovalString takes player p, string s returns nothing
  161. local string retrieved = ""
  162. local string heroname = ""
  163. local string temp = ""
  164. local integer toRemove
  165. local integer i = 8
  166. local integer breaker = 0
  167. local group g = CreateGroup()
  168. local unit fog = null
  169. loop
  170. set temp = SubString(s,i,i+1)
  171. exitwhen temp == "," or breaker==100
  172. set heroname = heroname + temp
  173. set i = i + 1
  174. set breaker = breaker + 1
  175. endloop
  176. set i = i + 1
  177. loop
  178. set temp = SubString(s,i,i+1)
  179. exitwhen temp == "" or breaker==100
  180. set retrieved = retrieved + temp
  181. set i = i + 1
  182. set breaker = breaker + 1
  183. endloop
  184. set toRemove = convertAbilityNameToId(retrieved)
  185.  
  186. if(heroname=="Beast")then
  187. call DisplayTextToPlayer(p,0,0,"|cFF0080FFDo not remove spells from Beast-type heroes.|r")
  188. return
  189. endif
  190.  
  191. if(breaker==100 or toRemove==0)then
  192. call DisplayTextToPlayer(p,0,0,"|cFF0080FFInvalid ability input. Please follow the exact format: ''-remove Hero Name,Ability Name''|r")
  193. else
  194. call GroupEnumUnitsInRect(g,GetPlayableMapRect(),null)
  195. loop
  196. set fog = FirstOfGroup(g)
  197. exitwhen fog==null or (GetUnitName(fog)==heroname and GetOwningPlayer(fog)==p)
  198. call GroupRemoveUnit(g,fog)
  199. endloop
  200. if(fog==null)then
  201. call DisplayTextToPlayer(p,0,0,"|cFF0080FFInvalid unit input. Please follow the exact format: ''-remove Hero Name,Ability Name''|r")
  202. else
  203. call UnitRemoveAbility(fog,toRemove)
  204. call DisplayTextToPlayer(p,0,0,"|cFF0080FFSuccessfully removed " + retrieved + " from " + heroname + "|r")
  205. endif
  206. endif
  207. endfunction
  208.  
  209. /**
  210. * Returns how many abilities unit u has
  211. */
  212. public function countAbilities takes unit u returns integer
  213. local integer i = 0
  214. local integer abil = 0
  215. local integer abilities = 0
  216. loop
  217. exitwhen i>count
  218. set abil = actions[i].getId()
  219. if(GetUnitAbilityLevel(u,abil)>0)then
  220. set abilities = abilities + 1
  221. endif
  222. set i = i + 1
  223. endloop
  224. return abilities
  225. endfunction
  226.  
  227. public function saveSkills takes unit u returns nothing
  228. local integer which = 0
  229. local integer i = 0
  230. local integer abil = 0
  231. local integer abilities = 0
  232. loop
  233. exitwhen i>count
  234. set abil = actions[i].getId()
  235. if(GetUnitAbilityLevel(u,abil)>0)then
  236. set savedSkills[which]=abil
  237. set which = which + 1
  238. endif
  239. set i = i + 1
  240. endloop
  241. endfunction
  242.  
  243. public function restoreSkills takes unit u returns nothing
  244. local integer i = 0
  245. loop
  246. exitwhen i>4
  247. if(savedSkills[i]!=0)then
  248. call UnitAddAbility(u,savedSkills[i])
  249. endif
  250. set savedSkills[i]=0
  251. set i = i + 1
  252. endloop
  253. endfunction
  254.  
  255. private function onInit takes nothing returns nothing
  256.  
  257. endfunction
  258.  
  259.  
  260. endlibrary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement