Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 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 = new Array();
  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. var i;
  51. var _identified;
  52. var _result = 0;
  53.  
  54. _identified = item.itemflag & 0x10;
  55.  
  56. for(i = 0 ; i < _NTIP_CheckList.length ; i++)
  57. {
  58. if(_NTIP_CheckList[i][0].length > 0)
  59. {
  60. if(eval(_NTIP_CheckList[i][0]))
  61. {
  62. if(_NTIP_CheckList[i][1].length > 0)
  63. {
  64. if(eval(_NTIP_CheckList[i][1]))
  65. {
  66. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  67. {
  68. if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0],_NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  69. {
  70. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  71. return 1;
  72. }
  73. else
  74. {
  75. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  76. return 0;
  77. }
  78. }
  79. else
  80. {
  81. //Print("No maximum for this item");
  82. return 1;
  83. }
  84. }
  85. else if(!_identified && _result == 0)
  86. _result = -1;
  87. }
  88. else
  89. {
  90. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  91. {
  92. if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0], null, false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  93. {
  94. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  95. return 1;
  96. }
  97. else
  98. {
  99. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  100. return 0;
  101. }
  102. }
  103. else
  104. {
  105. //Print("No maximum for this item");
  106. return 1;
  107. }
  108. }
  109. }
  110. }
  111. else if(_NTIP_CheckList[i][1].length > 0)
  112. {
  113. if(eval(_NTIP_CheckList[i][1]))
  114. {
  115. if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
  116. {
  117. if(NTIP_CheckQuantityOwned(null, _NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
  118. {
  119. //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  120. return 1;
  121. }
  122. else
  123. {
  124. //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  125. return 0;
  126. }
  127. }
  128. else
  129. {
  130. return 1;
  131. }
  132. }
  133. else if(!_identified && _result == 0)
  134. _result = -1;
  135. }
  136. }
  137.  
  138. return _result;
  139. }
  140.  
  141. // Internal function
  142. function NTIP_CheckQuantityOwned(item_type, item_stats, check_inventory_too)
  143. {
  144. var _nb = 0;
  145. var _items = me.GetItems();
  146. if (!_items)
  147. {
  148. Print("I can't find my items!");
  149. return 0;
  150. }
  151. for(var i = 0 ; i < _items.length ; i++)
  152. {
  153. if(_items[i].mode == 0 && _items[i].itemloc == 4)
  154. {
  155. var item = _items[i];
  156. if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  157. if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  158. _nb++;
  159. }
  160. else if(check_inventory_too && _items[i].mode == 0 && _items[i].itemloc == 0)
  161. {
  162. var item = _items[i];
  163. if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  164. if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  165. if(NTConfig_Columns[_items[i].y][_items[i].x] > 0) // we check only space that is supposed to be free
  166. _nb++;
  167. }
  168. }
  169. //Print("I have "+_nb+" of these.");
  170. return _nb;
  171. }
  172.  
  173. function NTIPParseLineInt(input)
  174. {
  175. var i;
  176. var _start, _end;
  177. var _section, _keyword;
  178. var _result;
  179.  
  180. _end = input.indexOf("//");
  181. if(_end != -1)
  182. input = input.substring(0, _end);
  183.  
  184. input = input.replace(/ |;|\t/g, "").toLowerCase();
  185.  
  186. if(input.length < 5)
  187. return null;
  188.  
  189. _result = input.split("#");
  190.  
  191. if(_result[0] && _result[0].length > 4)
  192. {
  193. _section = _result[0].split("[");
  194.  
  195. _result[0] = _section[0];
  196.  
  197. for(i = 1 ; i < _section.length ; i++)
  198. {
  199. _end = _section[i].indexOf("]") + 1;
  200.  
  201. switch(_section[i][0])
  202. {
  203. case 't':
  204. _result[0] += "item.itemtype";
  205. break;
  206. case 'n':
  207. _result[0] += "item.classid";
  208. break;
  209. case 'c':
  210. _result[0] += "item.itemclass";
  211. break;
  212. case 'q':
  213. _result[0] += "item.quality";
  214. break;
  215. case 'f':
  216. if(_section[i][_end] == '!')
  217. _result[0] += "!(item.itemflag&";
  218. else
  219. _result[0] += "(item.itemflag&";
  220.  
  221. _end += 2;
  222. break;
  223. case 'l':
  224. _result[0] += "item.itemlevel";
  225. break;
  226. case 'p':
  227. _result[0] += "item.itemprefix";
  228. break;
  229. case 's':
  230. _result[0] += "item.itemsuffix";
  231. break;
  232. default:
  233. Print("Unknown Keyword : " + input);
  234. break;
  235. }
  236.  
  237. for(_start = _end ; _end < _section[i].length ; _end++)
  238. {
  239. if(!NTIPIsSyntaxInt(_section[i][_end]))
  240. break;
  241. }
  242.  
  243. _result[0] += _section[i].substring(_start, _end);
  244.  
  245. for(_start = _end ; _end < _section[i].length ; _end++)
  246. {
  247. if(NTIPIsSyntaxInt(_section[i][_end]))
  248. break;
  249. }
  250.  
  251. _keyword = _section[i].substring(_start, _end);
  252.  
  253. if(isNaN(_keyword))
  254. {
  255. switch(_section[i][0])
  256. {
  257. case 't':
  258. _result[0] += _NTIPAliasType[_keyword];
  259. break;
  260. case 'n':
  261. _result[0] += _NTIPAliasClassID[_keyword];
  262. break;
  263. case 'c':
  264. _result[0] += _NTIPAliasClass[_keyword];
  265. break;
  266. case 'q':
  267. _result[0] += _NTIPAliasQuality[_keyword];
  268. break;
  269. case 'f':
  270. _result[0] += _NTIPAliasFlag[_keyword] + ")";
  271. break;
  272. }
  273. }
  274. else
  275. {
  276. if(_section[i][0] == 'f')
  277. _result[0] += _keyword + ")";
  278. else
  279. _result[0] += _keyword;
  280. }
  281.  
  282. _result[0] += _section[i].substring(_end);
  283. }
  284. }
  285. else
  286. _result[0] = "";
  287.  
  288. if(_result[1] && _result[1].length > 4)
  289. {
  290. _section = _result[1].split("[");
  291.  
  292. _result[1] = _section[0];
  293.  
  294. for(i = 1 ; i < _section.length ; i++)
  295. {
  296. _end = _section[i].indexOf("]");
  297.  
  298. _keyword = _section[i].substring(0, _end);
  299.  
  300. if(isNaN(_keyword))
  301. _result[1] += "item.GetStat(" + _NTIPAliasStat[_keyword] + ")";
  302. else
  303. _result[1] += "item.GetStat(" + _keyword + ")";
  304.  
  305. _result[1] += _section[i].substring(_end+1);
  306. }
  307. }
  308. else
  309. _result[1] = "";
  310.  
  311. if(_result[2] && _result[2].replace(/^\s+|\s+$/, "").length > 0)
  312. {
  313. _section = _result[2].split("[");
  314. _result[2] = new Array();
  315.  
  316. for(i = 1 ; i < _section.length ; i++)
  317. {
  318. _end = _section[i].indexOf("]");
  319.  
  320. _keyword = _section[i].substring(0, _end);
  321.  
  322. if(_keyword.toLowerCase().replace(/^\s+|\s+$/, "") == "maxquantity")
  323. {
  324. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").indexOf("//");
  325. if(_end == -1)
  326. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").length;
  327. var _quantity = parseInt(_section[i].split("==")[1].replace(/^\s+|\s+$/, "").substring(0, _end));
  328. _result[2]["MaxQuantity"] = _quantity;
  329. }
  330. else
  331. {
  332. Print("Error in your NIP file : unknown 3rd part keyword.");
  333. }
  334. }
  335. }
  336.  
  337. return _result;
  338. }
  339.  
  340. function NTIPIsSyntaxInt(ch)
  341. {
  342. return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement