Module:Npcinfo/datagen

-- to gen data slice.

-- 1.4.0.2

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 NpcIdSets = require('Module:Npcinfo/idSets').getValue local ProjectileInfo = require('Module:Projectileinfo').getProjectileInfo

---

local NetIdMap = { 81, 81, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 31, 31, 77, 42, 42, 176, 176, 176, 176, 173, 173, 183, 183, 3, 3, 132, 132, 186, 186, 187, 187, 188, 188, 189, 189, 190, 191, 192, 193, 194, 2, 200, 200, 21, 21, 201, 201, 202, 202, 203, 203, 223, 223, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235 }

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

local AmmoID = {} do 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; end

local NpcRarityColor = {} do NpcRarityColor.AmberMinus11 = -11 NpcRarityColorTrashMinus1 = -1 NpcRarityColorWhite0 = 0 NpcRarityColorBlue1 = 1 NpcRarityColorGreen2 = 2 NpcRarityColorOrange3 = 3 NpcRarityColorLightRed4 = 4 NpcRarityColorPink5 = 5 NpcRarityColorLightPurple6 = 6 NpcRarityColorLime7 = 7 NpcRarityColorYellow8 = 8 NpcRarityColorCyan9 = 9 NpcRarityColorStrongRed10 = 10 NpcRarityColorPurple11 = 11 end

local SoundID = {} for i = 1, 172 do	SoundID['Npc'..i] = 'Npc_'..i end

local this = {}

local function SetShopValues(rarity, coinValue) this.rare = rarity; this.value = coinValue; end

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.isAShopNpc = false this.expertOnly = false this.instanced = false this.questNpc = 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.timeSinceTheNpcHasBeenReservedForSomeone = 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

SetDefaults = function (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 NpcIdSets('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 --this.dye = GetShaderIdFromNpcId(this.type) --if this.hairDye ~= 0 then -- -1 by default --	this.hairDye = GameShaders.Hair.GetShaderIdFromNpcId(this.type) --end if this.type == 2015 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 2016 then this.value = Npc.sellPrice(0, 0, 7, 50) end if this.type == 2017 then this.value = Npc.sellPrice(0, 0, 7, 50) end if this.type == 2019 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 2018 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 3563 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 261 then this.value = Npc.sellPrice(0, 0, 7, 50) end if this.type == 2205 then this.value = Npc.sellPrice(0, 0, 12, 50) end if this.type == 2123 then this.value = Npc.sellPrice(0, 0, 7, 50) end if this.type == 2122 then this.value = Npc.sellPrice(0, 0, 7, 50) end if this.type == 2003 then this.value = Npc.sellPrice(0, 0, 10, 0) end if this.type == 2156 then this.value = Npc.sellPrice(0, 0, 15, 0) end if this.type == 2157 then this.value = Npc.sellPrice(0, 0, 15, 0) end if this.type == 2121 then this.value = Npc.sellPrice(0, 0, 15, 0) end if this.type == 1992 then this.value = Npc.sellPrice(0, 0, 3, 0) end if this.type == 2004 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 2002 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 2740 then this.value = Npc.sellPrice(0, 0, 2, 50) end if this.type == 2006 then this.value = Npc.sellPrice(0, 0, 10, 0) end if this.type == 3191 then this.value = Npc.sellPrice(0, 0, 20, 0) end if this.type == 3192 then this.value = Npc.sellPrice(0, 0, 2, 50) end if this.type == 3193 then this.value = Npc.sellPrice(0, 0, 5, 0) end if this.type == 3194 then this.value = Npc.sellPrice(0, 0, 10, 0) end if this.type == 2007 then this.value = Npc.sellPrice(0, 0, 50, 0) end if this.type == 2673 then this.value = Npc.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 = Npc.sellPrice(0, 0, 5, 0) end if num == 4 then this.value = Npc.sellPrice(0, 0, 10, 0) end if num == 6 then this.value = Npc.sellPrice(0, 0, 15, 0) end if num == 3 then this.value = Npc.sellPrice(0, 0, 20, 0) end if num == 7 then this.value = Npc.sellPrice(0, 0, 30, 0) end if num == 2 then this.value = Npc.sellPrice(0, 0, 40, 0) end if num == 1 then this.value = Npc.sellPrice(0, 0, 75, 0) end if num == 5 then this.value = Npc.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 = Npc.sellPrice(0, 2, 0, 0) end if ProjectileInfo(this.shoot).aiStyle == 7 then --if Main.projHook[this.shoot] then this.useStyle = 0 this.useTime = 0 this.useAnimation = 0 end if NpcIdSets('IsDrill', this.type) or NpcIdSets('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 NpcIdSets('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 = NpcID.Sets.IsAMaterial[this.type] // use

--RebuildTooltip // use or 	if this.type > 0 and this.type < 5043 and NpcIdSets('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 function npcinfo(npcid) local info if NpcIdSets('IsFood',npcid) then info = require('Module:Npcinfo/datagen4').getInfo(npcid) -- food npcs in datagen4 elseif npcid <= 1000 then info = require('Module:Npcinfo/datagen1').getInfo(npcid) elseif npcid <= 2001 then info = require('Module:Npcinfo/datagen2').getInfo(npcid) elseif npcid <= 3000 then info = require('Module:Npcinfo/datagen3').getInfo(npcid) elseif npcid > 3989 then info = require('Module:Npcinfo/datagen5').getInfo(npcid) else info = require('Module:Npcinfo/datagen4').getInfo(npcid) end -- other stats: info.dye = require('Module:Npcinfo/idSets').getValue('dyes', npcid) and 1 or 0 info.hairDye = require('Module:Npcinfo/idSets').getValue('hairDyes', npcid) local frame = mw.getCurrentFrame info.internalName = frame:expandTemplate{ title = 'NpcInternalNameFromId', args = {npcid} } info.name = frame:expandTemplate{ title = 'gameText', args = { ('NPCName.' .. info.internalName), lang = 'en' } } info.stack = nil return info end

---

local p = {

getInfo = function(npcid) return npcinfo(npcid) end,

gen = function (frame) currentFrame = frame -- cache local min = tonumber(getArg(1)) or 0 local max = tonumber(getArg(2)) or 0 local output = '' SetDefaults(0) local reset = {name = , internalName =  } for k,v in pairs(this) do			reset[k] = v		end for npcid = min, max do			local d = npcinfo(npcid) local t = {} if npcid ~= 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 t.type = nil output = output .. '\n[' .. npcid .. '] = ' .. export(t) .. ',\n' end return output end, } return p