Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Equipment, ItemsRegistry,
- __hasProp = {}.hasOwnProperty,
- __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- window.Item = (function(_super) {
- __extends(Item, _super);
- function Item(data) {
- data.price = data.funds;
- delete data.funds;
- this.data = data;
- this.setProperties(data);
- }
- Item.prototype.buy = function(cb, count) {
- var _this = this;
- if (cb == null) {
- cb = (function() {});
- }
- if (count == null) {
- count = 1;
- }
- return Server.post('items/' + this.id() + '/purchase.json', {
- 'count': count
- }, function(data) {
- if (data.status === "success") {
- _this.count(data.remain);
- ko.mapping.fromJS(Object.select(data, 'balance'), currentPlayer);
- currentPlayer.balance.total_balance(currentPlayer.balance.total_balance() - (_this.price.upkeep() * count));
- }
- return cb(data);
- });
- };
- Item.prototype.sell = function(cb, count) {
- var _this = this;
- if (cb == null) {
- cb = (function() {});
- }
- if (count == null) {
- count = 1;
- }
- return Server.post('items/' + this.id() + '/sale.json', {
- 'count': count
- }, function(data) {
- if (data.status === "success") {
- _this.count(data.remain);
- ko.mapping.fromJS(Object.select(data, 'balance'), currentPlayer);
- currentPlayer.balance.total_balance(currentPlayer.balance.total_balance() + (_this.price.upkeep() * count));
- }
- return cb(data);
- });
- };
- Item.prototype.dificitPrice = function(count) {
- if (count == null) {
- count = 1;
- }
- return I18n.notify.error.money + ' <span class="text-money">' + ((this.price.buy() * count) - currentPlayer.balance.cash()) + '</span>';
- };
- Item.struct = function() {
- return {
- id: 0,
- title: '',
- type: '',
- level: 0,
- icon: {
- x40: '',
- x70: '',
- x138: ''
- },
- attack: 0,
- defence: 0,
- price: {
- buy: 0,
- sell: 0,
- upkeep: 0
- },
- count: 0
- };
- };
- return Item;
- })(AbstractModel);
- ItemsRegistry = (function() {
- function ItemsRegistry() {}
- ItemsRegistry.items = [];
- ItemsRegistry.append = function(item) {
- return ItemsRegistry.items.push(new Item(item));
- };
- return ItemsRegistry;
- }).call(this);
- Equipment = (function() {
- function Equipment(items) {
- var i, properties, _i, _len, _ref;
- properties = items.p;
- _ref = items.s;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- i = _ref[_i];
- i.count = properties[i.id] || 0;
- ItemsRegistry.append(i);
- }
- }
- Equipment.prototype.asActiveRecord = function(logs) {
- var result, special;
- if (logs == null) {
- logs = true;
- }
- special = $.extend(true, {}, this.asSpecial);
- special.constructor = window.ActiveRecord;
- result = this.asSpecial || new window.ActiveRecord(ItemsRegistry.items, logs);
- this.asSpecial = null;
- return result;
- };
- Equipment.prototype.exclude = function(exclusions) {
- var items;
- items = ItemsRegistry.items.slice(0).remove(function(item) {
- return exclusions.any(function(exclusion) {
- return (typeof item.title === 'function' ? item.title() : item.title.toString()()) === exclusion;
- });
- });
- this.asSpecial = new window.ActiveRecord(items, false);
- return this;
- };
- Equipment.prototype.getById = function(id) {
- return this.asActiveRecord(false).where('id==%1', [id]).limit(1).execute()[0];
- };
- Equipment.prototype.getByLevel = function(level) {
- return this.asActiveRecord(false).where('level==%1', [level]).execute();
- };
- Equipment.prototype.getBoughtByType = function(type) {
- return this.asActiveRecord().where('type==%1 && count>0', [type]).order('level count', 'desc').execute();
- };
- Equipment.prototype.getPreviewItems = function(type) {
- var avl, dsbl;
- avl = this.asActiveRecord().where('type==%1 && level<=%2 && price.buy>0', [type, currentPlayer.indicator.level()]).order('level').desc().execute();
- dsbl = this.asActiveRecord().where('type==%1 && level>%2 && price.buy>0', [type, currentPlayer.indicator.level()]).order('level').limit(2).desc().execute();
- return dsbl.concat(avl);
- };
- Equipment.prototype.getAll = function() {
- return ItemsRegistry.items;
- };
- Equipment.prototype.getByType = function(type) {
- if (type !== "peoples" && type !== "documents" && type !== "organizations") {
- new Exception('Undefined type in Equipment::getByType');
- } else {
- return this.asActiveRecord().where('type==%1', [type]).order('id').execute();
- }
- };
- return Equipment;
- })();
- window.Models.register('Equipment', Equipment);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement