Module:Inventory: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(16 intermediate revisions by 2 users not shown)
Line 10: Line 10:
local quantity = frame.args[2] or '1'
local quantity = frame.args[2] or '1'
local chance = frame.args[4] or '100'
local chance = frame.args[4] or '100'
local ispop = frame.args[5] or 'no'
local weaponhtml
local weaponhtml


Line 16: Line 17:
local objname
local objname
local name
local name
local favilinked
local favilinkhtml
   
   
  if frame.args[1] ~= nil and frame.args[1] ~= '' then
if frame.args[1] ~= nil and frame.args[1] ~= '' then
   objname = mw.text.trim(frame.args[1])
   objname = mw.text.trim(frame.args[1])
   --return name
else
   error "There is no argument specified! [[Category:pages with inventory errors]]"
end
 
 
if ispop ~= 'yes' then
  --[logic for basic objects]--
 
  --[special case for random items, ex: K-Goninon]--
  if objname == '$CALLBLUEPRINTMETHOD:Qud.API.EncountersAPI.GetAnItemBlueprint' then
    favilinkhtml = mw.html.create('div')
                :addClass('qud-inv-favilink-wrapper')
                :node(mw.html.create('div')
                      :addClass('qud-inv-poptable-icon')
                      :wikitext('?'))
                      :node(mw.html.create('span')
                      :wikitext('Any random item'))
 
  --[Otherwise, define typical favilink...]--
   else
   else
    error "There is no argument specified! [[Category:pages with inventory errors]]"
    favilinked = frame:expandTemplate{title='Favilink id', args={objname,'displayname-tooltip-override'}}
 
    favilinkhtml = mw.html.create('div')
end
                :addClass('qud-inv-favilink-wrapper')
                :wikitext(favilinked)


local result = cargo.query('ItemsTable,GeneralData',
    --[If it can be found in the items or missle weapon table, define weapon html]--
'PlainName,Vibro,MaxPV,BasePV,Damage,GeneralData._pageName=Page',
    local result = cargo.query('ItemsTable=IT,GeneralData=GD,MissileWeaponData=MWD',
{ where='GeneralData._pageNamespace="0" AND GeneralData.ObjectID="'.. objname .. '"',
    'PlainName,Vibro,MaxPV,BasePV,Damage,PenetratingAmmo,GD.JoinKey=Page',
default='0',
    { where='(GD._pageNamespace="0" OR GD._pageNamespace="10002") AND (GD.ObjectID="' .. objname .. '" OR GD.IDAliases HOLDS "' .. objname .. '")',
limit='1',
    default='0',
join='GeneralData._pageName=ItemsTable._pageName'} )
    limit='1',
    join='GD.JoinKey=IT.JoinKey,GD.JoinKey=MWD.JoinKey'} )


if not next(result) then
    --[Exit if not found, it's an item that doesn't have combat data and only needs favilink and quantity]
  return '[[' .. objname.. ']][[Category:pages with inventory errors]]'
    if next(result) ~= nil then
else
    --[If damage, return weapon html that specifies damage, PV and max PV]--
  name = result[1]['PlainName']
end


local favilinked = frame:expandTemplate{title='idfavilink', args={objname,'displayname-tooltip-override'}}
    local damage = result[1]['Damage']
    local piercingTemplate = ''
    if result[1]['PenetratingAmmo'] ~= nil and result[1]['PenetratingAmmo'] == '1' then
      piercingTemplate = frame:expandTemplate{title='PV', args={'pierce'}}
    else
      piercingTemplate = frame:expandTemplate{title='PV'}
    end


--[If damage, return weapon html that specifies damage, PV and max PV]--
    if damage ~= nil and damage ~= ''  then
      if result[1]['Vibro'] == '1' then
        pv = '≈'
      elseif result[1]['BasePV'] ~= nil then
        pv = result[1]['BasePV']
        maxpv = result[1]['MaxPV']
      end


local damage= result[1]['Damage']
      local pvstr = ''


if damage ~= nil and damage ~= '' then
      if maxpv ~= nil and maxpv ~= '' then
  if result[1]['Vibro'] == '1' then
        pvstr = '<span style="color:#155352;">/' .. maxpv.. '</span>'
    pv = ''
      end
  elseif result[1]['BasePV'] ~= nil then
    --[Define weaponhtml]
    pv = result[1]['BasePV']
      weaponhtml = mw.html.create('span')
    maxpv = result[1]['MaxPV']
                :addClass('qud-inline-weap-stats')
  end
                :node(mw.html.create('span')
                      :addClass('qud-inline-damage')
                      :wikitext(frame:expandTemplate{title='Heart'} .. '<span class="qud-inline-damage">' ..
                        damage .. '</span> '.. piercingTemplate  ..
                        '<span class="qud-inline-pv">' .. pv ..'</span>' .. pvstr) )
    end


  local pvstr = ''


  if maxpv ~= nil and maxpv ~= '' then
    if weaponhtml ~= nil then
     pvstr = '<span style="color:#155352;">/' .. maxpv.. '</span>'
      favilinkhtml:node(weaponhtml)
    end
    end
  end
else
  --[logic for population tables]--
  local descprefix = 'Item from '
  if quantity == '*' then
     descprefix = 'Items from '
   end
   end
--[Define weaponhtml]
  wikipagename = string.gsub(string.gsub(objname, '{', '*'), '}', '*')
   weaponhtml = mw.html.create('span')
   favilinkhtml = mw.html.create('div')
            :addClass('qud-inline-weap-stats')
              :addClass('qud-inv-favilink-wrapper')
            :node(mw.html.create('span')
              :node(mw.html.create('div')
                  :addClass('qud-inline-damage')
                    :addClass('qud-inv-poptable-icon')
                  :wikitext(frame:expandTemplate{title='Heart'} .. '<span class="qud-inline-damage">' ..
                    :wikitext('?'))
                    damage .. '</span>'..frame:expandTemplate{title='PV'} ..  
                    :node(mw.html.create('span')
                    '<span class="qud-inline-pv">' .. pv ..'</span>' .. pvstr) )
                    :wikitext(descprefix .. '[[Population:' .. wikipagename .. '|' .. objname .. ']]'))
end
end


--[Define html...]--
local quantitystr = '*'
local favilinkhtml = mw.html.create('div')
if quantity ~= '*' then
            :addClass('qud-inv-favilink-wrapper')
   quantitystr = 'x' .. quantity
            :wikitext(favilinked)
if weaponhtml ~= nil then
   favilinkhtml:node(weaponhtml)
end
end
local inventoryhtml = mw.html.create('div')
local inventoryhtml = mw.html.create('div')
inventoryhtml
inventoryhtml
Line 81: Line 122:
         :node(mw.html.create('span')
         :node(mw.html.create('span')
             :addClass('qud-item-qty')
             :addClass('qud-item-qty')
             :wikitext('x' .. quantity)
             :wikitext(quantitystr)
             :node(mw.html.create('span')
             :node(mw.html.create('span')
                   :addClass('qud-item-chance chance-' .. chance)
                   :addClass('qud-item-chance chance-' .. chance)

Latest revision as of 01:01, 27 January 2023


local p = {}
local cargo= mw.ext.cargo
local favilink = require'Module:Favilink'

function p.main(frame)

local frame = mw.getCurrentFrame()
local pv = ''
local maxpv = ''
local quantity = frame.args[2] or '1'
local chance = frame.args[4] or '100'
local ispop = frame.args[5] or 'no'
local weaponhtml

--[Getting query results...]

local objname
local name
local favilinked
local favilinkhtml
 
if frame.args[1] ~= nil and frame.args[1] ~= '' then
  objname = mw.text.trim(frame.args[1])
else
  error "There is no argument specified! [[Category:pages with inventory errors]]"
end


if ispop ~= 'yes' then
  --[logic for basic objects]--

  --[special case for random items, ex: K-Goninon]--
  if objname == '$CALLBLUEPRINTMETHOD:Qud.API.EncountersAPI.GetAnItemBlueprint' then
    favilinkhtml = mw.html.create('div')
                 :addClass('qud-inv-favilink-wrapper')
                 :node(mw.html.create('div')
                      :addClass('qud-inv-poptable-icon')
                      :wikitext('?'))
                      :node(mw.html.create('span')
                      :wikitext('Any random item'))

  --[Otherwise, define typical favilink...]--
  else
    favilinked = frame:expandTemplate{title='Favilink id', args={objname,'displayname-tooltip-override'}}
    favilinkhtml = mw.html.create('div') 
                 :addClass('qud-inv-favilink-wrapper')
                 :wikitext(favilinked)

    --[If it can be found in the items or missle weapon table, define weapon html]--
    local result = cargo.query('ItemsTable=IT,GeneralData=GD,MissileWeaponData=MWD',
    'PlainName,Vibro,MaxPV,BasePV,Damage,PenetratingAmmo,GD.JoinKey=Page',
    { where='(GD._pageNamespace="0" OR GD._pageNamespace="10002") AND (GD.ObjectID="' .. objname .. '" OR GD.IDAliases HOLDS "' .. objname .. '")',
    default='0',
    limit='1',
    join='GD.JoinKey=IT.JoinKey,GD.JoinKey=MWD.JoinKey'} )

    --[Exit if not found, it's an item that doesn't have combat data and only needs favilink and quantity]
    if next(result) ~= nil then
    --[If damage, return weapon html that specifies damage, PV and max PV]--

    local damage = result[1]['Damage']
    local piercingTemplate = ''
    if result[1]['PenetratingAmmo'] ~= nil and result[1]['PenetratingAmmo'] == '1' then
      piercingTemplate = frame:expandTemplate{title='PV', args={'pierce'}}
    else
      piercingTemplate = frame:expandTemplate{title='PV'}
    end

    if damage ~= nil and damage ~= ''  then
      if result[1]['Vibro'] == '1' then
        pv = '≈'
      elseif result[1]['BasePV'] ~= nil then
        pv = result[1]['BasePV']
        maxpv = result[1]['MaxPV']
      end

      local pvstr = ''

      if maxpv ~= nil and maxpv ~= '' then
        pvstr = '<span style="color:#155352;">/' .. maxpv.. '</span>'
      end
    --[Define weaponhtml]
      weaponhtml = mw.html.create('span')
                 :addClass('qud-inline-weap-stats')
                 :node(mw.html.create('span')
                      :addClass('qud-inline-damage')
                      :wikitext(frame:expandTemplate{title='Heart'} .. '<span class="qud-inline-damage">' .. 
                         damage .. '</span> '.. piercingTemplate  .. 
                         '<span class="qud-inline-pv">' .. pv ..'</span>' .. pvstr) )
    end


    if weaponhtml ~= nil then
      favilinkhtml:node(weaponhtml)
    end
    end
  end
else
  --[logic for population tables]--
  local descprefix = 'Item from '
  if quantity == '*' then
    descprefix = 'Items from '
  end
  wikipagename = string.gsub(string.gsub(objname, '{', '*'), '}', '*')
  favilinkhtml = mw.html.create('div')
               :addClass('qud-inv-favilink-wrapper')
               :node(mw.html.create('div')
                    :addClass('qud-inv-poptable-icon')
                    :wikitext('?'))
                    :node(mw.html.create('span')
                    :wikitext(descprefix .. '[[Population:' .. wikipagename .. '|' .. objname .. ']]'))
end

local quantitystr = '*'
if quantity ~= '*' then
  quantitystr = 'x' .. quantity
end
local inventoryhtml = mw.html.create('div')
inventoryhtml
        :addClass('qud-inventory-item')
        :node(favilinkhtml)
        :node(mw.html.create('span')
             :addClass('qud-item-qty')
             :wikitext(quantitystr)
             :node(mw.html.create('span')
                  :addClass('qud-item-chance chance-' .. chance)
                  :wikitext('(' .. chance .. '%)')))
        

return tostring(inventoryhtml)

end

return p