108 lines
3.7 KiB
Java
108 lines
3.7 KiB
Java
/*
|
|
* 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.itemhandlers;
|
|
|
|
import java.util.List;
|
|
|
|
import com.l2jmobius.gameserver.enums.ItemSkillType;
|
|
import com.l2jmobius.gameserver.enums.ShotType;
|
|
import com.l2jmobius.gameserver.handler.IItemHandler;
|
|
import com.l2jmobius.gameserver.model.actor.L2Playable;
|
|
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
|
import com.l2jmobius.gameserver.model.holders.ItemSkillHolder;
|
|
import com.l2jmobius.gameserver.model.items.L2Weapon;
|
|
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
|
import com.l2jmobius.gameserver.model.items.type.ActionType;
|
|
import com.l2jmobius.gameserver.network.SystemMessageId;
|
|
import com.l2jmobius.gameserver.network.serverpackets.MagicSkillUse;
|
|
import com.l2jmobius.gameserver.util.Broadcast;
|
|
|
|
public class SpiritShot implements IItemHandler
|
|
{
|
|
@Override
|
|
public boolean useItem(L2Playable playable, L2ItemInstance item, boolean forceUse)
|
|
{
|
|
if (!playable.isPlayer())
|
|
{
|
|
playable.sendPacket(SystemMessageId.YOUR_PET_CANNOT_CARRY_THIS_ITEM);
|
|
return false;
|
|
}
|
|
|
|
final L2PcInstance activeChar = playable.getActingPlayer();
|
|
final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
|
|
final L2Weapon weaponItem = activeChar.getActiveWeaponItem();
|
|
final List<ItemSkillHolder> skills = item.getItem().getSkills(ItemSkillType.NORMAL);
|
|
if (skills == null)
|
|
{
|
|
_log.warning(getClass().getSimpleName() + ": is missing skills!");
|
|
return false;
|
|
}
|
|
|
|
final int itemId = item.getId();
|
|
|
|
// Check if SpiritShot can be used
|
|
if ((weaponInst == null) || (weaponItem.getSpiritShotCount() == 0))
|
|
{
|
|
if (!activeChar.getAutoSoulShot().contains(itemId))
|
|
{
|
|
activeChar.sendPacket(SystemMessageId.YOU_MAY_NOT_USE_SPIRITSHOTS);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Check if SpiritShot is already active
|
|
if (activeChar.isChargedShot(ShotType.SPIRITSHOTS))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Check for correct grade
|
|
final boolean gradeCheck = item.isEtcItem() && (item.getEtcItem().getDefaultAction() == ActionType.SPIRITSHOT) && (weaponInst.getItem().getCrystalTypePlus() == item.getItem().getCrystalTypePlus());
|
|
|
|
if (!gradeCheck)
|
|
{
|
|
if (!activeChar.getAutoSoulShot().contains(itemId))
|
|
{
|
|
activeChar.sendPacket(SystemMessageId.YOUR_SPIRITSHOT_DOES_NOT_MATCH_THE_WEAPON_S_GRADE);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Consume SpiritShot if player has enough of them
|
|
if (!activeChar.destroyItemWithoutTrace("Consume", item.getObjectId(), weaponItem.getSpiritShotCount(), null, false))
|
|
{
|
|
if (!activeChar.disableAutoShot(itemId))
|
|
{
|
|
activeChar.sendPacket(SystemMessageId.YOU_DO_NOT_HAVE_ENOUGH_SPIRITSHOT_FOR_THAT);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Charge Spirit shot
|
|
activeChar.setChargedShot(ShotType.SPIRITSHOTS, true);
|
|
|
|
// Send message to client
|
|
if (!activeChar.getAutoSoulShot().contains(item.getId()))
|
|
{
|
|
activeChar.sendPacket(SystemMessageId.YOUR_SPIRITSHOT_HAS_BEEN_ENABLED);
|
|
}
|
|
skills.forEach(holder -> Broadcast.toSelfAndKnownPlayersInRadius(activeChar, new MagicSkillUse(activeChar, activeChar, holder.getSkillId(), holder.getSkillLvl(), 0, 0), 600));
|
|
return true;
|
|
}
|
|
}
|