Module:Test/data/virtual
< Module:Test | data
Jump to navigation
Jump to search
Revision as of 13:09, 16 May 2021 by Dr. Strangelove (talk | contribs) (support for extra precalculated fields)
This page has been marked as needing documentation of its function and purpose. You can help RimWorld Wiki by creating it here |
-- New wiki page: Remove this with text of the new pagelocal DefInfo = DefInfo or require "DefInfo" local VF = {} VF.vfields = {} --------------- -- tools.DPS -- --------------- function VF.vfields.unarmedDPS(def) if not def.tools then return nil end for _,tool in ipairs(def.tools) do local dps = tool.power / tool.cooldownTime if dps then tool.DPS = Util.round(dps, 3) end end end --------------- -- verbs.DPS -- --------------- function VF.vfields.verbsDPS(def) local filters = { {'verbs', 1, 'defaultProjectile'}, {'verbs', 1, 'warmupTime'}, {'statBases', 'RangedWeapon_Cooldown'} } if not Util.table.checkMultiple(def, filters) then return nil end local projectile = DefInfo.getDef(def.verbs[1].defaultProjectile) local warmup = def.verbs[1].warmupTime local cooldown = def.statBases.RangedWeapon_Cooldown if not projectile then return nil end local burst = def.verbs[1].burstShotCount local pause = def.verbs[1].ticksBetweenBurstShots local damage = Util.table.check(projectile, 'projectile', 'damageAmountBase') and projectile.projectile.damageAmountBase local dps if burst and pause then dps = damage * burst / (warmup + cooldown + burst*(pause/60)) else dps = damage / (warmup + cooldown) end if dps then def.verbs[1].DPS = Util.round(dps, 3) end end ------------------------------------- -- naturally lives in these biomes -- ------------------------------------- function VF.vfields.raceLivesIn(def) if def.thingClass ~= 'Pawn' then return nil end local biomes = {} for biomeK,biome in pairs(Data) do if Util.table.check(biome, 'wildAnimals') then for animalK,animal in pairs(biome.wildAnimals) do if animalK == def.defName then table.insert(biomes, biome.defName) end end end end if #biomes > 0 then def._.livesIn = biomes end end ------------------------ -- module entry point -- ------------------------ function VF.expand(mergedDef) for k,func in pairs(VF.vfields) do func(mergedDef) end end return VF