extracted character code
This commit is contained in:
1 parent
a0ea5d71c5
commit
7b8e45b6be
2 files changed
+101
-94
No files matched your search
@@ -0,0 +1,99 @@
|
||||
local classes = require "data.classes"
|
||||
local races = require "data.races"
|
||||
|
||||
local character = {}
|
||||
|
||||
local base_stat_roll = function()
|
||||
return 3 + math.random(1, 6) + math.random(1, 6) + math.random(1, 6)
|
||||
end
|
||||
|
||||
local naive_random_name = function(length)
|
||||
local vowels = "aaeeeiioouuy"
|
||||
local consonants = "bcdfghjklmnpqrstvwxyz"
|
||||
local text = ""
|
||||
for i = 1, length do
|
||||
local c
|
||||
if i % 2 == 0 then
|
||||
c = math.random(1, #vowels)
|
||||
text = text .. vowels:sub(c, c)
|
||||
else
|
||||
c = math.random(1, #consonants)
|
||||
text = text .. consonants:sub(c, c)
|
||||
end
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
local progress_quest_random_name = function()
|
||||
local parts = {
|
||||
("br|cr|dr|fr|gr|j|kr|l|m|n|pr||||r|sh|tr|v|wh|x|y|z"):split("|"),
|
||||
("a|a|e|e|i|i|o|o|u|u|ae|ie|oo|ou"):split("|"),
|
||||
("b|ck|d|g|k|m|n|p|t|v|x|z"):split("|"),
|
||||
}
|
||||
local name = ""
|
||||
for i = 0, 5 do
|
||||
local part = parts[i % 3 + 1]
|
||||
name = name .. part[math.random(1, #part)]
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
local random_stat_up = function(character)
|
||||
local core_stats = {
|
||||
"charisma", "constitution", "dexterity", "intelligence", "strength", "wisdom",
|
||||
}
|
||||
local selected_stat = core_stats[math.random(1, #core_stats)]
|
||||
character[selected_stat] = character[selected_stat] + 1
|
||||
end
|
||||
|
||||
|
||||
|
||||
character.new = function(name)
|
||||
name = name or progress_quest_random_name() -- name not affected by seed
|
||||
|
||||
local seed = math.random()
|
||||
math.randomseed(seed)
|
||||
|
||||
local character = {
|
||||
seed = seed,
|
||||
name = name,
|
||||
race = races[math.random(1, #races)],
|
||||
class = classes[math.random(1, #classes)],
|
||||
charisma = base_stat_roll(),
|
||||
constitution = base_stat_roll(),
|
||||
dexterity = base_stat_roll(),
|
||||
intelligence = base_stat_roll(),
|
||||
strength = base_stat_roll(),
|
||||
wisdom = base_stat_roll(),
|
||||
level = 1,
|
||||
experience = 0,
|
||||
}
|
||||
character.health = math.random(1, 8) + math.floor(character.constitution / 6)
|
||||
character.magic = math.random(1, 8) + math.floor(character.intelligence / 6)
|
||||
|
||||
for _, stat_name in ipairs(races[character.race].stats) do
|
||||
character[stat_name] = character[stat_name] + math.random(1, 3)
|
||||
end
|
||||
for _, stat_name in ipairs(classes[character.class].stats) do
|
||||
character[stat_name] = character[stat_name] + math.random(1, 3)
|
||||
end
|
||||
|
||||
character.max_encumberance = character.strength + 10
|
||||
character.inventory = {}
|
||||
|
||||
return character
|
||||
end
|
||||
|
||||
character.level_up = function(character)
|
||||
character.health = character.health + 1 + math.floor(character.constitution / 3) + math.random(1, 4)
|
||||
character.magic = character.magic + 1 + math.floor(character.intelligence / 3) + math.random(1, 4)
|
||||
|
||||
random_stat_up(character)
|
||||
random_stat_up(character)
|
||||
|
||||
character.max_encumberance = character.strength + 10
|
||||
|
||||
-- TODO this is where a spell could be added, and
|
||||
end
|
||||
|
||||
return character
|
||||
+2
-94
@@ -1,5 +1,6 @@
|
||||
local window_width, window_height = love.graphics.getDimensions()
|
||||
|
||||
local character = require "lib.character"
|
||||
local log = require "lib.log"
|
||||
local lovebird = require "lib.lovebird"
|
||||
local macOS_say = require "lib.macOS_say"
|
||||
@@ -16,106 +17,13 @@ log{
|
||||
}
|
||||
|
||||
local constants = require "data.constants"
|
||||
local classes = require "data.classes"
|
||||
local images = require "data.images"
|
||||
local races = require "data.races"
|
||||
|
||||
|
||||
|
||||
local new_character = function(name)
|
||||
local base_stat_roll = function()
|
||||
return 3 + math.random(1, 6) + math.random(1, 6) + math.random(1, 6)
|
||||
end
|
||||
|
||||
local naive_random_name = function(length)
|
||||
local vowels = "aaeeeiioouuy"
|
||||
local consonants = "bcdfghjklmnpqrstvwxyz"
|
||||
local text = ""
|
||||
for i = 1, length do
|
||||
local c
|
||||
if i % 2 == 0 then
|
||||
c = math.random(1, #vowels)
|
||||
text = text .. vowels:sub(c, c)
|
||||
else
|
||||
c = math.random(1, #consonants)
|
||||
text = text .. consonants:sub(c, c)
|
||||
end
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
local progress_quest_random_name = function()
|
||||
local parts = {
|
||||
("br|cr|dr|fr|gr|j|kr|l|m|n|pr||||r|sh|tr|v|wh|x|y|z"):split("|"),
|
||||
("a|a|e|e|i|i|o|o|u|u|ae|ie|oo|ou"):split("|"),
|
||||
("b|ck|d|g|k|m|n|p|t|v|x|z"):split("|"),
|
||||
}
|
||||
local name = ""
|
||||
for i = 0, 5 do
|
||||
local part = parts[i % 3 + 1]
|
||||
name = name .. part[math.random(1, #part)]
|
||||
end
|
||||
return name
|
||||
end
|
||||
|
||||
name = name or progress_quest_random_name() -- name not affected by seed
|
||||
|
||||
local seed = math.random()
|
||||
math.randomseed(seed)
|
||||
|
||||
local character = {
|
||||
seed = seed,
|
||||
name = name,
|
||||
race = races[math.random(1, #races)],
|
||||
class = classes[math.random(1, #classes)],
|
||||
charisma = base_stat_roll(),
|
||||
constitution = base_stat_roll(),
|
||||
dexterity = base_stat_roll(),
|
||||
intelligence = base_stat_roll(),
|
||||
strength = base_stat_roll(),
|
||||
wisdom = base_stat_roll(),
|
||||
level = 1,
|
||||
experience = 0,
|
||||
}
|
||||
character.health = math.random(1, 8) + math.floor(character.constitution / 6)
|
||||
character.magic = math.random(1, 8) + math.floor(character.intelligence / 6)
|
||||
|
||||
for _, stat_name in ipairs(races[character.race].stats) do
|
||||
character[stat_name] = character[stat_name] + math.random(1, 3)
|
||||
end
|
||||
for _, stat_name in ipairs(classes[character.class].stats) do
|
||||
character[stat_name] = character[stat_name] + math.random(1, 3)
|
||||
end
|
||||
|
||||
character.max_encumberance = character.strength + 10
|
||||
character.inventory = {}
|
||||
|
||||
return character
|
||||
end
|
||||
|
||||
local level_up = function(character)
|
||||
local random_stat_up = function(character)
|
||||
local core_stats = {
|
||||
"charisma", "constitution", "dexterity", "intelligence", "strength", "wisdom",
|
||||
}
|
||||
local selected_stat = core_stats[math.random(1, #core_stats)]
|
||||
character[selected_stat] = character[selected_stat] + 1
|
||||
end
|
||||
|
||||
character.health = character.health + 1 + math.floor(character.constitution / 3) + math.random(1, 4)
|
||||
character.magic = character.magic + 1 + math.floor(character.intelligence / 3) + math.random(1, 4)
|
||||
|
||||
random_stat_up(character)
|
||||
random_stat_up(character)
|
||||
|
||||
character.max_encumberance = character.strength + 10
|
||||
|
||||
-- TODO this is where a spell could be added, and
|
||||
end
|
||||
|
||||
-- TEMP
|
||||
local test_new_character = function()
|
||||
local character = new_character()
|
||||
local character = character.new()
|
||||
local message = "My name is " .. character.name .. ", and I am a " .. character.class .. " " .. character.race .. "!"
|
||||
macOS_say(message)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user