text: ---
  --- Generated by EmmyLua(https://github.com/EmmyLua)
  --- Created by mike.
  --- DateTime: 6/6/20 8:28 PM
  ---
  
  local RPD                 = require "scripts/lib/commonClasses"
  
  local spell               = require "scripts/lib/spell"
  
  local spellLevel = 2
  
  local function spellTier(caster)
      return math.min(caster:skillLevel() - spellLevel + 1, 3)
  end
  
  return spell.init{
      desc  = function ()
          return {
              image         = 3,
              imageFile     = "spellsIcons/rogue.png",
              name          = "KunaiThrow_Name",
              info          = "KunaiThrow_Info",
              magicAffinity = "Rogue",
              targetingType = "self",
              level         = spellLevel,
              castTime      = 0.01,
              spellCost     = 5
          }
      end,
  
      cast = function(self, spell, caster)
          local n = spellTier(caster)
  
          local enemies = caster:visibleEnemies()
  
          if enemies == 0 then
              return false
          end
  
          local ownPos = caster:getPos()
  
          for i = 1, n do
              local tgt = caster:randomEnemy()
  
              RPD.zapEffect(ownPos,tgt:getPos(),"Kunai")
              tgt:damage(math.random(n,n + caster:lvl()), caster)
          end
  
          return true
      end,
  
      image = function(self, spell, caster)
          local lvl2img = {1,4,5}
          return lvl2img[spellTier(caster)]
      end
  }