target.lua 985 B

12345678910111213141516171819202122232425
  1. local target = {}
  2. function target.objectAtPosition(x, y)
  3. local candidates = {}
  4. candidates = util.concat(candidates, util.filter(app.context.objects, 'isMinion'))
  5. candidates = util.concat(candidates, util.filter(app.context.objects, 'isEnemy'))
  6. candidates = util.concat(candidates, { app.context.objects.muju })
  7. candidates = util.concat(candidates, util.filter(app.context.objects, function(object)
  8. return object.isShruju and not object.carrier and (object.initialPosition.x ~= object.position.x and object.initialPosition.y ~= object.position.y)
  9. end))
  10. table.sort(candidates, function(a, b)
  11. local d1 = util.distance(x, y, a.position.x, a.position.y)
  12. local d2 = util.distance(x, y, b.position.x, b.position.y)
  13. local y1 = -a.position.y / 10
  14. local y2 = -b.position.y / 10
  15. return d1 + y1 < d2 + y2
  16. end)
  17. return util.match(candidates, function(candidate)
  18. return candidate:isTargetable() and candidate:isHovered(x, y)
  19. end)
  20. end
  21. return target