Use simple arrays to store ItemInstance ensoul data.

This commit is contained in:
MobiusDevelopment 2019-03-31 23:34:07 +00:00
parent 1fd1f80099
commit d8afa9fbbc
20 changed files with 1004 additions and 500 deletions

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1536,7 +1534,9 @@ public final class ItemInstance extends WorldObject
*/ */
public class ItemDropTask implements Runnable public class ItemDropTask implements Runnable
{ {
private int _x, _y, _z; private int _x;
private int _y;
private int _z;
private final Creature _dropper; private final Creature _dropper;
private final ItemInstance _itеm; private final ItemInstance _itеm;
@ -1627,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2182,8 +2203,14 @@ public final class ItemInstance extends WorldObject
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2193,8 +2220,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2224,6 +2257,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2240,6 +2278,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2295,27 +2338,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1536,7 +1534,9 @@ public final class ItemInstance extends WorldObject
*/ */
public class ItemDropTask implements Runnable public class ItemDropTask implements Runnable
{ {
private int _x, _y, _z; private int _x;
private int _y;
private int _z;
private final Creature _dropper; private final Creature _dropper;
private final ItemInstance _itеm; private final ItemInstance _itеm;
@ -1627,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2182,8 +2203,14 @@ public final class ItemInstance extends WorldObject
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2193,8 +2220,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2224,6 +2257,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2240,6 +2278,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2295,27 +2338,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1629,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1677,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2139,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2186,20 +2205,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2207,19 +2226,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2229,8 +2254,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2260,6 +2291,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2276,6 +2312,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2331,27 +2372,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1629,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1677,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2139,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2186,20 +2205,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2207,19 +2226,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2229,8 +2254,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2260,6 +2291,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2276,6 +2312,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2331,27 +2372,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1629,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1677,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2139,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2186,20 +2205,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2207,19 +2226,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2229,8 +2254,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2260,6 +2291,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2276,6 +2312,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2331,27 +2372,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1629,14 +1627,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1677,14 +1674,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2139,41 +2135,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2186,20 +2205,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2207,19 +2226,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2229,8 +2254,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2260,6 +2291,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2276,6 +2312,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2331,27 +2372,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_USING_THE_PRIVATE_STORE_WORKSHOP);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FROZEN);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_TRADING);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_SEATED);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE); player.sendPacket(SystemMessageId.CANNOT_USE_THE_SOUL_CRYSTAL_SYSTEM_WHILE_IN_BATTLE);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1627,14 +1625,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1672,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2133,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2184,20 +2203,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2205,19 +2224,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2227,8 +2252,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2258,6 +2289,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2274,6 +2310,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2329,27 +2370,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1627,14 +1625,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1672,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2133,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2184,20 +2203,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2205,19 +2224,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2227,8 +2252,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2258,6 +2289,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2274,6 +2310,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2329,27 +2370,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1627,14 +1625,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1672,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2133,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2184,20 +2203,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2205,19 +2224,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2227,8 +2252,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2258,6 +2289,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2274,6 +2310,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2329,27 +2370,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");

View File

@ -25,11 +25,9 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level; import java.util.logging.Level;
@ -176,8 +174,8 @@ public final class ItemInstance extends WorldObject
private final DropProtection _dropProtection = new DropProtection(); private final DropProtection _dropProtection = new DropProtection();
private final List<Options> _enchantOptions = new ArrayList<>(); private final List<Options> _enchantOptions = new ArrayList<>();
private final Map<Integer, EnsoulOption> _ensoulOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulOptions = new EnsoulOption[3];
private final Map<Integer, EnsoulOption> _ensoulSpecialOptions = new LinkedHashMap<>(3); private final EnsoulOption[] _ensoulSpecialOptions = new EnsoulOption[3];
/** /**
* Constructor of the ItemInstance from the objectId and the itemId. * Constructor of the ItemInstance from the objectId and the itemId.
@ -1627,14 +1625,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -1675,14 +1672,13 @@ public final class ItemInstance extends WorldObject
{ {
updateItemOptions(con); updateItemOptions(con);
} }
if (_elementals != null) if (_elementals != null)
{ {
updateItemElements(con); updateItemElements(con);
} }
if ((_ensoulOptions != null) || (_ensoulSpecialOptions != null))
{ updateSpecialAbilities(con);
updateSpecialAbilities(con);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -2137,41 +2133,64 @@ public final class ItemInstance extends WorldObject
public Collection<EnsoulOption> getSpecialAbilities() public Collection<EnsoulOption> getSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulOption : _ensoulOptions)
{
if (_ensoulOption != null)
{
result.add(_ensoulOption);
}
}
return result;
} }
public EnsoulOption getSpecialAbility(int index) public EnsoulOption getSpecialAbility(int index)
{ {
return _ensoulOptions.get(index); return _ensoulOptions[index];
} }
public Collection<EnsoulOption> getAdditionalSpecialAbilities() public Collection<EnsoulOption> getAdditionalSpecialAbilities()
{ {
return Collections.unmodifiableCollection(_ensoulSpecialOptions.values()); final List<EnsoulOption> result = new ArrayList<>();
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
if (_ensoulSpecialOption != null)
{
result.add(_ensoulSpecialOption);
}
}
return result;
} }
public EnsoulOption getAdditionalSpecialAbility(int index) public EnsoulOption getAdditionalSpecialAbility(int index)
{ {
return _ensoulSpecialOptions.get(index); return _ensoulSpecialOptions[index];
} }
public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB) public void addSpecialAbility(EnsoulOption option, int position, int type, boolean updateInDB)
{ {
if ((position < 0) || (position > 2))
{
return;
}
if (type == 1) // Adding regular ability if (type == 1) // Adding regular ability
{ {
final EnsoulOption oldOption = _ensoulOptions.put(position, option); final EnsoulOption oldOption = _ensoulOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulOptions[position] = option;
} }
else if (type == 2) // Adding special ability else if (type == 2) // Adding special ability
{ {
final EnsoulOption oldOption = _ensoulSpecialOptions.put(position, option); final EnsoulOption oldOption = _ensoulSpecialOptions[position];
if (oldOption != null) if (oldOption != null)
{ {
removeSpecialAbility(oldOption); removeSpecialAbility(oldOption);
} }
_ensoulSpecialOptions[position] = option;
} }
if (updateInDB) if (updateInDB)
@ -2184,20 +2203,20 @@ public final class ItemInstance extends WorldObject
{ {
if (type == 1) if (type == 1)
{ {
final EnsoulOption option = _ensoulOptions.get(position); final EnsoulOption option = _ensoulOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulOptions.remove(position); _ensoulOptions[position] = null;
// Rearrange. // Rearrange.
if (position == 0) if (position == 0)
{ {
final EnsoulOption secondEnsoul = _ensoulOptions.get(1); final EnsoulOption secondEnsoul = _ensoulOptions[1];
if (secondEnsoul != null) if (secondEnsoul != null)
{ {
removeSpecialAbility(secondEnsoul); removeSpecialAbility(secondEnsoul);
_ensoulOptions.remove(1); _ensoulOptions[1] = null;
addSpecialAbility(secondEnsoul, 0, 1, true); addSpecialAbility(secondEnsoul, 0, 1, true);
} }
} }
@ -2205,19 +2224,25 @@ public final class ItemInstance extends WorldObject
} }
else if (type == 2) else if (type == 2)
{ {
final EnsoulOption option = _ensoulSpecialOptions.get(position); final EnsoulOption option = _ensoulSpecialOptions[position];
if (option != null) if (option != null)
{ {
removeSpecialAbility(option); removeSpecialAbility(option);
_ensoulSpecialOptions.remove(position); _ensoulSpecialOptions[position] = null;
} }
} }
} }
public void clearSpecialAbilities() public void clearSpecialAbilities()
{ {
_ensoulOptions.values().forEach(this::clearSpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::clearSpecialAbility); {
clearSpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
clearSpecialAbility(_ensoulSpecialOption);
}
} }
public void applySpecialAbilities() public void applySpecialAbilities()
@ -2227,8 +2252,14 @@ public final class ItemInstance extends WorldObject
return; return;
} }
_ensoulOptions.values().forEach(this::applySpecialAbility); for (EnsoulOption _ensoulOption : _ensoulOptions)
_ensoulSpecialOptions.values().forEach(this::applySpecialAbility); {
applySpecialAbility(_ensoulOption);
}
for (EnsoulOption _ensoulSpecialOption : _ensoulSpecialOptions)
{
applySpecialAbility(_ensoulSpecialOption);
}
} }
private void removeSpecialAbility(EnsoulOption option) private void removeSpecialAbility(EnsoulOption option)
@ -2258,6 +2289,11 @@ public final class ItemInstance extends WorldObject
private void applySpecialAbility(EnsoulOption option) private void applySpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2274,6 +2310,11 @@ public final class ItemInstance extends WorldObject
private void clearSpecialAbility(EnsoulOption option) private void clearSpecialAbility(EnsoulOption option)
{ {
if (option == null)
{
return;
}
final Skill skill = option.getSkill(); final Skill skill = option.getSkill();
if (skill != null) if (skill != null)
{ {
@ -2329,27 +2370,37 @@ public final class ItemInstance extends WorldObject
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?")) try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_special_abilities (`objectId`, `type`, `optionId`, `position`) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE type = ?, optionId = ?, position = ?"))
{ {
ps.setInt(1, getObjectId()); ps.setInt(1, getObjectId());
for (Entry<Integer, EnsoulOption> entry : _ensoulOptions.entrySet()) for (int i = 0; i < _ensoulOptions.length; i++)
{ {
if (_ensoulOptions[i] == null)
{
continue;
}
ps.setInt(2, 1); // regular options ps.setInt(2, 1); // regular options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 1); // regular options ps.setInt(5, 1); // regular options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
for (Entry<Integer, EnsoulOption> entry : _ensoulSpecialOptions.entrySet()) for (int i = 0; i < _ensoulSpecialOptions.length; i++)
{ {
if (_ensoulSpecialOptions[i] == null)
{
continue;
}
ps.setInt(2, 2); // special options ps.setInt(2, 2); // special options
ps.setInt(3, entry.getValue().getId()); ps.setInt(3, _ensoulSpecialOptions[i].getId());
ps.setInt(4, entry.getKey()); ps.setInt(4, i);
ps.setInt(5, 2); // special options ps.setInt(5, 2); // special options
ps.setInt(6, entry.getValue().getId()); ps.setInt(6, _ensoulSpecialOptions[i].getId());
ps.setInt(7, entry.getKey()); ps.setInt(7, i);
ps.execute(); ps.execute();
} }
} }

View File

@ -81,36 +81,36 @@ public class RequestItemEnsoul implements IClientIncomingPacket
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHEN_PRIVATE_STORE_AND_WORKSHOP_ARE_OPENED);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.FREEZING)) if (player.hasAbnormalType(AbnormalType.FREEZING))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_FROZEN_STATE);
} }
else if (player.isDead()) if (player.isDead())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_IF_THE_CHARACTER_IS_DEAD);
return; return;
} }
else if ((player.getActiveTradeList() != null) || player.hasItemRequest()) if ((player.getActiveTradeList() != null) || player.hasItemRequest())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_EXCHANGE);
return; return;
} }
else if (player.hasAbnormalType(AbnormalType.PARALYZE)) if (player.hasAbnormalType(AbnormalType.PARALYZE))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_PETRIFIED);
return; return;
} }
else if (player.isFishing()) if (player.isFishing())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_DURING_FISHING);
return; return;
} }
else if (player.isSitting()) if (player.isSitting())
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_SITTING);
return; return;
} }
else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player)) if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
{ {
player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT); player.sendPacket(SystemMessageId.RUNE_INSERTION_IS_IMPOSSIBLE_WHILE_IN_COMBAT);
return; return;
@ -122,32 +122,31 @@ public class RequestItemEnsoul implements IClientIncomingPacket
LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without having it!");
return; return;
} }
else if (!item.isEquipable()) if (!item.isEquipable())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul non equippable item: " + item + "!");
return; return;
} }
else if (!item.isWeapon()) if (!item.isWeapon())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul item that's not a weapon: " + item + "!");
return; return;
} }
else if (item.isCommonItem()) if (item.isCommonItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul common item: " + item + "!");
return; return;
} }
else if (item.isShadowItem()) if (item.isShadowItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul shadow item: " + item + "!");
return; return;
} }
else if (item.isHeroItem()) if (item.isHeroItem())
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!"); LOGGER.warning("Player: " + player + " attempting to ensoul hero item: " + item + "!");
return; return;
} }
if ((_options == null) || (_options.length == 0)) if ((_options == null) || (_options.length == 0))
{ {
LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!"); LOGGER.warning("Player: " + player + " attempting to ensoul item without any special ability declared!");