Merged with released L2J-Unity files.
This commit is contained in:
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.commons.util.Rnd;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.L2Party;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.templates.L2CubicTemplate;
|
||||
import com.l2jmobius.gameserver.model.skills.Skill;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.ExUserInfoCubic;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class CubicInstance
|
||||
{
|
||||
private final L2PcInstance _owner;
|
||||
private final L2PcInstance _caster;
|
||||
private final L2CubicTemplate _template;
|
||||
private ScheduledFuture<?> _skillUseTask;
|
||||
private ScheduledFuture<?> _expireTask;
|
||||
|
||||
public CubicInstance(L2PcInstance owner, L2PcInstance caster, L2CubicTemplate template)
|
||||
{
|
||||
_owner = owner;
|
||||
_caster = caster;
|
||||
_template = template;
|
||||
activate();
|
||||
}
|
||||
|
||||
private void activate()
|
||||
{
|
||||
_skillUseTask = ThreadPoolManager.getInstance().scheduleAiAtFixedRate(this::tryToUseSkill, 0, _template.getDelay() * 1000);
|
||||
_expireTask = ThreadPoolManager.getInstance().scheduleAi(this::deactivate, _template.getDuration() * 1000);
|
||||
}
|
||||
|
||||
public void deactivate()
|
||||
{
|
||||
if ((_skillUseTask != null) && !_skillUseTask.isDone())
|
||||
{
|
||||
_skillUseTask.cancel(true);
|
||||
}
|
||||
_skillUseTask = null;
|
||||
|
||||
if ((_expireTask != null) && !_expireTask.isDone())
|
||||
{
|
||||
_expireTask.cancel(true);
|
||||
}
|
||||
_expireTask = null;
|
||||
_owner.getCubics().remove(_template.getId());
|
||||
_owner.sendPacket(new ExUserInfoCubic(_owner));
|
||||
_owner.broadcastCharInfo();
|
||||
}
|
||||
|
||||
private void tryToUseSkill()
|
||||
{
|
||||
final double random = Rnd.nextDouble() * 100;
|
||||
double commulativeChance = 0;
|
||||
for (CubicSkill cubicSkill : _template.getSkills())
|
||||
{
|
||||
if ((commulativeChance += cubicSkill.getTriggerRate()) > random)
|
||||
{
|
||||
final Skill skill = cubicSkill.getSkill();
|
||||
if ((skill != null) && (Rnd.get(100) < cubicSkill.getSuccessRate()))
|
||||
{
|
||||
final L2Character target = findTarget(cubicSkill);
|
||||
if (target != null)
|
||||
{
|
||||
_caster.broadcastPacket(new MagicSkillUse(_owner, target, skill.getDisplayId(), skill.getDisplayLevel(), skill.getHitTime(), skill.getReuseDelay()));
|
||||
skill.activateSkill(_owner, target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private L2Character findTarget(CubicSkill cubicSkill)
|
||||
{
|
||||
switch (_template.getTargetType())
|
||||
{
|
||||
case BY_SKILL:
|
||||
{
|
||||
if (!_template.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final Skill skill = cubicSkill.getSkill();
|
||||
if (skill != null)
|
||||
{
|
||||
switch (cubicSkill.getTargetType())
|
||||
{
|
||||
case HEAL:
|
||||
{
|
||||
final L2Party party = _owner.getParty();
|
||||
if (party != null)
|
||||
{
|
||||
return party.getMembers().stream().filter(member -> cubicSkill.validateConditions(this, _owner, member) && member.isInsideRadius(_owner, Config.ALT_PARTY_RANGE, true, true)).sorted(Comparator.comparingInt(L2Character::getCurrentHpPercent).reversed()).findFirst().orElse(null);
|
||||
}
|
||||
if (cubicSkill.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MASTER:
|
||||
{
|
||||
if (cubicSkill.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TARGET:
|
||||
{
|
||||
final L2Object possibleTarget = skill.getTarget(_owner, false, false, false);
|
||||
if ((possibleTarget != null) && possibleTarget.isCharacter())
|
||||
{
|
||||
if (cubicSkill.validateConditions(this, _owner, (L2Character) possibleTarget))
|
||||
{
|
||||
return (L2Character) possibleTarget;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TARGET:
|
||||
{
|
||||
switch (cubicSkill.getTargetType())
|
||||
{
|
||||
case HEAL:
|
||||
{
|
||||
final L2Party party = _owner.getParty();
|
||||
if (party != null)
|
||||
{
|
||||
return party.getMembers().stream().filter(member -> cubicSkill.validateConditions(this, _owner, member) && member.isInsideRadius(_owner, Config.ALT_PARTY_RANGE, true, true)).sorted(Comparator.comparingInt(L2Character::getCurrentHpPercent).reversed()).findFirst().orElse(null);
|
||||
}
|
||||
if (cubicSkill.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MASTER:
|
||||
{
|
||||
if (cubicSkill.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TARGET:
|
||||
{
|
||||
final L2Object targetObject = _owner.getTarget();
|
||||
if ((targetObject != null) && targetObject.isCharacter())
|
||||
{
|
||||
final L2Character target = (L2Character) targetObject;
|
||||
if (cubicSkill.validateConditions(this, _owner, target))
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case HEAL:
|
||||
{
|
||||
final L2Party party = _owner.getParty();
|
||||
if (party != null)
|
||||
{
|
||||
return party.getMembers().stream().filter(member -> member.isInsideRadius(_owner, Config.ALT_PARTY_RANGE, true, true)).sorted(Comparator.comparingInt(L2Character::getCurrentHpPercent).reversed()).findFirst().orElse(null);
|
||||
}
|
||||
if (cubicSkill.validateConditions(this, _owner, _owner))
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link L2Character} that owns this cubic
|
||||
*/
|
||||
public L2Character getOwner()
|
||||
{
|
||||
return _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link L2Character} that casted this cubic
|
||||
*/
|
||||
public L2Character getCaster()
|
||||
{
|
||||
return _caster;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if cubic is casted from someone else but the owner, {@code false}
|
||||
*/
|
||||
public boolean isGivenByOther()
|
||||
{
|
||||
return _caster != _owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link L2CubicTemplate} of this cubic
|
||||
*/
|
||||
public L2CubicTemplate getTemplate()
|
||||
{
|
||||
return _template;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.model.StatsSet;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.cubic.conditions.ICubicCondition;
|
||||
import com.l2jmobius.gameserver.model.holders.SkillHolder;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class CubicSkill extends SkillHolder implements ICubicConditionHolder
|
||||
{
|
||||
private final int _triggerRate;
|
||||
private final int _successRate;
|
||||
private final boolean _canUseOnStaticObjects;
|
||||
private final CubicSkillTargetType _targetType;
|
||||
private final List<ICubicCondition> _conditions = new ArrayList<>();
|
||||
private final boolean _targetDebuff;
|
||||
|
||||
public CubicSkill(StatsSet set)
|
||||
{
|
||||
super(set.getInt("id"), set.getInt("level"));
|
||||
_triggerRate = set.getInt("triggerRate", 100);
|
||||
_successRate = set.getInt("successRate", 100);
|
||||
_canUseOnStaticObjects = set.getBoolean("canUseOnStaticObjects", false);
|
||||
_targetType = set.getEnum("target", CubicSkillTargetType.class, CubicSkillTargetType.TARGET);
|
||||
_targetDebuff = set.getBoolean("targetDebuff", false);
|
||||
}
|
||||
|
||||
public int getTriggerRate()
|
||||
{
|
||||
return _triggerRate;
|
||||
}
|
||||
|
||||
public int getSuccessRate()
|
||||
{
|
||||
return _successRate;
|
||||
}
|
||||
|
||||
public boolean canUseOnStaticObjects()
|
||||
{
|
||||
return _canUseOnStaticObjects;
|
||||
}
|
||||
|
||||
public CubicSkillTargetType getTargetType()
|
||||
{
|
||||
return _targetType;
|
||||
}
|
||||
|
||||
public boolean isTargetingDebuff()
|
||||
{
|
||||
return _targetDebuff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateConditions(CubicInstance cubic, L2Character owner, L2Character target)
|
||||
{
|
||||
return (!_targetDebuff || (_targetDebuff && target.getEffectList().hasDebuffs())) && (_conditions.isEmpty() || _conditions.stream().allMatch(condition -> condition.test(cubic, owner, target)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCondition(ICubicCondition condition)
|
||||
{
|
||||
_conditions.add(condition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "Cubic skill id: " + getSkillId() + " level: " + getSkillLvl() + " triggerRate: " + _triggerRate + " successRate: " + _successRate + " canUseOnStaticObjects: " + _canUseOnStaticObjects + " targetType: " + _targetType + " isTargetingDebuff: " + _targetDebuff + Config.EOL;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public enum CubicSkillTargetType
|
||||
{
|
||||
HEAL,
|
||||
MASTER,
|
||||
TARGET
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public enum CubicTargetType
|
||||
{
|
||||
BY_SKILL,
|
||||
TARGET,
|
||||
HEAL;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.cubic.conditions.ICubicCondition;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public interface ICubicConditionHolder
|
||||
{
|
||||
public boolean validateConditions(CubicInstance cubic, L2Character owner, L2Character target);
|
||||
|
||||
public void addCondition(ICubicCondition condition);
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic.conditions;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.cubic.CubicInstance;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class GeneralCondition implements ICubicCondition
|
||||
{
|
||||
private final GeneralConditionType _type;
|
||||
private final int _hpPer;
|
||||
private final int _hp;
|
||||
|
||||
public GeneralCondition(GeneralConditionType type, int hpPer, int hp)
|
||||
{
|
||||
_type = type;
|
||||
_hpPer = hpPer;
|
||||
_hp = hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CubicInstance cubic, L2Character owner, L2Character target)
|
||||
{
|
||||
final double hpPer = target.getCurrentHpPercent();
|
||||
switch (_type)
|
||||
{
|
||||
case GREATER:
|
||||
{
|
||||
if (hpPer < _hpPer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.getCurrentHp() < _hp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LESSER:
|
||||
{
|
||||
if (hpPer > _hpPer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (target.getCurrentHp() > _hp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + " chance: " + _hpPer + " range: " + _hp;
|
||||
}
|
||||
|
||||
public static enum GeneralConditionType
|
||||
{
|
||||
GREATER,
|
||||
LESSER;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic.conditions;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.cubic.CubicInstance;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class HealthCondition implements ICubicCondition
|
||||
{
|
||||
private final int _min;
|
||||
private final int _max;
|
||||
|
||||
public HealthCondition(int min, int max)
|
||||
{
|
||||
_min = min;
|
||||
_max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(CubicInstance cubic, L2Character owner, L2Character target)
|
||||
{
|
||||
final double hpPer = target.getCurrentHpPercent();
|
||||
return (hpPer > _min) && (hpPer < _max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getSimpleName() + " min: " + _min + " max: " + _max;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 com.l2jmobius.gameserver.model.cubic.conditions;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.cubic.CubicInstance;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public interface ICubicCondition
|
||||
{
|
||||
public boolean test(CubicInstance cubic, L2Character owner, L2Character target);
|
||||
}
|
Reference in New Issue
Block a user