Addition of GiveItemByExp effect handler.
This commit is contained in:
@@ -171,6 +171,7 @@ public class EffectMasterHandler
|
||||
EffectHandler.getInstance().registerHandler("GiveClanReputation", GiveClanReputation::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveExpAndSp", GiveExpAndSp::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveFame", GiveFame::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveItemByExp", GiveItemByExp::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveRecommendation", GiveRecommendation::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveSp", GiveSp::new);
|
||||
EffectHandler.getInstance().registerHandler("GiveXp", GiveXp::new);
|
||||
|
87
L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/effecthandlers/GiveItemByExp.java
vendored
Normal file
87
L2J_Mobius_08.2_Homunculus/dist/game/data/scripts/handlers/effecthandlers/GiveItemByExp.java
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.actor.Creature;
|
||||
import org.l2jmobius.gameserver.model.actor.Playable;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.effects.AbstractEffect;
|
||||
import org.l2jmobius.gameserver.model.events.EventType;
|
||||
import org.l2jmobius.gameserver.model.events.impl.creature.player.OnPlayableExpChanged;
|
||||
import org.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
|
||||
import org.l2jmobius.gameserver.model.item.instance.Item;
|
||||
import org.l2jmobius.gameserver.model.skill.Skill;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class GiveItemByExp extends AbstractEffect
|
||||
{
|
||||
private static final Map<Player, Long> CREATURE_VALUES = new ConcurrentHashMap<>();
|
||||
|
||||
private final long _exp;
|
||||
private final int _itemId;
|
||||
|
||||
public GiveItemByExp(StatSet params)
|
||||
{
|
||||
_exp = params.getLong("exp", 0);
|
||||
_itemId = params.getInt("itemId", 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Creature effector, Creature effected, Skill skill, Item item)
|
||||
{
|
||||
if (effected.isPlayer())
|
||||
{
|
||||
effected.addListener(new ConsumerEventListener(effected, EventType.ON_PLAYABLE_EXP_CHANGED, (OnPlayableExpChanged event) -> onExperienceReceived(event.getPlayable(), (event.getNewExp() - event.getOldExp())), this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExit(Creature effector, Creature effected, Skill skill)
|
||||
{
|
||||
if (effected.isPlayer())
|
||||
{
|
||||
CREATURE_VALUES.remove(effected.getActingPlayer());
|
||||
effected.removeListenerIf(EventType.ON_PLAYABLE_EXP_CHANGED, listener -> listener.getOwner() == this);
|
||||
}
|
||||
}
|
||||
|
||||
private void onExperienceReceived(Playable playable, long exp)
|
||||
{
|
||||
if (exp < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = playable.getActingPlayer();
|
||||
final long sum = CREATURE_VALUES.getOrDefault(player, 0L) + exp;
|
||||
if (sum >= _exp)
|
||||
{
|
||||
CREATURE_VALUES.remove(player);
|
||||
player.addItem("GiveItemByExp effect", _itemId, 1, player, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CREATURE_VALUES.put(player, sum);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user