Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- [Item-parser Syntax Information]
- 1. [Keyword] separates into two groups
- - [Property Keywords] : [Type], [Name], [Class], [Quality], [Flag], [Level], [Prefix], [Suffix]
- - [Stat Keywords] : [Number or Alias]
- 2. [Keyword] must be surrounded by '[' and ']'
- 3. [Property Keywords] must be placed first
- 4. Insert '#' symbol between [Property Keywords] and [Stat Keywords]
- 5. Use '+', '-', '*', '/', '(', ')', '&&', '||', '>', '>=', '<', '<=', '==', '!=' symbols for comparison
- 6. Use '//' symbol for comment
- */
- Include("libs/common/NTItemAlias.ntl");
- var _NTIP_CheckList = [];
- function NTIPOpenFile(filepath)
- {
- var _nipfile;
- var _line;
- _nipfile = FileOpen(filepath, 0);
- if(!_nipfile)
- return false;
- while(!_nipfile.eof)
- {
- _line = NTIPParseLineInt(_nipfile.ReadLine());
- if(_line)
- _NTIP_CheckList.push(_line);
- }
- _nipfile.Close();
- return true;
- }
- function NTIPCheckItem(item)
- {
- var i;
- var _identified;
- var _result = 0;
- _identified = item.itemflag & 0x10;
- for(i = 0 ; i < _NTIP_CheckList.length ; i++)
- {
- if(_NTIP_CheckList[i][0].length > 0)
- {
- if(eval(_NTIP_CheckList[i][0]))
- {
- if(_NTIP_CheckList[i][1].length > 0)
- {
- if(eval(_NTIP_CheckList[i][1]))
- {
- if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
- {
- if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0],_NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
- {
- //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
- return 1;
- }
- else
- {
- //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
- return 0;
- }
- }
- else
- {
- //Print("No maximum for this item");
- return 1;
- }
- }
- else if(!_identified && _result == 0)
- _result = -1;
- }
- else
- {
- if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
- {
- if(NTIP_CheckQuantityOwned(_NTIP_CheckList[i][0], null, false) < _NTIP_CheckList[i][2]["MaxQuantity"])
- {
- //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
- return 1;
- }
- else
- {
- //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
- return 0;
- }
- }
- else
- {
- //Print("No maximum for this item");
- return 1;
- }
- }
- }
- }
- else if(_NTIP_CheckList[i][1].length > 0)
- {
- if(eval(_NTIP_CheckList[i][1]))
- {
- if(_NTIP_CheckList[i][2] && _NTIP_CheckList[i][2]["MaxQuantity"] && !isNaN(_NTIP_CheckList[i][2]["MaxQuantity"]))
- {
- if(NTIP_CheckQuantityOwned(null, _NTIP_CheckList[i][1], false) < _NTIP_CheckList[i][2]["MaxQuantity"])
- {
- //Print("I need more of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3));
- return 1;
- }
- else
- {
- //Print("I already have enough of these "+NTC_ItemQualityToMGRColor[item.quality] + item.itemdesc.split("\n")[0].substring(3)+" in my stash!");
- return 0;
- }
- }
- else
- {
- return 1;
- }
- }
- else if(!_identified && _result == 0)
- _result = -1;
- }
- }
- return _result;
- }
- // Internal function
- function NTIP_CheckQuantityOwned(item_type, item_stats, check_inventory_too)
- {
- var _nb = 0;
- var _items = me.GetItems();
- if (!_items)
- {
- Print("I can't find my items!");
- return 0;
- }
- for(var i = 0 ; i < _items.length ; i++)
- {
- if(_items[i].mode == 0 && _items[i].itemloc == 4)
- {
- var item = _items[i];
- if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
- if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
- _nb++;
- }
- else if(check_inventory_too && _items[i].mode == 0 && _items[i].itemloc == 0)
- {
- var item = _items[i];
- if((item_type != null && item_type.length > 0 && eval(item_type)) || item_type == null)
- if((item_stats != null && item_stats.length > 0 && eval(item_stats)) || item_stats == null)
- if(NTConfig_Columns[_items[i].y][_items[i].x] > 0) // we check only space that is supposed to be free
- _nb++;
- }
- }
- //Print("I have "+_nb+" of these.");
- return _nb;
- }
- function NTIPParseLineInt(input)
- {
- var i;
- var _start, _end;
- var _section, _keyword;
- var _result;
- _end = input.indexOf("//");
- if(_end != -1)
- input = input.substring(0, _end);
- input = input.replace(/ |;|\t/g, "").toLowerCase();
- if(input.length < 5)
- return null;
- _result = input.split("#");
- if(_result[0] && _result[0].length > 4)
- {
- _section = _result[0].split("[");
- _result[0] = _section[0];
- for(i = 1 ; i < _section.length ; i++)
- {
- _end = _section[i].indexOf("]") + 1;
- switch(_section[i][0])
- {
- case 't':
- _result[0] += "item.itemtype";
- break;
- case 'n':
- _result[0] += "item.classid";
- break;
- case 'c':
- _result[0] += "item.itemclass";
- break;
- case 'q':
- _result[0] += "item.quality";
- break;
- case 'f':
- if(_section[i][_end] == '!')
- _result[0] += "!(item.itemflag&";
- else
- _result[0] += "(item.itemflag&";
- _end += 2;
- break;
- case 'l':
- _result[0] += "item.itemlevel";
- break;
- case 'p':
- _result[0] += "item.itemprefix";
- break;
- case 's':
- _result[0] += "item.itemsuffix";
- break;
- default:
- Print("Unknown Keyword : " + input);
- break;
- }
- for(_start = _end ; _end < _section[i].length ; _end++)
- {
- if(!NTIPIsSyntaxInt(_section[i][_end]))
- break;
- }
- _result[0] += _section[i].substring(_start, _end);
- for(_start = _end ; _end < _section[i].length ; _end++)
- {
- if(NTIPIsSyntaxInt(_section[i][_end]))
- break;
- }
- _keyword = _section[i].substring(_start, _end);
- if(isNaN(_keyword))
- {
- switch(_section[i][0])
- {
- case 't':
- _result[0] += _NTIPAliasType[_keyword];
- break;
- case 'n':
- _result[0] += _NTIPAliasClassID[_keyword];
- break;
- case 'c':
- _result[0] += _NTIPAliasClass[_keyword];
- break;
- case 'q':
- _result[0] += _NTIPAliasQuality[_keyword];
- break;
- case 'f':
- _result[0] += _NTIPAliasFlag[_keyword] + ")";
- break;
- }
- }
- else
- {
- if(_section[i][0] == 'f')
- _result[0] += _keyword + ")";
- else
- _result[0] += _keyword;
- }
- _result[0] += _section[i].substring(_end);
- }
- }
- else
- _result[0] = "";
- if(_result[1] && _result[1].length > 4)
- {
- _section = _result[1].split("[");
- _result[1] = _section[0];
- for(i = 1 ; i < _section.length ; i++)
- {
- _end = _section[i].indexOf("]");
- _keyword = _section[i].substring(0, _end);
- if(_keyword.toLowerCase() == "description")
- {
- _string = _section[i].split("\"")[1];
- _result[1] += "(item.itemloc == 0 || item.itemloc == 1) && ";
- _result[1] += "item.itemdesc.replace(/ |;|\t/g, \"\").toLowerCase().indexOf(\"" + _string + "\") > -1";
- _result[1] += _section[i].split("\"")[2];
- }
- else
- {
- if(isNaN(_keyword))
- _result[1] += "item.GetStatEx(" + _NTIPAliasStat[_keyword] + ")";
- else
- _result[1] += "item.GetStatEx(" + _keyword + ")";
- _result[1] += _section[i].substring(_end+1);
- }
- }
- }
- else
- _result[1] = "";
- if(_result[2] && _result[2].replace(/^\s+|\s+$/, "").length > 0)
- {
- _section = _result[2].split("[");
- _result[2] = new Array();
- for(i = 1 ; i < _section.length ; i++)
- {
- _end = _section[i].indexOf("]");
- _keyword = _section[i].substring(0, _end);
- if(_keyword.toLowerCase().replace(/^\s+|\s+$/, "") == "maxquantity")
- {
- _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").indexOf("//");
- if(_end == -1)
- _end = _section[i].split("==")[1].replace(/^\s+|\s+$/, "").length;
- var _quantity = parseInt(_section[i].split("==")[1].replace(/^\s+|\s+$/, "").substring(0, _end));
- _result[2]["MaxQuantity"] = _quantity;
- }
- else
- {
- Print("Error in your NIP file : unknown 3rd part keyword.");
- }
- }
- }
- return _result;
- }
- function NTIPIsSyntaxInt(ch)
- {
- return (ch == '!' || ch == '%' || ch == '&' || (ch >= '(' && ch <= '+') || ch == '-' || ch == '/' || (ch >= ':' && ch <= '?') || ch == '|');
- }
- // prototypes
- Object.prototype.GetStatEx = function (id, subid) {
- var i, desc, string, value;
- if (this.itemflag & _NTIPAliasFlag["runeword"]) { // some properties are bugged for runewords
- if (id === 18 && subid === 0) { // enhanced damage
- desc = this.itemdesc;
- desc = desc.split("\n");
- string = GetLocaleString(10023);
- for (i = 0; i < desc.length; i += 1) {
- if (desc[i].indexOf(string.substring(0, string.length - 1)) > -1) {
- value = parseInt(desc[i].split("+")[1].split("%")[0], 10);
- return value;
- }
- }
- } else if (id === 92 && !subid) { // level requirement
- desc = this.itemdesc;
- desc = desc.split("\n");
- string = GetLocaleString(3469);
- for (i = 0; i < desc.length; i += 1) {
- if (desc[i].indexOf(string) > -1) {
- value = parseInt(desc[i].split(string)[1], 10);
- return value;
- }
- }
- }
- }
- if (id === 204 && subid === 54) { // teleport charges, doesn't support non-english
- desc = this.itemdesc;
- desc = desc.split("\n");
- for (i = 0; i < desc.length; i += 1) {
- if (desc[i].indexOf("Teleport") > -1 && desc[i].indexOf("Charges") > -1) {
- value = parseInt(desc[i].split("Level ")[1].split(" Charges")[0], 10);
- return value;
- }
- }
- }
- if (subid) {
- return this.GetStat(id, subid);
- }
- return this.GetStat(id);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement