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

From RimWorld Wiki
Jump to navigation Jump to search
(tweak to weapon DPS calculatiob)
Line 4: Line 4:
 
   DefInfo = DefInfo or require "DefInfo"
 
   DefInfo = DefInfo or require "DefInfo"
 
end
 
end
 
 
  
 
local VF = {}
 
local VF = {}
Line 34: Line 32:
  
 
   local projectile = DefInfo.getDef(def.verbs[1].defaultProjectile)
 
   local projectile = DefInfo.getDef(def.verbs[1].defaultProjectile)
 +
  if not projectile then return nil end
 +
 +
  def.verbs[1].defaultProjectile = projectile
 +
 +
  local damage
 +
 +
  if Util.table.check(projectile, 'projectile', 'damageAmountBase') then
 +
    damage = projectile.projectile.damageAmountBase
 +
  elseif Util.table.check(projectile, 'projectile', 'damageDef') and projectile.projectile.damageDef == 'Bomb' then
 +
    local bomb = DefInfo.getDef(projectile.projectile.damageDef)
 +
    if bomb then
 +
      damage = bomb.defaultDamage
 +
      def.verbs[1].defaultProjectile.projectile.damageDef = bomb
 +
    end
 +
  end
 +
 
   local warmup    = def.verbs[1].warmupTime
 
   local warmup    = def.verbs[1].warmupTime
 
   local cooldown  = def.statBases.RangedWeapon_Cooldown
 
   local cooldown  = def.statBases.RangedWeapon_Cooldown
 
  if not projectile then return nil end
 
 
 
   local burst      = def.verbs[1].burstShotCount
 
   local burst      = def.verbs[1].burstShotCount
 
   local pause      = def.verbs[1].ticksBetweenBurstShots
 
   local pause      = def.verbs[1].ticksBetweenBurstShots
  local damage    = Util.table.check(projectile, 'projectile', 'damageAmountBase') and projectile.projectile.damageAmountBase
+
 
 
   local dps
 
   local dps
  

Revision as of 17:04, 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)
  if not projectile then return nil end

  def.verbs[1].defaultProjectile = projectile

  local damage

  if Util.table.check(projectile, 'projectile', 'damageAmountBase') then
    damage = projectile.projectile.damageAmountBase
  elseif Util.table.check(projectile, 'projectile', 'damageDef') and projectile.projectile.damageDef == 'Bomb' then
    local bomb = DefInfo.getDef(projectile.projectile.damageDef)
    if bomb then
      damage = bomb.defaultDamage
      def.verbs[1].defaultProjectile.projectile.damageDef = bomb
    end
  end

  local warmup     = def.verbs[1].warmupTime
  local cooldown   = def.statBases.RangedWeapon_Cooldown
  local burst      = def.verbs[1].burstShotCount
  local pause      = def.verbs[1].ticksBetweenBurstShots

  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