Advertisement
dzik

Diablo 2 - ETAL - NTItemParser.ntl

Jun 22nd, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // no colors to convert
  2. /*
  3.  
  4. [Item-parser Syntax Information]
  5.  
  6. 1. [Keyword] separates into three groups
  7.    - [Property Keywords] : [Type], [Name], [Class], [Quality], [Flag], [Level], [Prefix], [Suffix]
  8.    - [Stat Keywords] : [Number or Alias]
  9.    - [Quantity Keywords] : [MaxQuantity]
  10.  
  11. 2. [Keyword] must be surrounded by '[' and ']'
  12.  
  13. 3. [Property Keywords] must be placed first
  14.  
  15. 4. Valid in the Stat section is the keyword description where [description] = "any part of item description" <- must be contained inside quotes
  16.      e.g. [type] == armor && [quality] == magic # [description] == "required level: 25"
  17.  
  18. 5. Insert '#' symbol between [Property Keywords] and [Stat Keywords]
  19.  
  20. 6. Insert '#' symbol between [Stat Keywords] and [Quantity Keywords]
  21.  
  22. 7. Use '+', '-', '*', '/', '(', ')', '&&', '||', '>', '>=', '<', '<=', '==', '!=' symbols for comparison
  23.  
  24. 8. Use '//' symbol for comment
  25.  
  26. */
  27.  
  28. Include("libs/common/NTItemAlias.ntl");
  29. var _NTIP_CheckList = new Array();
  30.  
  31. function NTIPOpenFile(filepath) {
  32.     var _nipfile;
  33.     var _line, _originalLine;
  34.     var _lineNumber = 0;
  35.     var errorCaught = false;
  36.     var item;
  37.     var items = me.GetItems();
  38.     if (items) {
  39.         for(var i = 0 ; i < items.length ; i++) {
  40.             thisItem = items[i];
  41.             item = thisItem;
  42.         }
  43.     } else {
  44.         Print (COLOR_1 + "Fatal Error!  Character stash/inventory/body is all completely empty!");
  45.         Delay(20000);
  46.         return false;
  47.     }
  48.     _nipfile = FileOpen(filepath, 0);
  49.     if (!_nipfile) return false;
  50.     while(!_nipfile.eof) {
  51.         var tempCheckList = new Array();
  52.         _lineNumber++;
  53.         _originalLine = _nipfile.ReadLine();
  54.         _line = NTIPParseLineInt(_originalLine);
  55.         if(_line) {
  56.             tempCheckList.push(_line);
  57.            
  58.             try {
  59.                 if(tempCheckList[0][0].length > 0) if (eval(tempCheckList[0][0]));
  60.                 if(tempCheckList[0][1].length > 0) if (eval(tempCheckList[0][1]));
  61.                 if(tempCheckList[0][2].length > 0) if (eval(tempCheckList[0][2]));
  62.             }
  63.             catch(err) {
  64.                 Print (COLOR_1 + "Error in NIP, line ignored: " + filepath + ", line: " + _lineNumber);
  65.                 errorCaught = true;
  66.                 _line = "";
  67.             }
  68.         }
  69.         if(_line && _line != "") {
  70.             _line.push(filepath);
  71.             _line.push(_lineNumber);
  72.             _NTIP_CheckList.push(_line);
  73.         }
  74.     }
  75.     _nipfile.Close();
  76.     if (errorCaught) Print (COLOR_1 + "Please use the numpad + key to run the NipChecker!");
  77.     return true;
  78. }
  79.  
  80. function NTIPCheckItem(item) {
  81.     var _identified = item.itemflag & 0x10;
  82.     var resultArray = new Array();
  83.     resultArray[0] = 0;
  84.     try {
  85.         for(i = 0 ; i < _NTIP_CheckList.length ; i++) {
  86.             resultArray[1] = _NTIP_CheckList[i][3];
  87.             resultArray[2] = _NTIP_CheckList[i][4];
  88.             if(_NTIP_CheckList[i][0].length > 0) {
  89.                 if(eval(_NTIP_CheckList[i][0])) {
  90.                     if(_NTIP_CheckList[i][1].length > 0) {
  91.                         if(eval(_NTIP_CheckList[i][1])) {return (NTIP_CheckQuantity(item,i,resultArray));}
  92.                         else if(!_identified && resultArray[0] == 0) {resultArray[0] = -1; return resultArray;}
  93.                     }
  94.                     else {return (NTIP_CheckQuantity(item,i,resultArray));}
  95.                 }
  96.             } else if(_NTIP_CheckList[i][1].length > 0) {
  97.                 if(eval(_NTIP_CheckList[i][1])) {return (NTIP_CheckQuantity(item,i,resultArray));}
  98.                 else if(!_identified && resultArray[0] == 0) {resultArray[0] = -1; return resultArray;}
  99.             }
  100.        
  101.         }
  102.     } catch(err) {
  103.         resultArray[0] = 0;
  104.         SendCopyData("D2NT Manager", null, (D2NT_MGR_PRINT_LOG<<16), "NTIPCheckItem: Bad NIP detected: " + _NTIP_CheckList[i][0] + "#" + _NTIP_CheckList[i][1] + "#" + _NTIP_CheckList[i][2] + ": " + _NTIP_CheckList[i][3] + ", " + _NTIP_CheckList[i][4]);
  105.         SendCopyData("D2NT Manager", null, (D2NT_MGR_PRINT_LOG<<16), "    Error: " + err);
  106.     }
  107.     return resultArray;
  108. }
  109.  
  110. function NTIP_CheckQuantity(item,i,resultArray) {
  111.     resultArray[0] = 0;
  112.     if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"])) {
  113.         var phrase0 = _NTIP_CheckList[i][0];
  114.         var phrase1 = _NTIP_CheckList[i][1];
  115.         if (_NTIP_CheckList[i][0].length <= 0) {phrase0=null;}
  116.         if (_NTIP_CheckList[i][1].length <= 0) {phrase1=null;}
  117.         if(NTIP_CheckQuantityOwned(phrase0, phrase1, false) < _NTIP_CheckList[i][2]["MaxQuantity"]) {
  118.             //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
  119.             resultArray[0] = 1;
  120.         } else {
  121.             //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
  122.             resultArray[0] = 0;
  123.         }
  124.     } else {resultArray[0] = 1;}
  125.     return resultArray;
  126. }
  127.                
  128. // Internal function
  129. function NTIP_CheckQuantityOwned(item_type, item_stats, check_inventory_too) {
  130.     var _nb = 0;
  131.     var _items = me.GetItems();
  132.     if (!_items) {
  133.         Print("I can't find my items!");
  134.         return 0;
  135.     }
  136.     for(var i = 0 ; i < _items.length ; i++) {
  137.         if(_items[i].mode == 0 && _items[i].itemloc == 4) {
  138.             var item = _items[i];
  139.             if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  140.                 if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  141.                     _nb++;
  142.         } else if(check_inventory_too && _items[i].mode == 0 && _items[i].itemloc == 0) {
  143.             var item = _items[i];
  144.             if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
  145.                 if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
  146.                     if(NTConfig_Columns[_items[i].y][_items[i].x] > 0) // we check only space that is supposed to be free
  147.                         _nb++;
  148.         }
  149.     }
  150.     //Print("I have "+_nb+" of these.");
  151.     return _nb;
  152. }
  153.  
  154. function NTIPParseLineInt(input) {
  155.     var i;
  156.     var _start, _end;
  157.     var _section, _keyword;
  158.     var _result;
  159.     _end = input.indexOf("//");
  160.     if(_end != -1) input = input.substring(0, _end);
  161.     input = input.replace(/\s+|;/g, "").toLowerCase();
  162.     if(input.length < 5) return null;
  163.     _result = input.split("#");
  164.     if(_result[0] && _result[0].length > 4) {
  165.         _section = _result[0].split("[");
  166.         _result[0] = _section[0];
  167.         for(i = 1 ; i < _section.length ; i++) {
  168.             _end = _section[i].indexOf("]") + 1;
  169.             switch(_section[i][0]) {
  170.             case 't':
  171.                 _result[0] += "item.itemtype";
  172.                 break;
  173.             case 'n':
  174.                 _result[0] += "item.classid";
  175.                 break;
  176.             case 'c':
  177.                 _result[0] += "item.itemclass";
  178.                 break;
  179.             case 'q':
  180.                 _result[0] += "item.quality";
  181.                 break;
  182.             case 'f':
  183.                 if(_section[i][_end] == '!')
  184.                     _result[0] += "!(item.itemflag&";
  185.                 else
  186.                     _result[0] += "(item.itemflag&";
  187.                 _end += 2;
  188.                 break;
  189.             case 'l':
  190.                 _result[0] += "item.itemlevel";
  191.                 break;
  192.             case 'p':
  193.                 _result[0] += "item.itemprefix";
  194.                 break;
  195.             case 's':
  196.                 _result[0] += "item.itemsuffix";
  197.                 break;
  198.             default:
  199.                 Print("Unknown Keyword : " + input);
  200.                 break;
  201.             }
  202.             for(_start = _end ; _end < _section[i].length ; _end++) {
  203.                 if(!NTIPIsSyntaxInt(_section[i][_end]))
  204.                     break;
  205.             }
  206.             _result[0] += _section[i].substring(_start, _end);
  207.             for(_start = _end ; _end < _section[i].length ; _end++) {
  208.                 if(NTIPIsSyntaxInt(_section[i][_end]))
  209.                     break;
  210.             }
  211.             _keyword = _section[i].substring(_start, _end);
  212.             if(isNaN(_keyword)) {
  213.                 switch(_section[i][0]) {
  214.                 case 't':
  215.                     _result[0] += _NTIPAliasType[_keyword];
  216.                     break;
  217.                 case 'n':
  218.                     _result[0] += _NTIPAliasClassID[_keyword];
  219.                     break;
  220.                 case 'c':
  221.                     _result[0] += _NTIPAliasClass[_keyword];
  222.                     break;
  223.                 case 'q':
  224.                     _result[0] += _NTIPAliasQuality[_keyword];
  225.                     break;
  226.                 case 'f':
  227.                     _result[0] += _NTIPAliasFlag[_keyword] + ")";
  228.                     break;
  229.                 }
  230.             } else {
  231.                 if(_section[i][0] == 'f')
  232.                     _result[0] += _keyword + ")";
  233.                 else
  234.                     _result[0] += _keyword;
  235.             }
  236.             _result[0] += _section[i].substring(_end);
  237.             if (_NTIP_UseAdvancedItemTypes) _result[0] = NTIP_ConvertToAdvancedItemTypeSyntax(_result[0]);
  238.         }
  239.     } else _result[0] = "";
  240.     if(_result[1] && _result[1].length > 4) {
  241.         _section = _result[1].split("[");
  242.         _result[1] = _section[0];
  243.         for(i = 1 ; i < _section.length ; i++) {
  244.             _end = _section[i].indexOf("]");
  245.             _keyword = _section[i].substring(0, _end);
  246.             if(_keyword.toLowerCase() == "description") {
  247.                 _string = _section[i].split("\"")[1];
  248.                 _result[1] += "item.itemloc == 0 &&";
  249.                 _result[1] += "item.itemdesc.replace(/ |;|\t/g, \"\").toLowerCase().indexOf(\"" + _string + "\") > -1";
  250.                 _result[1] += _section[i].split("\"")[2];
  251.             } else {           
  252.                 if(isNaN(_keyword))
  253.                     _result[1] += "item.GetStat(" + _NTIPAliasStat[_keyword] + ")";
  254.                 else
  255.                     _result[1] += "item.GetStat(" + _keyword + ")";
  256.                 _result[1] += _section[i].substring(_end+1);
  257.             }
  258.         }
  259.     } else _result[1] = "";
  260.     if(_result[2] && _result[2].replace(/^\s+|\s+$/, "").length > 0) {
  261.         _section = _result[2].split("[");
  262.         _result[2] = new Array();
  263.         for(i = 1 ; i < _section.length ; i++) {
  264.             _end = _section[i].indexOf("]");
  265.             _keyword = _section[i].substring(0, _end);
  266.             if(_keyword.toLowerCase().replace(/^\s+|\s+$/, "") == "maxquantity") {
  267.                 _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").indexOf("//");
  268.                 if(_end == -1)
  269.                     _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").length;
  270.                 var _quantity = parseInt(_section[i].split("==")[1].replace(/^\s+|\s+$/, "").substring(0, _end));
  271.                 _result[2]["MaxQuantity"] = _quantity;
  272.             } else {
  273.                 Print("Error in your NIP file : unknown 3rd part keyword.");
  274.             }
  275.         }
  276.     } else _result[2] = "";
  277.     return _result;
  278. }
  279.  
  280. function NTIPIsSyntaxInt(ch) {
  281.     return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
  282. }
  283.  
  284. function NTIPCheckNipSyntax(line,f) {
  285.     var end, regexp, i, j, k, openp, closep, phrase, keyword, partialEq, leftEq, rightEq, keys, regexp2;
  286.     var subphrase = new Array;
  287.     // if the line is too short, it must be broken
  288.     if (line && line.length <5) {
  289.         NTIPCheckNipSyntaxDisplay(line,f,"Line is too short to contain a valid entry");
  290.         return false;
  291.     }
  292.     // split the line into property, stat and quantity phrases
  293.     regexp = /#/;
  294.     phrase = line.split(regexp);
  295.     if (phrase[3]) {
  296.         NTIPCheckNipSyntaxDisplay(line,f,"Too many phrases in the line");
  297.         return false;
  298.     }
  299.     for (i = 0; i<=2; i++) {
  300.         // make sure a phrase exists before we parse anything
  301.         if (phrase[i]) {
  302.             // if the phrase exists but is too short to be anything, bail out
  303.             if (phrase[i].length <5) {
  304.                 NTIPCheckNipSyntaxDisplay(line,f,"Phrase "+i+" is too short to contain a valid entry");
  305.                 return false;
  306.             }
  307.             // strip out matching sets of regular parens
  308.             regexp = /.*\(.+\).*/;
  309.             while (phrase[i].match(regexp)) {
  310.                 openp = phrase[i].indexOf("(");
  311.                 phrase[i] = phrase[i].substring(0,openp) + phrase[i].substring(openp+1,phrase[i].length);
  312.                 closep = phrase[i].indexOf(")");
  313.                 phrase[i] = phrase[i].substring(0,closep) + phrase[i].substring(closep+1,phrase[i].length);
  314.             }
  315.             // if any parens remain they are mismatched
  316.             regexp = /^.*[\(\)].*$/;
  317.             if (phrase[i].match(regexp)) {
  318.                 NTIPCheckNipSyntaxDisplay(line,f,"Mismatched parens");
  319.                 return false;
  320.             }
  321.             // check for trailing && and ||
  322.             regexp = /(\&\&|\|\|)$/;
  323.             if (phrase[i].match(regexp)) {
  324.                 NTIPCheckNipSyntaxDisplay(line,f,"Trailing conjunction at end of phrase");
  325.                 return false;
  326.             }
  327.             // check for leading && and ||
  328.             regexp = /^(\&\&|\|\|)/;
  329.             if (phrase[i].match(regexp)) {
  330.                 NTIPCheckNipSyntaxDisplay(line,f,"Leading conjunction at end of phrase");
  331.                 return false;
  332.             }
  333.             // split into subphrases based on && and ||
  334.             regexp = /\&\&|\|\|/;
  335.             subphrase[i] = phrase[i].split(regexp);
  336.             for (j = 0; subphrase[i][j]; j++) {
  337.                 // split equations into left and right sides while removing the comparitive
  338.                 regexp = /\=\=|!=|<=|>=|<|>/;
  339.                 partialEq = subphrase[i][j].split(regexp);
  340.                 leftEq = "";
  341.                 rightEq = "";
  342.                 if (partialEq[0] && partialEq[0].length>0) {leftEq = partialEq[0];} else {
  343.                     NTIPCheckNipSyntaxDisplay(line,f,"Invalid Equation");
  344.                     return false;
  345.                 }
  346.                 if (partialEq[1] && partialEq[1].length>0) {rightEq = partialEq[1];} else {
  347.                     NTIPCheckNipSyntaxDisplay(line,f,"Invalid Equation");
  348.                     return false;
  349.                 }
  350.                 // if any comparitives remain they are mismatched
  351.                 regexp = /[=<>]+/;
  352.                 if ((leftEq.match(regexp)) || (rightEq.match(regexp))) {
  353.                     NTIPCheckNipSyntaxDisplay(line,f,"Invalid Comparitive");
  354.                     return false;
  355.                 }
  356.                 // there can only be a left and right side to any equation
  357.                 if (partialEq[2]) {
  358.                     NTIPCheckNipSyntaxDisplay(line,f,"Malformed equation");
  359.                     return false;
  360.                 }
  361.                 // unless enclosed in ""
  362.                 // allow word characters (letters and digits), apostrophes and decimals separated but valid arithmatic operators on the right
  363.                 regexp = /^[\w\.\-\']+([\+,\-,\*,\/][\w|\.\-\']+)*$/;
  364.                 regexp2 = /^\"(.)*\"$/;
  365.                 if (!rightEq.match(regexp) && !rightEq.match(regexp2)) {
  366.                     NTIPCheckNipSyntaxDisplay(line,f,"right side equation syntax error");
  367.                     return false;
  368.                 }
  369.                 // on the left split based on arithmatic operator        
  370.                 regexp = /[\+\-\*\/\%]+/;
  371.                 keys = leftEq.split(regexp);
  372.                 for (k = 0; keys[k]; k++) {
  373.                     // on the left allow numbers with decimals and keywords only
  374.                     regexp = /^[\d\.]+$/;
  375.                     regexp2 = /^\[[a-z0-9]+\]$/;
  376.                     if (!keys[k].match(regexp) && !keys[k].match(regexp2)) {
  377.                         NTIPCheckNipSyntaxDisplay(line,f,"invalid left side equation entry");
  378.                         return false;
  379.                     }
  380.                     // if the entry was a keyword and not a number, validate the keyword against the list
  381.                     if (keys[k].match(regexp2)) {
  382.                         keyword = keys[k].substring(1,keys[k].length-1);
  383.                         if (!NTIPcheckKeyword(keyword,i)) {
  384.                             NTIPCheckNipSyntaxDisplay(line,f,"invalid keyword *"+keyword+"* in segment "+i);
  385.                             return false;
  386.                         }
  387.                     }
  388.                 }
  389.             }
  390.             // check for &&&&, ||||, ||&&, &&||
  391.             if (j < subphrase[i].length) {
  392.                 NTIPCheckNipSyntaxDisplay(line,f,"Invalid Conjunction");
  393.                 return false;
  394.             }
  395.         }
  396.     }
  397.     return true;
  398. }
  399.  
  400. function NTIPcheckKeyword(keyword,i) {
  401.     var k, j;
  402.     var failedKeyword = "";
  403.     var isMember = false;  
  404.     var keywordList = new Array;
  405.     var numeric = false;
  406.     var defined = false;
  407.     keywordList[0] = new Array("name","quality","flag","type","level","prefix","suffix","class");
  408.     keywordList[1] = new Array("description");
  409.     keywordList[2] = new Array("maxquantity");
  410.     for (k=0; k < keywordList[i].length; k++) {
  411.       if (keyword==keywordList[i][k]) {isMember=true;}
  412.     }
  413.     // check stat keywords
  414.     if (i==1) {
  415.         // bypass the check if they are already numeric
  416.         if (keyword.match(/^\d+$/)) {numeric=true;}
  417.         if (_NTIPAliasStat[keyword] || _NTIPAliasStat[keyword]==0) {defined = true;}
  418.         if (defined || numeric) {isMember=true;}
  419.     }
  420.     return(isMember);
  421. }
  422.  
  423. function NTIPCheckNipSyntaxDisplay(line,f,err) {
  424.     var screenDisplay = false;
  425.     if (!f) screenDisplay=true;
  426.     if (screenDisplay) {
  427.         Print (COLOR_3 +"NIP Error detected: Use the numpad '+' key to run the NIP check utility.");
  428.     } else {
  429.         f.WriteLine("NIP Error: "+err);
  430.         f.WriteLine("    "+line);
  431.         f.WriteLine("");
  432.     }
  433. }
  434.  
  435. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  436. //  Begin Advanced Item Types
  437. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438. var _NTIP_UseAdvancedItemTypes = true;
  439. var _NTIP_ItemTypeMappings = {
  440.     /*
  441.         The following mappings indicate that an item of type [key] is also
  442.         of type [value[key]]. i.e. a Scepter is also of types: Weapon,
  443.         MeleeWeapon, StavesAndRods, and Blunt.
  444.  
  445.         * Categorization based on info from the Arreat Summit + common sense
  446.     */
  447.  
  448.     //==== Weapons ====
  449.     24: {45:1,46:1,55:1,57:1}, //scepter
  450.     25: {45:1,46:1,55:1,57:1}, //wand
  451.     26: {45:1,46:1,55:1,57:1}, //staff
  452.     27: {45:1,47:1}, //bow
  453.     28: {45:1,46:1}, //axe
  454.     29: {45:1,46:1,57:1}, //club
  455.     30: {45:1,46:1}, //sword
  456.     31: {45:1,46:1,57:1}, //hammer
  457.     32: {45:1,46:1}, //knife
  458.     33: {45:1,46:1}, //spear
  459.     34: {45:1,46:1}, //polearm
  460.     35: {45:1,47:1}, //crossbow
  461.     36: {45:1,46:1,57:1}, //mace
  462.     38: {45:1,48:1}, //missilepotion
  463.     42: {45:1,48:1}, //throwingknife
  464.     43: {45:1,48:1}, //throwingaxe
  465.     44: {45:1,48:1,33:1}, //javelin
  466.     // 45: {}, //weapon
  467.     // 46: {}, //meleeweapon
  468.     // 47: {}, //missileweapon  // MissileWeapons should NOT include Javelins/Zon-Javelins, despite the AS.
  469.     // 48: {}, //thrownweapon   // The Arreat Summit has conflicting notes on what constitutes "thrown" and
  470.     // 49: {}, //comboweapon    // "combo" weapons, so we will use common sense here. ComboWeapon remains unused.
  471.     // 55: {}, //stavesandrods  // Scepters, Wands, Staves, (Not Orbs?)
  472.     // 57: {}, //blunt          // Unclear, so we will call it anything with the 50% damage to undead auto-mod,
  473.     // 60: {}, //amazonitem     // ^ Scepters, Wands, Staves, Clubs, Hammers, Maces ^
  474.     // 64: {}, //sorceressitem
  475.     // 65: {}, //assassinitem
  476.     67: {59:1,45:1,46:1,65:1}, //handtohand //unskilled
  477.     68: {59:1,45:1,46:1,64:1}, //orb
  478.     85: {59:1,45:1,47:1,27:1,60:1}, //amazonbow
  479.     86: {59:1,45:1,46:1,33:1,60:1}, //amazonspear
  480.     87: {59:1,45:1,48:1,33:1,44:1,60:1}, //amazonjavelin
  481.     88: {59:1,45:1,46:1,65:1}, //assassinclaw //skilled
  482.  
  483.     // 59: {}, //classspecific  //umbrella type
  484.  
  485.     //==== ARMOR ====
  486.     2: {50:1,51:1}, //shield
  487.     3: {50:1}, //armor
  488.     15: {50:1}, //boots
  489.     16: {50:1}, //gloves
  490.     19: {50:1}, //belt
  491.     37: {50:1}, //helm
  492.     // 50: {}, //anyarmor
  493.     // 51: {}, //anyshield
  494.     // 61: {}, //barbarianitem
  495.     // 62: {}, //necromanceritem
  496.     // 63: {}, //paladinitem
  497.     // 66: {}, //druiditem
  498.     69: {59:1,50:1,51:1,62:1}, //voodooheads
  499.     70: {59:1,50:1,51:1,63:1}, //auricshields
  500.     71: {59:1,50:1,37:1,61:1}, //primalhelm
  501.     72: {59:1,50:1,37:1,66:1}, //pelt
  502.  
  503.     //==== MISC ====
  504.     // 4: {}, //gold
  505.     // 5: {}, //bow quiver
  506.     // 6: {}, //crossbow quiver
  507.     // 7: {}, //playerbodypart
  508.     // 8: {}, //herb
  509.     // 9: {}, //potion
  510.     // 10: {}, //ring
  511.     // 11: {}, //elixir
  512.     // 12: {}, //amulet
  513.     // 13: {}, //charm
  514.     // 14: {}, //notused
  515.     // 17: {}, //notused
  516.     // 18: {}, //book
  517.     // 20: {}, //gem
  518.     // 21: {}, //torch
  519.     // 22: {}, //scroll
  520.     // 23: {}, //notused
  521.     // 39: {}, //quest
  522.     // 40: {}, //bodypart
  523.     // 41: {}, //key
  524.     // 52: {}, //miscellaneous
  525.     // 53: {}, //socketfiller
  526.     // 54: {}, //secondhand
  527.     // 56: {}, //missile
  528.     // 58: {}, //jewel
  529.     // 73: {}, //cloak
  530.     // 74: {}, //rune
  531.     // 75: {}, //circlet
  532.     76: {9:1}, //healingpotion
  533.     77: {9:1}, //manapotion
  534.     78: {9:1}, //rejuvpotion
  535.     79: {9:1}, //staminapotion
  536.     80: {9:1}, //antidotepotion
  537.     81: {9:1}, //thawingpotion
  538.     82: {13:1}, //smallcharm
  539.     83: {13:1}, //mediumcharm
  540.     84: {13:1}, //largecharm
  541.     // 89: {}, //magicbowquiv
  542.     // 90: {}, //magicxbowquiv
  543.     // 91: {}, //chippedgem
  544.     // 92: {}, //flawedgem
  545.     // 93: {}, //standardgem
  546.     // 94: {}, //flawlessgem
  547.     // 95: {}, //perfectgem
  548.     96: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //amethyst
  549.     97: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //diamond
  550.     98: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //emerald
  551.     99: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //ruby
  552.     100: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //sapphire
  553.     101: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"}, //topaz
  554.     102: {20:1,91:"item.classid%5==2",92:"item.classid%5==3",93:"item.classid%5==4",94:"item.classid%5==0",95:"item.classid%5==1"} //skull
  555. };
  556.  
  557. function NTIP_CheckItemType(item, type) {
  558.     if (item.itemtype == type) return true;
  559.     var typeHash = _NTIP_ItemTypeMappings[item.itemtype];
  560.     if (typeHash) {
  561.         var isType = typeHash[type];
  562.         if (isType) {
  563.             if (isType == 1) {
  564.                 return true;
  565.             } else {
  566.                 return eval(isType);
  567.             }
  568.         }
  569.     }
  570.     return false;
  571. }
  572.  
  573. function NTIP_ConvertToAdvancedItemTypeSyntax(syntax) {
  574.     return syntax.replace(
  575.         /item\.itemtype==(\d+)/, "NTIP_CheckItemType(item,\$1)").replace(
  576.         /item\.itemtype!=(\d+)/, "!NTIP_CheckItemType(item,\$1)");
  577. }
  578. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  579. //   End Advanced Item Types
  580. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement