Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 18th, 2012  |  syntax: None  |  size: 4.51 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.                                                 return 1;
  66.                                         else if(!_identified && _result == 0)
  67.                                                 _result = -1;
  68.                                 }
  69.                                 else
  70.                                         return 1;
  71.                         }
  72.                 }
  73.                 else if(_NTIP_CheckList[i][1].length > 0)
  74.                 {
  75.                         if(eval(_NTIP_CheckList[i][1]))
  76.                                 return 1;
  77.                         else if(!_identified && _result == 0)
  78.                                 _result = -1;
  79.                 }
  80.         }
  81.  
  82.         return _result;
  83. }
  84.  
  85. // Internal function
  86. function NTIPParseLineInt(input)
  87. {
  88.         var i;
  89.         var _start, _end;
  90.         var _section, _keyword;
  91.         var _result;
  92.  
  93.         _end = input.indexOf("//");
  94.         if(_end != -1)
  95.                 input = input.substring(0, _end);
  96.  
  97.         input = input.replace(/ |;/g, "").toLowerCase();
  98.  
  99.         if(input.length < 5)
  100.                 return null;
  101.  
  102.         _result = input.split("#");
  103.  
  104.         if(_result[0] && _result[0].length > 4)
  105.         {
  106.                 _section = _result[0].split("[");
  107.  
  108.                 _result[0] = _section[0];
  109.  
  110.                 for(i = 1 ; i < _section.length ; i++)
  111.                 {
  112.                         _end = _section[i].indexOf("]") + 1;
  113.  
  114.                         switch(_section[i][0])
  115.                         {
  116.                         case 't':
  117.                                 _result[0] += "item.itemtype";
  118.                                 break;
  119.                         case 'n':
  120.                                 _result[0] += "item.classid";
  121.                                 break;
  122.                         case 'c':
  123.                                 _result[0] += "item.itemclass";
  124.                                 break;
  125.                         case 'q':
  126.                                 _result[0] += "item.quality";
  127.                                 break;
  128.                         case 'f':
  129.                                 if(_section[i][_end] == '!')
  130.                                         _result[0] += "!(item.itemflag&";
  131.                                 else
  132.                                         _result[0] += "(item.itemflag&";
  133.  
  134.                                 _end += 2;
  135.                                 break;
  136.                         case 'l':
  137.                                 _result[0] += "item.itemlevel";
  138.                                 break;
  139.                         case 'p':
  140.                                 _result[0] += "item.itemprefix";
  141.                                 break;
  142.                         case 's':
  143.                                 _result[0] += "item.itemsuffix";
  144.                                 break;
  145.                         default:
  146.                                 Print("Unknown Keyword : " + input);
  147.                                 break;
  148.                         }
  149.  
  150.                         for(_start = _end ; _end < _section[i].length ; _end++)
  151.                         {
  152.                                 if(!NTIPIsSyntaxInt(_section[i][_end]))
  153.                                         break;
  154.                         }
  155.  
  156.                         _result[0] += _section[i].substring(_start, _end);
  157.  
  158.                         for(_start = _end ; _end < _section[i].length ; _end++)
  159.                         {
  160.                                 if(NTIPIsSyntaxInt(_section[i][_end]))
  161.                                         break;
  162.                         }
  163.  
  164.                         _keyword = _section[i].substring(_start, _end);
  165.  
  166.                         if(isNaN(_keyword))
  167.                         {
  168.                                 switch(_section[i][0])
  169.                                 {
  170.                                 case 't':
  171.                                         _result[0] += _NTIPAliasType[_keyword];
  172.                                         break;
  173.                                 case 'n':
  174.                                         _result[0] += _NTIPAliasClassID[_keyword];
  175.                                         break;
  176.                                 case 'c':
  177.                                         _result[0] += _NTIPAliasClass[_keyword];
  178.                                         break;
  179.                                 case 'q':
  180.                                         _result[0] += _NTIPAliasQuality[_keyword];
  181.                                         break;
  182.                                 case 'f':
  183.                                         _result[0] += _NTIPAliasFlag[_keyword] + ")";
  184.                                         break;
  185.                                 }
  186.                         }
  187.                         else
  188.                         {
  189.                                 if(_section[i][0] == 'f')
  190.                                         _result[0] += _keyword + ")";
  191.                                 else
  192.                                         _result[0] += _keyword;
  193.                         }
  194.  
  195.                         _result[0] += _section[i].substring(_end);
  196.                 }
  197.         }
  198.         else
  199.                 _result[0] = "";
  200.  
  201.         if(_result[1] && _result[1].length > 4)
  202.         {
  203.                 _section = _result[1].split("[");
  204.  
  205.                 _result[1] = _section[0];
  206.  
  207.                 for(i = 1 ; i < _section.length ; i++)
  208.                 {
  209.                         _end = _section[i].indexOf("]");
  210.  
  211.                         _keyword = _section[i].substring(0, _end);
  212.  
  213.                         if(isNaN(_keyword))
  214.                                 _result[1] += "item.GetStat(" + _NTIPAliasStat[_keyword] + ")";
  215.                         else
  216.                                 _result[1] += "item.GetStat(" + _keyword + ")";
  217.  
  218.                         _result[1] += _section[i].substring(_end+1);
  219.                 }
  220.         }
  221.         else
  222.                 _result[1] = "";
  223.  
  224.         return _result;
  225. }
  226.  
  227. function NTIPIsSyntaxInt(ch)
  228. {
  229.         return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
  230. }