Difference between revisions of "Module:Test/data/virtual"

From RimWorld Wiki
Jump to navigation Jump to search
m
(tweak to weapon DPS calculatiob)
Line 1: Line 1:
 
if mw then
 
if mw then
local DefInfo = DefInfo or require("Module:Test")
+
  DefInfo = DefInfo or require("Module:Test")
 
else
 
else
local DefInfo = DefInfo or require "DefInfo"
+
  DefInfo = DefInfo or require "DefInfo"
 
end
 
end
 +
 +
  
 
local VF = {}
 
local VF = {}
Line 43: Line 45:
  
 
   if burst and pause then
 
   if burst and pause then
     dps = damage * burst / (warmup + cooldown + burst*(pause/60))
+
     dps = damage * burst / (warmup + cooldown + (burst-1)*(pause/60))
 
   else
 
   else
 
     dps = damage / (warmup + cooldown)
 
     dps = damage / (warmup + cooldown)

Revision as of 13:45, 16 May 2021


if mw then
  DefInfo = DefInfo or require("Module:Test")
else
  DefInfo = DefInfo or require "DefInfo"
end



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-1)*(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