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,
- })
- local defaultVocation = 0
- function Vocations.new(currentVocation)
- local x = setmetatable({}, Vocations)
- -- default vocations
- x.types = { [0] = 'None', 'Sorcerer', 'Druid', 'Paladin', 'Knight' }
- -- default storage
- x.storage = {}
- x.base = {vocation = 0, maxHp = 150, maxMana = 0, hp = 5, mana = 0, soul = 0, hpticks = 5, manaticks = 5, soulticks = 0, level = 8}
- x.level = x.base.level
- x.vocation = x.base.vocation
- x.playerSkills =
- { -- default skills for vocations
- [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
- {level = 0, modifier = 1.0, tries = 0}, -- club
- {level = 0, modifier = 1.0, tries = 0}, -- sword
- {level = 0, modifier = 1.0, tries = 0}, -- axe
- {level = 0, modifier = 1.0, tries = 0}, -- distance
- {level = 0, modifier = 1.0, tries = 0}, -- shield
- {level = 0, modifier = 1.0, tries = 0}, -- fish
- {level = 0, modifier = 1.0, tries = 0} -- magic
- }
- x:constructVocation(currentVocation or defaultVocation)
- return x
- end
- -- the vocations which can be applied to the player cannot have multiples of the same vocation
- Vocations.playerVocations = {
- [1] = {hpgain = 5, managain = 30, soul = 100, hpticks = 5, manaticks = 15, soulticks = 5}, -- sorcerer
- [2] = {hpgain = 5, managain = 30, soul = 100, hpticks = 5, manaticks = 15, soulticks = 5}, -- druid
- [3] = {hpgain = 20, managain = 10, soul = 100, hpticks = 5, manaticks = 5, soulticks = 5}, -- paladin
- [4] = {hpgain = 25, managain = 5, soul = 100, hpticks = 10, manaticks = 5, soulticks = 5} -- knight
- }
- Vocations.vocationSkills = {
- -- skillLvl, modifier, tries
- { -- 1
- [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
- {level = 0, modifier = 1.0, tries = 0}, -- club
- {level = 0, modifier = 1.0, tries = 0}, -- sword
- {level = 0, modifier = 1.0, tries = 0}, -- axe
- {level = 0, modifier = 1.0, tries = 0}, -- distance
- {level = 0, modifier = 1.0, tries = 0}, -- shield
- {level = 0, modifier = 1.0, tries = 0}, -- fish
- {level = 0, modifier = 1.0, tries = 0} -- magic
- },
- { -- 2
- [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
- {level = 0, modifier = 1.0, tries = 0}, -- club
- {level = 0, modifier = 1.0, tries = 0}, -- sword
- {level = 0, modifier = 1.0, tries = 0}, -- axe
- {level = 0, modifier = 1.0, tries = 0}, -- distance
- {level = 0, modifier = 1.0, tries = 0}, -- shield
- {level = 0, modifier = 1.0, tries = 0}, -- fish
- {level = 0, modifier = 1.0, tries = 0} -- magic
- },
- { -- 3
- [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
- {level = 0, modifier = 1.0, tries = 0}, -- club
- {level = 0, modifier = 1.0, tries = 0}, -- sword
- {level = 0, modifier = 1.0, tries = 0}, -- axe
- {level = 0, modifier = 1.0, tries = 0}, -- distance
- {level = 0, modifier = 1.0, tries = 0}, -- shield
- {level = 0, modifier = 1.0, tries = 0}, -- fish
- {level = 0, modifier = 1.0, tries = 0} -- magic
- },
- { -- 4
- [0] = {level = 0, modifier = 1.0, tries = 0}, -- fist
- {level = 0, modifier = 1.0, tries = 0}, -- club
- {level = 0, modifier = 1.0, tries = 0}, -- sword
- {level = 0, modifier = 1.0, tries = 0}, -- axe
- {level = 0, modifier = 1.0, tries = 0}, -- distance
- {level = 0, modifier = 1.0, tries = 0}, -- shield
- {level = 0, modifier = 1.0, tries = 0}, -- fish
- {level = 0, modifier = 1.0, tries = 0} -- magic
- }
- }
- Vocations.specialAttributes = {
- [1] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
- [2] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
- [3] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}},
- [4] = {block = 0, reflect = 0, atkspeed = 0, critical = 0, damage = 0, immunity = {--[[ place types here]]}}
- }
- -- construct the vocation of the player
- function Vocations:constructVocation(v)
- self:setPlayerVocation(v)
- end
- function Vocations:setSkillProperty(id, property, value)
- self.playerSkills[id][property] = value
- end
- function Vocations:getSkills(vocation)
- return self.skills[vocation]
- end
- function Vocations:setSkills()
- for i = 0, #self:getSkills() do
- self:setSkillProperty(i, "modifier")
- end
- end
- -- set the player's vocation
- function Vocations:setPlayerVocation(v)
- self.storage[self.types[v]] = v
- end
- -- get the level of the player
- function Vocations:getLevel()
- return self.level
- end
- -- set the level of the player
- function Vocations:setPlayerLevel(l)
- self.level = l
- end
- -- return the storage table which holds all of the player's vocations
- function Vocations:getVocation()
- return self.storage
- end
- -- get the hp of the player based on the vocations & the player's lvl
- function Vocations:getHp()
- local hp = 0
- for vocation, id in pairs(self:getVocation()) do
- if id ~= defaultVocation then
- hp = hp + self.playerVocations[id].hpgain
- end
- end
- return self:getBase(hp, "hp", "maxHp")
- end
- -- get the mana of the player based on the vocations & the player's lvl
- function Vocations:getMana()
- local mana = 0
- for vocation, id in pairs(self:getVocation()) do
- if id ~= defaultVocation then
- mana = mana + self.playerVocations[id].managain
- end
- end
- return self:getBase(mana, "mana", "maxMana")
- end
- function Vocations:getBase(a, b, c)
- a = (a == 0) and self.base[b] or a
- local e = (a * (self.level - self.base.level)) + self.base[c]
- return (e < 0) and 0 or e
- end
- -- what you will see when you look at the player
- -- this function will exclude none if the player has a vocation already set
- function Vocations:onLook()
- local text = ''
- for vocation, id in pairs(self.storage) do
- text = text .. vocation .. '/'
- end
- if sizeOf(self.storage) > 1 then
- text = text:sub(1, string.find(text, self.types[defaultVocation], 1, true) - 2)
- else
- text = text:sub(1, #text - 1)
- end
- text = text .. "\nLevel: " .. self:getLevel() .."\nHP: " .. self:getHp() .. " / Mana: " .. self:getMana()
- return text
- end
- -- return the size of a table
- function sizeOf(t)
- local c = 0
- for k, v in pairs(t) do
- c = c + 1
- end
- return c
- end
- -- add new vocations to the player
- function Vocations:addPlayerVocation(voc)
- self.storage[self.types[voc]] = voc
- end
- -- if no argument in Vocations it defaults to 0 which is no vocation, default level is 8
- local v = Vocations()
- --v:addPlayerVocation(1)
- v:addPlayerVocation(2)
- v:addPlayerVocation(3)
- --v:addPlayerVocation(4)
- v:setPlayerLevel(11)
- print(v:onLook())
- v:setSkills()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement