Ensoul system implementation.

Contributed by Mathael.
This commit is contained in:
MobiusDev
2016-03-05 16:25:48 +00:00
parent 7a9de77047
commit 240332641f
23 changed files with 1680 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ import com.l2jmobius.gameserver.model.buylist.Product;
import com.l2jmobius.gameserver.model.items.L2Item;
import com.l2jmobius.gameserver.model.items.L2WarehouseItem;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
/**
* Get all information from L2ItemInstance to generate ItemInfo.
@@ -76,6 +77,9 @@ public class ItemInfo
private int _visualId;
private long _visualExpiration;
private SoulCrystalOption[] _commonSoulCrystalOptions = new SoulCrystalOption[2];
private SoulCrystalOption _specialSoulCrystalOption;
/**
* Get all information from L2ItemInstance to generate ItemInfo.
* @param item
@@ -149,6 +153,9 @@ public class ItemInfo
}
_option = item.getEnchantOptions();
_visualId = item.getVisualId();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
public ItemInfo(L2ItemInstance item, int change)
@@ -212,6 +219,8 @@ public class ItemInfo
_option = item.getEnchantOptions();
_visualId = item.getVisualId();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
public ItemInfo(Product item)
@@ -301,6 +310,9 @@ public class ItemInfo
_elemDefAttr[i] = item.getElementDefAttr(i);
}
_option = item.getEnchantOptions();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
public int getObjectId()
@@ -407,4 +419,24 @@ public class ItemInfo
{
return _visualExpiration;
}
public SoulCrystalOption[] getCommonSoulCrystalOptions()
{
return _commonSoulCrystalOptions;
}
public void setSoulCrystalOptions(SoulCrystalOption[] options)
{
_commonSoulCrystalOptions = options;
}
public SoulCrystalOption getSpecialSoulCrystalOption()
{
return _specialSoulCrystalOption;
}
public void setSpecialSoulCrystalOption(SoulCrystalOption option)
{
_specialSoulCrystalOption = option;
}
}

View File

@@ -18,6 +18,7 @@ package com.l2jmobius.gameserver.model;
import com.l2jmobius.gameserver.model.items.L2Item;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
public class TradeItem
{
@@ -50,6 +51,8 @@ public class TradeItem
private final int _time;
private final int _visualId;
private final long _visualExpiration;
private SoulCrystalOption[] _commonSoulCrystalOptions;
private SoulCrystalOption _specialSoulCrystalOption;
public TradeItem(L2ItemInstance item, long count, long price)
{
@@ -76,6 +79,8 @@ public class TradeItem
_time = item.isTimeLimitedItem() ? (int) (item.getRemainingTime() / 1000) : -9999;
_visualId = item.getVisualId();
_visualExpiration = item.getTime();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
public TradeItem(L2Item item, long count, long price, int enchantLevel, int attackAttribute, int attackAttributeValue, int defenseAttributes[], int appearanceId)
@@ -104,6 +109,8 @@ public class TradeItem
_time = -9999;
_visualId = appearanceId;
_visualExpiration = -1;
_commonSoulCrystalOptions = new SoulCrystalOption[2];
_specialSoulCrystalOption = null;
}
public TradeItem(TradeItem item, long count, long price, int enchantLevel, int attackAttribute, int attackAttributeValue, int defenseAttributes[], int appearanceId)
@@ -132,6 +139,8 @@ public class TradeItem
_time = item.isTimeLimitedItem() ? (int) (item.getRemainingTime() / 1000) : -9999;
_visualId = item.getVisualId();
_visualExpiration = item.getVisualExpiration();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
public L2ItemInstance getItemInstance()
@@ -263,4 +272,24 @@ public class TradeItem
{
return _time;
}
public SoulCrystalOption[] getCommonSoulCrystalOptions()
{
return _commonSoulCrystalOptions;
}
public void setSoulCrystalOptions(SoulCrystalOption[] options)
{
_commonSoulCrystalOptions = options;
}
public SoulCrystalOption getSpecialSoulCrystalOption()
{
return _specialSoulCrystalOption;
}
public void setSpecialSoulCrystalOption(SoulCrystalOption option)
{
_specialSoulCrystalOption = option;
}
}

View File

@@ -375,6 +375,7 @@ public abstract class Inventory extends ItemContainer
}
item.clearEnchantStats();
item.removeSoulCrystalOptionEffect();
final SkillHolder[] skills = it.getSkills();
@@ -504,6 +505,7 @@ public abstract class Inventory extends ItemContainer
}
item.applyEnchantStats();
item.applySoulCrystalOptionEffect();
final SkillHolder[] skills = it.getSkills();

View File

@@ -1109,6 +1109,7 @@ public class PcInventory extends Inventory
{
item.giveSkillsToOwner();
item.applyEnchantStats();
item.applySoulCrystalOptionEffect();
}
}
}

View File

@@ -115,6 +115,7 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
private final int _itemId;
private final int _displayId;
private final String _name;
private final String _additionalName;
private final String _icon;
private final int _weight;
private final boolean _stackable;
@@ -175,6 +176,7 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
_itemId = set.getInt("item_id");
_displayId = set.getInt("displayId", _itemId);
_name = set.getString("name");
_additionalName = set.getString("additionalName", null);
_icon = set.getString("icon", null);
_weight = set.getInt("weight", 0);
_materialType = set.getEnum("material", MaterialType.class, MaterialType.STEEL);
@@ -537,6 +539,14 @@ public abstract class L2Item extends ListenersContainer implements IIdentifiable
return _name;
}
/**
* @return the item's additional name.
*/
public String getAdditionalName()
{
return _additionalName;
}
/**
* @return the base elemental of the item.
*/

View File

@@ -19,6 +19,7 @@ package com.l2jmobius.gameserver.model.items;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.items.type.CrystalType;
import com.l2jmobius.gameserver.model.items.type.ItemType;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
/**
* This class contains L2ItemInstance<BR>
@@ -62,6 +63,9 @@ public class L2WarehouseItem
private final int _time;
private SoulCrystalOption[] _commonSoulCrystalOptions;
private SoulCrystalOption _specialSoulCrystalOption;
public L2WarehouseItem(L2ItemInstance item)
{
_item = item.getItem();
@@ -92,6 +96,9 @@ public class L2WarehouseItem
_elemDefAttr[i] = item.getElementDefAttr(i);
}
_enchantOptions = item.getEnchantOptions();
_commonSoulCrystalOptions = item.getCommonSoulCrystalOptions();
_specialSoulCrystalOption = item.getSpecialSoulCrystalOption();
}
/**
@@ -286,6 +293,26 @@ public class L2WarehouseItem
return _time;
}
public SoulCrystalOption[] getCommonSoulCrystalOptions()
{
return _commonSoulCrystalOptions;
}
public void setSoulCrystalOptions(SoulCrystalOption[] options)
{
_commonSoulCrystalOptions = options;
}
public SoulCrystalOption getSpecialSoulCrystalOption()
{
return _specialSoulCrystalOption;
}
public void setSpecialSoulCrystalOption(SoulCrystalOption option)
{
_specialSoulCrystalOption = option;
}
/**
* @return the name of the item
*/

View File

@@ -38,6 +38,7 @@ import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.data.xml.impl.AppearanceItemData;
import com.l2jmobius.gameserver.data.xml.impl.EnchantItemOptionsData;
import com.l2jmobius.gameserver.data.xml.impl.OptionData;
import com.l2jmobius.gameserver.data.xml.impl.SoulCrystalOptionsData;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.enums.InstanceType;
import com.l2jmobius.gameserver.enums.ItemLocation;
@@ -77,6 +78,7 @@ import com.l2jmobius.gameserver.model.options.Options;
import com.l2jmobius.gameserver.model.stats.functions.AbstractFunction;
import com.l2jmobius.gameserver.model.variables.ItemVariables;
import com.l2jmobius.gameserver.network.SystemMessageId;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
import com.l2jmobius.gameserver.network.serverpackets.DropItem;
import com.l2jmobius.gameserver.network.serverpackets.ExAdenaInvenCount;
import com.l2jmobius.gameserver.network.serverpackets.ExUserInfoEquipSlot;
@@ -132,6 +134,10 @@ public final class L2ItemInstance extends L2Object
/** Augmented Item */
private L2Augmentation _augmentation = null;
/** Soul Crystal **/
private SoulCrystalOption[] _commonSoulCrystalOptions = new SoulCrystalOption[2];
private SoulCrystalOption _specialSoulCrystalOption;
/** Shadow item */
private int _mana = -1;
private boolean _consumingMana = false;
@@ -1554,6 +1560,11 @@ public final class L2ItemInstance extends L2Object
if (inst.isEquipable())
{
inst.restoreAttributes();
if (inst.isWeapon())
{
inst.restoreSoulCrystalOptions();
}
}
return inst;
@@ -1731,6 +1742,7 @@ public final class L2ItemInstance extends L2Object
{
updateItemElements(con);
}
// TODO: Soul Crystal
}
catch (Exception e)
{
@@ -1771,6 +1783,12 @@ public final class L2ItemInstance extends L2Object
ps.setInt(1, getObjectId());
ps.executeUpdate();
}
try (PreparedStatement ps = con.prepareStatement("DELETE FROM item_soulcrystal WHERE object_id = ?"))
{
ps.setInt(1, getObjectId());
ps.executeUpdate();
}
}
catch (Exception e)
{
@@ -2359,4 +2377,167 @@ public final class L2ItemInstance extends L2Object
{
return isWeapon() || isArmor();
}
public SoulCrystalOption[] getCommonSoulCrystalOptions()
{
return _commonSoulCrystalOptions;
}
public SoulCrystalOption getSpecialSoulCrystalOption()
{
return _specialSoulCrystalOption;
}
public void setCommonSoulCrystalOptions(SoulCrystalOption[] options)
{
_commonSoulCrystalOptions = options;
}
public void addCommonSoulCrystalOption(SoulCrystalOption option)
{
if ((isEquipped()) && (_commonSoulCrystalOptions[option.getSlot() - 1] != null) && (getActingPlayer() != null))
{
getActingPlayer().removeSkill(_commonSoulCrystalOptions[option.getSlot() - 1].getSkill(), true);
}
_commonSoulCrystalOptions[option.getSlot() - 1] = option;
}
public void setSpecialSoulCrystalOption(SoulCrystalOption special)
{
if ((isEquipped()) && (_specialSoulCrystalOption != null) && (getActingPlayer() != null))
{
getActingPlayer().removeSkill(_specialSoulCrystalOption.getSkill(), true);
}
_specialSoulCrystalOption = special;
}
public void addSoulCrystalOption(SoulCrystalOption option)
{
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
if (insertSoulCrystalOption(con, option))
{
if (!option.isSpecial())
{
addCommonSoulCrystalOption(option);
}
else
{
setSpecialSoulCrystalOption(option);
}
applySoulCrystalOptionEffect();
}
}
catch (SQLException e)
{
_log.log(Level.SEVERE, "Could not insert soul crystal option for item: " + this + " from DB:", e);
}
}
private boolean insertSoulCrystalOption(Connection con, SoulCrystalOption option)
{
boolean result = true;
try (PreparedStatement ps = con.prepareStatement("INSERT INTO item_soulcrystal VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE effect_id = ?"))
{
ps.setInt(1, getObjectId());
ps.setInt(2, option.getSlot());
ps.setBoolean(3, option.isSpecial()); // special or not
ps.setInt(4, option.getEffect());
ps.setInt(5, option.getEffect());
ps.executeUpdate();
ps.close();
}
catch (SQLException e)
{
result = false;
_log.log(Level.SEVERE, "Could not insert soul crystal option for item: " + this + " from DB:", e);
}
return result;
}
public void restoreSoulCrystalOptions()
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT effect_id, slot_id FROM item_soulcrystal WHERE object_id=? ORDER BY object_id, effect_id, slot_id ASC");)
{
statement.setInt(1, getObjectId());
try (ResultSet rs = statement.executeQuery())
{
while (rs.next())
{
final int effect_id = rs.getInt("effect_id");
final int slot_id = rs.getInt("slot_id");
if (effect_id != 0)
{
SoulCrystalOption sco = SoulCrystalOptionsData.getInstance().getByEffectId(effect_id);
sco.setSlot(slot_id);
if (sco.isSpecial())
{
setSpecialSoulCrystalOption(sco);
}
else
{
addCommonSoulCrystalOption(sco);
}
}
}
applySoulCrystalOptionEffect();
}
statement.close();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Could not restore soul crystal data for item " + this + " from DB: " + e.getMessage(), e);
}
}
public void applySoulCrystalOptionEffect()
{
L2PcInstance owner = getActingPlayer();
if ((owner == null) || (!isEquipped()))
{
return;
}
for (SoulCrystalOption sco : getCommonSoulCrystalOptions())
{
if (sco != null)
{
owner.addSkill(sco.getSkill(), false);
}
}
if (getSpecialSoulCrystalOption() != null)
{
owner.addSkill(getSpecialSoulCrystalOption().getSkill(), false);
}
owner.sendSkillList();
}
public void removeSoulCrystalOptionEffect()
{
L2PcInstance owner = getActingPlayer();
if ((owner == null) || (isEquipped()))
{
return;
}
for (SoulCrystalOption sco : getCommonSoulCrystalOptions())
{
if (sco != null)
{
owner.removeSkill(sco.getSkill(), false);
}
}
if (getSpecialSoulCrystalOption() != null)
{
owner.removeSkill(getSpecialSoulCrystalOption().getSkill(), false);
}
owner.sendSkillList();
}
}