2014-07-03 18:03:22 -06:00
|
|
|
--scripts/modtools/skill-change.lua
|
|
|
|
--author expwnent
|
|
|
|
--based on skillChange.lua by Putnam
|
2014-07-09 04:21:52 -06:00
|
|
|
--TODO: update skill level once experience increases/decreases
|
|
|
|
--TODO: skill rust?
|
2015-10-23 17:57:04 -06:00
|
|
|
--[[=begin
|
2014-07-03 18:03:22 -06:00
|
|
|
|
2015-10-23 17:57:04 -06:00
|
|
|
modtools/skill-change
|
|
|
|
=====================
|
|
|
|
Sets or modifies a skill of a unit. Args:
|
|
|
|
|
|
|
|
:-help: print the help message
|
|
|
|
:-skill skillName: set the skill that we're talking about
|
|
|
|
:-mode (add/set): are we adding experience/levels or setting them?
|
|
|
|
:-granularity (experience/level):
|
|
|
|
direct experience, or experience levels?
|
|
|
|
:-unit id: id of the target unit
|
|
|
|
:-value amount: how much to set/add
|
|
|
|
|
|
|
|
=end]]
|
2014-07-03 18:03:22 -06:00
|
|
|
local utils = require 'utils'
|
|
|
|
|
|
|
|
validArgs = validArgs or utils.invert({
|
|
|
|
'help',
|
|
|
|
'skill',
|
|
|
|
'mode',
|
|
|
|
'value',
|
|
|
|
'granularity',
|
|
|
|
'unit'
|
|
|
|
})
|
|
|
|
|
|
|
|
mode = mode or utils.invert({
|
|
|
|
'add',
|
|
|
|
'set',
|
|
|
|
})
|
|
|
|
|
|
|
|
granularity = granularity or utils.invert({
|
|
|
|
'experience',
|
|
|
|
'level',
|
|
|
|
})
|
|
|
|
|
|
|
|
local args = utils.processArgs({...}, validArgs)
|
|
|
|
|
2014-07-03 18:07:13 -06:00
|
|
|
if args.help then
|
|
|
|
print([[scripts/modtools/skill-change.lua
|
|
|
|
arguments
|
|
|
|
-help
|
|
|
|
print this help message
|
|
|
|
-skill skillName
|
|
|
|
set the skill that we're talking about
|
|
|
|
-mode (add/set)
|
|
|
|
are we adding experience/levels or setting them?
|
2015-02-11 17:08:23 -07:00
|
|
|
-granularity (experience/level)
|
2014-07-03 18:07:13 -06:00
|
|
|
direct experience, or experience levels?
|
|
|
|
-unit id
|
|
|
|
id of the target unit
|
|
|
|
-value amount
|
|
|
|
how much to set/add
|
|
|
|
]])
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-07-03 18:03:22 -06:00
|
|
|
if not args.unit or not tonumber(args.unit) or not df.unit.find(tonumber(args.unit)) then
|
|
|
|
error 'Invalid unit.'
|
|
|
|
end
|
|
|
|
args.unit = df.unit.find(tonumber(args.unit))
|
|
|
|
|
|
|
|
args.skill = df.job_skill[args.skill]
|
|
|
|
args.mode = mode[args.mode or 'set']
|
|
|
|
args.granularity = granularity[args.granularity or 'level']
|
|
|
|
args.value = tonumber(args.value)
|
|
|
|
|
|
|
|
if not args.skill then
|
|
|
|
error('invalid skill')
|
|
|
|
end
|
|
|
|
if not args.value then
|
|
|
|
error('invalid value')
|
|
|
|
end
|
|
|
|
|
|
|
|
local skill
|
|
|
|
for _,skill_c in ipairs(args.unit.status.current_soul.skills) do
|
|
|
|
if skill_c.id == args.skill then
|
|
|
|
skill = skill_c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not skill then
|
|
|
|
skill = df.unit_skill:new()
|
|
|
|
skill.id = args.skill
|
2015-01-18 10:53:08 -07:00
|
|
|
utils.insert_sorted(args.unit.status.current_soul.skills,skill,'id')
|
2014-07-03 18:03:22 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
print('old: ' .. skill.rating .. ': ' .. skill.experience)
|
|
|
|
if args.granularity == granularity.experience then
|
|
|
|
if args.mode == mode.set then
|
|
|
|
skill.experience = args.value
|
|
|
|
elseif args.mode == mode.add then
|
|
|
|
skill.experience = skill.experience + args.value
|
|
|
|
else
|
|
|
|
error 'bad mode'
|
|
|
|
end
|
|
|
|
elseif args.granularity == granularity.level then
|
|
|
|
if args.mode == mode.set then
|
2015-02-11 17:08:23 -07:00
|
|
|
skill.rating = args.value
|
2014-07-03 18:03:22 -06:00
|
|
|
elseif args.mode == mode.add then
|
2015-02-11 17:08:23 -07:00
|
|
|
skill.rating = args.value + skill.rating
|
2014-07-03 18:03:22 -06:00
|
|
|
else
|
|
|
|
error 'bad mode'
|
|
|
|
end
|
|
|
|
else
|
|
|
|
error 'bad granularity'
|
|
|
|
end
|
|
|
|
|
|
|
|
print('new: ' .. skill.rating .. ': ' .. skill.experience)
|
|
|
|
|