Addition of ReplaceSkillBySkill effect.

This commit is contained in:
MobiusDevelopment 2022-10-04 21:00:35 +00:00
parent 60010a0367
commit 26d118bd37
5 changed files with 141 additions and 0 deletions

View File

@ -300,6 +300,7 @@ public class EffectMasterHandler
EffectHandler.getInstance().registerHandler("ReflectSkill", ReflectSkill::new);
EffectHandler.getInstance().registerHandler("RefuelAirship", RefuelAirship::new);
EffectHandler.getInstance().registerHandler("Relax", Relax::new);
EffectHandler.getInstance().registerHandler("ReplaceSkillBySkill", ReplaceSkillBySkill::new);
EffectHandler.getInstance().registerHandler("ResetInstanceEntry", ResetInstanceEntry::new);
EffectHandler.getInstance().registerHandler("ResistAbnormalByCategory", ResistAbnormalByCategory::new);
EffectHandler.getInstance().registerHandler("ResistDDMagic", ResistDDMagic::new);

View File

@ -0,0 +1,113 @@
/*
* 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 org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.data.xml.SkillData;
import org.l2jmobius.gameserver.enums.ShortcutType;
import org.l2jmobius.gameserver.model.Shortcut;
import org.l2jmobius.gameserver.model.StatSet;
import org.l2jmobius.gameserver.model.actor.Creature;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
import org.l2jmobius.gameserver.model.holders.SkillHolder;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.skill.Skill;
import org.l2jmobius.gameserver.network.serverpackets.ShortCutInit;
import org.l2jmobius.gameserver.network.serverpackets.ShortCutRegister;
/**
* @author Mobius
*/
public class ReplaceSkillBySkill extends AbstractEffect
{
private final SkillHolder _existingSkill;
private final SkillHolder _replacementSkill;
public ReplaceSkillBySkill(StatSet params)
{
_existingSkill = new SkillHolder(params.getInt("existingSkillId"), params.getInt("existingSkillLevel", -1));
_replacementSkill = new SkillHolder(params.getInt("replacementSkillId"), params.getInt("replacementSkillLevel", -1));
}
@Override
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
{
if (effected.isPlayer())
{
final Player player = effected.getActingPlayer();
final Skill knownSkill = player.getKnownSkill(_existingSkill.getSkillId());
if ((knownSkill == null) || (knownSkill.getLevel() < _existingSkill.getSkillLevel()))
{
return;
}
final Skill addedSkill = SkillData.getInstance().getSkill(_replacementSkill.getSkillId(), _replacementSkill.getSkillLevel() < 1 ? knownSkill.getLevel() : _replacementSkill.getSkillLevel(), knownSkill.getSubLevel());
player.addSkill(addedSkill, false);
player.addReplacedSkill(_existingSkill.getSkillId());
for (Shortcut shortcut : player.getAllShortCuts())
{
if ((shortcut.getType() == ShortcutType.SKILL) && (shortcut.getId() == knownSkill.getId()) && (shortcut.getLevel() == knownSkill.getLevel()))
{
final int slot = shortcut.getSlot();
final int page = shortcut.getPage();
final int characterType = shortcut.getCharacterType();
player.deleteShortCut(slot, page);
final Shortcut newShortcut = new Shortcut(slot, page, ShortcutType.SKILL, addedSkill.getId(), addedSkill.getLevel(), addedSkill.getSubLevel(), characterType);
player.registerShortCut(newShortcut);
player.sendPacket(new ShortCutRegister(newShortcut));
}
}
player.removeSkill(knownSkill, false);
player.sendSkillList();
ThreadPool.schedule(() -> player.sendPacket(new ShortCutInit(player)), 1100);
}
}
@Override
public void onExit(Creature effector, Creature effected, Skill skill)
{
final Player player = effected.getActingPlayer();
final Skill knownSkill = player.getKnownSkill(_replacementSkill.getSkillId());
if (knownSkill == null)
{
return;
}
final Skill addedSkill = SkillData.getInstance().getSkill(_existingSkill.getSkillId(), _existingSkill.getSkillLevel() < 1 ? knownSkill.getLevel() : _existingSkill.getSkillLevel(), knownSkill.getSubLevel());
player.addSkill(addedSkill, false);
player.removeReplacedSkill(_existingSkill.getSkillId());
for (Shortcut shortcut : player.getAllShortCuts())
{
if ((shortcut.getType() == ShortcutType.SKILL) && (shortcut.getId() == knownSkill.getId()) && (shortcut.getLevel() == knownSkill.getLevel()))
{
final int slot = shortcut.getSlot();
final int page = shortcut.getPage();
final int characterType = shortcut.getCharacterType();
player.deleteShortCut(slot, page);
final Shortcut newShortcut = new Shortcut(slot, page, ShortcutType.SKILL, addedSkill.getId(), addedSkill.getLevel(), addedSkill.getSubLevel(), characterType);
player.registerShortCut(newShortcut);
player.sendPacket(new ShortCutRegister(newShortcut));
}
}
player.removeSkill(knownSkill, false);
player.sendSkillList();
ThreadPool.schedule(() -> player.sendPacket(new ShortCutInit(player)), 1100);
}
}

View File

@ -269,6 +269,7 @@ ReflectMagic: Deflects magical damage back to the attacker.
ReflectSkill: Deflects physical/magical debuffs back to the attacker.
RefuelAirship: Increases Airship's fuel.
Relax: Sits down and increases HP regeneration until full.
ReplaceSkillBySkill: While active replaces a skill with an alternative skill. (l2jmobius)
ResetInstanceEntry: Resets instance re-entry time. (l2jmobius)
ResistAbnormalByCategory: Buff/debuff resist stat.
ResistDDMagic: Magic resist stat (magic attack 50% effective or 1 damage)

View File

@ -703,6 +703,11 @@ public class SkillTreeData implements IXmlReader
continue;
}
if (player.hasReplacedSkill(skill.getSkillId()))
{
continue;
}
if (player.getLevel() >= skill.getGetLevel())
{
if (skill.getSkillLevel() > SkillData.getInstance().getMaxLevel(skill.getSkillId()))
@ -1477,6 +1482,11 @@ public class SkillTreeData implements IXmlReader
continue;
}
if (player.hasReplacedSkill(skill.getSkillId()))
{
continue;
}
if (minLevelForNewSkill <= skill.getGetLevel())
{
final Skill oldSkill = player.getKnownSkill(skill.getSkillId());

View File

@ -828,6 +828,7 @@ public class Player extends Playable
/** Map containing all custom skills of this player. */
private Map<Integer, Skill> _customSkills = null;
public final Set<Integer> _replacedSkills = ConcurrentHashMap.newKeySet(1);
private volatile int _actionMask;
@ -13126,6 +13127,21 @@ public class Player extends Playable
}
}
public void addReplacedSkill(int skillId)
{
_replacedSkills.add(skillId);
}
public void removeReplacedSkill(int skillId)
{
_replacedSkills.remove(skillId);
}
public boolean hasReplacedSkill(int skillId)
{
return _replacedSkills.contains(skillId);
}
/**
* @return {@code true} if current player can revive and shows 'To Village' button upon death, {@code false} otherwise.
*/