Fandom

Old School RuneScape Wiki

Module:ExchangeDefault

15,958pages on
this wiki
Add New Page
Discuss0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

-- <pre>
-- Default view for {{ExchangeItem}} for use on Exchange ns pages
--
-- Use of this via #invoke is deprecated and will eventually be removed
-- This is intended for use by [[Module:Exchange]]
--
 
local p = {}
 
-- imports
local excgdata = require( 'Module:ExchangeData' )._main
local round = require( 'Module:Number' )._round
local timeago = require( 'Module:TimeAgo' )._ago
local yesno = require( 'Module:Yesno' )
 
function p.main( item )
    local frame = mw.getCurrentFrame()
    local lang = mw.language.getContentLanguage()
    local title = mw.title.getCurrentTitle()
    local data  = mw.loadData( 'Module:Exchange/' .. item )
 
    -- set variables here if possible to keep table building easier to follow
    local rowspan = 8
    local volDate = data.volumeDate or lang:formatDate( 'c' )
    local dateDiffZ = lang:formatDate( 'z' ) - lang:formatDate( 'z', volDate )
    local dateDiffY = lang:formatDate( 'Y' ) - lang:formatDate( 'Y', volDate )
    local price = data.price and lang:formatNum( data.price ) or '<i>Unknown</i>'
    local date = '<i>Unknown</i>'
    local lowAlch = '<i>Not alchable</i>'
    local highAlch = '<i>Not alchable</i>'
    local memsIcon = ''
 
    if data.volume and ( dateDiffZ + 365 * dateDiffY ) <= 7 then
        rowspan = 10
    end
 
    if data.date then
        date = lang:formatDate( 'j F Y, H:i "(UTC)"', data.date )
    end
 
    if data.alchable == nil or yesno( data.alchable ) then
        if data.value then
            lowAlch = lang:formatNum( math.floor( data.value * 0.4 ) )
            highAlch = lang:formatNum( math.floor( data.value * 0.6 ) )
        else
            lowAlch, highAlch = '<i>Unknown</i>', '<i>Unknown</i>'
        end
    end
 
    if data.members ~= nil then
        if data.members then
            memsIcon = '[[File:P2P icon.png|link=Members|middle]]'
        else
            memsIcon = '[[File:F2P icon.png|link=Free-to-play|middle]]'
        end
    end
 
    -- build table
    local tbl = mw.html.create( 'table' )
        :addClass( 'wikitable' )
        :css( {
            ['border'] = '0',
            ['border-collapse'] = 'separate',
            ['margin-top'] = '-1em',
            ['margin-bottom'] = '0'
        } )
        :tag( 'tr' )
            :tag( 'th' )
                :attr( 'colspan', '2' )
                :css( {
                    border = '0',
                    padding = '0'
                } )
                :tag( 'table' )
                    :css( {
                        width = '100%',
                        ['border-collapse'] = 'collapse'
                    } )
                    :tag( 'tr' )
                        :tag( 'td' )
                            :css( {
                                padding = '8px 16px',
                                ['border-right'] = '0'
                            } )
                            :wikitext( '[[File:' .. ( data.icon or 'Coins 1000' ) .. '|link=' .. item .. ']]' )
                            :done()
                        :tag( 'td' )
                            :css( {
                                width = '100%',
                                ['font-size'] = '135%',
                                ['text-align'] = 'left',
                                ['white-space'] = 'normal',
                                padding = '8px 0',
                                ['border-left'] = '0',
                                ['border-right'] = '0'
                            } )
                            -- this used to default to [[Grand Exchange Market Watch]] if item wasn't supplied
                            -- but that only happened on 6 user pages, an orphanage and a preload
                            :wikitext( '[[' .. item .. ']]' )
                            :tag( 'br' )
                                :done()
                            :tag( 'span' )
                                :css( {
                                    ['font-weight'] = 'normal',
                                    ['font-size'] = '75%'
                                } )
                                :wikitext( data.examine or '' )
                                :done()
                            :done()
                        :tag( 'td' )
                            :css( {
                                padding = '8px 16px',
                                ['border-left'] = '0'
                            } )
                            :wikitext( memsIcon )
                            :done()
                        :done()
                    :done()
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :css( {
                    ['text-align'] = 'left',
                    ['padding-left'] = '10px'
                } )
                :wikitext( 'Price data' )
                :done()
            :tag( 'td' )
                :attr( 'rowspan', rowspan ) 
                :css( 'vertical-align', 'top' )
                :tag( 'div' )
                    :addClass( 'GEPage' )
                    :css( {
                        padding = '10px 5px 0 5px',
                        float = 'right'
                    } )
                    :tag( 'div' )
                        :addClass( 'GEdatachart' )
                        :css( {
                            margin = '5px 0 25px 0',
                            ['min-width'] = '700px',
                            ['height'] = '500px'
                        } )
                        -- GE Chart goes here
                        :done()
                    :done()
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'td' )
                :css( {
                    ['vertical-align'] = 'top',
                    ['padding-bottom'] = '5px'
                } )
                :tag( 'ul' )
                    :tag( 'li' )
                        :wikitext( '<b>Price:</b> ' )
                        :tag( 'span' )
                            :attr( 'id', 'GEPrice' )
                            :wikitext( price )
                            :done()
                        :done()
                    :tag( 'li' )
                        :wikitext( '<b>Last updated:</b> ' .. timeago{data.date, purge='yes'} )
                        :tag( 'br' )
                            :done()
                        :tag( 'span' )
                            :attr( 'id', 'GEDate' )
                            :wikitext( date )
                            :done()
                        :done()
                    :done()
                :done()
            :done()
 
    if data.volume and ( dateDiffZ + 365 * dateDiffY ) <= 7 then
        tbl
            :tag( 'tr' )
                :tag( 'th' )
                    :css( {
                        ['text-align'] = 'left',
                        ['padding-left'] = '10px'
                    } )
                    :wikitext( 'Volume data' )
                    :done()
                :done()
            :tag( 'tr' )
                :tag( 'td' )
                    :attr( 'id', 'volumeData' )
                    :css ( {
                        ['vertical-align'] = 'top',
                        ['padding-bottom'] = '5px'
                    } )
                    :tag( 'ul' )
                        :tag( 'li' )
                            :wikitext( '<b>7-day total:</b> ' )
                                :tag( 'span' )
                                    :attr( 'id', 'GEVolume' )
                                    :wikitext( lang:formatNum( 1000000 * data.volume ) )
                                    :done()
                            :done()
                        :tag( 'li' )
                            :wikitext( '<b>1-day average</b> ' .. lang:formatNum( round( 1000000 / 7 * data.volume, -3 ) ) )
                            :done()
                        :tag( 'li' )
                            :wikitext( '<b>Last updated:</b> ' .. timeago{data.volumeDate, purge='yes'} )
                            :tag( 'br' )
                                :done()
                            :tag( 'span' )
                                :attr( 'id', 'GEVolumeDate' )
                                :wikitext( lang:formatDate( 'j F Y, H:i "(UTC)"', data.volumeDate ) )
                            :done()
                        :done()
                    :done()
                :done()
    end
 
    tbl
        :tag( 'tr' )
            :tag( 'th' )
                :css( {
                    ['text-align'] = 'left',
                    ['padding-left'] = '10px'
                } )
                :wikitext( 'Other details' )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'td' )
                :css( {
                    ['vertical-align'] = 'top',
                    ['padding-bottom'] = '5px'
                } )
                :tag( 'ul' )
                    :tag( 'li' )
                        :wikitext( '<b>[[Grand Exchange Database|Exchange ID]]:</b> ' )
                        :tag( 'span' )
                            :attr( 'id', 'GEDBID' )
                            :wikitext( data.itemId or '<i>Unknown</i>' )
                            :done()
                        :done()
                    :tag( 'li' )
                        :wikitext( '<b>Low Alchemy:</b> ' .. lowAlch )
                        :done()
                    :tag( 'li' )
                        :wikitext( '<b>High Alchemy:</b> ' .. highAlch )
                        :done()
                    :tag( 'li' )
                        :wikitext( '<b>[[Value]]:</b> ' .. ( data.value and lang:formatNum( data.value ) or '<i>Unknown</i>' ) )
                        :done()
                    :tag( 'li' )
                        :wikitext( '<b>[[Grand Exchange#Trade restrictions|Exchange limit]]:</b> ' .. ( data.limit and lang:formatNum( data.limit ) or '<i>Unknown</i>' ) )
                        :done()
                    :done()
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :css( {
                    ['text-align'] = 'left',
                    ['padding-left'] = '10px'
                } )
                :wikitext( 'External links' )
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'td' )
                :css( {
                    ['vertical-align'] = 'top',
                    ['padding-bottom'] = '5px'
                } )
                :tag( 'ul' )
                    :tag( 'li' )
                        :wikitext( '[http://services.runescape.com/m=itemdb_oldschool/viewitem.ws?obj=' .. data.itemId .. ' Look up current price]' )
                        :done()
                    :tag( 'li' )
                        :wikitext( '[http://services.runescape.com/m=itemdb_oldschool/results.ws?query=' .. mw.uri.encode( item, 'QUERY' ) .. ' Search for relevant prices]' )
                        :done()
                    :done()
                :done()
            :done()
        :tag( 'tr' )
            :tag( 'th' )
                :css( {
                    ['text-align'] = 'left',
                    ['padding-left'] = '10px'
                } )
                :wikitext( 'Usage' )
                :done()
            :done()
 
    tbl = tostring( tbl )
 
    -- categories
    local cats = ''
    local natPrice
 
    if title.nsText == 'Exchange' then
        cats = cats .. '[[Category:Grand Exchange]]'
                    .. '[[Category:Wikia Game Guides exchange]]'
                    .. '[[Category:Grand Exchange by date updated|*' .. lang:formatDate( 'c', data.date ) .. data.itemId .. ']]'
 
        if item ~= title.text then
            cats = cats .. '[[Category:Exchange names that needs checking]]'
        end
 
        -- have to preprocess this for it to work
        cats = cats .. frame:preprocess( '{{DEFAULTSORT:' .. data.item .. '}}' )
 
        if not data.itemId then
            cats = cats .. '[[Category:Exchange items with no ID]]'
        end
 
        if not data.icon then
            cats = cats .. '[[Category:Exchange items missing icon]]'
        end
 
        if data.price and data.value and ( data.alchable == nil or yesno( data.alchable ) ) then
            if mw.ustring.lower( item ) == 'nature rune' then
                natPrice = data.price
            else
                natPrice = mw.loadData( 'Module:Exchange/Nature rune' ).price
            end
 
            if math.floor( ( data.value * 0.6 ) - data.price - natPrice ) > 0 then
                cats = cats .. '[[Category:Profitable Alchemy Items]]'
            end
 
            if math.floor( ( data.value * 0.4 ) - data.price - natPrice ) > 0 then
                cats = cats .. '[[Category:Profitable Low Alchemy Items]]'
            end
 
            if math.floor( ( data.value * 0.3 ) - data.price ) > 0 then
                cats = cats .. '[[Category:Profitable General Store Items]]'
            end
 
        elseif not data.value then
            cats = cats .. '[[Category:Exchange items missing value]]'
        end
 
        -- this doesn't allow for the update time to be in the previous day but less than 24 hours
        -- if that's the case, then the page will end up in the 7 days category
        -- the same will happen for the other 2 categories too
        -- but it's not so noticeable given the already elapsed time
        local lastUpdate = ( lang:formatDate( 'z' ) - lang:formatDate( 'z', data.date ) + 365 * ( lang:formatDate( 'Y' ) - lang:formatDate( 'Y', data.date ) ) + 3 ) / 7
        lastUpdate = round( lastUpdate, 0 )
 
        if lastUpdate == 1 then
            cats = cats .. '[[Category:Needs price update/7 days]]'
        elseif lastUpdate >= 2 and lastUpdate <= 4 then
            cats = cats .. '[[Category:Needs price update/28 days]]'
        elseif lastUpdate > 4 then
            cats = cats .. '[[Category:Needs price update/29+ days]]'
        end
 
        if not data.limit then
            cats = cats .. '[[Category:Exchange items missing limit]]'
        end
 
 
        -- Error checking
        if not data.price or data.price < 1 then
            cats = cats .. '[[Category:Exchange items with no price]]'
        end
    end
 
    -- help header
    local help = mw.html.create( 'div' )
        :attr( 'id', 'gemw_guide' )
        :css( {
            padding = '5px 10px',
            color = '#000',
            border = '1px solid #aaa',
            background = '#f2f2f2'
        } )
        :wikitext( 'If you need assistance on editing this page, or trying to understand how these Exchange pages work, please add a comment to [[Talk:Grand Exchange Market Watch]].' )
 
    help = tostring( help )
 
    local noErr, data = pcall( excgdata, { item }, true )
 
    if not noErr then
        data = ''
    end
 
    local links = mw.html.create( 'div' )
        :addClass( 'module-links' )
        :css( {
            ['font-size'] = 'smaller',
            ['padding-left'] = '5px'
        } )
        :wikitext( '[[Module:Exchange/' .. item .. '|&#91;info&#93;]] &bull; [[Module:Exchange/' .. item .. '/Data|&#91;data&#93;]]' )
 
    links = tostring( links )
 
    return help .. '<br />' .. tbl .. links .. data .. cats
end
 
return p

Also on Fandom

Random Wiki