diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java index 585d10c271..a8e114971f 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/model/items/Item.java @@ -175,6 +175,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable private boolean _isAppearanceable; private boolean _isBlessed; + private int _artifactSlot; + /** * Constructor of the Item that fill class variables.
*
@@ -219,6 +221,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable _for_npc = set.getBoolean("for_npc", false); _isAppearanceable = set.getBoolean("isAppearanceable", false); _isBlessed = set.getBoolean("blessed", false); + _artifactSlot = set.getInt("artifactSlot", 0); _immediate_effect = set.getBoolean("immediate_effect", false); _ex_immediate_effect = set.getBoolean("ex_immediate_effect", false); @@ -911,6 +914,11 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return _isBlessed; } + public int getArtifactSlot() + { + return _artifactSlot; + } + /** * Returns the name of the item followed by the item ID. * @return the name and the ID of the item diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java index 81f6bbaf79..eeb17e1a0e 100644 --- a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java @@ -457,7 +457,7 @@ public enum ExIncomingPackets implements IIncomingPackets REQUEST_BLOCK_LIST_FOR_AD(0x15E, null, ConnectionState.IN_GAME), REQUEST_USER_BAN_INFO(0x15F, null, ConnectionState.IN_GAME), EX_INTERACT_MODIFY(0x160, null, ConnectionState.IN_GAME), // 152 - EX_TRY_ENCHANT_ARTIFACT(0x161, null, ConnectionState.IN_GAME), // 152 + EX_TRY_ENCHANT_ARTIFACT(0x161, RequestExTryEnchantArtifact::new, ConnectionState.IN_GAME), // 152 EX_XIGN_CODE(0x162, null, ConnectionState.IN_GAME); // 152 public static final ExIncomingPackets[] PACKET_ARRAY; diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java new file mode 100644 index 0000000000..35cbf4f8be --- /dev/null +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java @@ -0,0 +1,170 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.clientpackets; + +import java.util.HashSet; +import java.util.Set; + +import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; +import org.l2jmobius.gameserver.model.items.Item; +import org.l2jmobius.gameserver.model.items.instance.ItemInstance; +import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.SystemMessageId; +import org.l2jmobius.gameserver.network.serverpackets.ExTryEnchantArtifactResult; +import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate; +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class RequestExTryEnchantArtifact implements IClientIncomingPacket +{ + private static final int[] ENCHANT_CHANCES = + { + 100, + 70, + 70, + 50, + 40, + 40, + 40, + 30, + 30, + 20 + }; + + private int _targetObjectId = 0; + private int _count = 0; + private final Set _ingridients = new HashSet<>(); + + @Override + public boolean read(GameClient client, PacketReader packet) + { + _targetObjectId = packet.readD(); + _count = packet.readD(); + for (int i = 0; i < _count; i++) + { + _ingridients.add(packet.readD()); + } + return !_ingridients.contains(_targetObjectId); + } + + @Override + public void run(GameClient client) + { + final PlayerInstance player = client.getPlayer(); + if (player == null) + { + return; + } + + if (player.hasBlockActions() || player.isInStoreMode() || player.isProcessingRequest() || player.isFishing() || player.isInTraingCamp() || (_count != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final ItemInstance targetItem = player.getInventory().getItemByObjectId(_targetObjectId); + if (targetItem == null) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final Item item = targetItem.getItem(); + final int artifactSlot = item.getArtifactSlot(); + if (artifactSlot <= 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final int enchantLevel = targetItem.getEnchantLevel(); + + int needCount = 0; + if (enchantLevel <= 6) + { + needCount = 3; + } + else if (enchantLevel <= 9) + { + needCount = 2; + } + + if ((needCount == 0) || (needCount != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int chance = ENCHANT_CHANCES[enchantLevel]; + if (chance == 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int minIngridientEnchant = -1; + if (enchantLevel <= 2) + { + minIngridientEnchant = 0; + } + else if (enchantLevel <= 6) + { + minIngridientEnchant = 2; + } + else if (enchantLevel <= 9) + { + minIngridientEnchant = 3; + } + + if (minIngridientEnchant == -1) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + for (int objectId : _ingridients) + { + final ItemInstance ingridient = player.getInventory().getItemByObjectId(objectId); + if ((ingridient == null) || (ingridient.getEnchantLevel() < minIngridientEnchant) || (ingridient.getItem().getArtifactSlot() != artifactSlot)) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + player.destroyItem("Artifact", ingridient, 1, player, true); + } + + if (Rnd.get(100) < chance) + { + targetItem.setEnchantLevel(enchantLevel + 1); + final InventoryUpdate iu = new InventoryUpdate(); + iu.addModifiedItem(targetItem); + player.sendPacket(iu); + player.sendPacket(new SystemMessage(SystemMessageId.ARTIFACT_UPGRADE_SUCCEEDED_AND_YOU_OBTAINED_S1).addItemName(targetItem.getId())); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.SUCCESS, targetItem.getEnchantLevel())); + } + else + { + player.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_UPGRADE_ARTIFACT_THE_ITEM_S_UPGRADE_LEVEL_WILL_REMAIN_THE_SAME)); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.FAIL, targetItem.getEnchantLevel())); + } + } +} diff --git a/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java new file mode 100644 index 0000000000..f860c2a40f --- /dev/null +++ b/L2J_Mobius_5.5_EtinasFate/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.serverpackets; + +import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.network.OutgoingPackets; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class ExTryEnchantArtifactResult implements IClientOutgoingPacket +{ + public static final int SUCCESS = 0; + public static final int FAIL = 1; + public static final int ERROR = 2; + + public static final ExTryEnchantArtifactResult ERROR_PACKET = new ExTryEnchantArtifactResult(ERROR, 0); + + private final int _state; + private final int _enchant; + + public ExTryEnchantArtifactResult(int state, int enchant) + { + _state = state; + _enchant = enchant; + } + + @Override + public boolean write(PacketWriter packet) + { + OutgoingPackets.EX_TRY_ENCHANT_ARTIFACT_RESULT.writeId(packet); + + packet.writeD(_state); + packet.writeD(_enchant); + packet.writeD(0); + packet.writeD(0); + packet.writeD(0); + return true; + } +} \ No newline at end of file diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java index 16437d956d..127c0c475d 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/model/items/Item.java @@ -175,6 +175,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable private boolean _isAppearanceable; private boolean _isBlessed; + private int _artifactSlot; + /** * Constructor of the Item that fill class variables.
*
@@ -219,6 +221,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable _for_npc = set.getBoolean("for_npc", false); _isAppearanceable = set.getBoolean("isAppearanceable", false); _isBlessed = set.getBoolean("blessed", false); + _artifactSlot = set.getInt("artifactSlot", 0); _immediate_effect = set.getBoolean("immediate_effect", false); _ex_immediate_effect = set.getBoolean("ex_immediate_effect", false); @@ -912,6 +915,11 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return _isBlessed; } + public int getArtifactSlot() + { + return _artifactSlot; + } + /** * Returns the name of the item followed by the item ID. * @return the name and the ID of the item diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java index e78635577a..6b6796d430 100644 --- a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java @@ -458,7 +458,7 @@ public enum ExIncomingPackets implements IIncomingPackets REQUEST_BLOCK_LIST_FOR_AD(0x15E, null, ConnectionState.IN_GAME), REQUEST_USER_BAN_INFO(0x15F, null, ConnectionState.IN_GAME), EX_INTERACT_MODIFY(0x160, null, ConnectionState.IN_GAME), // 152 - EX_TRY_ENCHANT_ARTIFACT(0x161, null, ConnectionState.IN_GAME), // 152 + EX_TRY_ENCHANT_ARTIFACT(0x161, RequestExTryEnchantArtifact::new, ConnectionState.IN_GAME), // 152 EX_XIGN_CODE(0x162, null, ConnectionState.IN_GAME); // 152 public static final ExIncomingPackets[] PACKET_ARRAY; diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java new file mode 100644 index 0000000000..35cbf4f8be --- /dev/null +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java @@ -0,0 +1,170 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.clientpackets; + +import java.util.HashSet; +import java.util.Set; + +import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; +import org.l2jmobius.gameserver.model.items.Item; +import org.l2jmobius.gameserver.model.items.instance.ItemInstance; +import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.SystemMessageId; +import org.l2jmobius.gameserver.network.serverpackets.ExTryEnchantArtifactResult; +import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate; +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class RequestExTryEnchantArtifact implements IClientIncomingPacket +{ + private static final int[] ENCHANT_CHANCES = + { + 100, + 70, + 70, + 50, + 40, + 40, + 40, + 30, + 30, + 20 + }; + + private int _targetObjectId = 0; + private int _count = 0; + private final Set _ingridients = new HashSet<>(); + + @Override + public boolean read(GameClient client, PacketReader packet) + { + _targetObjectId = packet.readD(); + _count = packet.readD(); + for (int i = 0; i < _count; i++) + { + _ingridients.add(packet.readD()); + } + return !_ingridients.contains(_targetObjectId); + } + + @Override + public void run(GameClient client) + { + final PlayerInstance player = client.getPlayer(); + if (player == null) + { + return; + } + + if (player.hasBlockActions() || player.isInStoreMode() || player.isProcessingRequest() || player.isFishing() || player.isInTraingCamp() || (_count != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final ItemInstance targetItem = player.getInventory().getItemByObjectId(_targetObjectId); + if (targetItem == null) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final Item item = targetItem.getItem(); + final int artifactSlot = item.getArtifactSlot(); + if (artifactSlot <= 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final int enchantLevel = targetItem.getEnchantLevel(); + + int needCount = 0; + if (enchantLevel <= 6) + { + needCount = 3; + } + else if (enchantLevel <= 9) + { + needCount = 2; + } + + if ((needCount == 0) || (needCount != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int chance = ENCHANT_CHANCES[enchantLevel]; + if (chance == 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int minIngridientEnchant = -1; + if (enchantLevel <= 2) + { + minIngridientEnchant = 0; + } + else if (enchantLevel <= 6) + { + minIngridientEnchant = 2; + } + else if (enchantLevel <= 9) + { + minIngridientEnchant = 3; + } + + if (minIngridientEnchant == -1) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + for (int objectId : _ingridients) + { + final ItemInstance ingridient = player.getInventory().getItemByObjectId(objectId); + if ((ingridient == null) || (ingridient.getEnchantLevel() < minIngridientEnchant) || (ingridient.getItem().getArtifactSlot() != artifactSlot)) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + player.destroyItem("Artifact", ingridient, 1, player, true); + } + + if (Rnd.get(100) < chance) + { + targetItem.setEnchantLevel(enchantLevel + 1); + final InventoryUpdate iu = new InventoryUpdate(); + iu.addModifiedItem(targetItem); + player.sendPacket(iu); + player.sendPacket(new SystemMessage(SystemMessageId.ARTIFACT_UPGRADE_SUCCEEDED_AND_YOU_OBTAINED_S1).addItemName(targetItem.getId())); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.SUCCESS, targetItem.getEnchantLevel())); + } + else + { + player.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_UPGRADE_ARTIFACT_THE_ITEM_S_UPGRADE_LEVEL_WILL_REMAIN_THE_SAME)); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.FAIL, targetItem.getEnchantLevel())); + } + } +} diff --git a/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java new file mode 100644 index 0000000000..f860c2a40f --- /dev/null +++ b/L2J_Mobius_6.0_Fafurion/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.serverpackets; + +import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.network.OutgoingPackets; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class ExTryEnchantArtifactResult implements IClientOutgoingPacket +{ + public static final int SUCCESS = 0; + public static final int FAIL = 1; + public static final int ERROR = 2; + + public static final ExTryEnchantArtifactResult ERROR_PACKET = new ExTryEnchantArtifactResult(ERROR, 0); + + private final int _state; + private final int _enchant; + + public ExTryEnchantArtifactResult(int state, int enchant) + { + _state = state; + _enchant = enchant; + } + + @Override + public boolean write(PacketWriter packet) + { + OutgoingPackets.EX_TRY_ENCHANT_ARTIFACT_RESULT.writeId(packet); + + packet.writeD(_state); + packet.writeD(_enchant); + packet.writeD(0); + packet.writeD(0); + packet.writeD(0); + return true; + } +} \ No newline at end of file diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java index 16437d956d..127c0c475d 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/model/items/Item.java @@ -175,6 +175,8 @@ public abstract class Item extends ListenersContainer implements IIdentifiable private boolean _isAppearanceable; private boolean _isBlessed; + private int _artifactSlot; + /** * Constructor of the Item that fill class variables.
*
@@ -219,6 +221,7 @@ public abstract class Item extends ListenersContainer implements IIdentifiable _for_npc = set.getBoolean("for_npc", false); _isAppearanceable = set.getBoolean("isAppearanceable", false); _isBlessed = set.getBoolean("blessed", false); + _artifactSlot = set.getInt("artifactSlot", 0); _immediate_effect = set.getBoolean("immediate_effect", false); _ex_immediate_effect = set.getBoolean("ex_immediate_effect", false); @@ -912,6 +915,11 @@ public abstract class Item extends ListenersContainer implements IIdentifiable return _isBlessed; } + public int getArtifactSlot() + { + return _artifactSlot; + } + /** * Returns the name of the item followed by the item ID. * @return the name and the ID of the item diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java index 530152478e..e1c9c44485 100644 --- a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/ExIncomingPackets.java @@ -466,7 +466,7 @@ public enum ExIncomingPackets implements IIncomingPackets REQUEST_BLOCK_LIST_FOR_AD(0x15D, null, ConnectionState.IN_GAME), REQUEST_USER_BAN_INFO(0x15E, null, ConnectionState.IN_GAME), EX_INTERACT_MODIFY(0x15F, null, ConnectionState.IN_GAME), // 152 - EX_TRY_ENCHANT_ARTIFACT(0x160, null, ConnectionState.IN_GAME), // 152 + EX_TRY_ENCHANT_ARTIFACT(0x160, RequestExTryEnchantArtifact::new, ConnectionState.IN_GAME), // 152 EX_XIGN_CODE(0x161, null, ConnectionState.IN_GAME), // 152 EX_OPEN_HTML(0x164, ExOpenDimensionalHtml::new, ConnectionState.IN_GAME), // 228 EX_REQUEST_CLASS_CHANGE(0x165, ExRequestClassChange::new, ConnectionState.IN_GAME), // 228 diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java new file mode 100644 index 0000000000..35cbf4f8be --- /dev/null +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/clientpackets/RequestExTryEnchantArtifact.java @@ -0,0 +1,170 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.clientpackets; + +import java.util.HashSet; +import java.util.Set; + +import org.l2jmobius.commons.network.PacketReader; +import org.l2jmobius.commons.util.Rnd; +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance; +import org.l2jmobius.gameserver.model.items.Item; +import org.l2jmobius.gameserver.model.items.instance.ItemInstance; +import org.l2jmobius.gameserver.network.GameClient; +import org.l2jmobius.gameserver.network.SystemMessageId; +import org.l2jmobius.gameserver.network.serverpackets.ExTryEnchantArtifactResult; +import org.l2jmobius.gameserver.network.serverpackets.InventoryUpdate; +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class RequestExTryEnchantArtifact implements IClientIncomingPacket +{ + private static final int[] ENCHANT_CHANCES = + { + 100, + 70, + 70, + 50, + 40, + 40, + 40, + 30, + 30, + 20 + }; + + private int _targetObjectId = 0; + private int _count = 0; + private final Set _ingridients = new HashSet<>(); + + @Override + public boolean read(GameClient client, PacketReader packet) + { + _targetObjectId = packet.readD(); + _count = packet.readD(); + for (int i = 0; i < _count; i++) + { + _ingridients.add(packet.readD()); + } + return !_ingridients.contains(_targetObjectId); + } + + @Override + public void run(GameClient client) + { + final PlayerInstance player = client.getPlayer(); + if (player == null) + { + return; + } + + if (player.hasBlockActions() || player.isInStoreMode() || player.isProcessingRequest() || player.isFishing() || player.isInTraingCamp() || (_count != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final ItemInstance targetItem = player.getInventory().getItemByObjectId(_targetObjectId); + if (targetItem == null) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final Item item = targetItem.getItem(); + final int artifactSlot = item.getArtifactSlot(); + if (artifactSlot <= 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + final int enchantLevel = targetItem.getEnchantLevel(); + + int needCount = 0; + if (enchantLevel <= 6) + { + needCount = 3; + } + else if (enchantLevel <= 9) + { + needCount = 2; + } + + if ((needCount == 0) || (needCount != _ingridients.size())) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int chance = ENCHANT_CHANCES[enchantLevel]; + if (chance == 0) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + int minIngridientEnchant = -1; + if (enchantLevel <= 2) + { + minIngridientEnchant = 0; + } + else if (enchantLevel <= 6) + { + minIngridientEnchant = 2; + } + else if (enchantLevel <= 9) + { + minIngridientEnchant = 3; + } + + if (minIngridientEnchant == -1) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + + for (int objectId : _ingridients) + { + final ItemInstance ingridient = player.getInventory().getItemByObjectId(objectId); + if ((ingridient == null) || (ingridient.getEnchantLevel() < minIngridientEnchant) || (ingridient.getItem().getArtifactSlot() != artifactSlot)) + { + player.sendPacket(ExTryEnchantArtifactResult.ERROR_PACKET); + return; + } + player.destroyItem("Artifact", ingridient, 1, player, true); + } + + if (Rnd.get(100) < chance) + { + targetItem.setEnchantLevel(enchantLevel + 1); + final InventoryUpdate iu = new InventoryUpdate(); + iu.addModifiedItem(targetItem); + player.sendPacket(iu); + player.sendPacket(new SystemMessage(SystemMessageId.ARTIFACT_UPGRADE_SUCCEEDED_AND_YOU_OBTAINED_S1).addItemName(targetItem.getId())); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.SUCCESS, targetItem.getEnchantLevel())); + } + else + { + player.sendPacket(new SystemMessage(SystemMessageId.FAILED_TO_UPGRADE_ARTIFACT_THE_ITEM_S_UPGRADE_LEVEL_WILL_REMAIN_THE_SAME)); + player.sendPacket(new ExTryEnchantArtifactResult(ExTryEnchantArtifactResult.FAIL, targetItem.getEnchantLevel())); + } + } +} diff --git a/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java new file mode 100644 index 0000000000..f860c2a40f --- /dev/null +++ b/L2J_Mobius_7.0_PreludeOfWar/java/org/l2jmobius/gameserver/network/serverpackets/ExTryEnchantArtifactResult.java @@ -0,0 +1,55 @@ +/* + * 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 . + */ +package org.l2jmobius.gameserver.network.serverpackets; + +import org.l2jmobius.commons.network.PacketWriter; +import org.l2jmobius.gameserver.network.OutgoingPackets; + +/** + * @author Bonux (bonuxq@gmail.com) + * @date 09.09.2019 + **/ +public class ExTryEnchantArtifactResult implements IClientOutgoingPacket +{ + public static final int SUCCESS = 0; + public static final int FAIL = 1; + public static final int ERROR = 2; + + public static final ExTryEnchantArtifactResult ERROR_PACKET = new ExTryEnchantArtifactResult(ERROR, 0); + + private final int _state; + private final int _enchant; + + public ExTryEnchantArtifactResult(int state, int enchant) + { + _state = state; + _enchant = enchant; + } + + @Override + public boolean write(PacketWriter packet) + { + OutgoingPackets.EX_TRY_ENCHANT_ARTIFACT_RESULT.writeId(packet); + + packet.writeD(_state); + packet.writeD(_enchant); + packet.writeD(0); + packet.writeD(0); + packet.writeD(0); + return true; + } +} \ No newline at end of file