Module:Iteminfo/datagen

-- to gen data slice. --local data = mw.loadData( 'Module:iteminfo/database' ) -- loading data table. (What a hell!)

local trim = mw.text.trim -- cache local currentFrame local getArg = function(key) local value = currentFrame.args[key] if not value then return nil end value = trim(value) if value == '' then return nil else return value end end

local ItemIdSets = require('Module:Iteminfo/idSets').getValue

local Item = {} Item.buyPrice = function(platinum, gold, silver, copper) return copper + silver * 100 + gold * 100 * 100 + platinum * 100 * 100 * 100 end Item.sellPrice = function(platinum, gold, silver, copper) return (copper + silver * 100 + gold * 100 * 100 + platinum * 100 * 100 * 100) * 5 end

local AmmoID = {} AmmoID.None = 0; AmmoID.Gel = 23; AmmoID.Arrow = 40; AmmoID.Coin = 71; AmmoID.FallenStar = 75; AmmoID.Bullet = 97; AmmoID.Sand = 169; AmmoID.Dart = 283; AmmoID.Rocket = 771; AmmoID.Solution = 780; AmmoID.Flare = 931; AmmoID.Snowball = 949; AmmoID.StyngerBolt = 1261; AmmoID.CandyCorn = 1783; AmmoID.JackOLantern = 1785; AmmoID.Stake = 1836; AmmoID.NailFriendly = 3108;

local this = {}

local function ResetStats(Type) this.tooltipContext = -1 this.BestiaryNotes = null this.sentry = false this.canBePlacedInVanityRegardlessOfConditions = false this.DD2Summon = false this.shopSpecialCurrency = -1 this.shopCustomPrice = null this.expert = false this.isAShopItem = false this.expertOnly = false this.instanced = false this.questItem = false this.fishingPole = 0 this.bait = 0 --this.hairDye = -1 this.makeNPC = 0 --this.dye = 0 this.paint = 0 this.tileWand = -1 this.notAmmo = false this.netID = 0 this.prefix = 0 this.crit = 0 this.mech = false this.flame = false this.reuseDelay = 0 this.melee = false this.magic = false this.ranged = false this.summon = false this.placeStyle = 0 this.buffTime = 0 this.buffType = 0 this.mountType = -1 this.cartTrack = false -- this.material = false this.noWet = false this.vanity = false this.mana = 0 this.wet = false this.wetCount = 0 this.lavaWet = false this.channel = false this.manaIncrease = 0 --this.timeSinceTheItemHasBeenReservedForSomeone = 0 this.noMelee = false this.noUseGraphic = false this.lifeRegen = 0 this.shootSpeed = 0 this.active = true this.alpha = 0 this.ammo = AmmoID.None this.useAmmo = AmmoID.None this.autoReuse = false this.accessory = false this.axe = 0 this.healMana = 0 this.bodySlot = -1 this.legSlot = -1 this.headSlot = -1 this.potion = false -- this.color = new_Color this.glowMask = -1 this.consumable = false this.createTile = -1 this.createWall = -1 this.damage = -1 this.defense = 0 this.hammer = 0 this.healLife = 0 this.holdStyle = 0 this.knockBack = 0 this.maxStack = 1 this.pick = 0 this.rare = 0 this.scale = 1 this.shoot = 0 this.stack = 1 --this.ToolTip = null this.tileBoost = 0 this.useStyle = 0 this.UseSound = null this.useTime = 100 this.useAnimation = 100 this.value = 0 this.useTurn = false this.buy = false this.handOnSlot = -1 this.handOffSlot = -1 this.backSlot = -1 this.frontSlot = -1 this.shoeSlot = -1 this.waistSlot = -1 this.wingSlot = -1 this.shieldSlot = -1 this.neckSlot = -1 this.faceSlot = -1 this.balloonSlot = -1 this.uniqueStack = false this.favorited = false this.type = Type end

local function netDefaults(type) if type == -1 then SetDefaults(3521) return end if type == -2 then SetDefaults(3520) return end if type == -3 then SetDefaults(3519) return end if type == -4 then SetDefaults(3518) return end if type == -5 then SetDefaults(3517) return end if type == -6 then SetDefaults(3516) return end if type == -7 then SetDefaults(3515) return end if type == -8 then SetDefaults(3514) return end if type == -9 then SetDefaults(3513) return end if type == -10 then SetDefaults(3512) return end if type == -11 then SetDefaults(3511) return end if type == -12 then SetDefaults(3510) return end if type == -13 then SetDefaults(3509) return end if type == -14 then SetDefaults(3508) return end if type == -15 then SetDefaults(3507) return end if type == -16 then SetDefaults(3506) return end if type == -17 then SetDefaults(3505) return end if type == -18 then SetDefaults(3504) return end if type == -19 then SetDefaults(3764) return end if type == -20 then SetDefaults(3765) return end if type == -21 then SetDefaults(3766) return end if type == -22 then SetDefaults(3767) return end if type == -23 then SetDefaults(3768) return end if type == -24 then SetDefaults(3769) return end if type == -25 then SetDefaults(3503) return end if type == -26 then SetDefaults(3502) return end if type == -27 then SetDefaults(3501) return end if type == -28 then SetDefaults(3500) return end if type == -29 then SetDefaults(3499) return end if type == -30 then SetDefaults(3498) return end if type == -31 then SetDefaults(3497) return end if type == -32 then SetDefaults(3496) return end if type == -33 then SetDefaults(3495) return end if type == -34 then SetDefaults(3494) return end if type == -35 then SetDefaults(3493) return end if type == -36 then SetDefaults(3492) return end if type == -37 then SetDefaults(3491) return end if type == -38 then SetDefaults(3490) return end if type == -39 then SetDefaults(3489) return end if type == -40 then SetDefaults(3488) return end if type == -41 then SetDefaults(3487) return end if type == -42 then SetDefaults(3486) return end if type == -43 then SetDefaults(3485) return end if type == -44 then SetDefaults(3484) return end if type == -45 then SetDefaults(3483) return end if type == -46 then SetDefaults(3482) return end if type == -47 then SetDefaults(3481) return end if type == -48 then SetDefaults(3480) return end end

local function SetDefaults(Type) if Type < 0 then netDefaults(Type) return end ResetStats(Type) if this.type >= 5043 then this.type = 0 end if this.type == 0 then this.netID = 0 this.stack = 0 elseif ItemIdSets('IsFood',this.type) then SetFoodDefaults(this.type) elseif this.type <= 1000 then SetDefaults1(this.type) elseif this.type <= 2001 then SetDefaults2(this.type) elseif this.type <= 3000 then SetDefaults3(this.type) elseif this.type > 3989 then SetDefaults5(this.type) else SetDefaults4(this.type) end -- // after setDefaultsX, all dyes will have non-zero value, 1 = basic dye; 2 = other dye. -- // the method below will give all dyes unique int values one by one, it is not necessary for determine "isDye" n	-- this.dye = (byte)GameShaders.Armor.GetShaderIdFromItemId(this.type) -- // Similarly, give all hair dyes unique int values. --if this.hairDye ~= 0 then --	this.hairDye = GameShaders.Hair.GetShaderIdFromItemId(this.type) --end if this.type == 2015 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 2016 then this.value = Item.sellPrice(0, 0, 7, 50) end if this.type == 2017 then this.value = Item.sellPrice(0, 0, 7, 50) end if this.type == 2019 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 2018 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 3563 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 261 then this.value = Item.sellPrice(0, 0, 7, 50) end if this.type == 2205 then this.value = Item.sellPrice(0, 0, 12, 50) end if this.type == 2123 then this.value = Item.sellPrice(0, 0, 7, 50) end if this.type == 2122 then this.value = Item.sellPrice(0, 0, 7, 50) end if this.type == 2003 then this.value = Item.sellPrice(0, 0, 10, 0) end if this.type == 2156 then this.value = Item.sellPrice(0, 0, 15, 0) end if this.type == 2157 then this.value = Item.sellPrice(0, 0, 15, 0) end if this.type == 2121 then this.value = Item.sellPrice(0, 0, 15, 0) end if this.type == 1992 then this.value = Item.sellPrice(0, 0, 3, 0) end if this.type == 2004 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 2002 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 2740 then this.value = Item.sellPrice(0, 0, 2, 50) end if this.type == 2006 then this.value = Item.sellPrice(0, 0, 10, 0) end if this.type == 3191 then this.value = Item.sellPrice(0, 0, 20, 0) end if this.type == 3192 then this.value = Item.sellPrice(0, 0, 2, 50) end if this.type == 3193 then this.value = Item.sellPrice(0, 0, 5, 0) end if this.type == 3194 then this.value = Item.sellPrice(0, 0, 10, 0) end if this.type == 2007 then this.value = Item.sellPrice(0, 0, 50, 0) end if this.type == 2673 then this.value = Item.sellPrice(0, 10, 0, 0) end if this.bait > 0 then if this.bait >= 50 then this.rare = 3 elseif this.bait >= 30 then this.rare = 2 elseif this.bait >= 15 then this.rare = 1 end end if this.type >= 1994 and this.type <= 2001 then local num = this.type - 1994 if num == 0 then this.value = Item.sellPrice(0, 0, 5, 0) end if num == 4 then this.value = Item.sellPrice(0, 0, 10, 0) end if num == 6 then this.value = Item.sellPrice(0, 0, 15, 0) end if num == 3 then this.value = Item.sellPrice(0, 0, 20, 0) end if num == 7 then this.value = Item.sellPrice(0, 0, 30, 0) end if num == 2 then this.value = Item.sellPrice(0, 0, 40, 0) end if num == 1 then this.value = Item.sellPrice(0, 0, 75, 0) end if num == 5 then this.value = Item.sellPrice(0, 1, 0, 0) end end if this.type == 2663 or this.type == 1720 or this.type == 2137 or this.type == 2155 or this.type == 2151 or this.type == 1704 or this.type == 2143 or this.type == 1710 or this.type == 2238 or this.type == 2133 or this.type == 2147 or this.type == 2405 or this.type == 1716 or this.type == 1705 then this.value = Item.sellPrice(0, 2, 0, 0) end if Main.projHook[this.shoot] then this.useStyle = 0 this.useTime = 0 this.useAnimation = 0 end if ItemIdSets('IsDrill', this.type) or ItemIdSets('IsChainsaw', this.type) then this.useTime = math.floor(this.useTime * 0.6) if this.useTime < 1 then this.useTime = 1 end this.useAnimation = math.floor(this.useAnimation * 0.6) if this.useAnimation < 1 then this.useAnimation = 1 end this.tileBoost = this.tileBoost - 1 end if ItemIdSets('IsFood', this.type) then this.holdStyle = 1 end if this.type >= 1803 and this.type <= 1807 then SetDefaults(1533 + this.type - 1803) end if this.dye > 0 then this.maxStack = 99 end if this.createTile == 19 then this.maxStack = 999 end this.netID = this.type -- this.material = ItemID.Sets.IsAMaterial[this.type] // use

--RebuildTooltip // use or 	if this.type > 0 and this.type < 5043 and ItemIdSets('Deprecated', this.type) then this.netID = 0 this.type = 0 this.stack = 0 end end

---

local function export(var) local t = mw.dumpObject(var) t = string.gsub(t, "table#1 ", "") t = string.gsub(t, "metatable = table#2", "") t = string.gsub(t, " +", "") t = string.gsub(t, "\n+", "\n") return t end

---

local p = { getInfo = function(itemid) SetDefaults(itemid) return export(this) end, gen = function (frame) currentFrame = frame -- cache local min = tonumber(getArg(1)) or 0 local max = tonumber(getArg(2)) or 0

local output = '' local reset = resetStats(9999)

for itemid = min, max do			local d = iteminfo(itemid) local t = {} if itemid ~= 0 then for k,v in pairs(reset) do					if d[k] ~= reset[k] then t[k] = d[k] end end else t = d			end output = output .. '\n[' .. itemid .. '] = ' .. export(t) .. ',\n' end return output end, }

p.getinfo = p.getInfo p.GetInfo = p.getInfo

return p