Advertisement
kolton

Untitled

Sep 16th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.24 KB | None | 0 0
  1. /*
  2.  
  3. [Item-parser Syntax Information]
  4.  
  5. 1. [Keyword] separates into two groups
  6. - [Property Keywords] : [Type], [Name], [Class], [Quality], [Flag], [Level], [Prefix], [Suffix]
  7. - [Stat Keywords] : [Number or Alias]
  8.  
  9. 2. [Keyword] must be surrounded by '[' and ']'
  10.  
  11. 3. [Property Keywords] must be placed first
  12.  
  13. 4. Insert '#' symbol between [Property Keywords] and [Stat Keywords]
  14.  
  15. 5. Use '+', '-', '*', '/', '(', ')', '&&', '||', '>', '>=', '<', '<=', '==', '!=' symbols for comparison
  16.  
  17. 6. Use '//' symbol for comment
  18.  
  19. */
  20.  
  21. Include("libs/common/NTItemAlias.ntl");
  22.  
  23. var _NTIP_CheckList = [];
  24.  
  25. function NTIPOpenFile(filepath)
  26. {
  27. var _nipfile;
  28. var _line;
  29.  
  30. _nipfile = FileOpen(filepath, 0);
  31.  
  32. if(!_nipfile)
  33. return false;
  34.  
  35. while(!_nipfile.eof)
  36. {
  37. _line = NTIPParseLineInt(_nipfile.ReadLine());
  38.  
  39. if(_line)
  40. _NTIP_CheckList.push(_line);
  41. }
  42.  
  43. _nipfile.Close();
  44.  
  45. return true;
  46. }
  47.  
  48. function NTIPCheckItem(item)
  49. {
  50. item.GetStatEx = function (id, subid) {
  51. var i, desc, string, value;
  52.  
  53. if (this.itemflag & _NTIPAliasFlag["runeword"]) { // some properties are bugged for runewords
  54. if (id === 18 && subid === 0) { // enhanced damage
  55. desc = this.itemdesc;
  56. desc = desc.split("\n");
  57. string = GetLocaleString(10023);
  58.  
  59. for (i = 0; i < desc.length; i += 1) {
  60. if (desc[i].indexOf(string.substring(0, string.length - 1)) > -1) {
  61. value = parseInt(desc[i].split("+")[1].split("%")[0], 10);
  62.  
  63. return value;
  64. }
  65. }
  66. } else if (id === 92 && !subid) { // level requirement
  67. desc = this.itemdesc;
  68. desc = desc.split("\n");
  69. string = GetLocaleString(3469);
  70.  
  71. for (i = 0; i < desc.length; i += 1) {
  72. if (desc[i].indexOf(string) > -1) {
  73. value = parseInt(desc[i].split(string)[1], 10);
  74.  
  75. return value;
  76. }
  77. }
  78. }
  79. }
  80.  
  81. if (id === 204 && subid === 54 && this.itemflag & _NTIPAliasFlag["identified"]) { // teleport charges, doesn't support non-english
  82. desc = this.itemdesc;
  83. desc = desc.split("\n");
  84.  
  85. for (i = 0; desc && i < desc.length; i += 1) {
  86. if (desc[i].indexOf("Teleport") > -1 && desc[i].indexOf("Charges") > -1) {
  87. value = parseInt(desc[i].split("Level ")[1].split(" Charges")[0], 10);
  88.  
  89. return value;
  90. }
  91. }
  92. }
  93.  
  94. if (subid) {
  95. return this.GetStat(id, subid);
  96. }
  97.  
  98. return this.GetStat(id);
  99. }
  100.  
  101. var i;
  102. var _identified;
  103. var _result = 0;
  104.  
  105. _identified = item.itemflag & 0x10;
  106.  
  107. for(i = 0 ; i < _NTIP_CheckList.length ; i++)
  108. {
  109. if(_NTIP_CheckList[i][0].length > 0)
  110. {
  111. if(eval(_NTIP_CheckList[i][0]))
  112. {
  113. if(_NTIP_CheckList[i][1].length > 0)
  114. {
  115. if(eval(_NTIP_CheckList[i][1]))
  116. {
  117. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  118. {
  119. if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0],_NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  120. {
  121. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  122. return 1;
  123. }
  124. else
  125. {
  126. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  127. return 0;
  128. }
  129. }
  130. else
  131. {
  132. //Print("No maximum for this item");
  133. return 1;
  134. }
  135. }
  136. else if(!_identified && _result == 0)
  137. _result = -1;
  138. }
  139. else
  140. {
  141. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  142. {
  143. if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0], null, false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  144. {
  145. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  146. return 1;
  147. }
  148. else
  149. {
  150. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  151. return 0;
  152. }
  153. }
  154. else
  155. {
  156. //Print("No maximum for this item");
  157. return 1;
  158. }
  159. }
  160. }
  161. }
  162. else if(_NTIP_CheckList[i][1].length > 0)
  163. {
  164. if(eval(_NTIP_CheckList[i][1]))
  165. {
  166. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  167. {
  168. if(NTIP_CheckQuantityOwned(null, _NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  169. {
  170. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  171. return 1;
  172. }
  173. else
  174. {
  175. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  176. return 0;
  177. }
  178. }
  179. else
  180. {
  181. return 1;
  182. }
  183. }
  184. else if(!_identified && _result == 0)
  185. _result = -1;
  186. }
  187. }
  188.  
  189. return _result;
  190. }
  191.  
  192. // Internal function
  193. function NTIP_CheckQuantityOwned(item_type, item_stats, check_inventory_too)
  194. {
  195. var _nb = 0;
  196. var _items = me.GetItems();
  197. if (!_items)
  198. {
  199. Print("I can't find my items!");
  200. return 0;
  201. }
  202. for(var i = 0 ; i < _items.length ; i++)
  203. {
  204. if(_items[i].mode == 0 && _items[i].itemloc == 4)
  205. {
  206. var item = _items[i];
  207. if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  208. if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  209. _nb++;
  210. }
  211. else if(check_inventory_too && _items[i].mode == 0 && _items[i].itemloc == 0)
  212. {
  213. var item = _items[i];
  214. if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  215. if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  216. if(NTConfig_Columns[_items[i].y][_items[i].x] > 0) // we check only space that is supposed to be free
  217. _nb++;
  218. }
  219. }
  220. //Print("I have "+_nb+" of these.");
  221. return _nb;
  222. }
  223.  
  224. function NTIPParseLineInt(input)
  225. {
  226. var i;
  227. var _start, _end;
  228. var _section, _keyword;
  229. var _result;
  230.  
  231. _end = input.indexOf("//");
  232. if(_end != -1)
  233. input = input.substring(0, _end);
  234.  
  235. input = input.replace(/ |;|\t/g, "").toLowerCase();
  236.  
  237. if(input.length < 5)
  238. return null;
  239.  
  240. _result = input.split("#");
  241.  
  242. if(_result[0] && _result[0].length > 4)
  243. {
  244. _section = _result[0].split("[");
  245.  
  246. _result[0] = _section[0];
  247.  
  248. for(i = 1 ; i < _section.length ; i++)
  249. {
  250. _end = _section[i].indexOf("]") + 1;
  251.  
  252. switch(_section[i][0])
  253. {
  254. case 't':
  255. _result[0] += "item.itemtype";
  256. break;
  257. case 'n':
  258. _result[0] += "item.classid";
  259. break;
  260. case 'c':
  261. _result[0] += "item.itemclass";
  262. break;
  263. case 'q':
  264. _result[0] += "item.quality";
  265. break;
  266. case 'f':
  267. if(_section[i][_end] == '!')
  268. _result[0] += "!(item.itemflag&";
  269. else
  270. _result[0] += "(item.itemflag&";
  271.  
  272. _end += 2;
  273. break;
  274. case 'l':
  275. _result[0] += "item.itemlevel";
  276. break;
  277. case 'p':
  278. _result[0] += "item.itemprefix";
  279. break;
  280. case 's':
  281. _result[0] += "item.itemsuffix";
  282. break;
  283. default:
  284. Print("Unknown Keyword : " + input);
  285. break;
  286. }
  287.  
  288. for(_start = _end ; _end < _section[i].length ; _end++)
  289. {
  290. if(!NTIPIsSyntaxInt(_section[i][_end]))
  291. break;
  292. }
  293.  
  294. _result[0] += _section[i].substring(_start, _end);
  295.  
  296. for(_start = _end ; _end < _section[i].length ; _end++)
  297. {
  298. if(NTIPIsSyntaxInt(_section[i][_end]))
  299. break;
  300. }
  301.  
  302. _keyword = _section[i].substring(_start, _end);
  303.  
  304. if(isNaN(_keyword))
  305. {
  306. switch(_section[i][0])
  307. {
  308. case 't':
  309. _result[0] += _NTIPAliasType[_keyword];
  310. break;
  311. case 'n':
  312. _result[0] += _NTIPAliasClassID[_keyword];
  313. break;
  314. case 'c':
  315. _result[0] += _NTIPAliasClass[_keyword];
  316. break;
  317. case 'q':
  318. _result[0] += _NTIPAliasQuality[_keyword];
  319. break;
  320. case 'f':
  321. _result[0] += _NTIPAliasFlag[_keyword] + ")";
  322. break;
  323. }
  324. }
  325. else
  326. {
  327. if(_section[i][0] == 'f')
  328. _result[0] += _keyword + ")";
  329. else
  330. _result[0] += _keyword;
  331. }
  332.  
  333. _result[0] += _section[i].substring(_end);
  334. }
  335. }
  336. else
  337. _result[0] = "";
  338.  
  339. if(_result[1] && _result[1].length > 4)
  340. {
  341. _section = _result[1].split("[");
  342. _result[1] = _section[0];
  343.  
  344. for(i = 1 ; i < _section.length ; i++)
  345. {
  346. _end = _section[i].indexOf("]");
  347. _keyword = _section[i].substring(0, _end);
  348.  
  349. if(_keyword.toLowerCase() == "description")
  350. {
  351. _string = _section[i].split("\"")[1];
  352. _result[1] += "(item.itemloc == 0 || item.itemloc == 1) && ";
  353. _result[1] += "item.itemdesc.replace(/ |;|\t/g, \"\").toLowerCase().indexOf(\"" + _string + "\") > -1";
  354. _result[1] += _section[i].split("\"")[2];
  355. }
  356. else
  357. {
  358. if(isNaN(_keyword))
  359. _result[1] += "item.GetStatEx(" + _NTIPAliasStat[_keyword] + ")";
  360. else
  361. _result[1] += "item.GetStatEx(" + _keyword + ")";
  362.  
  363. _result[1] += _section[i].substring(_end+1);
  364. }
  365. }
  366. }
  367. else
  368. _result[1] = "";
  369.  
  370. if(_result[2] && _result[2].replace(/^\s+|\s+$/, "").length > 0)
  371. {
  372. _section = _result[2].split("[");
  373. _result[2] = new Array();
  374.  
  375. for(i = 1 ; i < _section.length ; i++)
  376. {
  377. _end = _section[i].indexOf("]");
  378.  
  379. _keyword = _section[i].substring(0, _end);
  380.  
  381. if(_keyword.toLowerCase().replace(/^\s+|\s+$/, "") == "maxquantity")
  382. {
  383. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").indexOf("//");
  384. if(_end == -1)
  385. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").length;
  386. var _quantity = parseInt(_section[i].split("==")[1].replace(/^\s+|\s+$/, "").substring(0, _end));
  387. _result[2]["MaxQuantity"] = _quantity;
  388. }
  389. else
  390. {
  391. Print("Error in your NIP file : unknown 3rd part keyword.");
  392. }
  393. }
  394. }
  395.  
  396. return _result;
  397. }
  398.  
  399. function NTIPIsSyntaxInt(ch)
  400. {
  401. return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
  402. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement