Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. Vocations = {}
  2. Vocations.__index = Vocations
  3.  
  4. setmetatable(Vocations, {
  5. __call = function(cls, ...)
  6. return cls.new(...)
  7. end,
  8. })
  9.  
  10. local defaultVocation = 0
  11.  
  12. function Vocations.new(currentVocation)
  13. local x = setmetatable({}, Vocations)
  14. -- default vocations
  15. x.types = { [0] = 'None', 'Sorcerer', 'Druid', 'Paladin', 'Knight' }
  16. -- default storage
  17. x.storage = {}
  18. x.base = {vocation = 0, maxHp = 150, maxMana = 0, hp = 5, mana = 0, soul = 0, hpticks = 5, manaticks = 5, soulticks = 0, level = 8}
  19. x.level = x.base.level
  20. x.vocation = x.base.vocation
  21. x.playerSkills =
  22. { -- default skills for vocations
  23. [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
  24. {level = 0, modifier = 1.0, tries = 0}, -- club
  25. {level = 0, modifier = 1.0, tries = 0}, -- sword
  26. {level = 0, modifier = 1.0, tries = 0}, -- axe
  27. {level = 0, modifier = 1.0, tries = 0}, -- distance
  28. {level = 0, modifier = 1.0, tries = 0}, -- shield
  29. {level = 0, modifier = 1.0, tries = 0}, -- fish
  30. {level = 0, modifier = 1.0, tries = 0} -- magic
  31. }
  32. x:constructVocation(currentVocation or defaultVocation)
  33. return x
  34. end
  35.  
  36. -- the vocations which can be applied to the player cannot have multiples of the same vocation
  37. Vocations.playerVocations = {
  38. [1] = {hpgain = 5, managain = 30, soul = 100, hpticks = 5, manaticks = 15, soulticks = 5}, -- sorcerer
  39. [2] = {hpgain = 5, managain = 30, soul = 100, hpticks = 5, manaticks = 15, soulticks = 5}, -- druid
  40. [3] = {hpgain = 20, managain = 10, soul = 100, hpticks = 5, manaticks = 5, soulticks = 5}, -- paladin
  41. [4] = {hpgain = 25, managain = 5, soul = 100, hpticks = 10, manaticks = 5, soulticks = 5} -- knight
  42. }
  43.  
  44. Vocations.vocationSkills = {
  45. -- skillLvl, modifier, tries
  46. { -- 1
  47. [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
  48. {level = 0, modifier = 1.0, tries = 0}, -- club
  49. {level = 0, modifier = 1.0, tries = 0}, -- sword
  50. {level = 0, modifier = 1.0, tries = 0}, -- axe
  51. {level = 0, modifier = 1.0, tries = 0}, -- distance
  52. {level = 0, modifier = 1.0, tries = 0}, -- shield
  53. {level = 0, modifier = 1.0, tries = 0}, -- fish
  54. {level = 0, modifier = 1.0, tries = 0} -- magic
  55. },
  56. { -- 2
  57. [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
  58. {level = 0, modifier = 1.0, tries = 0}, -- club
  59. {level = 0, modifier = 1.0, tries = 0}, -- sword
  60. {level = 0, modifier = 1.0, tries = 0}, -- axe
  61. {level = 0, modifier = 1.0, tries = 0}, -- distance
  62. {level = 0, modifier = 1.0, tries = 0}, -- shield
  63. {level = 0, modifier = 1.0, tries = 0}, -- fish
  64. {level = 0, modifier = 1.0, tries = 0} -- magic
  65. },
  66. { -- 3
  67. [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
  68. {level = 0, modifier = 1.0, tries = 0}, -- club
  69. {level = 0, modifier = 1.0, tries = 0}, -- sword
  70. {level = 0, modifier = 1.0, tries = 0}, -- axe
  71. {level = 0, modifier = 1.0, tries = 0}, -- distance
  72. {level = 0, modifier = 1.0, tries = 0}, -- shield
  73. {level = 0, modifier = 1.0, tries = 0}, -- fish
  74. {level = 0, modifier = 1.0, tries = 0} -- magic
  75. },
  76. { -- 4
  77. [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
  78. {level = 0, modifier = 1.0, tries = 0}, -- club
  79. {level = 0, modifier = 1.0, tries = 0}, -- sword
  80. {level = 0, modifier = 1.0, tries = 0}, -- axe
  81. {level = 0, modifier = 1.0, tries = 0}, -- distance
  82. {level = 0, modifier = 1.0, tries = 0}, -- shield
  83. {level = 0, modifier = 1.0, tries = 0}, -- fish
  84. {level = 0, modifier = 1.0, tries = 0} -- magic
  85. }
  86. }
  87.  
  88. Vocations.specialAttributes = {
  89. [1] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
  90. [2] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
  91. [3] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
  92. [4] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}}
  93. }
  94.  
  95. -- construct the vocation of the player
  96. function Vocations:constructVocation(v)
  97. self:setPlayerVocation(v)
  98. end
  99.  
  100. function Vocations:setSkillProperty(id, property, value)
  101. self.playerSkills[id][property] = value
  102. end
  103.  
  104. function Vocations:getSkills(vocation)
  105. return self.skills[vocation]
  106. end
  107.  
  108. function Vocations:setSkills()
  109. for i = 0, #self:getSkills() do
  110. self:setSkillProperty(i, "modifier")
  111. end
  112. end
  113.  
  114. -- set the player's vocation
  115. function Vocations:setPlayerVocation(v)
  116. self.storage[self.types[v]] = v
  117. end
  118.  
  119. -- get the level of the player
  120. function Vocations:getLevel()
  121. return self.level
  122. end
  123.  
  124. -- set the level of the player
  125. function Vocations:setPlayerLevel(l)
  126. self.level = l
  127. end
  128.  
  129. -- return the storage table which holds all of the player's vocations
  130. function Vocations:getVocation()
  131. return self.storage
  132. end
  133.  
  134. -- get the hp of the player based on the vocations & the player's lvl
  135. function Vocations:getHp()
  136. local hp = 0
  137. for vocation, id in pairs(self:getVocation()) do
  138. if id ~= defaultVocation then
  139. hp = hp + self.playerVocations[id].hpgain
  140. end
  141. end
  142. return self:getBase(hp, "hp", "maxHp")
  143. end
  144.  
  145. -- get the mana of the player based on the vocations & the player's lvl
  146. function Vocations:getMana()
  147. local mana = 0
  148. for vocation, id in pairs(self:getVocation()) do
  149. if id ~= defaultVocation then
  150. mana = mana + self.playerVocations[id].managain
  151. end
  152. end
  153. return self:getBase(mana, "mana", "maxMana")
  154. end
  155.  
  156. function Vocations:getBase(a, b, c)
  157. a = (a == 0) and self.base[b] or a
  158. local e = (a * (self.level - self.base.level)) + self.base[c]
  159. return (e < 0) and 0 or e
  160. end
  161.  
  162. -- what you will see when you look at the player
  163. -- this function will exclude none if the player has a vocation already set
  164. function Vocations:onLook()
  165. local text = ''
  166. for vocation, id in pairs(self.storage) do
  167. text = text .. vocation .. '/'
  168. end
  169. if sizeOf(self.storage) > 1 then
  170. text = text:sub(1, string.find(text, self.types[defaultVocation], 1, true) - 2)
  171. else
  172. text = text:sub(1, #text - 1)
  173. end
  174. text = text .. "\nLevel: " .. self:getLevel() .."\nHP: " .. self:getHp() .. " / Mana: " .. self:getMana()
  175. return text
  176. end
  177.  
  178. -- return the size of a table
  179. function sizeOf(t)
  180. local c = 0
  181. for k, v in pairs(t) do
  182. c = c + 1
  183. end
  184. return c
  185. end
  186.  
  187. -- add new vocations to the player
  188. function Vocations:addPlayerVocation(voc)
  189. self.storage[self.types[voc]] = voc
  190. end
  191.  
  192. -- if no argument in Vocations it defaults to 0 which is no vocation, default level is 8
  193. local v = Vocations()
  194. --v:addPlayerVocation(1)
  195. v:addPlayerVocation(2)
  196. v:addPlayerVocation(3)
  197. --v:addPlayerVocation(4)
  198. v:setPlayerLevel(11)
  199. print(v:onLook())
  200.  
  201. v:setSkills()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement