Newer
Older
* L2J DataPack 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.
*
* L2J DataPack 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.l2jserver.datapack.handlers.itemhandlers;
import com.l2jserver.gameserver.ai.CtrlIntention;
import com.l2jserver.gameserver.handler.IItemHandler;
import com.l2jserver.gameserver.model.actor.L2Playable;
import com.l2jserver.gameserver.model.entity.TvTEvent;
import com.l2jserver.gameserver.model.holders.SkillHolder;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
/**
* Template for item skills handler.
* @author Zoey76
public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse) {
if (!playable.isPlayer() && !playable.isPet()) {
}
playable.sendPacket(ActionFailed.STATIC_PACKET);
// Pets can use items only when they are tradable.
playable.sendPacket(SystemMessageId.ITEM_NOT_FOR_PETS);
// Verify that item is not under reuse.
}
final SkillHolder[] skills = item.getEtcItem().getSkills();
_log.info("Item " + item + " does not have registered any skill for handler.");
return false;
}
for (SkillHolder skillInfo : skills) {
if (skillInfo == null) {
if (itemSkill != null) {
if (itemSkill.getItemConsumeId() > 0) {
if (!itemSkill.checkCondition(playable, itemSkill.getTargetType().getTarget(itemSkill, playable, playable.getTarget()), false)) {
}
return false;
}
// Verify that skill is not under reuse.
if (!item.isPotion() && !item.isElixir() && !item.isScroll() && !item.getItem().hasExImmediateEffect() && playable.isCastingNow()) {
// Send message to the master.
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.PET_USES_S1);
sm.addSkillName(itemSkill);
playable.sendPacket(sm);
if (itemSkill.isSimultaneousCast() || ((item.getItem().hasImmediateEffect() || item.getItem().hasExImmediateEffect()) && itemSkill.isStatic())) {
playable.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
playable.addTimeStamp(itemSkill, itemSkill.getReuseDelay());
if (checkConsume(item, hasConsumeSkill)) {
if (!playable.destroyItem("Consume", item.getObjectId(), 1, playable, false)) {
playable.sendPacket(SystemMessageId.NOT_ENOUGH_ITEMS);
return false;
}
}
* @return {@code true} check if item use consume item, {@code false} otherwise
*/
private boolean checkConsume(L2ItemInstance item, boolean hasConsumeSkill) {
case SKILL_REDUCE: {
if (!hasConsumeSkill && item.getItem().hasImmediateEffect()) {
return false;
* @param playable the character using the item or skill
* @param skill the skill being used, can be null
* @param item the item being used
* @return {@code true} if the the item or skill to check is available, {@code false} otherwise
private boolean checkReuse(L2Playable playable, Skill skill, L2ItemInstance item) {
final long remainingTime = (skill != null) ? playable.getSkillRemainingReuseTime(skill.getReuseHashCode()) : playable.getItemRemainingReuseTime(item.getObjectId());
final boolean isAvailable = remainingTime <= 0;
final int hours = (int) (remainingTime / 3600000L);
final int minutes = (int) (remainingTime % 3600000L) / 60000;
final int seconds = (int) ((remainingTime / 1000) % 60);
SystemMessage sm = null;
sm = SystemMessage.getSystemMessage(SystemMessageId.S2_HOURS_S3_MINUTES_S4_SECONDS_REMAINING_FOR_REUSE_S1);
sm.addItemName(item);
sm.addSkillName(skill);
}
sm = SystemMessage.getSystemMessage(SystemMessageId.S2_MINUTES_S3_SECONDS_REMAINING_FOR_REUSE_S1);
sm.addItemName(item);
sm.addSkillName(skill);
}
sm = SystemMessage.getSystemMessage(SystemMessageId.S2_SECONDS_REMAINING_FOR_REUSE_S1);
sm.addItemName(item);
sm.addSkillName(skill);
}
}
playable.sendPacket(sm);