Advertisement
Agent_Silence

GameDMG CALC

Apr 13th, 2016 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.44 KB | None | 0 0
  1. local shapes = {
  2.     --name = {targeting,modifier,incompatibility,exceptions}
  3.     projectile = {"either",1,{"wall","target","beam","self"},2},
  4.     burst = {"either",0.25,{},3},
  5.     zone = {"either",0.25,{},3},
  6.     target = {"either",0.75,{},2},
  7.     beam = {"either",0.33,{},2},
  8.     self = {"self",1,{},3},
  9.     rune = {"either",1.25,{},2},
  10.     wall = {"either",0.75,{},2},
  11.     aura = {"ally",0.10,{"all"},2},
  12.     presence = {"enemy",0.10,{"all"},2},
  13.     onCrit = {"either",0.66,{"onDeath","onKill","onFall"},1},
  14.     onDeath = {"either",2,{"onCrit","onKill","onFall"},1},
  15.     onKill = {"either",0.25,{"onDeath","onCrit","onFall"},1},
  16.     onFall = {"either",0.33,{"onDeath","onKill","onCrit"},1}
  17. }
  18.  
  19. local function checkSNames(tbl)
  20.     for i,v in pairs(tbl) do -- Checks if the shape does not exist
  21.         if shapes[v] == nil then
  22.             if type(v) == "table" then
  23.                 tbl = v
  24.             end
  25.             error("Shape '"..v.."' does not exist in shape index")
  26.         end
  27.     end
  28. end
  29.  
  30. local function shapeParse(...)
  31.     local tArgs = {...}
  32.     checkSNames(tArgs)
  33.     local incomp = {}
  34.     for k,val in pairs(tArgs) do -- Dumps incompatibilities into the incomp table
  35.         if shapes[val][3] then
  36.             for i,v in pairs(shapes[val][3]) do
  37.                 table.insert(incomp, v)
  38.             end
  39.         end
  40.     end
  41.     for i,v in pairs(incomp) do  -- Reads incomp table and makes sure no names in tArgs match any names in incomp
  42.         if v ~= "all" then
  43.             for i=1,#tArgs do
  44.                 if v == tArgs[i] then
  45.                     return false
  46.                 end
  47.             end
  48.         elseif v == "all" and #tArgs > 1 then -- Checks for multiple shapes if there is an "all" tag and renders it incompatible
  49.             return false
  50.         end
  51.     end
  52.     return true
  53. end
  54.  
  55. local function dmgCalc(baseDmg,...)
  56.     local tArgs = {...}
  57.     checkSNames(tArgs)
  58.     if shapeParse(unpack(tArgs)) == false then
  59.         error("Shapes aren't compatible")
  60.     end
  61.     for i,v in pairs(tArgs) do  --Finds multiplier values and multiplies baseDmg by it.
  62.         baseDmg = baseDmg*(shapes[v][2])
  63.     end
  64.     return math.ceil(baseDmg) --Being generous and rounding it to the highest value
  65. end
  66.  
  67. local function procOrder(...)
  68.     local tArgs = {...}
  69.     checkSNames(tArgs)
  70.     if not shapeParse(unpack(tArgs)) then
  71.         error("Shapes aren't compatible")
  72.     end
  73.     local order = {}
  74.     for i=#tArgs,1,-1 do
  75.         table.insert(order, shapes[tArgs[i]][4], tArgs[i])
  76.     end
  77.     return order
  78. end
  79.  
  80. local function newSpell(element,...)
  81.     local tArgs = {...}
  82.     checkSNames(tArgs)
  83.     if not shapeParse(unpack(tArgs)) then
  84.         error("Shapes aren't compatible")
  85.     end
  86.     return dmgCalc(element,...),unpack(procOrder(...))
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement