From yanfly's tips & tricks series, he replicated the ability Earth Shield from world of warcraft.
The code functions perfectly fine, however, if the recipient has low health, instead of dying, their HP is set to the value the shield is intended to heal. Does anyone know how this could be modified to ensure HP is above 0 before applying the heal, such that if it isn't, the character dies instead of surviving at the intended heal amount?
<Custom Apply Effect>
// Get the current 50% value of the caster's MAT upon the state being applied as the Earth Shield Heal value.
target._earthShieldHeal = Math.floor(origin.mat * 0.50);
// Set the number of charges on the state to 9.
target.setStateCounter(stateId, 9);
</Custom Apply Effect>
<Custom Remove Effect>
// When removed, clear the stored heal value.
target._earthShieldHeal = undefined;
// When removed, clear the number of charges on the state.
target.removeStateCounter(stateId);
</Custom Remove Effect>
<Custom React Effect>
// If the received action is an HP effect and if it's a Heal...
if (this.isHpEffect() && value < 0) {
// ...then increase the heal by 20%.
value = Math.floor(value * 1.20);
// Then reduce the state's charges by -1.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
}
</Custom React Effect>
<Custom Deselect Effect>
// Make a copy of the target's results.
var result = JsonEx.makeDeepCopy(target.result());
// Check if the target is alive and if the amount of damage received is above 0.
if (target.isAlive() && result.hpDamage > 0) {
// Set the amount of HP to heal equal to the stored Earth Shield Heal value.
var hpHealed = target._earthShieldHeal || 0;
// Make the target gain that much HP.
target.gainHp(hpHealed);
// Show the damage popup on the target.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
// Reduce the state's charges.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
// Reset the target's results back to what they were before.
target._result = result;
}
</Custom Deselect Effect>
// Get the current 50% value of the caster's MAT upon the state being applied as the Earth Shield Heal value.
target._earthShieldHeal = Math.floor(origin.mat * 0.50);
// Set the number of charges on the state to 9.
target.setStateCounter(stateId, 9);
</Custom Apply Effect>
<Custom Remove Effect>
// When removed, clear the stored heal value.
target._earthShieldHeal = undefined;
// When removed, clear the number of charges on the state.
target.removeStateCounter(stateId);
</Custom Remove Effect>
<Custom React Effect>
// If the received action is an HP effect and if it's a Heal...
if (this.isHpEffect() && value < 0) {
// ...then increase the heal by 20%.
value = Math.floor(value * 1.20);
// Then reduce the state's charges by -1.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
}
</Custom React Effect>
<Custom Deselect Effect>
// Make a copy of the target's results.
var result = JsonEx.makeDeepCopy(target.result());
// Check if the target is alive and if the amount of damage received is above 0.
if (target.isAlive() && result.hpDamage > 0) {
// Set the amount of HP to heal equal to the stored Earth Shield Heal value.
var hpHealed = target._earthShieldHeal || 0;
// Make the target gain that much HP.
target.gainHp(hpHealed);
// Show the damage popup on the target.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
// Reduce the state's charges.
target.addStateCounter(stateId, -1);
// If the state's charges reach 0 or less...
if (target.getStateCounter(stateId) <= 0) {
// ...then remove the state.
target.removeState(stateId);
}
// Reset the target's results back to what they were before.
target._result = result;
}
</Custom Deselect Effect>
The code functions perfectly fine, however, if the recipient has low health, instead of dying, their HP is set to the value the shield is intended to heal. Does anyone know how this could be modified to ensure HP is above 0 before applying the heal, such that if it isn't, the character dies instead of surviving at the intended heal amount?