/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package lineage2.gameserver.skills.skillclasses;
import java.util.List;
import lineage2.gameserver.model.Creature;
import lineage2.gameserver.model.Skill;
import lineage2.gameserver.network.serverpackets.SystemMessage;
import lineage2.gameserver.stats.Stats;
import lineage2.gameserver.templates.StatsSet;
/**
* @author Mobius
* @version $Revision: 1.0 $
*/
public class HealPercent extends Skill
{
/**
* Field _ignoreHpEff.
*/
private final boolean _ignoreHpEff;
/**
* Constructor for HealPercent.
* @param set StatsSet
*/
public HealPercent(StatsSet set)
{
super(set);
_ignoreHpEff = set.getBool("ignoreHpEff", true);
}
/**
* Method checkCondition.
* @param activeChar Creature
* @param target Creature
* @param forceUse boolean
* @param dontMove boolean
* @param first boolean
* @return boolean
*/
@Override
public boolean checkCondition(Creature activeChar, Creature target, boolean forceUse, boolean dontMove, boolean first)
{
if (activeChar.isPlayable() && target.isMonster())
{
return false;
}
return super.checkCondition(activeChar, target, forceUse, dontMove, first);
}
/**
* Method useSkill.
* @param activeChar Creature
* @param targets List<Creature>
*/
@Override
public void useSkill(Creature activeChar, List<Creature> targets)
{
for (Creature target : targets)
{
if (target != null)
{
if (target.isHealBlocked())
{
continue;
}
getEffects(activeChar, target, getActivateRate() > 0, false);
double hp = (_power * target.getMaxHp()) / 100.;
double newHp = (hp * (!_ignoreHpEff ? target.calcStat(Stats.HEAL_EFFECTIVNESS, 100., activeChar, this) : 100.)) / 100.;
double addToHp = Math.max(0, Math.min(newHp, ((target.calcStat(Stats.HP_LIMIT, null, null) * target.getMaxHp()) / 100.) - target.getCurrentHp()));
if (addToHp > 0)
{
target.setCurrentHp(addToHp + target.getCurrentHp(), false);
}
if (target.isPlayer())
{
if (activeChar != target)
{
target.sendPacket(new SystemMessage(SystemMessage.XS2S_HP_HAS_BEEN_RESTORED_BY_S1).addString(activeChar.getName()).addNumber(Math.round(addToHp)));
}
else
{
activeChar.sendPacket(new SystemMessage(SystemMessage.S1_HPS_HAVE_BEEN_RESTORED).addNumber(Math.round(addToHp)));
}
}
}
}
if (isSSPossible())
{
activeChar.unChargeShots(isMagic());
}
}
}