Skip to content

Instantly share code, notes, and snippets.

@Menencia
Created June 29, 2014 19:04
Show Gist options
  • Save Menencia/6efed162788c41e12c63 to your computer and use it in GitHub Desktop.
Save Menencia/6efed162788c41e12c63 to your computer and use it in GitHub Desktop.
compile js file with transpilator (v6 => v5)
"use strict";
var Item = function Item(game) {
this.game = game;
this.number = 1;
this.equipped = 0;
};
($traceurRuntime.createClass)(Item, {
load: function(data) {
for (var i in data) {
this[i] = data[i];
}
return this;
},
action: function(fn) {
if (this.canUse()) {
if (this.number > 1) {
this.number--;
} else {
_.remove(this.game.items.list, this);
}
} else {
throw "CANNOT USE";
}
if (this.game.battle.isBattle) {
this.game.characters.stopFighting();
fn();
this.game.characters.autoFighting();
} else {
fn();
}
},
getPrice: function() {
return this.price;
},
canBuy: function() {
return (this.game.gils >= this.getPrice());
},
buy: function() {
if (this.canBuy()) {
this.game.gils -= this.getPrice();
this.game.items.add(this);
}
},
inStock: function() {
var sum = 0;
for (var $__1 = this.game.items.list[Symbol.iterator](),
$__2; !($__2 = $__1.next()).done; ) {
var i = $__2.value;
{
if (i.name === this.name) {
sum += i.number;
}
}
}
return sum;
},
canEquip: function() {
return (this.game.items.getEquipped().length < this.game.items.MAX_ITEMS);
},
equip: function() {
this.equipped = this.number;
},
unequip: function() {
this.equipped = 0;
},
export: function() {
var json = _.pick(this, 'number', 'equipped');
json.model = this.constructor.name;
return json;
}
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment