Advertisement
kolton

Untitled

Sep 12th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var NTConfig_Entrance = false;
  2. var NTConfig_Dodge = true;
  3.  
  4. function NTMain() {
  5.     Include("libs/common/NTCommon.ntl");
  6.     NTC_IncludeLibs();
  7.  
  8.     NTC_IncludeConfig("NTBot/char_configs");
  9.     NT_LoadConfig();
  10.  
  11.     NTSI_LoadNIPFiles("NTBot/item_configs");
  12.    
  13.     NTA_Initialize();
  14.     Print(COLOR_3 + "Starting Diablo Script");
  15.    
  16.     if (!NTTM_CheckAct()) {
  17.         NTC_SendMsgToScript("NTBotGame.ntj", "NTTM_CheckAct()");
  18.         return;
  19.     }
  20.    
  21.     NTTMGR_TownManager();
  22.    
  23.     Print(COLOR_8 + "Going to River of Flame");
  24.    
  25.     if (!NTTM_TownMove("waypoint")) {
  26.         NTC_SendMsgToScript("NTBotGame.ntj", "NTTM_TownMove()");
  27.         return;
  28.     }
  29.    
  30.     if (!NTM_TakeWaypoint(107)) {
  31.         NTC_SendMsgToScript("NTBotGame.ntj", "NTM_TakeWaypoint()");
  32.         return;
  33.     }
  34.    
  35.     Print(COLOR_5 + "Precasting");
  36.     NTP_DoPrecast(true);
  37.     Print(COLOR_8 + "Going to Chaos Sanctuary");
  38.    
  39.     if (!NTM_MoveTo(108, 7797, 5600)) {
  40.         NTC_SendMsgToScript("NTBotGame.ntj", "NTM_MoveTo()");
  41.         return;
  42.     }
  43.    
  44.     NTM_TeleportTo(7797, 5560);
  45.    
  46.     if (!NTM_MoveTo(me.areaid, 7790, 5544)) {
  47.         NTC_SendMsgToScript("NTBotGame.ntj", "NTM_MoveTo()");
  48.         return;
  49.     }
  50.    
  51.     if (NTConfig_Entrance) {
  52.         NTCS_ClearPosition(30, EntranceSort);
  53.         NTM_MoveTo(me.areaid, 7790, 5544);
  54.         PubTP();
  55.         PubSay("Entrance TP up.");
  56.         BO_Party();
  57.         NTCS_ClearPosition(30, EntranceSort);
  58.        
  59.         var FrontToStarX = [7792,7794,7791,7777,7813,7769,7782,7802,7819,7768,7770,7791,7819, 7804];
  60.         var FrontToStarY = [5564,5529,5495,5486,5486,5445,5421,5421,5446,5390,5355,5355,5376, 5340];
  61.        
  62.         for (var i = 0; i < FrontToStarX.length; i += 1) {
  63.             NTM_MoveTo(me.areaid, FrontToStarX[i], FrontToStarY[i]);
  64.             NTCS_ClearPosition(35, EntranceSort);
  65.         }
  66.     }
  67.    
  68.     NTM_MoveTo(me.areaid, 7784, 5310);
  69.     NTCS_ClearPosition(30, SealSort);
  70.     NTM_MoveTo(me.areaid, 7784, 5310);
  71.     NTC_PingDelay(1000);
  72.     NTCS_ClearPosition(30, SealSort);
  73.     PubTP();
  74.     PubSay("Star TP up.");
  75.     BO_Party();
  76.     NTCS_ClearPosition(30, SealSort);
  77.    
  78.     if (!NT_OpenSealsInt()) {
  79.         NTC_SendMsgToScript("NTBotGame.ntj", "NT_OpenSealsInt()");
  80.         return;
  81.     }
  82.    
  83.     PubSay("Diablo.");
  84.     NTM_MoveTo(me.areaid, 7760, 5267);
  85.     PubTP();
  86.     PubSay("Diablo TP up.");
  87.     NTM_MoveTo(me.areaid, 7792, 5291);
  88.     NTTMGR_CheckSafe(NTConfig_CheckSelfSafe, NTConfig_CheckMercSafe);
  89.     Print(COLOR_8 + "Waiting for Diablo to spawn..");
  90.    
  91.     for (i = 0; i < 200; i += 1) {
  92.         if (GetUnit(NTC_UNIT_MONSTER, 243)) {
  93.             break;
  94.         }
  95.        
  96.         NTC_Delay(500);
  97.     }
  98.    
  99.     if (!NTA_KillMonster(243)) {
  100.         NTC_SendMsgToScript("NTBotGame.ntj", "NTA_KillMonster()");
  101.         return;
  102.     }
  103.    
  104.     NTSI_PickItems();
  105.     PubSay("NG " + NTC_GetNextGame());
  106.    
  107.     NTC_SendMsgToScript("NTBotGame.ntj", "SCRIPT_END");
  108. }
  109.  
  110. function NT_OpenSealsInt() {
  111.     var _unit;
  112.     var _result;
  113.    
  114.     _unit = GetPresetUnits(me.areaid, NTC_UNIT_OBJECT, 396);
  115.    
  116.     if (!_unit) {
  117.         return false;
  118.     }
  119.    
  120.     if (_unit[0].roomy * 5 + _unit[0].y == 5275) {
  121.         _result = NT_OpenVizierSealInt(1);
  122.     } else {
  123.         _result = NT_OpenVizierSealInt(2);
  124.     }
  125.    
  126.     NTP_DoPrecast(true);
  127.    
  128.     _unit = GetPresetUnits(me.areaid, NTC_UNIT_OBJECT, 394);
  129.    
  130.     if (_unit[0].roomx * 5 + _unit[0].x == 7773) {
  131.         _result = NT_OpenDeSeisSealInt(1);
  132.     } else {
  133.         _result = NT_OpenDeSeisSealInt(2);
  134.     }
  135.    
  136.     if (!_result) {
  137.         return false;
  138.     }
  139.    
  140.     PubTP();
  141.     BO_Party();
  142.     NTCS_ClearPosition(40, SealSortB);
  143.    
  144.     _unit = GetPresetUnits(me.areaid, NTC_UNIT_OBJECT, 392);
  145.    
  146.     if (!_unit) {
  147.         return false;
  148.     }
  149.    
  150.     if (_unit[0].roomx * 5 + _unit[0].x == 7893) {
  151.         _result = NT_OpenVenomSealInt(1);
  152.     } else {
  153.         _result = NT_OpenVenomSealInt(2);
  154.     }
  155.    
  156.     NTP_DoPrecast(true);
  157.    
  158.     return _result;
  159. }
  160.  
  161. function NT_OpenVizierSealInt(type) {
  162.     var i, n;
  163.    
  164.     if (type === 1) {
  165.         var vx = [7767,7756,7744,7747,7750,7741,7729,7720,7720,7721,7719,7712,7700,7687,7676, 7666, 7647];//   |||   |||
  166.         var vy = [5292,5284,5275,5290,5303,5310,5314,5312,5301,5288,5273,5292,5294,5294,5292, 5307, 5267];//      |||
  167.     } else {
  168.         var vx = [7768,7755,7741,7733,7723,7714,7707,7680,7666, 7655, 7649];//   |||||||||
  169.         var vy = [5289,5295,5282,5291,5300,5282,5315,5310,5311, 5282, 5269];//   |||
  170.     }
  171.    
  172.     for (var i = 0; i < vx.length; i += 1) {
  173.         NTM_MoveTo(me.areaid, vx[i], vy[i]);
  174.         NTCS_ClearPosition(30, SealSort);
  175.     }
  176.    
  177.     PubTP();
  178.     PubSay("Leech TP up.");
  179.    
  180.     if (!NT_OpenSealInt(395) || !NT_OpenSealInt(396)) {
  181.         return false;
  182.     }
  183.    
  184.     if (type == 1) {
  185.         NTM_MoveTo(me.areaid, 7691, 5292);
  186.     } else {
  187.         NTM_MoveTo(me.areaid, 7695, 5316);
  188.     }
  189.    
  190.     NTC_FindUnit(1, GetLocaleString(2851), 10);
  191.     NTCS_ClearPosition(40, SealSort);
  192.     NTA_KillMonster(GetLocaleString(2851)); // Grand Vizier of Chaos
  193.     NTCS_ClearPosition(40, SealSort);
  194.     PubSay("Vizier dead.");
  195.    
  196.     if(NTConfig_IdInField){
  197.         NT_FieldID();
  198.     }
  199.    
  200.     return true;
  201. }
  202.  
  203. function NT_OpenDeSeisSealInt(type) {
  204.     var i, n;
  205.    
  206.     if (type === 1) {
  207.         var sx = [7791,7783,7800,7809,7785,7773,7773,7776,7794,7811,7817,7815,7798,7785]; // Shape of "2"
  208.         var sy = [5265,5256,5247,5232,5230,5222,5212,5194,5194,5193,5177,5157,5155,5155];
  209.     } else {
  210.         var sx = [7786,7801,7786,7787,7810,7811,7810,7790,7774,7773,7794, 7821]; // shape of an "S" or "5"
  211.         var sy = [5263,5249,5245,5227,5233,5215,5198,5194,5181,5156,5154, 5160];
  212.     }
  213.    
  214.     for (var i = 0; i < sx.length; i += 1) {
  215.         NTM_MoveTo(me.areaid, sx[i], sy[i]);
  216.         NTCS_ClearPosition(30, type === 1 ? SealSort : SealSortB);
  217.     }
  218.    
  219.     PubTP();
  220.     PubSay("Leech TP up.");
  221.    
  222.     if (!NT_OpenSealInt(394)) {
  223.         return false;
  224.     }
  225.    
  226.     if (type == 1) {
  227.         NTM_MoveTo(me.areaid, 7797, 5201);
  228.        
  229.         for (i = 0; i < 3; i += 1) {
  230.             NTM_TeleportTo(7794, 5227);
  231.         }
  232.     } else {
  233.         NTM_MoveTo(me.areaid, 7798, 5186);
  234.     }
  235.    
  236.     NTCS_Preattack(GetLocaleString(2852));
  237.     NTCS_ClearPosition(40, DistanceSort);
  238.     NTA_KillMonster(GetLocaleString(2852)); // Lord De Seis
  239.     NTCS_ClearPosition(40, DistanceSort);
  240.     PubSay("De Seis dead.");
  241.    
  242.     if(NTConfig_IdInField){
  243.         NT_FieldID();
  244.     }
  245.    
  246.     return NTM_MoveTo(me.areaid, 7800, 5255);
  247. }
  248.  
  249. function NT_OpenVenomSealInt(type) {
  250.     if (type === 1) {
  251.         var IX = [7825,7827,7834,7845,7855,7852,7875,7896,7917, 7861]; // shape of a "t"
  252.         var IY = [5293,5276,5291,5315,5301,5278,5293,5295,5291, 5321];
  253.     } else {
  254.         var IX = [7822,7826,7832,7850,7868,7877,7891,7907,7927,7932, 7909]; // looks like a hook
  255.         var IY = [5297,5278,5307,5278,5297,5276,5276,5276,5279,5298, 5318];
  256.     }
  257.    
  258.     for (var i = 0; i < IX.length; i += 1) {
  259.         NTM_MoveTo(me.areaid, IX[i], IY[i]);
  260.         NTCS_ClearPosition(30, SealSortB);
  261.     }
  262.    
  263.     PubTP();
  264.     PubSay("Leech TP up.");
  265.    
  266.     if (!NT_OpenSealInt(393) || !NT_OpenSealInt(392)) {
  267.         return false;
  268.     }
  269.    
  270.     if (type === 1) {
  271.         type = 1; // temp
  272.     } else {
  273.         NTM_MoveTo(me.areaid, 7933, 5299);
  274.     }
  275.    
  276.     NTC_FindUnit(1, GetLocaleString(2853), 10);
  277.     NTCS_ClearPosition(40, DistanceSort);
  278.     NTA_KillMonster(GetLocaleString(2853)); // Infector of Souls
  279.     NTCS_ClearPosition(40, DistanceSort);
  280.     PubSay("Infector dead.");
  281.    
  282.     if(NTConfig_IdInField){
  283.         NT_FieldID();
  284.     }
  285.    
  286.     if (NTC_PutSkill(124, NTC_HAND_RIGHT)) {
  287.         NTC_PingDelay(1000);
  288.     }
  289.    
  290.     return true;
  291. }
  292.  
  293. function NT_OpenSealInt(classid) {
  294.     var warn;
  295.     switch (classid) {
  296.     case 396:
  297.     case 394:
  298.     case 392:
  299.         warn = true;
  300.         break;
  301.     default:
  302.         warn = false;
  303.         break;
  304.     }
  305.    
  306.     var i, seal;
  307.    
  308.     for (i = 0; i < 5; i += 1) {
  309.         NTM_MoveToPresetUnit(me.areaid, 2, classid, classid === 394 ? 5 : 2, classid === 394 ? 5 : 0);
  310.        
  311.         seal = NTC_FindUnit(NTC_UNIT_OBJECT, classid);
  312.        
  313.         if (!seal) {
  314.             return false;
  315.         }
  316.        
  317.         if (seal.mode) { // for pubbies
  318.             if (warn) {
  319.                 PubSay("Don't hit the seals.");
  320.             }
  321.            
  322.             return true;
  323.         }
  324.        
  325.         warn = false;
  326.        
  327.         NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, seal);
  328.         NTC_Delay(classid === 394 ? 1000 : 500);
  329.        
  330.         if (!seal.mode) {
  331.             if (classid === 394 && CheckCollision(seal.x + 15, seal.y)) { // de seis optimization
  332.                 NTM_MoveTo(me.areaid, seal.x + 15, seal.y);
  333.             } else {
  334.                 NTM_MoveTo(me.areaid, seal.x - 5, seal.y - 5);
  335.             }
  336.            
  337.             NTC_Delay(500);
  338.         } else {
  339.             return true;
  340.         }
  341.     }
  342.    
  343.     return false;
  344. }
  345.  
  346. function BO_Party() {
  347.     if (NTConfig_PublicMode) {
  348.         Say("Come get BO.");
  349.         NTC_Delay(1000);
  350.     }
  351.    
  352.     NTP_DoPrecast(true);
  353. }
  354.  
  355. function NTC_GetNextGame() { // move this to ntc
  356.     function Pad(num) {
  357.         if (num < 10) {
  358.             num = 0 + "" + num;
  359.         }
  360.        
  361.         return num;
  362.     }
  363.    
  364.     var i, result, number,
  365.         game = me.gamename;
  366.    
  367.     for (i = game.length - 1; i > -1; i -= 1) {
  368.         if (isNaN(game[i])) {
  369.             break;
  370.         }
  371.     }
  372.    
  373.     result = game.substring(0, i + 1);
  374.     number = parseInt(game.substring(i + 1), 10) === 99 ? 0 : (parseInt(game.substring(i + 1), 10) + 1); // 99 correction
  375.     result += Pad(number);
  376.    
  377.     return result;
  378. }
  379.  
  380. //
  381.  
  382. function NTA_MonsterStats(unit) {
  383.     this.name = unit.name;
  384.     this.x = unit.x;
  385.     this.y = unit.y;
  386.     this.gid = unit.gid;
  387.     this.classid = unit.classid;
  388.     this.spectype = unit.spectype;
  389. }
  390.  
  391. function DistanceSort(unitA, unitB) {
  392.     if (GetDistance(me.x, me.y, unitA.x, unitA.y) < GetDistance(me.x, me.y, unitB.x, unitB.y)) {
  393.         return -1;
  394.     }
  395.    
  396.     return 1;
  397. }
  398.  
  399. function EntranceSort(unitA, unitB) {
  400.     if (GetDistance(unitA.x, unitA.y, 7790, 5544) < GetDistance(unitB.x, unitB.y, 7790, 5544)) {
  401.         return -1;
  402.     }
  403.    
  404.     return 1;
  405. }
  406.  
  407. function SealSort(unitA, unitB) {  
  408.     if (GetDistance(unitA.x, unitA.y, 7784, 5310) < GetDistance(unitB.x, unitB.y, 7784, 5310)) {
  409.         return -1;
  410.     }
  411.    
  412.     return 1;
  413. }
  414.  
  415. function SealSortB(unitA, unitB) { 
  416.     if (GetDistance(unitA.x, unitA.y, 7800, 5255) < GetDistance(unitB.x, unitB.y, 7800, 5255)) {
  417.         return -1;
  418.     }
  419.    
  420.     return 1;
  421. }
  422.  
  423. function NTCS_Preattack(name) {
  424.     var i, target;
  425.    
  426.     switch (me.classid) {
  427.         case 0:
  428.             break;
  429.         case 1:
  430.             break;
  431.         case 2:
  432.             break;
  433.         case 3:
  434.             NTC_FindUnit(1, name, 10); // don't wait for other classes
  435.            
  436.             if (!target) {
  437.                 return;
  438.             }
  439.            
  440.             if (CheckCollision(me.areaid, target.x + 6, target.y + 10, 1)) { // check if we can move there
  441.                 NTM_MoveTo(me.areaid, target.x + 6, target.y + 10);
  442.                 NTC_PutSkill(NTConfig_AttackSkill[2], NTC_HAND_RIGHT);
  443.                
  444.                 for (i = 0; i < 7; i += 1) {
  445.                     NTC_CastSkill(NTConfig_AttackSkill[1], 2);
  446.                 }
  447.             }
  448.            
  449.             break;
  450.         case 4:
  451.             NTC_FindUnit(1, name, 10); // don't wait for other classes
  452.            
  453.             if (!target) {
  454.                 return;
  455.             }
  456.            
  457.             if (CheckCollision(me.areaid, target.x, target.y + 10, 1)) { // check if we can move there
  458.                 NTM_MoveTo(me.areaid, target.x, target.y + 10);
  459.                
  460.                 for (i = 0; i < 2; i += 1) {
  461.                     NTC_CastSkill(130, NTC_HAND_RIGHT);
  462.                     NTC_Delay(150);
  463.                 }
  464.             }
  465.            
  466.             break;
  467.         case 5:
  468.             break;
  469.         case 6:
  470.             break;
  471.         case 7:
  472.             break;
  473.     }
  474. }
  475.  
  476. // general functions
  477.  
  478. function PubTP() {
  479.     if (NTConfig_PublicMode) {
  480.         NTM_MakeTP();
  481.     }
  482. }
  483.  
  484. function PubSay(string) {
  485.     if (NTConfig_PublicMode) {
  486.         Say(string);
  487.     }
  488. }
  489.  
  490. function NTT_CheckPotionSafe() {
  491.     var i, items, hpCheck, mpCheck;
  492.    
  493.     if (NTConfig_BeltColType.indexOf("hp") > -1 || NTConfig_BeltColType.indexOf("mp") > -1) {
  494.         items = me.GetItems();
  495.        
  496.         for (i = 0; i < items.length; i += 1) {
  497.             if (!hpCheck && items[i].mode === 2 && items[i].code.indexOf("hp") > -1) {
  498.                 hpCheck = true;
  499.             }
  500.            
  501.             if (!mpCheck && items[i].mode === 2 && items[i].code.indexOf("mp") > -1) {
  502.                 mpCheck = true;
  503.             }
  504.         }
  505.     }
  506.    
  507.     return !(hpCheck && mpCheck);
  508. }
  509.  
  510. function NTCS_ClearPosition(range, sortFunc) {
  511.     var i, orgx, orgy, monList, skipList, target, result,
  512.         gidAttack = [],
  513.         dodgeIDs = [310, 362],
  514.         attackcount = 0;
  515.        
  516.     if (NTConfig_AttackSkill[1] < 0 || NTConfig_AttackSkill[3] < 0) {
  517.         return false;
  518.     }
  519.    
  520.     switch (arguments.length) {
  521.     case 0:
  522.         range = 20;
  523.     case 1:
  524.         sortFunc = DistanceSort;
  525.         break;
  526.     }
  527.    
  528.     orgx = me.x;
  529.     orgy = me.y;
  530.     skipList = [];
  531.    
  532.     MainLoop : while (attackcount < 300) {
  533.         monList = [];
  534.         target = NTC_FindUnit(NTC_UNIT_MONSTER);
  535.        
  536.         if (target) {
  537.             do {
  538.                 if (skipList.indexOf(target.gid) < 0) {
  539.                     if (target.IsAttackable()) {
  540.                         if (NTA_IsValidMonster(target)) {
  541.                             if (GetDistance(orgx, orgy, target.x, target.y) <= range) {
  542.                                 monList.push(new NTA_MonsterStats(target));
  543.                             }
  544.                            
  545.                             if ((me.classid === 1 || me.classid === 2 || me.classid === 6) && NTConfig_Dodge && GetDistance(me, target) < 7 && dodgeIDs.indexOf(target.classid) > -1) {
  546.                                 NTA_Dodge(target, target.spectype & 0xA ? _NTA_SkillRange[1] : _NTA_SkillRange[3]);
  547.                                 continue MainLoop;
  548.                             }
  549.                         }
  550.                     } else {
  551.                         skipList.push(target.gid);
  552.                     }
  553.                 }
  554.             } while (target.GetNext());
  555.         }
  556.        
  557.         if (monList.length === 0) {
  558.             break;
  559.         }
  560.        
  561.         monList.sort(sortFunc);
  562.        
  563.         target = NTC_FindUnit(NTC_UNIT_MONSTER, monList[0].gid);
  564.        
  565.         if (target && target.IsAttackable()) {
  566.             result = NTA_Attack(target, attackcount % 30 === 0);
  567.            
  568.             switch (result) {
  569.             case 1:
  570.                 skipList.push(target.gid);
  571.                 monList.shift();
  572.                 break;
  573.             case 2:
  574.             case 3:
  575.                 if(!gidAttack[target.gid]) {
  576.                     gidAttack[target.gid] = 0;
  577.                 }
  578.                
  579.                 gidAttack[target.gid] += 1;
  580.                
  581.                 if (gidAttack[target.gid] > NTConfig_LowMaxAttacks) {
  582.                     Print(COLOR_1 + "Skipping " + target.name);
  583.                     monList.shift();
  584.                     skipList.push(target.gid);
  585.                 }
  586.                
  587.                 attackcount += 1;
  588.                
  589.                 if (target.mode === 0 || target.mode === 12) {
  590.                     NTSI_FastPick();
  591.                 }
  592.                
  593.                 break;
  594.             default:
  595.                 return false;
  596.             }
  597.         } else {
  598.             monList.shift();
  599.         }
  600.     }
  601.    
  602.     switch (me.classid) {
  603.         case NTC_CHAR_CLASS_PALADIN:
  604.             if (attackcount > 2 && (parseInt(me.hp * 100/ me.hpmax) < NTConfig_UseRedemptionHP || parseInt(me.mp * 100 / me.mpmax) < NTConfig_UseRedemptionMP)) {
  605.                 if (NTC_PutSkill(124, NTC_HAND_RIGHT)) {
  606.                     NTC_PingDelay(1000);
  607.                 }
  608.             }
  609.            
  610.             break;
  611.         case NTC_CHAR_CLASS_NECROMANCER:
  612.             if (typeof(NTA_SkeletonArmy) === 'function') {
  613.                 NTA_SkeletonArmy(NTConfig_SkeletonArmy);
  614.                 NTA_MageArmy(NTConfig_MageArmy);
  615.                 NTA_ReviveArmy(NTConfig_ReviveArmy);
  616.             } else {
  617.                 NTA_RaiseArmy();
  618.             }
  619.            
  620.             break;
  621.         case NTC_CHAR_CLASS_SORCERESS:
  622.             if (me.GetState(30) === 0) {
  623.                 NTC_CastSkill(58, NTC_HAND_RIGHT);
  624.             }
  625.            
  626.             break;
  627.         case NTC_CHAR_CLASS_BARBARIAN:
  628.             if (attackcount > 0) {
  629.                 if (NTConfig_UseFindItem && !NTA_CheckForCloseMonsters(10)) {
  630.                     NTA_FindItem(NTConfig_FindItemRange);
  631.                 }
  632.             }
  633.            
  634.             break;
  635.     }
  636.    
  637.     if (!NTC_GetMerc()) {
  638.         Print(COLOR_1 + "Merc died, going to town.");
  639.         NTTMGR_VisitTown();
  640.     }
  641.    
  642.     if (NTT_CheckPotionSafe()) {
  643.         Print(COLOR_1 + "Out of potions, going to town.");
  644.         NTTMGR_VisitTown();
  645.     }
  646.    
  647.     if (NTConfig_IdInField) {
  648.         if (!NTT_CheckSpace(NTConfig_FreeSpaceXY[0], NTConfig_FreeSpaceXY[1])) {
  649.             NT_FieldID();
  650.         }
  651.     }
  652.    
  653.     if (attackcount > 0) {
  654.         NTSI_PickItems();
  655.     }
  656.    
  657.     return true;
  658. }
  659.  
  660. function NTA_Dodge(target, distance) {
  661.     var i, j, coordx, coordy, monster, count,
  662.         maxcount = 999,
  663.         coords = [],
  664.         goodCoords = [],
  665.         monList = [],
  666.         angles = [45, 90, 135, 180, 225, 270, 305, 360];
  667.        
  668.     for (i = 0; i < angles.length; i += 1) {
  669.         coordx = Math.round((Math.cos(angles[i] * Math.PI / 180)) * distance + target.x);
  670.         coordy = Math.round((Math.sin(angles[i] * Math.PI / 180)) * distance + target.y);
  671.        
  672.         if (CheckCollision(me.areaid, coordx, coordy, 1)) {
  673.             coords.push([coordx, coordy]);
  674.         }
  675.     }
  676.    
  677.     if (coords.length === 0) { // no valid positions - don't move
  678.         return true;
  679.     }
  680.    
  681.     coords.sort(NTA_SortRooms);
  682.    
  683.     monster = GetUnit(1);
  684.    
  685.     if (monster) {
  686.         do {
  687.             if (monster.hp > 0) {
  688.                 monList.push(new NTA_MonsterStats(target));
  689.             }
  690.         } while (monster.GetNext());
  691.     }
  692.    
  693.     for (i = 0; i < coords.length; i += 1) {
  694.         count = 0;
  695.        
  696.         for (j = 0; j < monList.length; j += 1) {
  697.             if (monList[j].hp > 0 && GetDistance(monList[j].x, monList[j].y, coords[i][0], coords[i][1]) < 10) {
  698.                 count += 1;
  699.             }
  700.         }
  701.        
  702.         if (count < maxcount) {
  703.             goodCoords = [coords[i][0], coords[i][1]];
  704.             maxcount = count;
  705.            
  706.             if (count === 0) {
  707.                 break;
  708.             }
  709.         }
  710.     }
  711.    
  712.     if (goodCoords.length > 0) { // just in case goodCoords is empty (shouldn't happen)
  713.         if (Math.abs(me.x - goodCoords[0]) < 3 && Math.abs(me.y - goodCoords[1]) < 3) { // close enough
  714.             return true;
  715.         }
  716.        
  717.         Say("!Dodge " + target.name);
  718.         NTM_MoveTo(me.areaid, goodCoords[0], goodCoords[1]);
  719.     }
  720.    
  721.     return true;
  722. }
  723.  
  724. function NTA_SortRooms(a, b) {
  725.     if (GetDistance(me.x, me.y, a[0], a[1]) < GetDistance(me.x, me.y, b[0], b[1])) {
  726.         return -1;
  727.     }
  728.    
  729.     return 1;
  730. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement