Addition of ChangeAttributeCrystal item handler.

This commit is contained in:
MobiusDev
2017-09-11 01:07:26 +00:00
parent 82de3b7a62
commit fe21a7d72b
48 changed files with 1987 additions and 44 deletions

View File

@@ -186,6 +186,7 @@ import handlers.itemhandlers.BlessedSpiritShot;
import handlers.itemhandlers.Book;
import handlers.itemhandlers.Bypass;
import handlers.itemhandlers.Calculator;
import handlers.itemhandlers.ChangeAttributeCrystal;
import handlers.itemhandlers.CharmOfCourage;
import handlers.itemhandlers.Elixir;
import handlers.itemhandlers.EnchantAttribute;
@@ -525,6 +526,7 @@ public class MasterHandler
Book.class,
Bypass.class,
Calculator.class,
ChangeAttributeCrystal.class,
CharmOfCourage.class,
Elixir.class,
EnchantAttribute.class,

View 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.itemhandlers;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.l2jmobius.gameserver.enums.ItemGrade;
import com.l2jmobius.gameserver.enums.PrivateStoreType;
import com.l2jmobius.gameserver.handler.IItemHandler;
import com.l2jmobius.gameserver.model.ItemInfo;
import com.l2jmobius.gameserver.model.actor.L2Playable;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import com.l2jmobius.gameserver.network.serverpackets.attributechange.ExChangeAttributeItemList;
/**
* @author Mobius
*/
public class ChangeAttributeCrystal implements IItemHandler
{
private static final Map<Integer, ItemGrade> ITEM_GRADES = new HashMap<>();
{
ITEM_GRADES.put(33502, ItemGrade.S);
ITEM_GRADES.put(35749, ItemGrade.R);
ITEM_GRADES.put(45817, ItemGrade.R);
}
@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 player = playable.getActingPlayer();
if (player.getPrivateStoreType() != PrivateStoreType.NONE)
{
player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_CANNOT_CHANGE_AN_ATTRIBUTE_WHILE_USING_A_PRIVATE_STORE_OR_WORKSHOP));
return false;
}
if (ITEM_GRADES.get(item.getId()) == null)
{
player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CHANGING_ATTRIBUTES_HAS_BEEN_FAILED));
return false;
}
final List<ItemInfo> itemList = new ArrayList<>();
for (L2ItemInstance i : player.getInventory().getItems())
{
if (i.isWeapon() && i.hasAttributes() && (i.getItem().getItemGrade() == ITEM_GRADES.get(item.getId())))
{
itemList.add(new ItemInfo(i));
}
}
if (itemList.isEmpty())
{
player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.THE_ITEM_FOR_CHANGING_AN_ATTRIBUTE_DOES_NOT_EXIST));
return false;
}
player.sendPacket(new ExChangeAttributeItemList(item.getId(), itemList.toArray(new ItemInfo[itemList.size()])));
return true;
}
}