Advertisement
kolton

Untitled

Dec 17th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 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("common/NTItemAlias.dbl");
  22.  
  23. var _NTIP_CheckList = new Array();
  24.  
  25. function NTIPOpenFile(filepath)
  26. {
  27. var _nipfile;
  28. var _line;
  29.  
  30. _nipfile = File.open(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.getFlag(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].location == 7)
  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].location == 3)
  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.getFlag(";
  218. else
  219. _result[0] += "item.getFlag(";
  220.  
  221. _end += 2;
  222.  
  223. break;
  224. case 'l':
  225. _result[0] += "item.ilvl";
  226. break;
  227. case 'p':
  228. _result[0] += "item.prefixnum";
  229. break;
  230. case 's':
  231. _result[0] += "item.suffixnum";
  232. break;
  233. default:
  234. print("Unknown Keyword : " + input);
  235. break;
  236. }
  237.  
  238. for(_start = _end ; _end < _section[i].length ; _end++)
  239. {
  240. if(!NTIPIsSyntaxInt(_section[i][_end]))
  241. break;
  242. }
  243.  
  244. _result[0] += _section[i].substring(_start, _end);
  245.  
  246. for(_start = _end ; _end < _section[i].length ; _end++)
  247. {
  248. if(NTIPIsSyntaxInt(_section[i][_end]))
  249. break;
  250. }
  251.  
  252. _keyword = _section[i].substring(_start, _end);
  253.  
  254. if(isNaN(_keyword))
  255. {
  256. switch(_section[i][0])
  257. {
  258. case 't':
  259. _result[0] += _NTIPAliasType[_keyword];
  260. break;
  261. case 'n':
  262. _result[0] += _NTIPAliasClassID[_keyword];
  263. break;
  264. case 'c':
  265. _result[0] += _NTIPAliasClass[_keyword];
  266. break;
  267. case 'q':
  268. _result[0] += _NTIPAliasQuality[_keyword];
  269. break;
  270. case 'f':
  271. _result[0] += _NTIPAliasFlag[_keyword] + ")";
  272. break;
  273. }
  274. }
  275. else
  276. {
  277. if(_section[i][0] == 'f')
  278. _result[0] += _keyword + ")";
  279. else
  280. _result[0] += _keyword;
  281. }
  282.  
  283. _result[0] += _section[i].substring(_end);
  284. }
  285. }
  286. else
  287. _result[0] = "";
  288.  
  289. if(_result[1] && _result[1].length > 4)
  290. {
  291. _section = _result[1].split("[");
  292. _result[1] = _section[0];
  293.  
  294. for(i = 1 ; i < _section.length ; i++)
  295. {
  296. _end = _section[i].indexOf("]");
  297. _keyword = _section[i].substring(0, _end);
  298.  
  299. if(_keyword == "description")
  300. {
  301. var _string = _section[i].split("\"")[1];
  302. _result[1] += "item.location == 3 && ";
  303. _result[1] += "item.description.replace(/ |;|\t/g, \"\").toLowerCase().indexOf(\"" + _string + "\") > -1";
  304. _result[1] += _section[i].split("\"")[2];
  305. }
  306. else
  307. {
  308. if(isNaN(_keyword))
  309. _result[1] += "item.getStatEx(" + _NTIPAliasStat[_keyword] + ")";
  310. else
  311. _result[1] += "item.getStatEx(" + _keyword + ")";
  312.  
  313. _result[1] += _section[i].substring(_end+1);
  314. }
  315. }
  316. }
  317. else
  318. _result[1] = "";
  319.  
  320. if(_result[2] && _result[2].replace(/^\s+|\s+$/, "").length > 0)
  321. {
  322. _section = _result[2].split("[");
  323. _result[2] = new Array();
  324.  
  325. for(i = 1 ; i < _section.length ; i++)
  326. {
  327. _end = _section[i].indexOf("]");
  328.  
  329. _keyword = _section[i].substring(0, _end);
  330.  
  331. if(_keyword.toLowerCase().replace(/^\s+|\s+$/, "") == "maxquantity")
  332. {
  333. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").indexOf("//");
  334. if(_end == -1)
  335. _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").length;
  336. var _quantity = parseInt(_section[i].split("==")[1].replace(/^\s+|\s+$/, "").substring(0, _end));
  337. _result[2]["MaxQuantity"] = _quantity;
  338. }
  339. else
  340. {
  341. print("Error in your NIP file : unknown 3rd part keyword.");
  342. }
  343. }
  344. }
  345.  
  346. return _result;
  347. }
  348.  
  349. function NTIPIsSyntaxInt(ch)
  350. {
  351. return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
  352. }
  353.  
  354. // prototypes
  355.  
  356. Unit.prototype.__defineGetter__('itemclass',
  357. function() {
  358. if (NTC_GetBaseStat(0, this.classid, 'code') === undefined) {
  359. return 0;
  360. }
  361.  
  362. if (NTC_GetBaseStat(0, this.classid, 'code') === NTC_GetBaseStat(0, this.classid, 'ultracode')) {
  363. return 2;
  364. } else if (NTC_GetBaseStat(0, this.classid, 'code') === NTC_GetBaseStat(0, this.classid, 'ubercode')) {
  365. return 1;
  366. } else {
  367. return 0;
  368. }
  369. }
  370. );
  371.  
  372. Unit.prototype.getStatEx = function (ID, subID) {
  373. subID = subID || 0;
  374.  
  375. switch (ID) {
  376. case 31:
  377. if (arguments.length < 2) {
  378. return this.getStat(31);
  379. }
  380.  
  381. break;
  382. case 92:
  383. case 194:
  384. return this.getStat(ID);
  385. }
  386.  
  387. var stats = this.getStat(-2);
  388.  
  389. if (stats[ID] && stats[ID][subID]) {
  390. return stats[ID][subID];
  391. } else {
  392. return 0;
  393. }
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement