Advertisement
LosDaanos

NTTown

May 20th, 2011
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.57 KB | None | 0 0
  1. var _NTT_BeltColNeeded = new Array(4);
  2. _NTT_BeltColNeeded[0] = 0;
  3. _NTT_BeltColNeeded[1] = 0;
  4. _NTT_BeltColNeeded[2] = 0;
  5. _NTT_BeltColNeeded[3] = 0;
  6.  
  7. var _NTT_BeltSize = 0;
  8.  
  9. var _NTT_OldItems;
  10.  
  11. var _NTT_IgnoredItems = new Array(
  12. "aqv", // Arrows quiver
  13. "cqv", // Bolts quiver
  14. "key", // Keys
  15. "tbk", // Tome of Town Portal
  16. "ibk", // Tome of Identify
  17. "tsc", // Scroll of Town Portal
  18. "isc", // Scroll of Identify
  19. "yps", // Antidote potion
  20. "vps", // Stamina potion
  21. "wms", // Thawing potion
  22. "gps", // Rancid Gas Pot
  23. "ops", // Oil Potion
  24. "gpm", // Choking Gas Pot
  25. "opm", // Exploding Pot
  26. "gpl", // Strangling Gas
  27. "opl", // Fulminating Pot
  28. "hp1","hp2","hp3","hp4","hp5", // Healing potions
  29. "mp1","mp2","mp3","mp4","mp5", // Mana potions
  30. "rvs","rvl"); // Rejuvenation potions
  31.  
  32. // type : 1 = shop, 2 = ressurect, 3 = repair, 4 = potion, 5 = scrolls, 6 = gamble, 7 = ammo, 8 = healing
  33. function NTT_CheckNPC(npc, type)
  34. {
  35. var _npcclassid;
  36.  
  37. if(typeof(npc) == "number")
  38. _npcclassid = npc;
  39. else
  40. _npcclassid = npc.classid;
  41.  
  42. if(type == 1)
  43. {
  44. if(_npcclassid == 147 || _npcclassid == 148 || _npcclassid == 154 || _npcclassid == 177 ||
  45. _npcclassid == 178 || _npcclassid == 199 || _npcclassid == 202 || _npcclassid == 252 ||
  46. _npcclassid == 253 || _npcclassid == 254 || _npcclassid == 255 || _npcclassid == 257 ||
  47. _npcclassid == 405 || _npcclassid == 511 || _npcclassid == 512 || _npcclassid == 513)
  48. return true;
  49. else
  50. return false;
  51. }
  52.  
  53. if(type == 2)
  54. {
  55. if(_npcclassid == 150 || _npcclassid == 198 || _npcclassid == 252 || _npcclassid == 367 || _npcclassid == 515)
  56. return true;
  57. else
  58. return false;
  59. }
  60.  
  61. if(type == 3)
  62. {
  63. if(_npcclassid == 154 || _npcclassid == 178 || _npcclassid == 253 || _npcclassid == 257 || _npcclassid == 511)
  64. return true;
  65. else
  66. return false;
  67. }
  68.  
  69. if(type == 4)
  70. {
  71. if(_npcclassid == 148 || _npcclassid == 177 || _npcclassid == 198 || _npcclassid == 202 ||
  72. _npcclassid == 255 || _npcclassid == 405 || _npcclassid == 513)
  73. return true;
  74. else
  75. return false;
  76. }
  77.  
  78. if(type == 5)
  79. {
  80. if(_npcclassid == 148 || _npcclassid == 177 || _npcclassid == 255 || _npcclassid == 405 || _npcclassid == 513)
  81. return true;
  82. else
  83. return false;
  84. }
  85.  
  86. if(type == 6)
  87. {
  88. if(_npcclassid == 147 || _npcclassid == 199 || _npcclassid == 254 ||
  89. _npcclassid == 405 || _npcclassid == 512 || _npcclassid == 514)
  90. return true;
  91. else
  92. return false;
  93. }
  94.  
  95. if(type == 7)
  96. {
  97. if(_npcclassid == 147 || _npcclassid == 154 || _npcclassid == 178 || _npcclassid == 199 || _npcclassid == 252 ||
  98. _npcclassid == 253 || _npcclassid == 257 || _npcclassid == 511 || _npcclassid == 512)
  99. return true;
  100. else
  101. return false;
  102. }
  103.  
  104. if(type == 8)
  105. {
  106. if(_npcclassid == 148 || _npcclassid == 178 || _npcclassid == 255 || _npcclassid == 513)
  107. return true;
  108. else
  109. return false;
  110. }
  111.  
  112. return false;
  113. }
  114.  
  115. // npc : NPC, stash or cube
  116. function NTT_DoInteract(npc)
  117. {
  118. var _uiflag = 0x08;
  119.  
  120. if(!npc)
  121. return false;
  122.  
  123. if(npc.classid == NTC_UNIT_STASH)
  124. _uiflag = 0x19;
  125. else if(npc.classid == NTC_UNIT_CUBE)
  126. _uiflag = 0x1A;
  127.  
  128. if(GetUIState(_uiflag))
  129. return true;
  130.  
  131. for(var i = 0 ; i < 40 ; i++)
  132. {
  133. if((i % 10) == 0)
  134. {
  135. if(npc.classid == NTC_UNIT_CUBE)
  136. me.ClickItem(1, npc);
  137. else
  138. {
  139. if(i > 10)
  140. me.Cancel(0);
  141.  
  142. NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, npc);
  143. }
  144. }
  145.  
  146. NTC_Delay(200);
  147.  
  148. if(GetUIState(_uiflag))
  149. {
  150. NTC_PingDelay(500);
  151. return true;
  152. }
  153. }
  154.  
  155. return false;
  156. }
  157.  
  158. // type : 0 = shop, 1 = gamble
  159. function NTT_DoTrade(npc, type)
  160. {
  161. if(!npc)
  162. return false;
  163.  
  164. if(GetUIState(0x0C))
  165. return true;
  166.  
  167. if(arguments.length < 2)
  168. type = 0;
  169.  
  170. for(var i = 0 ; i < 20 ; i++)
  171. {
  172. if((i % 10) == 0)
  173. {
  174. if(NTT_CheckNPC(npc.classid, 3))
  175. me.SelectNPCMenu(0x0D06);
  176. else if(type == 1 && NTT_CheckNPC(npc.classid, 6))
  177. me.SelectNPCMenu(0x0D46);
  178. else
  179. me.SelectNPCMenu(0x0D44);
  180. }
  181.  
  182. NTC_Delay(200);
  183.  
  184. if(GetUIState(0x0C))
  185. {
  186. NTC_PingDelay(1000);
  187.  
  188. return true;
  189. }
  190. }
  191.  
  192. return false;
  193. }
  194.  
  195. function NTT_GetCorpses()
  196. {
  197. var _corpse;
  198.  
  199. for(var i = 0 ; i < 4 ; i++)
  200. {
  201. _corpse = NTC_FindUnit(NTC_UNIT_PLAYER);
  202.  
  203. if(_corpse)
  204. {
  205. do
  206. {
  207. if(_corpse.name == me.name && _corpse.hpmax == 0)
  208. {
  209. NTC_SwapWeapons(0);
  210.  
  211. NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, _corpse);
  212.  
  213. NTC_PingDelay(1000);
  214.  
  215. break;
  216. }
  217. } while(_corpse.GetNext());
  218. }
  219. }
  220. }
  221.  
  222. function NTT_CheckMerc()
  223. {
  224. if(NTConfig_UseMerc)
  225. {
  226. if(NTC_GetMerc())
  227. return false;
  228. else
  229. {
  230. if(NTC_MyGold() < me.GetMercCost())
  231. return false;
  232.  
  233. return true;
  234. }
  235. }
  236.  
  237. return false;
  238. }
  239.  
  240. function NTT_ReviveMerc()
  241. {
  242. var _mygold;
  243.  
  244. if(!NTT_CheckMerc())
  245. return true;
  246.  
  247. if(!GetUIState(0x08))
  248. return false;
  249.  
  250. _mygold = NTC_MyGold();
  251.  
  252. if(_mygold < me.GetMercCost())
  253. return false;
  254.  
  255. for(var i = 0 ; i < 8 ; i++)
  256. {
  257. if((i % 4) == 0)
  258. me.SelectNPCMenu(0x1507);
  259.  
  260. NTC_Delay(500);
  261.  
  262. if(_mygold > NTC_MyGold())
  263. return true;
  264. }
  265.  
  266. return false;
  267. }
  268.  
  269. function NTT_ResetWeaponMerc()
  270. {
  271. var i, n;
  272. var _merc, _items;
  273.  
  274. _merc = NTC_GetMerc();
  275.  
  276. if(!_merc)
  277. return false;
  278.  
  279. _items = _merc.GetItems();
  280.  
  281. if(!_items)
  282. return false;
  283.  
  284. for(i = 0 ; i < _items.length ; i++)
  285. {
  286. if(_items[i].itemloc == 4 && (_items[i].itemflag&0x4000000))
  287. {
  288. SetUIState(0x24, true);
  289.  
  290. for(n = 0 ; n < 80 ; n++)
  291. {
  292. if((n % 40) == 0)
  293. me.ClickMercItem(4);
  294.  
  295. NTC_Delay(100);
  296.  
  297. if(me.itemoncursor)
  298. {
  299. NTC_PingDelay(200);
  300. break;
  301. }
  302. }
  303.  
  304. if(n >= 80)
  305. {
  306. me.Cancel(1);
  307. break;
  308. }
  309.  
  310. for(n = 0 ; n < 120 ; n++)
  311. {
  312. if((n % 40) == 0)
  313. me.ClickMercItem(4);
  314.  
  315. NTC_Delay(100);
  316.  
  317. if(!me.itemoncursor)
  318. break;
  319. }
  320.  
  321. me.Cancel(1);
  322.  
  323. if(n < 120)
  324. return true;
  325.  
  326. break;
  327. }
  328. }
  329.  
  330. return false;
  331. }
  332.  
  333. function NTT_CheckRepair(repairpercent)
  334. {
  335. var _max_dur;
  336. var _percent;
  337. var _items = me.GetItems();
  338.  
  339. if(!_items)
  340. return false;
  341.  
  342. for(var i = 0 ; i < _items.length ; i++)
  343. {
  344. if(_items[i].mode == 1 && !(_items[i].itemflag&0x400000) && !_items[i].GetStat(152))
  345. {
  346. if(_items[i].itemtype == 42 || _items[i].itemtype == 43 || _items[i].itemtype == 44 || _items[i].itemtype == 87)
  347. _percent = Math.floor((_items[i].GetStat(70)*100) / (GetBaseStat("weapons.txt", _items[i].classid, 45)+_items[i].GetStat(254)));
  348. else
  349. {
  350. _max_dur = _items[i].GetStat(73);
  351. if(_max_dur == 0)
  352. continue;
  353.  
  354. _percent = Math.floor((_items[i].GetStat(72)*100) / (_max_dur*(_items[i].GetStat(75)/100 + 1)));
  355. }
  356.  
  357. if(_percent <= repairpercent)
  358. return true;
  359. }
  360. }
  361.  
  362. return false;
  363. }
  364.  
  365. function NTT_RepairItems(npc)
  366. {
  367. var _mygold;
  368.  
  369. if(!npc)
  370. return false;
  371.  
  372. if(!GetUIState(0x0C))
  373. return false;
  374.  
  375. _mygold = NTC_MyGold();
  376.  
  377. for(var i = 0 ; i < 8 ; i++)
  378. {
  379. if((i % 4) == 0)
  380. me.Repair();
  381.  
  382. NTC_Delay(500);
  383.  
  384. if(_mygold > NTC_MyGold())
  385. return true;
  386. }
  387.  
  388. return false;
  389. }
  390.  
  391. function NTT_CheckInventory()
  392. {
  393. var x, y;
  394. var _items;
  395.  
  396. _itemlist = new Array();
  397. _ignorestring = _NTT_IgnoredItems.join();
  398.  
  399. if(!NTC_StashGoldFull() && NTC_MyGoldCarry() > NTConfig_MinGoldToStash)
  400. return true;
  401.  
  402. _invspace = new Array(4);
  403. _invspace[0] = new Array(10);
  404. _invspace[1] = new Array(10);
  405. _invspace[2] = new Array(10);
  406. _invspace[3] = new Array(10);
  407.  
  408. for(y = 0 ; y < 4 ; y++)
  409. {
  410. for(x = 0 ; x < 10 ; x++)
  411. _invspace[y][x] = 0;
  412. }
  413.  
  414. _items = me.GetItems();
  415.  
  416. if(!_items)
  417. return false;
  418.  
  419. for(var i = 0 ; i < _items.length ; i++)
  420. {
  421. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  422. {
  423. if(NTConfig_Columns[_items[i].y][_items[i].x] > 0)
  424. _itemlist.push(_items[i].code);
  425.  
  426. for(y = 0 ; y < _items[i].ysize ; y++)
  427. {
  428. for(x = 0 ; x < _items[i].xsize ; x++)
  429. _invspace[y+_items[i].y][x+_items[i].x] = 1;
  430. }
  431. }
  432. }
  433.  
  434. _freecols = new Array(10);
  435.  
  436. for(x = 0 ; x < 10 ; x++)
  437. _freecols[x] = 0;
  438.  
  439. for(x = 0 ; x < 10 ; x++)
  440. {
  441. for(y = 0 ; y < 4 ; y++)
  442. {
  443. if(_invspace[y][x] == 1)
  444. {
  445. _freecols[x] = 1;
  446. break;
  447. }
  448. }
  449. }
  450.  
  451. _numfreecols = 0;
  452.  
  453. for(x = 0 ; x < 10 ; x++)
  454. {
  455. if(_freecols[x] == 0)
  456. _numfreecols++;
  457. }
  458.  
  459. if(NTConfig_FreeSpace > _numfreecols)
  460. {
  461. for(x = 0 ; x < _itemlist.length ; x++)
  462. {
  463. if(_ignorestring.indexOf(_itemlist[x]) != -1)
  464. _itemlist.splice(x, 1);
  465. }
  466.  
  467. if(_itemlist.length > 0)
  468. return true;
  469. }
  470.  
  471. return false;
  472. }
  473.  
  474. function NTT_CheckStash()
  475. {
  476. var x, y;
  477. var _items;
  478. var _StashHeight = (me.gametype == 0) ? 4 : 8;
  479. var _stashspace = new Array(_StashHeight);
  480.  
  481. for(y = 0 ; y < _StashHeight ; y++)
  482. _stashspace[y] = new Array(6);
  483.  
  484. for(y = 0 ; y < _StashHeight ; y++)
  485. {
  486. for(x = 0 ; x < 6 ; x++)
  487. _stashspace[y][x] = 0;
  488. }
  489.  
  490. _items = me.GetItems();
  491.  
  492. if(!_items)
  493. return false;
  494.  
  495. for(var i = 0 ; i < _items.length ; i++)
  496. {
  497. if(_items[i].mode == 0 && _items[i].itemloc == 4)
  498. {
  499. for(y = 0 ; y < _items[i].ysize ; y++)
  500. {
  501. for(x = 0 ; x < _items[i].xsize ; x++)
  502. _stashspace[y+_items[i].y][x+_items[i].x] = 1;
  503. }
  504. }
  505. }
  506.  
  507. for(y = 0 ; y < _StashHeight ; y++)
  508. {
  509. for(x = 0 ; x < 6 ; x++)
  510. {
  511. if(_stashspace[y][x] != 1)
  512. return true;
  513. }
  514. }
  515.  
  516. return false;
  517. }
  518.  
  519. function NTT_ManageStash(invitem)
  520. {
  521. var i, x, y;
  522. var _items;
  523. var _stashall;
  524. var StashHeight = (me.gametype == 0) ? 4 : 8;
  525. var _ignorestring = _NTT_IgnoredItems.join();
  526. var _ignoreitem;
  527.  
  528. if(!GetUIState(0x19))
  529. return false;
  530.  
  531. if(arguments.length < 1)
  532. _stashall = true;
  533. else
  534. _stashall = false;
  535.  
  536. if(!NTC_StashGoldFull() && NTC_MyGoldCarry() > NTConfig_MinGoldToStash)
  537. {
  538. var _mygold = NTC_MyGoldCarry();
  539.  
  540. Gold(3, _mygold);
  541.  
  542. for(i = 0 ; i < 2 ; i++)
  543. {
  544. NTC_Delay(500);
  545.  
  546. if(_mygold > NTC_MyGoldCarry())
  547. break;
  548. }
  549. }
  550.  
  551. var _stashspace = new Array(StashHeight);
  552.  
  553. for(y = 0 ; y < StashHeight ; y++)
  554. _stashspace[y] = new Array(6);
  555.  
  556. for(y = 0 ; y < StashHeight ; y++)
  557. {
  558. for(x = 0 ; x < 6 ; x++)
  559. _stashspace[y][x] = 0;
  560. }
  561.  
  562. _items = me.GetItems();
  563.  
  564. if(!_items)
  565. return false;
  566.  
  567. for(i = 0 ; i < _items.length ; i++)
  568. {
  569. if(_items[i].mode == 0 && _items[i].itemloc == 4)
  570. {
  571. for(y = 0 ; y < _items[i].ysize ; y++)
  572. {
  573. for(x = 0 ; x < _items[i].xsize ; x++)
  574. _stashspace[y+_items[i].y][x+_items[i].x] = 1;
  575. }
  576. }
  577. }
  578.  
  579. for(i = 0 ; i < _items.length ; i++)
  580. {
  581. if(_items[i].mode == 0 && _items[i].itemloc == 0 && (_stashall || (_items[i].x == invitem.x && _items[i].y == invitem.y)))
  582. {
  583. if(_stashall)
  584. {
  585. _ignoreitem = (NTConfig_Columns[_items[i].y][_items[i].x] == 0);
  586.  
  587. if(!_ignoreitem)
  588. {
  589. if( _ignorestring.indexOf(_items[i].code) != -1 || NTSI_CheckItem(_items[i]) <= 0 )
  590. _ignoreitem = true;
  591. }
  592. }
  593. else
  594. _ignoreitem = false;
  595.  
  596. if(!_ignoreitem)
  597. {
  598. _itemdone = false;
  599.  
  600. for(y = 0 ; y < StashHeight ; y++)
  601. {
  602. if(_itemdone)
  603. break;
  604.  
  605. for(x = 0 ; x < 6 ; x++)
  606. {
  607. if(_itemdone)
  608. break;
  609.  
  610. if(_stashspace[y][x] == 0)
  611. {
  612. if((x+_items[i].xsize-1) < 6 && (y+_items[i].ysize-1) < StashHeight)
  613. {
  614. var _havespace = true;
  615.  
  616. for(m = 0 ; m < _items[i].ysize ; m++)
  617. {
  618. for(n = 0 ; n < _items[i].xsize ; n++)
  619. {
  620. if(_stashspace[y+m][x+n] == 1)
  621. {
  622. _havespace = false;
  623. m = 4;
  624. break;
  625. }
  626. }
  627. }
  628.  
  629. if(_havespace)
  630. {
  631. if(NTC_ItemToCursor(_items[i]))
  632. {
  633. for(n = 0 ; n < 80 ; n++)
  634. {
  635. if((n % 40) == 0)
  636. me.ClickItem(0, x, y, 4);
  637.  
  638. NTC_Delay(100);
  639.  
  640. if(!me.itemoncursor)
  641. break;
  642. }
  643.  
  644. if(n < 80)
  645. {
  646. for(m = 0 ; m < _items[i].ysize ; m++)
  647. {
  648. for(n = 0 ; n < _items[i].xsize ; n++)
  649. _stashspace[y+m][x+n] = 1;
  650. }
  651. }
  652.  
  653. NTC_PingDelay(200);
  654. }
  655.  
  656. _itemdone = true;
  657. }
  658. }
  659. }
  660. }
  661. }
  662. }
  663.  
  664. if(!_stashall)
  665. return true;
  666. }
  667. }
  668.  
  669. return true;
  670. }
  671.  
  672. // type : id = 0, tp = 1
  673. function NTT_GetScroll(type)
  674. {
  675. var _items;
  676.  
  677. if(arguments.length < 1)
  678. type = 0;
  679.  
  680. if(type)
  681. _items = me.GetItems(529);
  682. else
  683. _items = me.GetItems(530);
  684.  
  685. if(_items)
  686. {
  687. for(var i = 0 ; i < _items.length ; i++)
  688. {
  689. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  690. return _items[i];
  691. }
  692. }
  693.  
  694. return null;
  695. }
  696.  
  697. // type : id = 0, tp = 1
  698. function NTT_GetTome(type)
  699. {
  700. var _items;
  701.  
  702. if(arguments.length < 1)
  703. type = 0;
  704.  
  705. if(type)
  706. _items = me.GetItems(518);
  707. else
  708. _items = me.GetItems(519);
  709.  
  710. if(_items)
  711. {
  712. for(var i = 0 ; i < _items.length ; i++)
  713. {
  714. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  715. return _items[i];
  716. }
  717. }
  718.  
  719. return null;
  720. }
  721.  
  722. // type : id = 0, tp = 1
  723. function NTT_FillTome(npc, type)
  724. {
  725. var _tome;
  726.  
  727. if(arguments.length < 1)
  728. return false;
  729.  
  730. if(arguments.length < 2)
  731. type = 0;
  732.  
  733. _tome = NTT_GetTome(type);
  734.  
  735. if(_tome)
  736. {
  737. var _items;
  738.  
  739. if(_tome.GetStat(70) >= 20)
  740. return true;
  741.  
  742. if(type)
  743. _items = npc.GetItems(529);
  744. else
  745. _items = npc.GetItems(530);
  746.  
  747. if(_items && _items.length > 0)
  748. return NTT_ShopItem(_items[0], npc, 3);
  749. }
  750.  
  751. return false;
  752. }
  753.  
  754. // type : id = 0, tp = 1
  755. function NTT_BuyScrolls(npc, type, amount)
  756. {
  757. var _items;
  758. var _counter = 0;
  759.  
  760. if(arguments.length < 1)
  761. return false;
  762.  
  763. if(arguments.length < 2)
  764. type = 0;
  765.  
  766. if(arguments.length < 3)
  767. amount = 1;
  768.  
  769. if(amount == 0)
  770. return false;
  771.  
  772. if(type)
  773. _items = npc.GetItems(529);
  774. else
  775. _items = npc.GetItems(530);
  776.  
  777. if(_items && _items.length > 0)
  778. {
  779. for(var i = 0 ; i < amount ; i++)
  780. {
  781. if(NTT_ShopItem(_items[0], npc, 2))
  782. _counter++;
  783. }
  784. }
  785.  
  786. return (_counter > 0);
  787. }
  788.  
  789. function NTT_GetKey()
  790. {
  791. var _items;
  792.  
  793. _items = me.GetItems(543);
  794.  
  795. if(_items)
  796. {
  797. for(var i = 0 ; i < _items.length ; i++)
  798. {
  799. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  800. return _items[i];
  801. }
  802. }
  803.  
  804. return null;
  805. }
  806.  
  807. function NTT_FillKey(npc)
  808. {
  809. var _key;
  810. var _items;
  811.  
  812. if(arguments.length < 1)
  813. return false;
  814.  
  815. _key = NTT_GetKey();
  816.  
  817. if(_key)
  818. {
  819. if(_key.GetStat(70) >= 12)
  820. return true;
  821.  
  822. _items = npc.GetItems(543);
  823.  
  824. if(_items && _items.length > 0)
  825. return NTT_ShopItem(_items[0], npc, 3);
  826. }
  827. else
  828. {
  829. _items = npc.GetItems(543);
  830.  
  831. if(_items && _items.length > 0)
  832. {
  833. NTT_ShopItem(_items[0], npc, 2);
  834. return NTT_ShopItem(_items[0], npc, 3);
  835. }
  836. }
  837.  
  838. return false;
  839. }
  840.  
  841. function NTT_CheckBelt()
  842. {
  843. var _needpotions = false;
  844.  
  845. for(var i = 0 ; i < 4 ; i++)
  846. {
  847. _NTT_BeltColNeeded[i] = NTT_GetNeededPotionsColInt(NTConfig_BeltColType[i], i);
  848.  
  849. if(_NTT_BeltColNeeded[i] > 0 && NTConfig_BeltColType[i] != "rv")
  850. _needpotions = true;
  851. }
  852.  
  853. return _needpotions;
  854. }
  855.  
  856. function NTT_FillBelt(npc)
  857. {
  858. if(!npc)
  859. return false;
  860.  
  861. if(!GetUIState(0x0C))
  862. return false;
  863.  
  864. if(_NTT_BeltSize < 1)
  865. _NTT_BeltSize = NTC_GetBeltSize();
  866.  
  867. if(_NTT_BeltColNeeded[3] == _NTT_BeltSize || _NTT_BeltColNeeded[2] == _NTT_BeltSize || _NTT_BeltColNeeded[1] == _NTT_BeltSize || _NTT_BeltColNeeded[0] == _NTT_BeltSize)
  868. NTT_BuyPotionsSlowInt(npc);
  869. else
  870. NTT_BuyPotionsFastInt(npc);
  871.  
  872. return true;
  873. }
  874.  
  875. function NTT_CheckHeal()
  876. {
  877. var _merc;
  878.  
  879. if(parseInt(me.hp*100/me.hpmax) < NTConfig_SkipHealLife || parseInt(me.mp*100/me.mpmax) < NTConfig_SkipHealMana)
  880. return true;
  881.  
  882. _merc = NTC_GetMerc();
  883.  
  884. if(_merc)
  885. {
  886. if(parseInt(_merc.hp*100/_merc.hpmax) < NTConfig_SkipHealLife)
  887. return true;
  888. }
  889.  
  890. return false;
  891. }
  892.  
  893. function NTT_CheckSpace(itemX, itemY)
  894. {
  895. var i, j, x, y;
  896. var _items;
  897.  
  898. _invspace = new Array(4);
  899. _invspace[0] = new Array(10);
  900. _invspace[1] = new Array(10);
  901. _invspace[2] = new Array(10);
  902. _invspace[3] = new Array(10);
  903.  
  904. for(y = 0 ; y < 4 ; y++)
  905. {
  906. for(x = 0 ; x < 10 ; x++)
  907. _invspace[y][x] = 0;
  908. }
  909.  
  910. _items = me.GetItems();
  911.  
  912. if(!_items)
  913. return false;
  914.  
  915. for(i = 0 ; i < _items.length ; i++)
  916. {
  917. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  918. {
  919. for(y = 0 ; y < _items[i].ysize ; y++)
  920. {
  921. for(x = 0 ; x < _items[i].xsize ; x++)
  922. _invspace[y+_items[i].y][x+_items[i].x] = 1;
  923. }
  924. }
  925. }
  926.  
  927. for(i = 0 ; i < 5-itemY ; i++)
  928. {
  929. invloop2:
  930.  
  931. for(j = 0 ; j < 11-itemX ; j++)
  932. {
  933. for(y = 0 ; y < itemY ; y++)
  934. {
  935. for(x = 0 ; x < itemX ; x++)
  936. {
  937. if(_invspace[i+y][j+x])
  938. continue invloop2;
  939. }
  940. }
  941.  
  942. return true;
  943. }
  944. }
  945.  
  946. return false;
  947. }
  948.  
  949. function NTT_CleanPotions()
  950. {
  951. var _items = me.GetItems();
  952.  
  953. if(!_items)
  954. return;
  955.  
  956. for(var i = 0 ; i < _items.length ; i++)
  957. {
  958. if(_items[i].mode == 0 && _items[i].itemloc == 0 && (_items[i].itemtype == 76 || _items[i].itemtype == 77 || _items[i].itemtype == 78))
  959. {
  960. if(NTConfig_Columns[_items[i].y][_items[i].x] > 0)
  961. {
  962. SetUIState(0x01, true);
  963.  
  964. me.ClickItem(1, _items[i]);
  965.  
  966. NTC_PingDelay(500);
  967. }
  968. }
  969. }
  970.  
  971. me.Cancel(1);
  972. }
  973.  
  974. function NTT_ClearInventory()
  975. {
  976. var _retval = true;
  977. var _ignorestring = _NTT_IgnoredItems.join();
  978. var _items;
  979.  
  980. _items = me.GetItems();
  981.  
  982. if(!_items)
  983. return false;
  984.  
  985. for(var i = 0 ; i < _items.length ; i++)
  986. {
  987. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  988. {
  989. if(NTConfig_Columns[_items[i].y][_items[i].x] > 0)
  990. {
  991. if(_ignorestring.indexOf(_items[i].code) != -1 || NTSI_CheckItem(_items[i]) != 0)
  992. continue;
  993.  
  994. SetUIState(0x01, true);
  995.  
  996. if(NTT_DropItem(_items[i]))
  997. NTC_PingDelay(200);
  998. else
  999. _retval = false;
  1000. }
  1001. }
  1002. }
  1003.  
  1004. me.Cancel(1);
  1005.  
  1006. return _retval;
  1007. }
  1008.  
  1009. function NTT_DropItem(item)
  1010. {
  1011. if(!item)
  1012. return false;
  1013.  
  1014. if(NTC_ItemToCursor(item))
  1015. return NTC_ClearCursor();
  1016.  
  1017. return false;
  1018. }
  1019.  
  1020. function NTT_ClearBelt()
  1021. {
  1022. var i;
  1023. var _result, _needdrop;
  1024. var _items;
  1025.  
  1026. do
  1027. {
  1028. _items = me.GetItems();
  1029.  
  1030. if(!_items)
  1031. {
  1032. _result = false;
  1033. break;
  1034. }
  1035.  
  1036. _result = true;
  1037.  
  1038. for(i = 0 ; i < _items.length ; i++)
  1039. {
  1040. if(_items[i].mode == 2 && _items[i].x < 4)
  1041. {
  1042. _needdrop = false;
  1043.  
  1044. switch(_items[i].itemtype)
  1045. {
  1046. case 76:
  1047. if(NTConfig_BeltColType[_items[i].x] != "hp")
  1048. _needdrop = true;
  1049. break;
  1050. case 77:
  1051. if(NTConfig_BeltColType[_items[i].x] != "mp")
  1052. _needdrop = true;
  1053. break;
  1054. case 78:
  1055. if(NTConfig_BeltColType[_items[i].x] != "rv")
  1056. _needdrop = true;
  1057. break;
  1058. default:
  1059. _needdrop = true;
  1060. break;
  1061. }
  1062.  
  1063. if(_needdrop)
  1064. {
  1065. SetUIState(0x1F, true);
  1066.  
  1067. if(NTT_DropItem(_items[i]))
  1068. NTC_PingDelay(200);
  1069.  
  1070. _result = false;
  1071. }
  1072. }
  1073. }
  1074. } while(!_result);
  1075.  
  1076. me.Cancel(1);
  1077.  
  1078. return _result;
  1079. }
  1080.  
  1081. // mode : 1 = sell, 2 = buy, 3 = shift buy
  1082. function NTT_ShopItem(item, npc, mode)
  1083. {
  1084. var _mygold = NTC_MyGold();
  1085.  
  1086. if(mode > 1)
  1087. {
  1088. if(item.GetItemCost(0, npc.classid) > _mygold)
  1089. return false;
  1090. }
  1091.  
  1092. if(mode > 1)
  1093. {
  1094. var _havespace = false;
  1095.  
  1096. if(item.classid == 529 || item.classid == 530)
  1097. {
  1098. var _book = (item.classid == 530) ? NTT_GetTome(0) : NTT_GetTome(1);
  1099.  
  1100. if(_book && _book.GetStat(70) < 20)
  1101. _havespace = true;
  1102. }
  1103.  
  1104. if(!_havespace)
  1105. {
  1106. if(NTT_CheckSpace(item.xsize, item.ysize))
  1107. _havespace = true;
  1108. }
  1109.  
  1110. if(_havespace)
  1111. {
  1112. for(var i = 0 ; i < 40 ; i++)
  1113. {
  1114. if((i % 20) == 0)
  1115. me.ClickItem(mode > 2 ? 3 : 1, item);
  1116.  
  1117. NTC_Delay(100);
  1118.  
  1119. if(_mygold > NTC_MyGold())
  1120. {
  1121. NTC_PingDelay(500);
  1122. return true;
  1123. }
  1124. }
  1125. }
  1126. }
  1127. else
  1128. {
  1129. if(NTC_ItemToCursor(item))
  1130. {
  1131. for(var i = 0 ; i < 40 ; i++)
  1132. {
  1133. if((i % 20) == 0)
  1134. me.ClickItem(0, 8, 6, 1);
  1135.  
  1136. NTC_Delay(100);
  1137.  
  1138. if(!me.itemoncursor)
  1139. {
  1140. NTC_PingDelay(800);
  1141. return true;
  1142. }
  1143. }
  1144. }
  1145. }
  1146.  
  1147. return false;
  1148. }
  1149.  
  1150. function NTT_IdItem(scroll, uniditem)
  1151. {
  1152. var i, _timer;
  1153.  
  1154. if(arguments.length < 1 || !scroll)
  1155. return false;
  1156.  
  1157. if(arguments.length < 2 || !uniditem)
  1158. return false;
  1159.  
  1160. if(uniditem.itemflag&0x10)
  1161. return true;
  1162.  
  1163. for(i = 0 ; i < 40 ; i++)
  1164. {
  1165. if((i % 20) == 0)
  1166. me.ClickItem(1, scroll);
  1167.  
  1168. NTC_Delay(100);
  1169.  
  1170. if(GetCursorType() == 6)
  1171. break;
  1172. }
  1173.  
  1174. if(i >= 40)
  1175. return false;
  1176.  
  1177. NTC_PingDelay(200);
  1178.  
  1179. for(i = 0 ; i < 40 ; i++)
  1180. {
  1181. if((i % 20) == 0)
  1182. me.ClickItem(0, uniditem);
  1183.  
  1184. NTC_Delay(100);
  1185.  
  1186. if(uniditem.itemflag&0x10)
  1187. {
  1188. NTC_PingDelay(200);
  1189. return true;
  1190. }
  1191. }
  1192.  
  1193. return false;
  1194. }
  1195.  
  1196. function NTT_CheckUnids()
  1197. {
  1198. var _unidcount = 0;
  1199. var _items = me.GetItems();
  1200.  
  1201. if(!_items)
  1202. return _unidcount;
  1203.  
  1204. for(var i = 0 ; i < _items.length ; i++)
  1205. {
  1206. if(_items[i].mode == 0 && _items[i].itemloc == 0 && !(_items[i].itemflag&0x10))
  1207. _unidcount++;
  1208. }
  1209.  
  1210. return _unidcount;
  1211. }
  1212.  
  1213. function NTT_GetUnidItems()
  1214. {
  1215. var _uniditems = new Array();
  1216. var _items = me.GetItems();
  1217.  
  1218. if(!_items)
  1219. return _uniditems;
  1220.  
  1221. for(var i = 0 ; i < _items.length ; i++)
  1222. {
  1223. if(_items[i].mode == 0 && _items[i].itemloc == 0 && !(_items[i].itemflag&0x10))
  1224. _uniditems.push(_items[i]);
  1225. }
  1226.  
  1227. return _uniditems;
  1228. }
  1229.  
  1230. function NTT_GambleIt(npc)
  1231. {
  1232. var _items, _newitem;
  1233.  
  1234. if(!npc)
  1235. return false;
  1236.  
  1237. if(!GetUIState(0x0C))
  1238. return false;
  1239.  
  1240. _items = npc.GetItems();
  1241.  
  1242. if(!_items)
  1243. return false;
  1244.  
  1245. for(var i = 0 ; i < _items.length ; i++)
  1246. {
  1247. if(NTC_MyGold() < NTConfig_GambleStopGold)
  1248. return false;
  1249.  
  1250. if(NTT_IsItemInGambleArrayInt(_items[i].classid))
  1251. {
  1252. if(NTT_CheckSpace(_items[i].xsize, _items[i].ysize))
  1253. {
  1254. NTT_GetOldItemsInt();
  1255.  
  1256. if(NTT_ShopItem(_items[i], npc, 2))
  1257. _newitem = NTT_GetGambledItemInt();
  1258. else
  1259. return false;
  1260.  
  1261. if(_newitem)
  1262. {
  1263. while(!(_newitem.itemflag&0x10))
  1264. NTC_Delay(100);
  1265.  
  1266. switch(NTSI_CheckItem(_newitem))
  1267. {
  1268. case 1:
  1269. NTC_SendLogToOOG(NTC_LOG_ITEM, "Kept " + NTC_ItemQualityToMGRColor[_newitem.quality] + _newitem.name.split("\n")[0] + ";" + _newitem.itemdesc);
  1270. case 2:
  1271. break;
  1272. default:
  1273. NTT_ShopItem(_newitem, npc, 1);
  1274. break;
  1275. }
  1276. }
  1277. }
  1278. }
  1279. }
  1280.  
  1281. return true;
  1282. }
  1283.  
  1284. // Internal function
  1285. function NTT_IsItemInGambleArrayInt(classid)
  1286. {
  1287. for(var i = 0 ; i < NTConfig_GambleItem.length ; i++)
  1288. {
  1289. if(classid == NTConfig_GambleItem[i])
  1290. return true;
  1291. }
  1292.  
  1293. return false;
  1294. }
  1295.  
  1296. function NTT_GetPotionAtNPCInt(type, npc)
  1297. {
  1298. var _items;
  1299.  
  1300. if(!type)
  1301. return null;
  1302.  
  1303. if(type == "hp" || type == "mp")
  1304. {
  1305. _items = npc.GetItems();
  1306.  
  1307. if(_items)
  1308. {
  1309. var n;
  1310.  
  1311. for(var i = 0 ; i < _items.length ; i++)
  1312. {
  1313. for(n = 5 ; n > 0 ; n--)
  1314. {
  1315. if(_items[i].code == (type+n))
  1316. return _items[i];
  1317. }
  1318. }
  1319. }
  1320. }
  1321. else
  1322. {
  1323. if(type == "rv")
  1324. return null;
  1325.  
  1326. _items = npc.GetItems(type);
  1327.  
  1328. if(_items && _items.length > 0)
  1329. return _items[0];
  1330. }
  1331.  
  1332. return null;
  1333. }
  1334.  
  1335. function NTT_BuyPotionsFastInt(npc)
  1336. {
  1337. var i, n;
  1338. var _insert, _potion;
  1339. var _typearray = new Array();
  1340.  
  1341. for(i = 0 ; i < 4 ; i++)
  1342. {
  1343. if(_NTT_BeltColNeeded[i] > 0)
  1344. {
  1345. if(_typearray.length == 0)
  1346. _typearray.push(NTConfig_BeltColType[i]);
  1347. else
  1348. {
  1349. _insert = true;
  1350.  
  1351. for(n = 0 ; n < _typearray.length ; n++)
  1352. {
  1353. if(_typearray[n] == NTConfig_BeltColType[i])
  1354. _insert = false;
  1355. }
  1356.  
  1357. if(_insert)
  1358. _typearray.push(NTConfig_BeltColType[i]);
  1359. }
  1360. }
  1361. }
  1362.  
  1363. for(i = 0 ; i < _typearray.length ; i++)
  1364. {
  1365. if(_typearray[i] == "rv")
  1366. continue;
  1367.  
  1368. _potion = NTT_GetPotionAtNPCInt(_typearray[i], npc);
  1369.  
  1370. if(_potion)
  1371. {
  1372. if(NTT_ShopItem(_potion, npc, 3))
  1373. continue;
  1374. else
  1375. return false;
  1376. }
  1377. else
  1378. return false;
  1379. }
  1380.  
  1381. return true;
  1382. }
  1383.  
  1384. function NTT_BuyPotionsColInt(npc, col)
  1385. {
  1386. var _numpotions;
  1387. var _potion;
  1388.  
  1389. if(col < 0 || col > 3)
  1390. return false;
  1391.  
  1392. if(NTConfig_BeltColType[col] == "rv")
  1393. return false;
  1394.  
  1395. _numpotions = _NTT_BeltColNeeded[col];
  1396.  
  1397. if(_numpotions == 0)
  1398. return false;
  1399.  
  1400. if(_numpotions > _NTT_BeltSize)
  1401. _numpotions = _NTT_BeltSize;
  1402.  
  1403. for(var _buyloop = 0 ; _buyloop < _numpotions ; _buyloop++)
  1404. {
  1405. _potion = NTT_GetPotionAtNPCInt(NTConfig_BeltColType[col], npc);
  1406.  
  1407. if(_potion)
  1408. NTT_ShopItem(_potion, npc, 2);
  1409. else
  1410. return false;
  1411. }
  1412.  
  1413. return true;
  1414. }
  1415.  
  1416. function NTT_BuyPotionsSlowInt(npc)
  1417. {
  1418. var _currentcol;
  1419.  
  1420. for(_currentcol = 0 ; _currentcol < 4 ; _currentcol++)
  1421. {
  1422. if(_NTT_BeltColNeeded[_currentcol] == _NTT_BeltSize)
  1423. {
  1424. NTT_BuyPotionsColInt(npc, _currentcol);
  1425. _NTT_BeltColNeeded[_currentcol] = 0;
  1426. }
  1427. }
  1428.  
  1429. for(_currentcol = 0 ; _currentcol < 4 ; _currentcol++)
  1430. NTT_BuyPotionsColInt(npc, _currentcol);
  1431.  
  1432. return true;
  1433. }
  1434.  
  1435. function NTT_GetNeededPotionsColInt(type, column)
  1436. {
  1437. var _restartloop = true;
  1438. var _amountneeded = 0;
  1439. var _items;
  1440.  
  1441. if(!type || column > 3)
  1442. return false;
  1443.  
  1444. if(_NTT_BeltSize < 1)
  1445. _NTT_BeltSize = NTC_GetBeltSize();
  1446.  
  1447. potionloop:
  1448. do
  1449. {
  1450. _amountneeded = _NTT_BeltSize;
  1451.  
  1452. _items = me.GetItems();
  1453.  
  1454. if(!_items)
  1455. continue potionloop;
  1456.  
  1457. for(i = 0 ; i < _items.length ; i++)
  1458. {
  1459. if(_items[i].mode == 2)
  1460. {
  1461. if(NTT_PotInRightColInt(_items[i].x, column, _NTT_BeltSize))
  1462. {
  1463. var _potcode = _items[i].code;
  1464.  
  1465. if(_potcode.indexOf(type) != -1)
  1466. _amountneeded--;
  1467. else
  1468. {
  1469. if(_potcode.indexOf("rv") != -1)
  1470. {
  1471. if(_items[i].x < 4)
  1472. {
  1473. me.Cancel(1);
  1474. return 0;
  1475. }
  1476. else
  1477. _amountneeded--;
  1478. }
  1479. else
  1480. {
  1481. SetUIState(0x1F, true);
  1482.  
  1483. me.ClickItem(1, _items[i]);
  1484.  
  1485. NTC_PingDelay(500);
  1486. continue potionloop;
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492.  
  1493. _restartloop = false;
  1494. } while(_restartloop);
  1495.  
  1496. me.Cancel(1);
  1497.  
  1498. return _amountneeded;
  1499. }
  1500.  
  1501. function NTT_PotInRightColInt(potx, column, beltsize)
  1502. {
  1503. for(var i = 0 ; i < beltsize ; i++)
  1504. {
  1505. if(potx-i*4 == column)
  1506. return true;
  1507. }
  1508.  
  1509. return false;
  1510. }
  1511.  
  1512. function NTT_GetGambledItemInt()
  1513. {
  1514. var i, n;
  1515. var _items;
  1516. var _founditem;
  1517.  
  1518. _items = me.GetItems();
  1519.  
  1520. if(!_items)
  1521. return null;
  1522.  
  1523. for(i = 0 ; i < _items.length ; i++)
  1524. {
  1525. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  1526. {
  1527. _founditem = true;
  1528.  
  1529. for(n = 0 ; n < _NTT_OldItems.length ; n++)
  1530. {
  1531. if(_items[i].gid == _NTT_OldItems[n])
  1532. {
  1533. _founditem = false;
  1534. break;
  1535. }
  1536. }
  1537.  
  1538. if(_founditem)
  1539. return _items[i];
  1540. }
  1541. }
  1542.  
  1543. return null;
  1544. }
  1545.  
  1546. function NTT_GetOldItemsInt()
  1547. {
  1548. var _items;
  1549.  
  1550. _NTT_OldItems = new Array();
  1551.  
  1552. _items = me.GetItems();
  1553.  
  1554. if(!_items)
  1555. return false;
  1556.  
  1557. for(var i = 0 ; i < _items.length ; i++)
  1558. {
  1559. if(_items[i].mode == 0 && _items[i].itemloc == 0)
  1560. _NTT_OldItems.push(_items[i].gid);
  1561. }
  1562.  
  1563. return true;
  1564. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement