Module:Creatures

From UO Outlands Wiki
Revision as of 23:24, 9 September 2024 by TheGmaster (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Creatures/doc

local p = {}

function mwtextsplit(inputstr, sep, plain)
  if sep == nil then
    sep = "%s"
  end
  local t = {}
  for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
    table.insert(t, str)
  end
  return t
end

function cloneTable (t)          
  local new_t = {}       
  local i, v = next(t, nil)
  while i do
    new_t[i] = v
    i, v = next(t, i)       
  end
  return new_t
end

function p.listCreatures(frame)
    -- Parameters passed when the function is invoked
    local creatureList = frame.args[1]

    -- Parameters from the template passed to the function
    local creatureName = frame.args[2]
    --local imageOverride = frame.args[3] -- sunwyrm.png

    local creatureArray = mwtextsplit(creatureList,")",true)

    local baseTable = {["name"]="",["dungeon"]="",["slayer"]="",["difficulty"]="",["goldvalue"]="",["hits"]="",["mindmg"]="",["maxdmg"]="",["wrestling"]="",["armor"]="",["magicresist"]="",["parry"]="",["attackspeed"]="",["magery"]="",["minspelldmg"]="",["maxspelldmg"]="",["poisontype"]="",["poisoning"]="",["poisonresist"]="",["stealth"]="",["ai"]="",["speed"]="",["uniquescaler"]="",}
    local statTable = {"name","dungeon","slayer","difficulty","goldvalue","hits","mindmg","maxdmg","wrestling","armor","magicresist","parry","attackspeed","magery","minspelldmg","maxspelldmg","poisontype","poisoning","poisonresist","stealth","ai","speed","uniquescaler",}
  
    local creatureObjects = {}

    for index, creature in pairs(creatureArray) do
      local creatureTable = cloneTable(baseTable)

      for i, statName in pairs(statTable) do
        local data = string.match(creature,statName..'=(.-),')
        if data then
          creatureTable[statName] = data
        else 
        end
      end

      local Name = string.gsub(creatureTable.name,"%p","")

      creatureObjects[Name] = creatureTable
    end

    local wikiTable = ""

    if creatureName and string.lower(creatureName) == "all" then
      wikiTable = "<th>Name<th>Dungeon<th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>Poisoning<th>PoisonResist<th>Stealth<th>AI<th>Speed<th>UniqueScalar"

      for i, creature in pairs(creatureObjects) do
        wikiTable = wikiTable.."<tr><td>"..creature.name.."<td>"..creature.dungeon.."<td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg.."<td>"..creature.poisontype.."<td>"..creature.poisoning.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai.."<td>"..creature.speed.."<td>"..creature.uniquescaler
      end
    elseif creatureObjects[creatureName] then
      local creature = creatureObjects[creatureName]
      local Name = string.gsub(creature.name,"%p","")
      local imageName = string.gsub(string.lower(Name),"%s","")

      wikiTable = '<th colspan="9"> [[File:'..imageName..".jpg]]<br />"..creature.name.."<tr><th>Slayer<th>Difficulty<th>GoldValue<th>Hits<th>MinDmg<th>MaxDmg<th>Wrestling<th>Armor<th>Resist<tr><td>"..creature.slayer.."<td>"..creature.difficulty.."<td>"..creature.goldvalue.."<td>"..creature.hits.."<td>"..creature.mindmg.."<td>"..creature.maxdmg.."<td>"..creature.wrestling.."<td>"..creature.armor.."<td>"..creature.magicresist.."<tr><th>Parry<th>AtkSpd<th>Magery<th>MinSpellDmg<th>MaxSpellDmg<th>Poison<th>PoisonResist<th>Stealth<th>AI<tr><td>"..creature.parry.."<td>"..creature.attackspeed.."<td>"..creature.magery.."<td>"..creature.minspelldmg.."<td>"..creature.maxspelldmg,"<td>"..creature.poisontype.."<td>"..creature.poisonresist.."<td>"..creature.stealth.."<td>"..creature.ai
    end
   return wikiTable
end

return p