Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vocations = {}
- Vocations.__index = Vocations
- setmetatable(Vocations, {
- __call = function(cls, ...)
- return cls.new(...)
- end,
- })
- function Vocations.new(currentVocation)
- local self = setmetatable({}, Vocations)
- -- default vocations
- self.types = { [0] = 'none', 'sorcerer', 'druid', 'paladin', 'knight' }
- -- default storage
- self.storage = { -1 }
- -- players current vocation
- self.playerVoc = currentVocation or 0
- self.skills = {
- -- skillLvl, modifier, tries
- [0] = {lvl = 0, modifier = 1.0, tries = 0}, -- fist
- {lvl = 0, modifier = 1.0, tries = 0}, -- club
- {lvl = 0, modifier = 1.0, tries = 0}, -- sword
- {lvl = 0, modifier = 1.0, tries = 0}, -- axe
- {lvl = 0, modifier = 1.0, tries = 0}, -- distance
- {lvl = 0, modifier = 1.0, tries = 0}, -- shield
- {lvl = 0, modifier = 1.0, tries = 0}, -- fish
- {lvl = 0, modifier = 1.0, tries = 0} -- magic
- }
- -- default vocation hp / mana
- self.playerVocations = {
- [0] = {hp = 150, mana = 0, hpgain = 5, managain = 0, hpticks = 5, manaticks = 0},
- [1] = {hp = 150, mana = 0, hpgain = 5, managain = 30, hpticks = 5, manaticks = 15},
- [2] = {hp = 150, mana = 0, hpgain = 5, managain = 30, hpticks = 5, manaticks = 15},
- [3] = {hp = 150, mana = 0, hpgain = 20, managain = 10, hpticks = 5, manaticks = 5},
- [4] = {hp = 150, mana = 0, hpgain = 25, managain = 5, hpticks = 10, manaticks = 5}
- }
- self.default = {hp = 150, mana = 0, hpgain = 5, managain = 0, hpticks = 5, manaticks = 0}
- self.level = 1
- self.base = {hp = 150, mana = 0}
- return self
- end
- -- this needs to be fixed, it needs to return only the combined hp & mana from the vocs but not the base hp / mana combined
- function Vocations:getPlayerTotalHp()
- local t = {hp = 0, mana = 0}
- local voc
- for storage, vocation in ipairs(self:getAllVocations()) do
- print(vocation)
- if vocation ~= -1 then
- t.hp = t.hp + self:getHp(vocation)
- t.mana = t.mana + self:getMana(vocation)
- end
- end
- return self.base.hp + t.hp, self.base.mana + t.mana
- end
- function Vocations:getPlayerLevel()
- return self.level
- end
- function Vocations:setPlayerLevel(lvl)
- self.level = lvl
- end
- function Vocations:getStorageValue(key)
- return key == nil and self.storage[1] or self.storage[key]
- end
- function Vocations:setStorageValue(key, value) -- set player storage
- self.storage[key] = value
- end
- -- this will update the types of vocations
- function Vocations:addNewVocations(vocs)
- if type(vocs) == 'table' then
- for _, value in ipairs(vocs) do
- table.insert(self.types, value)
- table.insert(self.playerVocations, self.default)
- end
- else
- table.insert(self.types, vocs)
- table.insert(self.playerVocations, self.default)
- end
- end
- -- add new vocations to the player
- function Vocations:addPlayerVocation(voc)
- self:setStorageValue(#self.storage + 1, voc)
- end
- -- remove vocations from the player
- function Vocations:removePlayerVocation(voc)
- for key = 1, #self.storage do
- if self:getStorageValue(key) == voc then
- self:setStorageValue(key, nil)
- end
- end
- end
- function Vocations:getAllVocations()
- return self.storage
- end
- -- what you will see when you look at the player
- function Vocations:onLook()
- local text = ''
- if self:getStorageValue() == -1 then
- self:setStorageValue(1, self.playerVoc)
- end
- for k, v in ipairs(self.storage) do
- if self.types[v] == self.types[0] and k == #self.storage then
- return self.types[0]
- end
- if self.types[v] ~= self.types[0] then
- text = text..(self.types[v]) ..(k == #self.storage and '' or '/')
- end
- end
- return text
- end
- function Vocations:getAllVocations()
- return self.storage
- end
- -- hp
- function Vocations:getHp(voc)
- local lvl = self:getPlayerLevel()
- local hpgain = self.playerVocations[voc].hpgain
- return (hpgain * (lvl - 1))
- end
- function Vocations:setHp(voc, hp)
- self.playerVocations[voc].hp = hp
- end
- -- mana
- function Vocations:getMana(voc)
- local lvl = self:getPlayerLevel()
- local managain = self.playerVocations[voc].managain
- return (managain * (lvl - 1))
- end
- function Vocations:setHpandMana(voc, hp, mana, hpgain, managain, hpticks, manaticks)
- self:setHp(voc, hp)
- self:setMana(voc, mana)
- self:setHpTicks(voc, ticks)
- setManaTicks(voc, ticks)
- end
- function Vocations:setMana(voc, mana)
- self.playerVocations[voc].mana = mana
- end
- -- hp ticks
- function Vocations:getHpTicks(voc)
- return self.playerVocations[voc].hpticks
- end
- function Vocations:setHpTicks(voc, ticks)
- self.playerVocations[voc].hpticks = ticks
- end
- -- mana ticks
- function Vocations:getManaTicks(voc)
- return self.playerVocations[voc].manaticks
- end
- function Vocations:setManaTicks(voc, ticks)
- self.playerVocations[voc].manaticks = ticks
- end
- -- skills
- function Vocations:getSkillLevel(id)
- return self.skills[id].lvl
- end
- function Vocations:setSkillLevel(Id, value)
- self.skills[id].lvl = value
- end
- -- skill tries
- function Vocations:getSkillTries(id)
- return self.skills[id].tries
- end
- function Vocations:setSkillTries(Id, value)
- self.skills[id].tries = value
- end
- -- the formula for how the player will gain skills, needs to be worked on
- function Vocations:getSkillGainFormula(id)
- return ((self.skills[id].modifier * 100) * (self.skills[id].lvl + 1)) * (self.skills[id].tries + 1)
- end
- --return Vocations
- local v = Vocations()
- print(v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement