Skip to content

Instantly share code, notes, and snippets.

@Codinablack
Last active March 22, 2022 02:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Codinablack/b8e935ba3e3ad7ce5f8cb5c03f47afc1 to your computer and use it in GitHub Desktop.
Save Codinablack/b8e935ba3e3ad7ce5f8cb5c03f47afc1 to your computer and use it in GitHub Desktop.
local spellsFile = io.open("data/test/spells.xml", "r")
local spellsFolder = "data/test/scripts/"
local convertsFolder = "data/test/converts/"
local instantSpells = {}
local function tobool(v)
return v and ( (type(v)=="number") and (v==1) or ( (type(v)=="string") and (v=="true") ) )
end
local function cleanSpaces(s)
return s:match( "^%s*(.-)%s*$" )
end
local function populateInstantSpells()
for i in spellsFile:read("*a"):gmatch("<instant (.-)</instant>") do
local spellData = {}
spellData.vocations = {}
spellData.name = i:match('name.-=.-"(.-)"')
spellData.id = tonumber(i:match('spellid.-=.-"(.-)"'))
spellData.group = i:match('group.-=.-"(.-)"')
spellData.cooldown = tonumber(i:match('cooldown.-=.-"(.-)"')) or tonumber(i:match('exhaustion.-=.-"(.-)"'))
spellData.groupCooldown = tonumber(i:match('groupcooldown.-=.-"(.-)"'))
spellData.level = tonumber(i:match('level.-=.-"(.-)"')) or tonumber(i:match('lvl.-=.-"(.-)"'))
spellData.magicLevel = tonumber(i:match('magiclevel.-=.-"(.-)"')) or tonumber(i:match('maglv.-=.-"(.-)"'))
spellData.mana = tonumber(i:match('mana.-=.-"(.-)"'))
spellData.manaPercent = tonumber(i:match('manapercent.-=.-"(.-)"'))
spellData.soul = tonumber(i:match('soul.-=.-"(.-)"'))
spellData.range = tonumber(i:match('range.-=.-"(.-)"'))
spellData.isPremium = tobool(tonumber(i:match('premium.-=.-"(.-)"'))) or tobool(tonumber(i:match('prem.-=.-"(.-)"')))
spellData.isEnabled = tobool(tonumber(i:match('enabled.-=.-"(.-)"')))
spellData.needTarget = tobool(tonumber(i:match('needtarget.-=.-"(.-)"')))
spellData.needWeapon = tobool(tonumber(i:match('needweapon.-=.-"(.-)"')))
spellData.needLearn = tobool(tonumber(i:match('needlearn.-=.-"(.-)"')))
spellData.isSelfTarget = tobool(tonumber(i:match('selfTarget.-=.-"(.-)"')))
spellData.isBlocking = tobool(tonumber(i:match('blocking.-=.-"(.-)"')))
spellData.isAggressive = tobool(tonumber(i:match('aggressive.-=.-"(.-)"')))
spellData.pzLock = tobool(tonumber(i:match('pzlock.-=.-"(.-)"')))
spellData.words = i:match('words.-=.-"(.-)"')
spellData.needDirection = tobool(tonumber(i:match('direction.-=.-"(.-)"')))
spellData.hasParams = tobool(tonumber(i:match('params.-=.-"(.-)"')))
spellData.hasPlayerNameParam = tobool(tonumber(i:match('playernameparam.-=.-"(.-)"')))
spellData.needCasterTargetOrDirection = tobool(tonumber(i:match('casterTargetOrDirection.-=.-"(.-)"')))
spellData.isBlockingWalls = tobool(tonumber(i:match('blockwalls.-=.-"(.-)"')))
spellData.scriptPath = i:match('script.-=.-"(.-)"')
for x in i:gmatch("<vocation (.-)/>") do
spellData.vocations[#spellData.vocations + 1] = x:match('name.-=.-"(.-)"')
end
instantSpells[spellData.name] = spellData
end
end
local function formatInstantSpellStringData()
for key, spell in pairs(instantSpells) do
local stringData = "----------------- \nlocal spell = Spell(SPELL_INSTANT)\n"
if spell.name then
stringData = stringData .. "\n---" .. spell.name .. "---"
stringData = stringData .. "\nspell:name('" .. spell.name .. "')"
end
if spell.words then
stringData = stringData .. "\nspell:words('" .. spell.words .. "')"
end
if spell.id then
stringData = stringData .. "\nspell:id(" .. spell.id .. ")"
end
if spell.group then
stringData = stringData .. "\nspell:group('" .. spell.group .. "')"
end
if spell.cooldown then
stringData = stringData .. "\nspell:cooldown(" .. spell.cooldown .. ")"
end
if spell.groupCooldown then
stringData = stringData .. "\nspell:groupCooldown(" .. spell.groupCooldown .. ")"
end
if spell.level then
stringData = stringData .. "\nspell:level(" .. spell.level .. ")"
end
if spell.magicLevel then
stringData = stringData .. "\nspell:magicLevel(" .. spell.magicLevel .. ")"
end
if spell.mana then
stringData = stringData .. "\nspell:mana(" .. spell.mana .. ")"
end
if spell.manapercent then
stringData = stringData .. "\nspell:manaPercent(" .. spell.manaPercent .. ")"
end
if spell.soul then
stringData = stringData .. "\nspell:soul(" .. spell.soul .. ")"
end
if spell.range then
stringData = stringData .. "\nspell:range(" .. spell.range .. ")"
end
if spell.isPremium then
stringData = stringData .. "\nspell:isPremium(" .. tostring(spell.isPremium) .. ")"
end
if spell.isEnabled then
stringData = stringData .. "\nspell:isEnabled(" .. tostring(spell.isEnabled) .. ")"
end
if spell.needTarget then
stringData = stringData .. "\nspell:needTarget(" .. tostring(spell.needTarget) .. ")"
end
if spell.needLearn then
stringData = stringData .. "\nspell:needLearn(" .. tostring(spell.needLearn) .. ")"
end
if spell.isSelfTarget then
stringData = stringData .. "\nspell:isSelfTarget(" .. tostring(spell.isSelfTarget) .. ")"
end
if spell.isBlocking then
stringData = stringData .. "\nspell:isBlocking(" .. tostring(spell.isBlocking) .. ")"
end
if spell.isAggressive then
stringData = stringData .. "\nspell:isAggressive(" .. tostring(spell.isAggressive) .. ")"
end
if spell.pzLock then
stringData = stringData .. "\nspell:isPzLock(" .. tostring(spell.pzLock) .. ")"
end
if spell.needDirection then
stringData = stringData .. "\nspell:needDirection(" .. tostring(spell.needDirection) .. ")"
end
if spell.hasParams then
stringData = stringData .. "\nspell:hasParams(" .. tostring(spell.hasParams) .. ")"
end
if spell.hasPlayerNameParam then
stringData = stringData .. "\nspell:hasPlayerNameParam(" .. tostring(spell.hasPlayerNameParam) .. ")"
end
if spell.needCasterTargetOrDirection then
stringData = stringData .. "\nspell:needCasterTargetOrDirection(" .. tostring(spell.needCasterTargetOrDirection) .. ")"
end
if spell.isBlockingWalls then
stringData = stringData .. "\nspell:blockWalls(" .. tostring(spell.isBlockingWalls) .. ")"
end
if #spell.vocations > 0 then
for i = 1, #spell.vocations do
stringData = stringData .. "\nspell:vocation('" .. spell.vocations[i] .. "')"
end
end
local scriptData = io.open(spellsFolder .. spell.scriptPath .. "", "r"):read("*a")
stringData = stringData .. "\n"
scriptData = scriptData:gsub("onCastSpell", "spell.onCastSpell")
stringData = stringData .. scriptData
stringData = stringData .. "\nspell:register()"
instantSpells[key].stringData = stringData
stringData = ""
end
end
local function dumpSpells()
for k,v in pairs(instantSpells) do
local file = io.open(convertsFolder .. "" ..v.name..".lua", "w+")
file:write(v.stringData)
file:close()
print(v.stringData)
end
end
local function populateRuneSpells()
end
local start = TalkAction("/runconverts")
function start.onSay()
populateInstantSpells()
formatInstantSpellStringData()
dumpSpells()
return true
end
start:register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment