Addition of RequestExTryEnchantArtifact packet.
Author: Bonux
This commit is contained in:
parent
42799b4998
commit
2a1459d484
@ -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.<BR>
|
||||
* <BR>
|
||||
@ -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
|
||||
|
@ -457,7 +457,7 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
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;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Integer> _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()));
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -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.<BR>
|
||||
* <BR>
|
||||
@ -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
|
||||
|
@ -458,7 +458,7 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
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;
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Integer> _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()));
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -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.<BR>
|
||||
* <BR>
|
||||
@ -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
|
||||
|
@ -466,7 +466,7 @@ public enum ExIncomingPackets implements IIncomingPackets<GameClient>
|
||||
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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Integer> _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()));
|
||||
}
|
||||
}
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user