Advertisement
Oysi

Fetid Lua Sim

Oct 1st, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1.  
  2. -- Code made by Oysi
  3.  
  4. local function f(n) return string.format("%.2f", n) end
  5.  
  6. local function ftime(n)
  7.     local min = math.floor(n/60)
  8.     local sec = math.floor(n%60*100 + 0.5)/100
  9.     local secStr = string.format("%.2f", n%60)
  10.     if min < 10 then
  11.         --min = "0" .. min
  12.     end
  13.     if sec < 10 then
  14.         secStr = "0" .. secStr
  15.     end
  16.     return min .. ":" .. secStr
  17. end
  18.  
  19. local function sim(data)
  20.     local timer = 0
  21.     local damage = 0
  22.     local bossMaxHP = data.bossMaxHP
  23.     local bossHP = bossMaxHP
  24.    
  25.     for i, dude in ipairs(data.dudes) do
  26.         dude.damage = 0
  27.         dude.aaTimer = 0
  28.         dude.cooldownAvailable = true
  29.         dude.cooldownTimer = 0
  30.     end
  31.    
  32.     local heroAvailable = true
  33.     local heroTimer = 0
  34.    
  35.     local delta = 0.01
  36.     while bossHP > 0 do
  37.         local haste = 1
  38.         local dmgmul = 1
  39.        
  40.         -- Dudes
  41.         for i, dude in ipairs(data.dudes) do
  42.             local haste = haste
  43.             local dmgmul = dmgmul
  44.            
  45.             -- Hero
  46.             heroTimer = math.max(heroTimer - delta, 0)
  47.             if heroAvailable and bossHP/bossMaxHP <= data.heroPercent then
  48.                 heroAvailable = false
  49.                 heroTimer = 40
  50.             end
  51.             if heroTimer > 0 then
  52.                 --haste = haste * 1.3
  53.                 dmgmul = dmgmul * 1.3
  54.             end
  55.            
  56.             -- Cooldown
  57.             dude.cooldownTimer = math.max(dude.cooldownTimer - delta, 0)
  58.             if dude.cooldownAvailable and bossHP/bossMaxHP <= dude.cooldownpercent then
  59.                 dude.cooldownAvailable = false
  60.                 dude.cooldownTimer = dude.cooldownduration
  61.             end
  62.             if dude.cooldownTimer > 0 then
  63.                 dmgmul = dmgmul * dude.cooldownmul
  64.             end
  65.            
  66.             -- Auto attack
  67.             dude.aaTimer = math.max(dude.aaTimer - delta*haste, 0)
  68.             if dude.aaTimer <= 0 then
  69.                 dude.aaTimer = 1
  70.                
  71.                 local aaDamage = dude.autoattack*dmgmul
  72.                 if bossHP <= bossMaxHP*data.executeStart then
  73.                     aaDamage = aaDamage * data.executeMul
  74.                 end
  75.                
  76.                 if bossHP <= 0 then
  77.                     aaDamage = 0
  78.                 end
  79.                
  80.                 dude.damage = dude.damage + aaDamage
  81.                 bossHP = bossHP - aaDamage
  82.                
  83.                 if data.print then
  84.                     print(
  85.                         ftime(timer) ..
  86.                         " - Dude #" .. i ..
  87.                         " - Damage: " .. f(aaDamage) ..
  88.                         " - Health: " .. f(bossHP) .. " (" .. f(bossHP/bossMaxHP*100) .. "%)" ..
  89.                         " - DPS: " .. string.format("%.3f", dude.damage/timer) ..
  90.                         (heroTimer > 0 and " - HERO" or "") ..
  91.                         (dude.cooldownTimer > 0 and " - COOLDOWN" or "")
  92.                     )
  93.                 end
  94.                
  95.                 -- on hit: generate new dude
  96.                 --[[
  97.                 if aaDamage > 0 then
  98.                     local newDude = {autoattack = 1, cooldownpercent = 0.5, cooldownmul = 2, cooldownduration = 20};
  99.                     newDude.damage = 0
  100.                     newDude.aaTimer = 1
  101.                     newDude.cooldownAvailable = true
  102.                     newDude.cooldownTimer = 0
  103.                     table.insert(data.dudes, newDude)
  104.                 end
  105.                 --]]
  106.             end
  107.         end
  108.        
  109.         -- Constant external dot
  110.         if data.externalDot and data.externalDot > 0 then
  111.             if bossHP <= bossMaxHP*data.executeStart then
  112.                 bossHP = bossHP - delta*data.externalDot*data.executeMul
  113.             else
  114.                 bossHP = bossHP - delta*data.externalDot
  115.             end
  116.         end
  117.        
  118.         timer = timer + delta
  119.     end
  120.    
  121.     return damage, timer
  122. end
  123.  
  124. sim {
  125.     bossMaxHP = 500;
  126.     heroPercent = 0.5;
  127.     executeStart = 0.5;
  128.     executeMul = 1.5;
  129.     externalDot = 0;
  130.     dudes = {
  131.         {autoattack = 1, cooldownpercent = 0.5, cooldownmul = 2, cooldownduration = 20};
  132.         {autoattack = 1, cooldownpercent = 0.5, cooldownmul = 2, cooldownduration = 20};
  133.     };
  134.     print = true;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement