Update player replaced skills with TimedHunting script.

This commit is contained in:
MobiusDevelopment
2022-09-16 23:57:46 +00:00
parent dc6ee5ad05
commit 44f157dd5a
7 changed files with 146 additions and 0 deletions

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

@@ -211,6 +211,7 @@ public class TimedHunting extends AbstractInstance
for (Entry<Integer, Integer> entry : SKILL_REPLACEMENTS.entrySet())
{
final int normalSkillId = entry.getKey().intValue();
player.addReplacedSkill(normalSkillId);
final Skill knownSkill = player.getKnownSkill(normalSkillId);
if (knownSkill == null)
{
@@ -260,6 +261,7 @@ public class TimedHunting extends AbstractInstance
}
final int normalSkillId = entry.getKey().intValue();
player.removeReplacedSkill(normalSkillId);
player.addSkill(SkillData.getInstance().getSkill(normalSkillId, knownSkill.getLevel(), knownSkill.getSubLevel()), false);
for (Shortcut shortcut : player.getAllShortCuts())
{

View File

@@ -274,6 +274,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

@@ -709,6 +709,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()))
@@ -1483,6 +1488,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

@@ -856,6 +856,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;
@@ -13406,6 +13407,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.
*/

View File

@@ -211,6 +211,7 @@ public class TimedHunting extends AbstractInstance
for (Entry<Integer, Integer> entry : SKILL_REPLACEMENTS.entrySet())
{
final int normalSkillId = entry.getKey().intValue();
player.addReplacedSkill(normalSkillId);
final Skill knownSkill = player.getKnownSkill(normalSkillId);
if (knownSkill == null)
{
@@ -260,6 +261,7 @@ public class TimedHunting extends AbstractInstance
}
final int normalSkillId = entry.getKey().intValue();
player.removeReplacedSkill(normalSkillId);
player.addSkill(SkillData.getInstance().getSkill(normalSkillId, knownSkill.getLevel(), knownSkill.getSubLevel()), false);
for (Shortcut shortcut : player.getAllShortCuts())
{

View File

@@ -215,6 +215,7 @@ public class TimedHunting extends AbstractInstance
for (Entry<Integer, Integer> entry : SKILL_REPLACEMENTS.entrySet())
{
final int normalSkillId = entry.getKey().intValue();
player.addReplacedSkill(normalSkillId);
final Skill knownSkill = player.getKnownSkill(normalSkillId);
if (knownSkill == null)
{
@@ -264,6 +265,7 @@ public class TimedHunting extends AbstractInstance
}
final int normalSkillId = entry.getKey().intValue();
player.removeReplacedSkill(normalSkillId);
player.addSkill(SkillData.getInstance().getSkill(normalSkillId, knownSkill.getLevel(), knownSkill.getSubLevel()), false);
for (Shortcut shortcut : player.getAllShortCuts())
{