Created
November 14, 2015 22:06
-
-
Save Langerz82/ae8457cbdffd95fc9469 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("../../shared/js/gametypes"), | |
| ItemsJson = require("../../shared/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(Types.isArmor(itemKind) || Types.isArcherArmor(itemKind)) { | |
| itemLevel = Items.getArmorLevel(itemKind); | |
| if(itemLevel < 20) { | |
| itemLevel = 0; | |
| } | |
| } else if(Types.isWeapon(itemKind) || Types.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); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment