Module:Creatures

From UO Outlands Wiki
Revision as of 02:31, 23 August 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 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] -- {|name=...

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

    local creatureArray = mw.text.split(creatureList,"|}\n{|",true)

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

    local creatureObjects = {}

    for i, creature in pairs(creatureArray) do
        local creatureTable = cloneTable(baseTable)
        table.insert(creatureObjects, creatureTable)

        for index, stat in pairs(creatureTable) do
          local data = string.match(creature,index.."= (%a+)\n")
          if data then
            stat = data
          end
        end
    end

    local wikiTable = ""
    
      if 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"
      end

    for i, creature in pairs(creatureObjects) do
        if string.lower(creatureName) == "all" then
          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
        elseif creature.name == creatureName then
          wikiTable = '<th colspan="9"> [[File:'..creatureName.lower()..".jpg]]<br />"..creatureName.."<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
    end

    return wikiTable
end

return p