Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. /**
  2. * Created by Hoax on 5/28/2019.
  3. */
  4.  
  5. object Skotizo {
  6.  
  7. @JvmField val script: Function1<Script, Unit> = s@ @Suspendable {
  8. val npc = it.npc()
  9. var target = EntityCombat.getTarget(it) ?: return@s
  10.  
  11. while (EntityCombat.targetOk(npc, target) && PlayerCombat.canAttack(npc, target)) {
  12. if (EntityCombat.canAttackDistant(npc, target, true, 7) && EntityCombat.attackTimerReady(npc)) {
  13. if (EntityCombat.canAttackMelee(npc, target, true)) { // Melee attack is 100% if in range.
  14. primary_melee_attack(npc, target)
  15. } else {
  16. // Only if out of melee distance.
  17. primate_magic_attack(npc, target)
  18. }
  19. target.putattrib(AttributeKey.LAST_DAMAGER, npc)
  20. target.putattrib(AttributeKey.LAST_WAS_ATTACKED_TIME, System.currentTimeMillis())
  21. npc.putattrib(AttributeKey.LAST_TARGET, target)
  22. EntityCombat.putCombatDelay(npc, npc.combatInfo().attackspeed)
  23. }
  24. EntityCombat.postHitLogic(npc)
  25. it.delay(1)
  26. target = EntityCombat.refreshTarget(it) ?: return@s
  27. }
  28. }
  29.  
  30.  
  31. @Suspendable fun primary_melee_attack(npc: Npc, target: Entity) {
  32. if (EntityCombat.attemptHit(npc, target, CombatStyle.MELEE))
  33. target.hit(npc, EntityCombat.randomHit(npc))
  34. else
  35. target.hit(npc, 0)
  36.  
  37. npc.animate(npc.attackAnimation())
  38. }
  39.  
  40. @Suspendable fun primate_magic_attack(npc: Npc, target: Entity) {
  41. val tileDist = npc.tile().transform(1, 1, 0).distance(target.tile())
  42. val delay = Math.max(1, (50 + (tileDist * 12)) / 30)
  43.  
  44. npc.animate(npc.attackAnimation())
  45. npc.world().spawnProjectile(npc, target, 1242, 40, 30, 50, 12 * tileDist, 14, 5)
  46.  
  47. if (EntityCombat.attemptHit(npc, target, CombatStyle.MAGIC))
  48. target.hit(npc, EntityCombat.randomHit(npc), delay).combatStyle(CombatStyle.MAGIC)
  49. else
  50. target.hit(npc, 0, delay)
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement