Merged with released L2J-Unity files.
This commit is contained in:
@@ -1,149 +1,169 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import com.l2jmobius.gameserver.enums.InstanceType;
|
||||
import com.l2jmobius.gameserver.handler.ITargetTypeHandler;
|
||||
import com.l2jmobius.gameserver.handler.TargetHandler;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.conditions.Condition;
|
||||
import com.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import com.l2jmobius.gameserver.model.events.EventType;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureDamageDealt;
|
||||
import com.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
import com.l2jmobius.gameserver.model.items.type.WeaponType;
|
||||
import com.l2jmobius.gameserver.model.skills.BuffInfo;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
import com.l2jmobius.gameserver.model.skills.targets.L2TargetType;
|
||||
import com.l2jmobius.util.Rnd;
|
||||
|
||||
/**
|
||||
* Trigger Skill By Attack effect implementation.
|
||||
* @author Zealar
|
||||
*/
|
||||
public final class TriggerSkillByAttack extends AbstractEffect
|
||||
{
|
||||
private final int _minAttackerLevel;
|
||||
private final int _maxAttackerLevel;
|
||||
private final int _minDamage;
|
||||
private final int _chance;
|
||||
private final SkillHolder _skill;
|
||||
private final L2TargetType _targetType;
|
||||
private final InstanceType _attackerType;
|
||||
private int _allowWeapons;
|
||||
private final boolean _isCritical;
|
||||
|
||||
/**
|
||||
* @param attachCond
|
||||
* @param applyCond
|
||||
* @param set
|
||||
* @param params
|
||||
*/
|
||||
public TriggerSkillByAttack(Condition attachCond, Condition applyCond, StatsSet set, StatsSet params)
|
||||
{
|
||||
super(attachCond, applyCond, set, params);
|
||||
|
||||
_minAttackerLevel = params.getInt("minAttackerLevel", 1);
|
||||
_maxAttackerLevel = params.getInt("maxAttackerLevel", 100);
|
||||
_minDamage = params.getInt("minDamage", 1);
|
||||
_chance = params.getInt("chance", 100);
|
||||
_skill = new SkillHolder(params.getInt("skillId"), params.getInt("skillLevel", 1));
|
||||
_targetType = params.getEnum("targetType", L2TargetType.class, L2TargetType.SELF);
|
||||
_attackerType = params.getEnum("attackerType", InstanceType.class, InstanceType.L2Character);
|
||||
_isCritical = params.getBoolean("isCritical", false);
|
||||
|
||||
if (params.getString("allowWeapons").equalsIgnoreCase("ALL"))
|
||||
{
|
||||
_allowWeapons = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : params.getString("allowWeapons").split(","))
|
||||
{
|
||||
_allowWeapons |= WeaponType.valueOf(s).mask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAttackEvent(OnCreatureDamageDealt event)
|
||||
{
|
||||
if (event.isDamageOverTime() || (_chance == 0) || (_skill.getSkillId() == 0) || (_skill.getSkillLvl() == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isCritical != event.isCritical())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final ITargetTypeHandler targetHandler = TargetHandler.getInstance().getHandler(_targetType);
|
||||
if (targetHandler == null)
|
||||
{
|
||||
_log.warning("Handler for target type: " + _targetType + " does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAttacker() == event.getTarget())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getAttacker().getLevel() < _minAttackerLevel) || (event.getAttacker().getLevel() > _maxAttackerLevel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getDamage() < _minDamage) || (Rnd.get(100) > _chance) || !event.getAttacker().getInstanceType().isType(_attackerType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_allowWeapons > 0) && ((event.getAttacker().getActiveWeaponItem() == null) || ((event.getAttacker().getActiveWeaponItem().getItemType().mask() & _allowWeapons) == 0)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Skill triggerSkill = _skill.getSkill();
|
||||
for (L2Object triggerTarget : targetHandler.getTargetList(triggerSkill, event.getAttacker(), false, event.getTarget()))
|
||||
{
|
||||
if ((triggerTarget == null) || !triggerTarget.isCharacter())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!((L2Character) triggerTarget).isInvul())
|
||||
{
|
||||
event.getAttacker().makeTriggerCast(triggerSkill, (L2Character) triggerTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(BuffInfo info)
|
||||
{
|
||||
info.getEffected().removeListenerIf(EventType.ON_CREATURE_DAMAGE_DEALT, listener -> listener.getOwner() == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(BuffInfo info)
|
||||
{
|
||||
info.getEffected().addListener(new ConsumerEventListener(info.getEffected(), EventType.ON_CREATURE_DAMAGE_DEALT, (OnCreatureDamageDealt event) -> onAttackEvent(event), this));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 handlers.effecthandlers;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.l2jmobius.commons.util.Rnd;
|
||||
import com.l2jmobius.gameserver.enums.InstanceType;
|
||||
import com.l2jmobius.gameserver.handler.TargetHandler;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import com.l2jmobius.gameserver.model.events.EventType;
|
||||
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureDamageDealt;
|
||||
import com.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
import com.l2jmobius.gameserver.model.items.type.WeaponType;
|
||||
import com.l2jmobius.gameserver.model.skills.BuffInfo;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
import com.l2jmobius.gameserver.model.skills.SkillCaster;
|
||||
import com.l2jmobius.gameserver.model.skills.targets.TargetType;
|
||||
|
||||
/**
|
||||
* Trigger Skill By Attack effect implementation.
|
||||
* @author Zealar
|
||||
*/
|
||||
public final class TriggerSkillByAttack extends AbstractEffect
|
||||
{
|
||||
private final int _minAttackerLevel;
|
||||
private final int _maxAttackerLevel;
|
||||
private final int _minDamage;
|
||||
private final int _chance;
|
||||
private final SkillHolder _skill;
|
||||
private final TargetType _targetType;
|
||||
private final InstanceType _attackerType;
|
||||
private int _allowWeapons;
|
||||
private final Boolean _isCritical;
|
||||
private final boolean _allowNormalAttack;
|
||||
private final boolean _allowSkillAttack;
|
||||
private final boolean _allowReflect;
|
||||
|
||||
/**
|
||||
* @param params
|
||||
*/
|
||||
|
||||
public TriggerSkillByAttack(StatsSet params)
|
||||
{
|
||||
_minAttackerLevel = params.getInt("minAttackerLevel", 1);
|
||||
_maxAttackerLevel = params.getInt("maxAttackerLevel", 127);
|
||||
_minDamage = params.getInt("minDamage", 1);
|
||||
_chance = params.getInt("chance", 100);
|
||||
_skill = new SkillHolder(params.getInt("skillId"), params.getInt("skillLevel", 1));
|
||||
_targetType = params.getEnum("targetType", TargetType.class, TargetType.SELF);
|
||||
_attackerType = params.getEnum("attackerType", InstanceType.class, InstanceType.L2Character);
|
||||
_isCritical = params.getObject("isCritical", Boolean.class);
|
||||
_allowNormalAttack = params.getBoolean("allowNormalAttack", true);
|
||||
_allowSkillAttack = params.getBoolean("allowSkillAttack", false);
|
||||
_allowReflect = params.getBoolean("allowReflect", false);
|
||||
|
||||
if (params.getString("allowWeapons", "ALL").equalsIgnoreCase("ALL"))
|
||||
{
|
||||
_allowWeapons = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String s : params.getString("allowWeapons").split(","))
|
||||
{
|
||||
_allowWeapons |= WeaponType.valueOf(s).mask();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onAttackEvent(OnCreatureDamageDealt event)
|
||||
{
|
||||
if (event.isDamageOverTime() || (_chance == 0) || ((_skill.getSkillId() == 0) || (_skill.getSkillLvl() == 0)) || (!_allowNormalAttack && !_allowSkillAttack))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if there is dependancy on critical.
|
||||
if ((_isCritical != null) && (_isCritical != event.isCritical()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// When no skill attacks are allowed.
|
||||
if (!_allowSkillAttack && (event.getSkill() != null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// When no normal attacks are allowed.
|
||||
if (!_allowNormalAttack && (event.getSkill() == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_allowReflect && event.isReflect())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getAttacker() == event.getTarget())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getAttacker().getLevel() < _minAttackerLevel) || (event.getAttacker().getLevel() > _maxAttackerLevel))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getDamage() < _minDamage) || (Rnd.get(100) > _chance) || !event.getAttacker().getInstanceType().isType(_attackerType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_allowWeapons > 0)
|
||||
{
|
||||
if ((event.getAttacker().getActiveWeaponItem() == null) || ((event.getAttacker().getActiveWeaponItem().getItemType().mask() & _allowWeapons) == 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final Skill triggerSkill = _skill.getSkill();
|
||||
L2Object target = null;
|
||||
try
|
||||
{
|
||||
target = TargetHandler.getInstance().getHandler(_targetType).getTarget(event.getAttacker(), event.getTarget(), triggerSkill, false, false, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Exception in ITargetTypeHandler.getTarget(): " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
if ((target != null) && target.isCharacter())
|
||||
{
|
||||
SkillCaster.triggerCast(event.getAttacker(), (L2Character) target, triggerSkill);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(BuffInfo info)
|
||||
{
|
||||
info.getEffected().removeListenerIf(EventType.ON_CREATURE_DAMAGE_DEALT, listener -> listener.getOwner() == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(BuffInfo info)
|
||||
{
|
||||
info.getEffected().addListener(new ConsumerEventListener(info.getEffected(), EventType.ON_CREATURE_DAMAGE_DEALT, (OnCreatureDamageDealt event) -> onAttackEvent(event), this));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user