//=============================================================================
// Durability.js
//=============================================================================
/*:
* @plugindesc Adds Minecraft-like durability of weapons/armors.
* <KockaDurability>
* @author KockaAdmiralac
*
* @help
* ============================================================================
* INTRODUCTION
* ============================================================================
* This plugin allows you to manage durability of your weapons and
* armors. It's very simple how durability is calculated :
* 1) 当你被攻击时, 你的防具会掉耐久度.
* 2) 当你攻击时, 你的武器会掉耐久度.
* 你的装备耐久度归0时,它会从你的装备栏转移到物品栏(至少本场战斗就用不了了)
*
* This plugin is made self-initiative.
* ============================================================================
* NOTETAGS
* ============================================================================
* There are three notetags :
* - Weapon and Armor notetag :
* <durability:x>
* 在这里设置装备的具体耐久度.
* Example : <durability:1>
* 武器/防具的耐久度只有1点(一碰就碎).
* 如果不指定耐久度,该装备就是坚不可摧的.
*
* - Item and Skill notetags :
* <durability_use:x>
* 在这里设置,使用该道具或技能会损失的耐久度.
* Example : <durability_use:10>
* 如果这个道具/技能是由英雄使用的,他的武器会失去10点耐久度
* 如果这个道具/技能是由敌人使用的,被击中的英雄们的防具会失去10点耐久度
*
* <durability_increase:[equips] increase>
* 这里是装备的耐久度提升(修复)的写法.
* [equips] - 这里填写的是装备的种类编号,具体参考下面范例
* increase - 这里可以填写一个具体的数值,也可以填写"MAX", 并且最多也就升到你设定的耐久度最大值
* Example :
* Notetag : <durability_increase:[1 2 3] 10>
* 这将修复你的1(武器)、2(盾牌)、3(头盔)号装备10点耐久度.
* Notetag : <durability_increase[2 3 4] MAX>
* 这将完全修复你的2(盾牌)、3(头盔)、4(铠甲)号装备的耐久度.
*
* Since version 1.1.1 you can set variable durability use/increase.
* 你现在可以设置与HP, MP, TP伤害或一些变量挂钩的耐久度加减.
* Example:
* Notetag : <durability_use:hpDamage>
* Result : 该技能会造成与HP伤害相等的耐久度伤害.
*
* Notetag : <durability_increase:$gameVariables.variable(1)>
* Result : 该技能/道具会修复与变量1相等的耐久度
* ============================================================================
* VERSION HISTORY
* ============================================================================
* Version | Description
* ________|___________________________________________________________________
* 1.0.0 | Initial release
* 1.1.0 | Added option for regenerating durability. [Adlw]
* 1.1.1 | Added option for variable durability use [Ozuma]
* ============================================================================
* COMPATIBILITY
* ============================================================================
* NEW :
* <None>
*
* ALIASED :
* - Game_Action :
* - apply
* - useItem
*
* OVERWRITTEN :
* <None>
* ============================================================================
* @param Weapons
* @desc Specify what are your weapon slots here, separated by a space
* @default 1
*
* @param Armors
* @desc Specify what are your armor slots here, separated by a space
* @default 2 3 4 5
*
* @param Default durability use
* @desc How much durability points will item/skill take from weapon/armor
* when none is specified?
* @default 1
*
* @param Durability message
* @desc What message will be displayed when weapon/armor cracks?
* Set to empty to disable.
* @default %1 cracked!
*/
(function(){
// Aliases
var _kocka_random_alias_apply_M7cAp2B8 = Game_Action.prototype.apply;
var _kocka_random_alias_useItem_eb8T3mP2 = Game_Actor.prototype.useItem;
// Parameters
var _plugin_params = $plugins.filter(function(p) { return p.description.contains('<KockaDurability>'); })[0].parameters;
var temp_weapons = _plugin_params["Weapons"];
var temp_armors = _plugin_params["Armors"];
var default_durability_use = Number(_plugin_params["Default durability use"]);
var durability_message = _plugin_params["Durability message"];
//-----------------------------------------------------------------------------
// Game_Action
//
// The game object class for a battle action.
Game_Action.prototype.apply = function(target)
{
_kocka_random_alias_apply_M7cAp2B8.apply(this, arguments);
if(target.result().idear())
{
var array = ((this.subject() instanceof Game_Actor) ? temp_weapons : temp_armors).split(" ");
var actor = (this.subject() instanceof Game_Actor) ? this.subject() : target;
for(var i = 0; i < array.length; ++i)
{
var equip = actor.equips()[array[i] - 1];
if(equip)
{
if(!equip.durability)equip.durability = equip.meta.durability ? equip.meta.durability : -1;
var hasDurability = equip.durability != -1;
var result = target.result();
var hpDamage = result.hpDamage;
var mpDamage = result.mpDamage;
var tpDamage = result.tpDamage;
if(hasDurability)equip.durability -= this.item().meta.durability_use ? eval(this.item().meta.durability_use) : this.item().meta.durability_increase ? 0 : eval(default_durability_use);
if(equip.durability <= 0 && hasDurability)
{
if(durability_message != "")$gameMessage.add(durability_message.format(equip.name));
actor.changeEquipById(array[i], 0);
}
}
}
}
}
Game_Actor.prototype.useItem = function(item)
{
_kocka_random_alias_useItem_eb8T3mP2.apply(this, arguments);
if(item.meta.durability_increase)
{
var arr = /\[(.+)\]\s*(\w+)/ig.exec(item.meta.durability_increase);
if(arr)
{
var equips = this.equips();
var splitEquips = arr[1].split(" ");
for(var i = 0; i < splitEquips.length; ++i)
{
var equip = equips[Number(splitEquips[i]) - 1];
if(equip)
{
if(equip.meta.durability)
{
var maxDurability = Number(equip.meta.durability);
if(!equip.durability)equip.durability = maxDurability;
else
{
if(arr[2] === "MAX")equip.durability = maxDurability;
else
{
equip.durability += Number(arr[2]);
if(equip.durability > maxDurability)equip.durability = maxDurability;
}
}
}
else console.log("[Durability] You can't increase durability on equip that has no durability!");
}
}
}
}
}
})();