Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. package.path = package.path .. ";data/scripts/lib/?.lua"
  2.  
  3. require ("galaxy")
  4. require ("randomext")
  5.  
  6. local rand = random()
  7.  
  8. local TurretGenerator = {}
  9.  
  10. function TurretGenerator.initialize(seed)
  11. if seed then
  12. rand = Random(seed)
  13. end
  14. end
  15.  
  16. function TurretGenerator.generate(x, y, offset_in, rarity_in, type_in, material_in) -- server
  17.  
  18. local offset = offset_in or 0
  19. local seed = rand:createSeed()
  20. local dps = 0
  21. local sector = math.floor(length(vec2(x, y))) + offset
  22.  
  23. local weaponDPS, weaponTech = Balancing_GetSectorWeaponDPS(sector, 0)
  24. local miningDPS, miningTech = Balancing_GetSectorMiningDPS(sector, 0)
  25. local materialProbabilities = Balancing_GetMaterialProbability(sector, 0)
  26. local material = material_in or Material(getValueFromDistribution(materialProbabilities))
  27. local weaponType = type_in or getValueFromDistribution(Balancing_GetWeaponProbability(sector, 0))
  28.  
  29. local tech = 0
  30. if weaponType == WeaponType.MiningLaser then
  31. dps = miningDPS * 3
  32. tech = miningTech
  33. elseif weaponType == WeaponType.SalvagingLaser then --added this to affect salvagers only
  34. dps = weaponDPS * 1.5
  35. tech = weaponTech
  36. elseif weaponType == WeaponType.ForceGun then
  37. dps = rand:getFloat(800, 1200); -- force
  38. tech = weaponTech
  39. else
  40. dps = weaponDPS
  41. tech = weaponTech
  42. end
  43.  
  44. local rarities = {}
  45. rarities[5] = 0.1 -- legendary
  46. rarities[4] = 1 -- exotic
  47. rarities[3] = 8 -- exceptional
  48. rarities[2] = 16 -- rare
  49. rarities[1] = 32 -- uncommon
  50. rarities[0] = 128 -- common
  51.  
  52. local rarity = rarity_in or Rarity(getValueFromDistribution(rarities))
  53.  
  54. --get the template and mess with reach
  55.  
  56. local template = GenerateTurretTemplate(seed, weaponType, dps, tech, rarity, material)
  57. local weapons = {template:getWeapons()}
  58. template:clearWeapons()
  59. for _, weapon in pairs(weapons) do
  60. -- if salvager or miner, double blength and adjust reach
  61. if weaponType == WeaponType.MiningLaser then
  62. weapon.blength = weapon.blength * 2
  63. weapon.reach = weapon.blength
  64. elseif weaponType == WeaponType.SalvagingLaser then
  65. weapon.reach = weapon.isBeam and weapon.blength * 2 or weapon.pvelocity*weapon.pmaximumTime
  66.  
  67. end
  68. template:addWeapon(weapon)
  69. end
  70. return template
  71. end
  72.  
  73. function TurretGenerator.generateArmed(x, y, offset_in, rarity_in, material_in) -- server
  74.  
  75. local offset = offset_in or 0
  76. local sector = math.floor(length(vec2(x, y))) + offset
  77. local types = Balancing_GetWeaponProbability(sector, 0)
  78.  
  79. types[WeaponType.RepairBeam] = nil
  80. types[WeaponType.MiningLaser] = nil
  81. types[WeaponType.SalvagingLaser] = nil
  82. types[WeaponType.ForceGun] = nil
  83.  
  84. local weaponType = getValueFromDistribution(types)
  85.  
  86. return TurretGenerator.generate(x, y, offset_in, rarity_in, weaponType, material_in)
  87. end
  88.  
  89. return TurretGenerator
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement