}
try
{
if (Rnd.get(1, 100) < _chance)
{
L2Skill skill = SkillTable.getInstance().getInfo(
_skills.get(Rnd.get(_skills.size())),
_level);
if (skill != null)
{
L2Character target, caster;
target = null;
if (_owner.isInParty())
{
caster = _owner;
L2PcInstance player = _owner;
L2Party party = player.getParty();
double percentleft = 100.0;
if (party != null)
{
// Get all visible objects in a spheric area near the L2Character
// Get a list of Party Members
List<L2PcInstance> partyList = party.getPartyMembers();
L2Character partyMember = null;
int x, y, z;
// temporary range check until real behavior of cubics is known/coded
int range = 400; //skill.getCastRange();
for (int i = 0; i < partyList.size(); i++)
{
partyMember = partyList.get(i);
if (!partyMember.isDead())
{
//if party member not dead, check if he is in castrange of heal cubic
x = (caster.getX() - partyMember.getX());
y = (caster.getY() - partyMember.getY());
z = (caster.getZ() - partyMember.getZ());
if ((x * x) + (y * y) + (z * z) > range * range) continue;
//member is in cubic casting range, check if he need heal and if he have the lowest HP
if (partyMember.getCurrentHp() < partyMember.getMaxHp())
{
if (percentleft > (partyMember.getCurrentHp() / partyMember.getMaxHp()))
{
percentleft = (partyMember.getCurrentHp() / partyMember.getMaxHp());
target = partyMember;
}
}
}
}
}
}
else
{
if (_owner.getCurrentHp() < _owner.getMaxHp()) target = _owner;
}
if (target != null)
{
L2Character[] targets = {target};
ISkillHandler handler = SkillHandler.getInstance().getSkillHandler(skill.getSkillType());
if (handler != null)
{
handler.useSkill(_owner, skill, targets);
}
else
{
skill.useSkill(_owner, targets);
}
MagicSkillUser msu = new MagicSkillUser(_owner, target, skill.getId(),
_level, 0, 0);
_owner.broadcastPacket(msu);
}
}
}