Created
November 15, 2015 08:21
-
-
Save Langerz82/2e3a2bb47affdd240f93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Items = {}, | |
| _ = require("underscore"), | |
| Types = require("gametypes"), | |
| ItemsJson = require("../data/items.json"); | |
| module.exports = Items; | |
| var ItemData = {}; | |
| _.each( ItemsJson, function( value, key ) { | |
| ItemData[key.toLowerCase()] = { | |
| kind: (value.kind) ? value.kind : 0, | |
| type: (value.type) ? value.type : "object", | |
| attack: (value.attack) ? value.attack : 0, | |
| defense: (value.defense) ? value.defense : 0, | |
| name: (value.name) ? value.name : "Blank", | |
| }; | |
| }); | |
| Items.getWeaponLevel = function(kind) { | |
| try { | |
| return ItemData[Types.getKindAsString(kind)].attack; | |
| } catch(e) { | |
| log.error("No level found for weapon: "+Types.getKindAsString(kind)); | |
| log.error('Error stack: ' + e.stack); | |
| } | |
| }; | |
| Items.getArmorLevel = function(kind) { | |
| try { | |
| return ItemData[Types.getKindAsString(kind)].defense; | |
| } catch(e) { | |
| log.error("No level found for weapon: "+Types.getKindAsString(kind)); | |
| log.error('Error stack: ' + e.stack); | |
| } | |
| }; | |
| Items.getType = function(kind) { | |
| return ItemData[Types.getKindAsString(kind)].type; | |
| }; | |
| Items.getBuyPrice = function(itemName) { | |
| if(Types.Store.Potions[itemName]) { | |
| if(Types.Store.isBuyByItem(Types.Store.Potions[itemName])) { | |
| return Types.Store.getBuyPriceByItem(Types.Store.Potions[itemName]); | |
| } | |
| } | |
| if(Types.Store.Armors[itemName]) { | |
| if(Types.Store.isBuyByItem(Types.Store.Armors[itemName])) { | |
| var result = Types.Store.getBuyPriceByItem(Types.Store.Armors[itemName]); | |
| if(result > 0) { | |
| return result; | |
| } else { | |
| var itemKind = Types.getKindFromString(itemName), | |
| itemLevel = Items.getArmorLevel(itemKind); | |
| return Math.ceil((itemLevel * itemLevel) / 1.5); | |
| } | |
| } | |
| } | |
| if(Types.Store.Weapons[itemName]) { | |
| if(Types.Store.isBuyByItem(Types.Store.Weapons[itemName])) { | |
| var result = Types.Store.getBuyPriceByItem(Types.Store.Weapons[itemName]); | |
| if(result > 0) { | |
| return result; | |
| } else { | |
| var itemKind = Types.getKindFromString(itemName), | |
| itemLevel = Items.getWeaponLevel(itemKind); | |
| return Math.ceil((itemLevel * itemLevel) / 1.5); | |
| } | |
| } | |
| } | |
| return 0; | |
| }; | |
| Items.getSellPrice = function(itemName) { | |
| var itemKind = Types.getKindFromString(itemName), | |
| itemLevel = 0; | |
| if(Items.isArmor(itemKind) || Items.isArcherArmor(itemKind)) { | |
| itemLevel = Items.getArmorLevel(itemKind); | |
| if(itemLevel < 20) { | |
| itemLevel = 0; | |
| } | |
| } else if(Items.isWeapon(itemKind) || Items.isArcherWeapon(itemKind)) { | |
| itemLevel = Items.getWeaponLevel(itemKind); | |
| if(itemLevel < 20) { | |
| itemLevel = 0; | |
| } | |
| } else if(Types.isPendant(itemKind)) { | |
| itemLevel = Types.getPendantRank(itemKind) + 1; | |
| } else if(Types.isRing(itemKind)) { | |
| itemLevel = Types.getRingRank(itemKind) + 1; | |
| } else if(Types.isBoots(itemKind)) { | |
| itemLevel = Types.getBootsRank(itemKind) + 1; | |
| } | |
| return Math.ceil(itemLevel / 2); | |
| }; | |
| Items.getItemDataByKind = function (kind) { | |
| _.each( ItemData, function( value, key ) { | |
| if (value.kind == kind) { | |
| //log.info(JSON.stringify(value)); | |
| return value; | |
| } | |
| }); | |
| return null; | |
| } | |
| Items.isArmor = function(kind) { | |
| var item = Items.getItemDataByKind(kind); | |
| if (!item) return false; | |
| return itemData.type == "armor"; | |
| }; | |
| Items.isArcherArmor = function(kind) { | |
| var item = Items.getItemDataByKind(kind); | |
| if (!item) return false; | |
| return itemData.type == "armorarcher"; | |
| }; | |
| Items.isWeapon = function(kind) { | |
| var item = Items.getItemDataByKind(kind); | |
| if (!item) return false; | |
| return itemData.type == "weapon"; | |
| }; | |
| Items.isArcherWeapon = function(kind) { | |
| var item = Items.getItemDataByKind(kind); | |
| if (!item) return false; | |
| return itemData.type == "weaponarcher"; | |
| }; | |
| Items.isHealingItem = function(kind) { | |
| return kind === Types.Entities.FLASK | |
| || kind === Types.Entities.BURGER | |
| || kind === Types.Entities.ROYALAZALEA; | |
| }; | |
| Items.isConsumableItem = function(kind) { | |
| return kind === Types.Entities.FLASK | |
| || kind === Types.Entities.BURGER | |
| || kind === Types.Entities.ROYALAZALEA; | |
| }; | |
| Items.isExpendableItem = function(kind) { | |
| return Types.isHealingItem(kind) | |
| || kind === Types.Entities.FIREPOTION | |
| || kind === Types.Entities.CAKE; | |
| }; | |
| Items.isItem = function (kind) { | |
| var item = Items.getItemDataByKind(kind); | |
| if (!item) return false; | |
| return itemData.type == "weaponarcher" || | |
| itemData.type == "weapon" || | |
| itemData.type == "armor" || | |
| itemData.type == "armorarcher" || | |
| itemData.type == "object"; | |
| } | |
| Items.forEachKind = function(callback) { | |
| for(var k in itemData) { | |
| log.info("k="+JSON.stringify(k)); | |
| //callback(kinds[k][0], k); | |
| } | |
| }; | |
| Items.forEachArmorKind = function(callback) { | |
| Types.forEachKind(function(kind, kindName) { | |
| if(Items.isArmor(kind)) { | |
| callback(kind, kindName); | |
| } | |
| }); | |
| }; | |
| Items.forEachWeaponKind = function(callback) { | |
| Types.forEachKind(function(kind, kindName) { | |
| if(Items.isWeapon(kind)) { | |
| callback(kind, kindName); | |
| } | |
| }); | |
| }; | |
| Items.forEachArcherArmorKind = function(callback) { | |
| Types.forEachKind(function(kind, kindName) { | |
| if(Items.isArcherArmor(kind)) { | |
| callback(kind, kindName); | |
| } | |
| }); | |
| }; | |
| Items.forEachArcherWeaponKind = function(callback) { | |
| Types.forEachKind(function(kind, kindName) { | |
| if(Items.isArcherWeapon(kind)) { | |
| callback(kind, kindName); | |
| } | |
| }); | |
| }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment