SHARE
TWEET

Kantaris the Banished

HalestormXV Apr 20th, 2019 (edited) 382 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Special thanks to Sakuya Izayoi for the Area Array, Cleanup Function, and RandomBlock Picker and Daot for his epic video on NPC Tactics for the teleporting\\
  2. /* VARIABLE FUNCTIONS */
  3. var rand = function(a, b){ return Math.random()*(b - a) + a };
  4. //-------------------\\
  5.  
  6. var ax, az, x, y, z, px, py, pz, flag=0, count=0;
  7. var offset = 3;
  8. var phase = 1;
  9. var maxHP;
  10. var currentHP;
  11. var _oldMeleeRange;
  12. var _oldRangedRange;
  13. var _rangeDelayMin = 35;
  14. var _rangeDelayMax = 50;
  15. var _moveSpeed = 4;
  16. var explosionTrigger = false;
  17.  
  18. /* ARENA ROOM VARIABLE CONTROL */
  19. var origin = { x:25, y:15, z:5 }
  20. var offsets = { x:0, z:0, y:0, xd:-20, zd:20, yd:-10 };
  21. var area = { x:origin.x + offsets.x, z:origin.z + offsets.z, y:origin.y + offsets.y, xd:origin.x + offsets.xd, zd:origin.z + offsets.zd, yd:origin.y + offsets.yd };
  22. //-------------------\\
  23.  
  24. function init(event)
  25. {
  26.     phase = 1;
  27.     var resetMinions = event.npc.world.getNearbyEntities(event.npc.getX(), event.npc.getY(), event.npc.getZ(), 64, 2);
  28.     for(var i = 0; i < resetMinions.length; i++) { if(resetMinions[i].display.name == "Minion of Kantaris") { resetMinions[i].despawn(); } }
  29.     explosionTrigger = false;
  30.     event.npc.timers.clear();
  31.     event.npc.display.setVisible(0);
  32.     event.npc.setHealth(event.npc.getMaxHealth());
  33.     event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Spawn master @p");
  34.     event.npc.world.broadcast("<Kantaris the Banished> \u00A7cAssuming control!");
  35.     event.npc.getAi().setWalkingSpeed(_moveSpeed);
  36.     event.npc.stats.getMelee().setRange(2);
  37.     event.npc.stats.getRanged().setRange(12);
  38.     event.npc.getAi().setNavigationType(0);
  39.     event.npc.stats.getRanged().setDelay(_rangeDelayMin, _rangeDelayMax);
  40.     cleanup(event);
  41. }
  42.  
  43. function kill(event)
  44. {
  45.     event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_KilledTarget master @p");
  46.     event.npc.world.broadcast("<Kantaris the Banished> \u00A7cI sense your weakness!");
  47.     var playersAlive = event.npc.world.getNearbyEntities(event.npc.getX(), event.npc.getY(), event.npc.getZ(), 200, EntityType_PLAYER);
  48.     if (playersAlive == 0){ totalReset(event); }
  49. }
  50.  
  51. function damaged(event)
  52. {
  53.     maxHP = event.npc.getMaxHealth();
  54.     currentHP = event.npc.getHealth();
  55.     var currentPercent = getWholePercent(currentHP, maxHP);
  56.     //Phase 1 Tactics - Evasion and Teleport
  57.     if (event.source != null)
  58.     {
  59.         if ((event.source.getType() == 1) && phase == 1)
  60.         {
  61.             event.npc.display.setVisible(1);
  62.             flag=1;
  63.             event.npc.getTempdata().put("player",event.source);  
  64.         }
  65.         //Change to Phase 2\\
  66.         if ((currentPercent <= 75) && (phase == 1)) { phaseChange(event); }
  67.         //Change to Phase 3\\
  68.         if ((currentPercent <= 50) && (phase == 2)) { phaseChange(event); }
  69.         //Change to Phase 4\\
  70.         if ((currentPercent <= 25) && (phase == 3)) { phaseChange(event); }
  71.     }
  72. }
  73.  
  74. function died(event)
  75. {
  76.     event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Died master @p");
  77.     event.npc.world.broadcast("<Kantaris the Banished> \u00A7cI will find you again...");
  78.     for (var i = 0; i < 6; i++)
  79.     {
  80.         if (event.npc.timers.has(i))
  81.         event.npc.timers.stop(i);
  82.     }
  83.     event.npc.timers.clear();
  84.     cleanup(event);
  85. }
  86.  
  87. function phaseChange(event)
  88. {
  89.     phase++
  90.     event.npc.display.setVisible(0);
  91.     event.npc.executeCommand('/execute @p[c=4] ~ ~ ~ title @p title {"text":"Entering Phase: '+phase+'!","color":"red"}');
  92.     switch(phase)
  93.     {
  94.     case 2:
  95.         event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Phase2 master @p");
  96.         event.npc.world.broadcast("<Kantaris the Banished> \u00A7cOur power is unmatched!");
  97.         break;
  98.     case 3:
  99.         event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Phase3 master @p");
  100.         event.npc.world.broadcast("<Kantaris the Banished> \u00A7cProgress cannot be halted!");
  101.         break;
  102.     case 4:
  103.         event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Phase4 master @p");
  104.         event.npc.world.broadcast("<Kantaris the Banished> \u00A7cDestroying this body gains you nothing!");
  105.         break;                    
  106.     }
  107. }
  108.  
  109. function tick(event)
  110. {
  111.     //Phase 1 - Utilizes Evasion Tactics
  112.     if ((flag) && (phase == 1))
  113.     {        
  114.         az = offset*Math.sin((event.npc.getTempdata().get("player").getRotation()+90)*Math.PI/180);  
  115.         ax = offset*Math.cos((event.npc.getTempdata().get("player").getRotation()+90)*Math.PI/180);
  116.         x = event.npc.getTempdata().get("player").getX()-ax;
  117.         z = event.npc.getTempdata().get("player").getZ()-az;
  118.         y = event.npc.getTempdata().get("player").getY();
  119.         if (!event.npc.world.getBlock(x,y,z)&&!event.npc.world.getBlock(x,y+1,z))
  120.         {  
  121.             event.npc.setPosition(x,y,z);
  122.             count++;
  123.             if (count==20)
  124.             {
  125.                 flag=0;
  126.                 count=0;
  127.             }
  128.             event.npc.display.setVisible(0);
  129.         }  else {
  130.             event.npc.display.setVisible(0);
  131.         }    
  132.     }
  133.    
  134.     //Phase 2 - Utilize Explosions
  135.     if (phase == 2)
  136.     {
  137.         if (!event.npc.timers.has(1))
  138.         {
  139.             event.npc.timers.start(1, 600, true);
  140.         }
  141.         if ((explosionTrigger) && (!event.npc.timers.has(3)))
  142.         {
  143.             event.npc.timers.start(3, 140, true);
  144.         }
  145.     }
  146.  
  147.     //Phase 3 - Summon Minions
  148.     if (phase == 3)
  149.     {
  150.         if (!event.npc.timers.has(4))
  151.         {
  152.             event.npc.timers.start(4, 600, true);
  153.         }
  154.     }
  155.  
  156.     //Phase 4 - Break Celing
  157.     if (phase == 4)
  158.     {
  159.         if (!event.npc.timers.has(5))
  160.         {
  161.             event.npc.timers.start(5, 220, true);
  162.         }
  163.     }
  164. }
  165.  
  166. function timer(event)
  167. {
  168.     if (event.id == 1) //Special Ability Placement for Explosions
  169.     {
  170.         event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_Phase2_Special master @p");        
  171.         event.npc.getAi().setNavigationType(1);
  172.         event.npc.navigateTo(16, 12, 15, 5);
  173.         event.npc.setPosition(16, 12, 15)
  174.         _oldMeleeRange = event.npc.stats.getMelee().getRange();
  175.         _oldRangesRange = event.npc.stats.getRanged().getRange();
  176.         event.npc.stats.getMelee().setRange(0);
  177.         event.npc.stats.getRanged().setRange(16);
  178.         event.npc.stats.getRanged().setDelay(15, 30);
  179.         event.npc.timers.start(2, 300, false);
  180.         explosionTrigger = true;
  181.         event.npc.getAi().setWalkingSpeed(0)
  182.     }
  183.     if (event.id == 2) //Expiration of Special Ability and Reset of All Previous Values and Position
  184.     {
  185.         event.npc.getAi().setNavigationType(0);
  186.         event.npc.getAi().setWalkingSpeed(_moveSpeed);
  187.         x = event.npc.getTempdata().get("player").getX();
  188.         z = event.npc.getTempdata().get("player").getZ();
  189.         y = event.npc.getTempdata().get("player").getY();
  190.         event.npc.navigateTo(x, y, z, 4);
  191.         event.npc.stats.getMelee().setRange(_oldMeleeRange);
  192.         event.npc.stats.getRanged().setRange(_oldRangedRange);
  193.         event.npc.stats.getRanged().setDelay(_rangeDelayMin, _rangeDelayMax);
  194.         explosionTrigger = false;
  195.     }
  196.     if (event.id == 3) //Trigger the Explosion
  197.     {
  198.         x = event.npc.getTempdata().get("player").getX();
  199.         z = event.npc.getTempdata().get("player").getZ();
  200.         y = event.npc.getTempdata().get("player").getY();
  201.         if (explosionTrigger){ event.npc.world.explode(x, y, z, 0.6, true, false); }
  202.     }
  203.     if (event.id == 4) //Minion Timer
  204.     {
  205.         var kantarisBoss = event.npc;
  206.         kantarisBoss.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_SpawnAdds master @p");
  207.         kantarisBoss.world.broadcast("<Kantaris the Banished> \u00A7cSentient beings need never feel pain!");
  208.         x = event.npc.getTempdata().get("player").getX();
  209.         z = event.npc.getTempdata().get("player").getZ();
  210.         y = event.npc.getTempdata().get("player").getY();
  211.         var minionCount = randomIntFromInterval(1, 3);
  212.         for (i = 0; i < minionCount; i++)
  213.         {
  214.            var kantarisMinion = event.API.getClones().get(1, "Minion of Kantaris", event.npc.getWorld());
  215.            kantarisMinion.setHome(kantarisBoss.x, kantarisBoss.y, kantarisBoss.z + 3);
  216.            kantarisMinion.setPosition(x + randomIntFromInterval(3, 8), y, z + randomIntFromInterval(2, 4));
  217.            kantarisMinion.spawn();
  218.         }
  219.     }
  220.     if (event.id == 5) //Final Phase Ceiling Collapse Timer
  221.     {
  222.         var targetBlock = chooseRandomBlock(event.npc.world, area.x, area.xd , area.z , area.zd, area.y)
  223.         targetBlock.remove();
  224.         event.npc.executeCommand("/execute @p[c=4] ~ ~ ~ playsound Kantaris_BreakRoof master @p");
  225.         event.npc.world.broadcast("<Kantaris the Banished> \u00A7cYou are bacteria!");
  226.     }
  227. }
  228. //----------------------------UTILITY FUNCTIONS----------------------------\\
  229. function randomGenWhole(){ return Math.floor(Math.random() * 20); }
  230. function randomIntFromInterval(min,max){ return Math.floor(Math.random()*(max-min+1)+min); }
  231. function getWholePercent(percentFor, percentOf){ return Math.floor(percentFor/percentOf * 100) }
  232. function chooseRandomBlock(world, x1, x2, z1, z2, y) { x = rand(x1, x2); z = rand(z1, z2); return world.getBlock(x, y, z); }
  233. function totalReset(event)
  234. {
  235.     phase = 1;
  236.     var resetMinions = event.npc.world.getNearbyEntities(event.npc.getX(), event.npc.getY(), event.npc.getZ(), 32, 2);
  237.     for(var i = 0; i < resetMinions.length; i++) { if(resetMinions[i].display.name == "Minion of Kantaris") { resetMinions[i].despawn(); } }
  238.     explosionTrigger = false;
  239.     event.npc.timers.clear();
  240.     event.npc.display.setVisible(0);
  241.     event.npc.setHealth(event.npc.getMaxHealth());
  242.     event.npc.getAi().setWalkingSpeed(_moveSpeed);
  243.     event.npc.stats.getMelee().setRange(2);
  244.     event.npc.stats.getRanged().setRange(12);
  245.     event.npc.getAi().setNavigationType(0);
  246.     event.npc.stats.getRanged().setDelay(_rangeDelayMin, _rangeDelayMax);
  247.     cleanup(event);
  248. }
  249. function cleanup(event)
  250. {
  251. /*repair glass*/
  252. /*two rows on +/- X*/
  253. var glassPlane = ''+(area.x-1)+' '+area.y+' '+area.z+' '+(area.xd+1)+' '+area.y+' '+area.zd
  254. event.npc.executeCommand('/fill '+glassPlane+' tconstruct:clear_glass 0 replace')
  255. var lavaArea = ''+area.x+' '+area.y+' '+area.z+' '+area.xd+' '+area.yd+' '+area.zd
  256. event.npc.executeCommand('/fill '+lavaArea+' minecraft:air 0 replace minecraft:lava')
  257. event.npc.executeCommand('/fill '+lavaArea+' minecraft:air 0 replace minecraft:flowing_lava')
  258. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top