From a741eaca97cea047632518e79b9e2042a6c67f0d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 13 May 2018 21:23:54 +0200 Subject: [PATCH] equip new orcs in e2 with lua and a hacky callback. --- res/eressea/equipment.xml | 5 --- scripts/eressea/equipment.lua | 83 +++++++++++++++++++++-------------- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml index d0f37a404..a03aba2ce 100644 --- a/res/eressea/equipment.xml +++ b/res/eressea/equipment.xml @@ -36,11 +36,6 @@ - - - - - diff --git a/scripts/eressea/equipment.lua b/scripts/eressea/equipment.lua index d7fa9d43a..423fc0280 100644 --- a/scripts/eressea/equipment.lua +++ b/scripts/eressea/equipment.lua @@ -1,6 +1,46 @@ --- Equipment +-- forward declaration required: +local sets = {} -local sets = { +local function equip_new_orc(u, flags) + local eqname = 'orc_' .. config.rules + local set = sets[eqname] + if set then + return equip_unit(u, eqname, flags) + end + return false +end + +function equip_unit(u, name, flags) + local set = sets[name] + if set then + local items = set['items'] + if items then + for k,v in pairs(items) do + u:add_item(k, v) + end + end + local skills = set['skills'] + if skills then + for k,v in pairs(skills) do + u:set_skill(k, v) + end + end + local spells = set['spells'] + if spells then + for k, v in ipairs(spells) do + u:add_spell(v) + end + end + local callback = set['callback'] + if callback and type(callback) == 'function' then + callback(u, flags) + end + return true + end + return false +end + +sets = { ['first_unit'] = { ['items'] = { ['money'] = 2500, @@ -25,6 +65,15 @@ local sets = { ['melee'] = 1 } }, + ['new_orc'] = { + ['callback'] = equip_new_orc + }, + ['orc_e2'] = { + ['skills'] = { + ['polearm'] = 1, + ['melee'] = 1 + } + }, ['seed_dwarf'] = { ['items'] = { ['axe'] = 1, @@ -108,34 +157,4 @@ local sets = { }, } -function equip_unit(u, name, flags) - local set = sets[name] - if set then - local items = set['items'] - if items then - for k,v in pairs(items) do - u:add_item(k, v) - end - end - local skills = set['skills'] - if skills then - for k,v in pairs(skills) do - u:set_skill(k, v) - end - end - local spells = set['spells'] - if spells then - for k, v in ipairs(spells) do - u:add_spell(v) - end - end - local callback = set['callback'] - if callback and type(callback) == 'function' then - callback(u) - end - return true - end - return false -end - return nil