//-----------------------------------------------------------------------------
// Game_Item
//
// The game object class for handling skills, items, weapons, and armor. It is
// required because save data should not include the database object itself.
/**
* The game object class for handling skills, items, weapons, and armor. It is required because save data should not include the database object itself.
*
* @class
*/
function Game_Item() {
this.initialize(...arguments);
}
/**
* Initialize the item
*
* @param {Object} item - The item data object to convert to game item object
*/
Game_Item.prototype.initialize = function(item) {
this._dataClass = "";
this._itemId = 0;
if (item) {
this.setObject(item);
}
};
/**
* Check if this item is a skill
*
* @return {boolean} True if skill
*/
Game_Item.prototype.isSkill = function() {
return this._dataClass === "skill";
};
/**
* Check if this item is an item
*
* @return {boolean} True if item
*/
Game_Item.prototype.isItem = function() {
return this._dataClass === "item";
};
/**
* Check if this item is usable (item or skill)
*
* @return {boolean} True if item or skill
*/
Game_Item.prototype.isUsableItem = function() {
return this.isSkill() || this.isItem();
};
/**
* Check if this item is a weapon
*
* @return {boolean} True if weapon
*/
Game_Item.prototype.isWeapon = function() {
return this._dataClass === "weapon";
};
/**
* Check if this item is an armor
*
* @return {boolean} True if armor
*/
Game_Item.prototype.isArmor = function() {
return this._dataClass === "armor";
};
/**
* Check if this item is an equip item (weapon or armor)
*
* @return {boolean} True if weapon or armor
*/
Game_Item.prototype.isEquipItem = function() {
return this.isWeapon() || this.isArmor();
};
/**
* Check if this item is null
*
* @return {boolean} True if null
*/
Game_Item.prototype.isNull = function() {
return this._dataClass === "";
};
/**
* Get the item id
*
* @return {number} The item's id
*/
Game_Item.prototype.itemId = function() {
return this._itemId;
};
/**
* Get the item data object
*
* @return {Object|null} The item data object, or null if no item
*/
Game_Item.prototype.object = function() {
if (this.isSkill()) {
return $dataSkills[this._itemId];
} else if (this.isItem()) {
return $dataItems[this._itemId];
} else if (this.isWeapon()) {
return $dataWeapons[this._itemId];
} else if (this.isArmor()) {
return $dataArmors[this._itemId];
} else {
return null;
}
};
/**
* Converts an item data object to an item game object
*
* @param {Object} item - The item data object to convert
*/
Game_Item.prototype.setObject = function(item) {
if (DataManager.isSkill(item)) {
this._dataClass = "skill";
} else if (DataManager.isItem(item)) {
this._dataClass = "item";
} else if (DataManager.isWeapon(item)) {
this._dataClass = "weapon";
} else if (DataManager.isArmor(item)) {
this._dataClass = "armor";
} else {
this._dataClass = "";
}
this._itemId = item ? item.id : 0;
};
/**
* Sets an equip item
*
* @param {boolean} isWeapon - If the item is a weapon or armor
* @param {number} itemId - The item's id
*/
Game_Item.prototype.setEquip = function(isWeapon, itemId) {
this._dataClass = isWeapon ? "weapon" : "armor";
this._itemId = itemId;
};