Advertisement
Guest User

Untitled

a guest
Sep 29th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.29 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. function Vocations.new(currentVocation)
  11.     local self = setmetatable({}, Vocations)
  12.     -- default vocations
  13.     self.types =  { [0] = 'none', 'sorcerer', 'druid', 'paladin', 'knight' }
  14.     -- default storage
  15.     self.storage = { -1 }
  16.     -- players current vocation
  17.     self.playerVoc = currentVocation or 0
  18.     self.skills = {
  19.         -- skillLvl, modifier, tries
  20.         [0] =   {lvl = 0, modifier = 1.0, tries = 0}, -- fist
  21.                 {lvl = 0, modifier = 1.0, tries = 0}, -- club
  22.                 {lvl = 0, modifier = 1.0, tries = 0}, -- sword
  23.                 {lvl = 0, modifier = 1.0, tries = 0}, -- axe
  24.                 {lvl = 0, modifier = 1.0, tries = 0}, -- distance
  25.                 {lvl = 0, modifier = 1.0, tries = 0}, -- shield
  26.                 {lvl = 0, modifier = 1.0, tries = 0}, -- fish
  27.                 {lvl = 0, modifier = 1.0, tries = 0}  -- magic
  28.     }
  29.     -- default vocation hp / mana
  30.     self.playerVocations = {
  31.         [0] = {hp = 150, mana = 0, hpgain = 5, managain = 0, hpticks = 5, manaticks = 0},
  32.         [1] = {hp = 150, mana = 0, hpgain = 5, managain = 30, hpticks = 5, manaticks = 15},
  33.         [2] = {hp = 150, mana = 0, hpgain = 5, managain = 30, hpticks = 5, manaticks = 15},
  34.         [3] = {hp = 150, mana = 0, hpgain = 20, managain = 10, hpticks = 5, manaticks = 5},
  35.         [4] = {hp = 150, mana = 0, hpgain = 25, managain = 5, hpticks = 10, manaticks = 5}
  36.     }
  37.     self.default = {hp = 150, mana = 0, hpgain = 5, managain = 0, hpticks = 5, manaticks = 0}
  38.     self.level = 1
  39.     self.base = {hp = 150, mana = 0}
  40.     return self
  41. end
  42. -- this needs to be fixed, it needs to return only the combined hp & mana from the vocs but not the base hp / mana combined
  43. function Vocations:getPlayerTotalHp()
  44.     local t = {hp = 0, mana = 0}
  45.     local voc
  46.     for storage, vocation in ipairs(self:getAllVocations()) do
  47.         print(vocation)
  48.         if vocation ~= -1 then
  49.             t.hp = t.hp + self:getHp(vocation)
  50.             t.mana = t.mana + self:getMana(vocation)
  51.         end
  52.     end
  53.     return self.base.hp + t.hp, self.base.mana + t.mana
  54. end
  55.  
  56. function Vocations:getPlayerLevel()
  57.     return self.level
  58. end
  59.  
  60. function Vocations:setPlayerLevel(lvl)
  61.     self.level = lvl
  62. end
  63.  
  64. function Vocations:getStorageValue(key)
  65.     return key == nil and self.storage[1] or self.storage[key]
  66. end
  67.  
  68. function Vocations:setStorageValue(key, value) -- set player storage
  69.     self.storage[key] = value
  70. end
  71. -- this will update the types of vocations
  72. function Vocations:addNewVocations(vocs)
  73.     if type(vocs) == 'table' then
  74.         for _, value in ipairs(vocs) do
  75.             table.insert(self.types, value)
  76.             table.insert(self.playerVocations, self.default)
  77.         end
  78.     else
  79.         table.insert(self.types, vocs)
  80.         table.insert(self.playerVocations, self.default)
  81.     end
  82.  
  83. end
  84.  
  85. -- add new vocations to the player
  86. function Vocations:addPlayerVocation(voc)
  87.     self:setStorageValue(#self.storage + 1, voc)
  88. end
  89.  
  90. -- remove vocations from the player
  91. function Vocations:removePlayerVocation(voc)
  92.     for key = 1, #self.storage do
  93.         if self:getStorageValue(key) == voc then
  94.             self:setStorageValue(key, nil)
  95.         end
  96.     end
  97. end
  98.  
  99. function Vocations:getAllVocations()
  100.     return self.storage
  101. end
  102.  
  103. -- what you will see when you look at the player
  104. function Vocations:onLook()
  105.     local text = ''
  106.     if self:getStorageValue() == -1 then
  107.         self:setStorageValue(1, self.playerVoc)
  108.     end
  109.     for k, v in ipairs(self.storage) do
  110.         if self.types[v] == self.types[0] and k == #self.storage then
  111.             return self.types[0]
  112.         end
  113.         if self.types[v] ~= self.types[0] then
  114.             text = text..(self.types[v]) ..(k == #self.storage and '' or '/')
  115.         end
  116.     end
  117.     return text
  118. end
  119.  
  120. function Vocations:getAllVocations()
  121.     return self.storage
  122. end
  123. -- hp
  124. function Vocations:getHp(voc)
  125.     local lvl = self:getPlayerLevel()
  126.     local hpgain = self.playerVocations[voc].hpgain
  127.     return (hpgain * (lvl - 1))
  128. end
  129.  
  130. function Vocations:setHp(voc, hp)
  131.     self.playerVocations[voc].hp = hp
  132. end
  133.  
  134. -- mana
  135. function Vocations:getMana(voc)
  136.     local lvl = self:getPlayerLevel()
  137.     local managain = self.playerVocations[voc].managain
  138.     return (managain * (lvl - 1))
  139. end
  140.  
  141. function Vocations:setHpandMana(voc, hp, mana, hpgain, managain, hpticks, manaticks)
  142.     self:setHp(voc, hp)
  143.     self:setMana(voc, mana)
  144.     self:setHpTicks(voc, ticks)
  145.     setManaTicks(voc, ticks)
  146. end
  147.  
  148. function Vocations:setMana(voc, mana)
  149.     self.playerVocations[voc].mana = mana
  150. end
  151.  
  152. -- hp ticks
  153. function Vocations:getHpTicks(voc)
  154.     return self.playerVocations[voc].hpticks
  155. end
  156.  
  157. function Vocations:setHpTicks(voc, ticks)
  158.     self.playerVocations[voc].hpticks = ticks
  159. end
  160.  
  161. -- mana ticks
  162. function Vocations:getManaTicks(voc)
  163.     return self.playerVocations[voc].manaticks
  164. end
  165.  
  166. function Vocations:setManaTicks(voc, ticks)
  167.     self.playerVocations[voc].manaticks = ticks
  168. end
  169.  
  170. -- skills
  171. function Vocations:getSkillLevel(id)
  172.     return self.skills[id].lvl
  173. end
  174.  
  175. function Vocations:setSkillLevel(Id, value)
  176.     self.skills[id].lvl = value
  177. end
  178.  
  179. -- skill tries
  180. function Vocations:getSkillTries(id)
  181.     return self.skills[id].tries
  182. end
  183.  
  184. function Vocations:setSkillTries(Id, value)
  185.     self.skills[id].tries = value
  186. end
  187.  
  188. -- the formula for how the player will gain skills, needs to be worked on
  189. function Vocations:getSkillGainFormula(id)
  190.     return ((self.skills[id].modifier * 100) * (self.skills[id].lvl + 1)) * (self.skills[id].tries + 1)
  191. end
  192.  
  193. --return Vocations
  194.  
  195. local v = Vocations()
  196. print(v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement