Initial how_progression baseline
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
-- Mission IDs and debug phases are strings. Existing /prog still parses its
|
||||
-- own arguments; this module is for future migration of that command.
|
||||
local definitions = {
|
||||
['crowbar:1'] = { contact = 'crowbar', number = 1, name = 'The Introduction', phases = { 'retrieve_vehicle', 'return_vehicle', 'complete' } },
|
||||
['crowbar:2'] = { contact = 'crowbar', number = 2, name = 'Get Some Wheels', phases = { 'steal_vehicle', 'complete' } },
|
||||
['crowbar:3'] = { contact = 'crowbar', number = 3, name = 'Quick Score', phases = { 'rob_register', 'lose_cops', 'complete' } },
|
||||
['crowbar:4'] = { contact = 'crowbar', number = 4, name = 'Wash the Cash', phases = { 'meet_mack', 'meet_gabe', 'wash_cash', 'complete' } },
|
||||
['crowbar:5'] = { contact = 'crowbar', number = 5, name = 'Buy In', phases = { 'get_package', 'escape_ambush', 'return_package', 'complete' } },
|
||||
['mack:1'] = { contact = 'mack', number = 1, name = 'Easy Rider', phases = {} },
|
||||
}
|
||||
|
||||
local M = { definitions = definitions }
|
||||
|
||||
function M.missionId(contact, number)
|
||||
if type(contact) ~= 'string' or not contact:match('^[a-z][a-z_]*$')
|
||||
or type(number) ~= 'number' or number % 1 ~= 0
|
||||
or number < 1 or number > 999
|
||||
then
|
||||
return nil
|
||||
end
|
||||
|
||||
return ('%s:%d'):format(contact, number)
|
||||
end
|
||||
|
||||
function M.phaseId(missionId, phaseName)
|
||||
if not definitions[missionId] or type(phaseName) ~= 'string'
|
||||
or not phaseName:match('^[a-z][a-z_]*$')
|
||||
then
|
||||
return nil
|
||||
end
|
||||
|
||||
return missionId .. ':' .. phaseName
|
||||
end
|
||||
|
||||
function M.parseProgPhase(contact, notation)
|
||||
if type(notation) ~= 'string' then return nil end
|
||||
|
||||
local missionText, phaseText = notation:match('^(%d+)%.(%d+)$')
|
||||
if not missionText then return nil end
|
||||
if #missionText > 3 or #phaseText > 3 then return nil end
|
||||
|
||||
local missionNumber, phaseNumber = tonumber(missionText), tonumber(phaseText)
|
||||
if not missionNumber or not phaseNumber or missionNumber < 1 or phaseNumber < 1 then
|
||||
return nil
|
||||
end
|
||||
|
||||
local id = M.missionId(contact, missionNumber)
|
||||
local definition = definitions[id]
|
||||
local phaseName = definition and definition.phases[phaseNumber]
|
||||
if not phaseName then return nil end
|
||||
|
||||
return {
|
||||
missionId = id,
|
||||
phaseId = M.phaseId(id, phaseName),
|
||||
missionNumber = missionNumber,
|
||||
phaseNumber = phaseNumber,
|
||||
phaseName = phaseName,
|
||||
notation = notation,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user