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

@ -82,6 +82,7 @@ import com.l2jmobius.gameserver.data.xml.impl.ShuttleData;
import com.l2jmobius.gameserver.data.xml.impl.SiegeScheduleData;
import com.l2jmobius.gameserver.data.xml.impl.SkillLearnData;
import com.l2jmobius.gameserver.data.xml.impl.SkillTreesData;
import com.l2jmobius.gameserver.data.xml.impl.SoulCrystalOptionsData;
import com.l2jmobius.gameserver.data.xml.impl.StaticObjectData;
import com.l2jmobius.gameserver.data.xml.impl.TeleportersData;
import com.l2jmobius.gameserver.data.xml.impl.TransformData;
@ -234,6 +235,7 @@ public final class GameServer
PrimeShopData.getInstance();
AppearanceItemData.getInstance();
LuckyGameData.getInstance();
SoulCrystalOptionsData.getInstance();
printSection("Characters");
ClassListData.getInstance();

View File

@ -0,0 +1,105 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.data.xml.impl;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.gameserver.model.holders.SkillHolder;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
import com.l2jmobius.util.data.xml.IXmlReader;
/**
* @author Mathael
*/
public class SoulCrystalOptionsData implements IXmlReader
{
private static final HashMap<Integer, SoulCrystalOption> _soulCrystalOptions = new HashMap<>();
protected SoulCrystalOptionsData()
{
load();
}
@Override
public void load()
{
_soulCrystalOptions.clear();
parseDatapackFile("soulCrystalOptions.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _soulCrystalOptions.size() + " Soul Crystal Options.");
}
@Override
public void parseDocument(Document doc)
{
int skillId;
int level;
int effectId;
int type;
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("SoulCrystalOptions".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("option".equalsIgnoreCase(d.getNodeName()))
{
final NamedNodeMap attrs = d.getAttributes();
skillId = parseInteger(attrs, "skillId", 0);
level = parseInteger(attrs, "level", 0);
effectId = parseInteger(attrs, "effectId", 0); // unique
type = parseInteger(attrs, "type", 1);
if (effectId == 0)
{
LOGGER.severe(getClass().getSimpleName() + ": Bad Soul Crystal Option [" + effectId + "] !");
return;
}
// Somes options need to be confirmed.
if (skillId != 0)
{
_soulCrystalOptions.put(effectId, new SoulCrystalOption(effectId, type == 2, new SkillHolder(skillId, level)));
}
}
}
}
}
}
public SoulCrystalOption getByEffectId(int effectId)
{
return _soulCrystalOptions.get(effectId);
}
public static SoulCrystalOptionsData getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final SoulCrystalOptionsData _instance = new SoulCrystalOptionsData();
}
}

View File

@ -98,6 +98,11 @@ public final class DocumentItem extends DocumentBase
final int itemId = Integer.parseInt(n.getAttributes().getNamedItem("id").getNodeValue());
final String className = n.getAttributes().getNamedItem("type").getNodeValue();
final String itemName = n.getAttributes().getNamedItem("name").getNodeValue();
String additionalName = null;
if (n.getAttributes().getNamedItem("additionalName") != null)
{
additionalName = n.getAttributes().getNamedItem("additionalName").getNodeValue();
}
_currentItem.id = itemId;
_currentItem.name = itemName;
@ -105,6 +110,7 @@ public final class DocumentItem extends DocumentBase
_currentItem.set = new StatsSet();
_currentItem.set.set("item_id", itemId);
_currentItem.set.set("name", itemName);
_currentItem.set.set("additionalName", additionalName);
final Node first = n.getFirstChild();
for (n = first; n != null; n = n.getNextSibling())

View File

@ -26,7 +26,8 @@ public enum ItemListType implements IUpdateTypeComponent
AUGMENT_BONUS(0x01),
ELEMENTAL_ATTRIBUTE(0x02),
ENCHANT_EFFECT(0x04),
VISUAL_ID(0x08);
VISUAL_ID(0x08),
SOUL_CRYSTAL(0x10);
private final int _mask;

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();
}
}

View File

@ -57,6 +57,7 @@ import com.l2jmobius.gameserver.network.clientpackets.crystalization.RequestCrys
import com.l2jmobius.gameserver.network.clientpackets.dailymission.RequestOneDayRewardReceive;
import com.l2jmobius.gameserver.network.clientpackets.dailymission.RequestTodoList;
import com.l2jmobius.gameserver.network.clientpackets.dailymission.RequestTodoListHTML;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.RequestItemEnsoul;
import com.l2jmobius.gameserver.network.clientpackets.friend.RequestAnswerFriendInvite;
import com.l2jmobius.gameserver.network.clientpackets.friend.RequestFriendDel;
import com.l2jmobius.gameserver.network.clientpackets.friend.RequestFriendDetailInfo;
@ -2614,7 +2615,7 @@ public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>,
}
case 0x107:
{
// msg = new RequestItemEnsoul();
msg = new RequestItemEnsoul();
break;
}
case 0x108:

View File

@ -0,0 +1,275 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets.ensoul;
import com.l2jmobius.gameserver.data.xml.impl.SoulCrystalOptionsData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.items.type.CrystalType;
import com.l2jmobius.gameserver.network.clientpackets.L2GameClientPacket;
import com.l2jmobius.gameserver.network.serverpackets.ExUserInfoInvenWeight;
import com.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
import com.l2jmobius.gameserver.network.serverpackets.ensoul.ExEnsoulResult;
/**
* @author Mathael
*/
public class RequestItemEnsoul extends L2GameClientPacket
{
private static final String _C__D0_107_REQUESTITEMENSOUL = "[C] D0:107 RequestItemEnsoul";
private static final int GEMSTONE_C = 2131;
private static final int GEMSTONE_B = 2132;
private static final int GEMSTONE_A = 2133;
private static final int GEMSTONE_S = 2134;
private static final int GEMSTONE_R = 19440;
private int _objectId;
private final SoulCrystalOption[] _common = new SoulCrystalOption[2]; // client can accept more.
private SoulCrystalOption _special; // client can accept more.
@Override
protected void readImpl()
{
_objectId = readD(); // weapon object id
final int changeCnt = readC();
for (int i = 0; i < changeCnt; i++)
{
final boolean special = readC() == 2; // Ensoul Type 1 = Common Soul Crystal ; 2 = Special Soul Crystal
final int slot = readC(); // [1,2] => Common slots ; [1] => Special slots
final int SCObjectId = readD(); // Soul Crystal objectId
final int effectId = readD(); // EffectId
SoulCrystalOption sco = SoulCrystalOptionsData.getInstance().getByEffectId(effectId);
sco.setSoulCrystalObjectId(SCObjectId);
sco.setSpecial(special);
sco.setSlot(slot);
if (sco.isSpecial())
{
_special = sco;
}
else
{
_common[sco.getSlot() - 1] = sco;
}
}
}
@Override
protected void runImpl()
{
// You can add a Soul Crystal effect to weapon via any Blacksmith in any township.
// There's no limit for Soul Crystal levels depending on your weapon grade.
// To weapon grade C-S80 you can apply 1 common Soul Crystal and 1 special Soul Crystal.
// To weapon grade R-R99 you can apply 2 common Soul Crystals and 1 special Soul Crystal.
// Source: https://l2wiki.com/Special_Abilities#Special_Abilities
final L2PcInstance activeChar = getClient().getActiveChar();
if (activeChar == null)
{
return;
}
final L2ItemInstance targetItem = activeChar.getInventory().getItemByObjectId(_objectId);
if (targetItem == null)
{
activeChar.sendPacket(ExEnsoulResult.FAILED);
return;
}
for (SoulCrystalOption sco : _common)
{
if (sco != null)
{
final L2ItemInstance soulcrystal = activeChar.getInventory().getItemByObjectId(sco.getSoulCrystalObjectId());
final boolean changing = targetItem.getCommonSoulCrystalOptions()[sco.getSlot() - 1] != null;
if (!checkAndConsume(activeChar, soulcrystal, targetItem, changing, false))
{
activeChar.sendPacket(ExEnsoulResult.FAILED);
return;
}
targetItem.addSoulCrystalOption(sco);
}
}
if (_special != null)
{
final L2ItemInstance specialsoulcrystal = activeChar.getInventory().getItemByObjectId(_special.getSoulCrystalObjectId());
final boolean changing = targetItem.getSpecialSoulCrystalOption() != null;
if (!checkAndConsume(activeChar, specialsoulcrystal, targetItem, changing, true))
{
activeChar.sendPacket(ExEnsoulResult.FAILED);
return;
}
targetItem.addSoulCrystalOption(_special);
}
activeChar.sendPacket(new ExEnsoulResult(1, targetItem.getCommonSoulCrystalOptions(), targetItem.getSpecialSoulCrystalOption()));
final InventoryUpdate iu = new InventoryUpdate();
iu.addModifiedItem(targetItem);
activeChar.sendPacket(iu);
activeChar.sendPacket(new ExUserInfoInvenWeight(activeChar));
}
private static final boolean checkAndConsume(L2PcInstance activeChar, L2ItemInstance soulcrystal, L2ItemInstance targetItem, boolean changing, boolean special)
{
final CrystalType targetItemGrade = targetItem.getItem().getCrystalType();
final int gemstoneId = getGemStoneId(targetItemGrade);
final long count = getGemstoneCount(targetItemGrade, targetItem.getCommonSoulCrystalOptions().length > 0, changing, special);
if ((gemstoneId == 0) || (count == 0))
{
return false;
}
if (changing && !special && !available2xCommonOption(targetItemGrade))
{
return false;
}
if ((soulcrystal == null) || (activeChar.getInventory().getInventoryItemCount(soulcrystal.getId(), -1) < 1))
{
return false;
}
if (activeChar.getInventory().getInventoryItemCount(gemstoneId, -1) < count)
{
return false;
}
if (!activeChar.destroyItem("RequestItemEnsoul", soulcrystal, 1, activeChar, true))
{
return false;
}
if (!activeChar.destroyItemByItemId("RequestItemEnsoul", gemstoneId, count, activeChar, true))
{
return false;
}
return true;
}
private static final long getGemstoneCount(CrystalType itemGrade, boolean price2x, boolean changing, boolean special)
{
switch (itemGrade)
{
case C:
{
return changing ? special ? 30 : 89 : special ? 60 : 177;
}
case B:
{
return changing ? special ? 19 : 56 : special ? 38 : 112;
}
case A:
{
return changing ? special ? 4 : 12 : special ? 8 : 24;
}
case S:
{
return changing ? special ? 4 : 10 : special ? 7 : 19;
}
case S80:
case S84:
{
return changing ? special ? 8 : 24 : special ? 16 : 48;
}
case R:
{
return changing ? special ? 4 : 10 : special ? 7 : price2x ? 40 : 20;
}
case R95:
{
return changing ? special ? 6 : 65 : special ? 11 : price2x ? 1249 : 129;
}
case R99:
{
return changing ? special ? 8 : 168 : special ? 16 : price2x ? 5266 : 335;
}
default:
{
return 0;
}
}
}
private static final int getGemStoneId(CrystalType itemGrade)
{
switch (itemGrade)
{
case C:
{
return GEMSTONE_C;
}
case B:
{
return GEMSTONE_B;
}
case A:
{
return GEMSTONE_A;
}
case S:
case S80:
case S84:
{
return GEMSTONE_S;
}
case R:
case R95:
case R99:
{
return GEMSTONE_R;
}
default:
{
return 0;
}
}
}
private static final boolean available2xCommonOption(CrystalType ct)
{
switch (ct)
{
case R:
case R95:
case R99:
{
return true;
}
default:
{
return false;
}
}
}
@Override
public String getType()
{
return _C__D0_107_REQUESTITEMENSOUL;
}
}

View File

@ -0,0 +1,95 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.clientpackets.ensoul;
import com.l2jmobius.gameserver.model.holders.SkillHolder;
import com.l2jmobius.gameserver.model.skills.Skill;
/**
* @author Mathael
*/
public class SoulCrystalOption
{
private int _objectId;
private int _effect;
private boolean _special;
private int _slot;
private SkillHolder _skill;
public SoulCrystalOption(int effect, boolean special, SkillHolder skill)
{
setSoulCrystalObjectId(0);
setSpecial(special);
setEffect(effect);
setSkill(skill);
}
public int getSoulCrystalObjectId()
{
return _objectId;
}
public void setSoulCrystalObjectId(int soulCrystalObjectId)
{
_objectId = soulCrystalObjectId;
}
public int getEffect()
{
return _effect;
}
private void setEffect(int effect)
{
_effect = effect;
}
public void setSlot(int slot)
{
_slot = slot;
}
public int getSlot()
{
return _slot;
}
public boolean isSpecial()
{
return _special;
}
public void setSpecial(boolean special)
{
_special = special;
}
public SkillHolder getSkillHolder()
{
return _skill;
}
public Skill getSkill()
{
return _skill.getSkill();
}
private void setSkill(SkillHolder skill)
{
_skill = skill;
}
}

View File

@ -23,6 +23,7 @@ import com.l2jmobius.gameserver.model.buylist.Product;
import com.l2jmobius.gameserver.model.itemcontainer.PcInventory;
import com.l2jmobius.gameserver.model.items.L2WarehouseItem;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
/**
* @author UnAfraid
@ -116,6 +117,10 @@ public abstract class AbstractItemPacket extends AbstractMaskPacket<ItemListType
{
writeD(item.getVisualId()); // Item remodel visual ID
}
if (containsMask(mask, ItemListType.SOUL_CRYSTAL))
{
writeItemSoulCrystalOptions(item);
}
}
protected static final int calculateMask(ItemInfo item)
@ -158,6 +163,24 @@ public abstract class AbstractItemPacket extends AbstractMaskPacket<ItemListType
{
mask |= ItemListType.VISUAL_ID.getMask();
}
if ((item.getCommonSoulCrystalOptions().length != 0) || (item.getSpecialSoulCrystalOption() != null))
{
for (SoulCrystalOption sco : item.getCommonSoulCrystalOptions())
{
if (sco != null)
{
mask |= ItemListType.SOUL_CRYSTAL.getMask();
break;
}
}
if (item.getSpecialSoulCrystalOption() != null)
{
mask |= ItemListType.SOUL_CRYSTAL.getMask();
}
}
return mask;
}
@ -217,4 +240,31 @@ public abstract class AbstractItemPacket extends AbstractMaskPacket<ItemListType
writeC(0);
writeC(0);
}
protected void writeItemSoulCrystalOptions(ItemInfo item)
{
int count = 0;
for (SoulCrystalOption sc : item.getCommonSoulCrystalOptions())
{
if (sc != null)
{
count++;
}
}
writeC(count);
for (SoulCrystalOption sco : item.getCommonSoulCrystalOptions())
{
if (sco != null)
{
writeD(sco.getEffect());
}
}
writeC(item.getSpecialSoulCrystalOption() != null);
if (item.getSpecialSoulCrystalOption() != null)
{
writeD(item.getSpecialSoulCrystalOption().getEffect());
}
}
}

View File

@ -0,0 +1,82 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets.ensoul;
import com.l2jmobius.gameserver.network.clientpackets.ensoul.SoulCrystalOption;
import com.l2jmobius.gameserver.network.serverpackets.L2GameServerPacket;
/**
* @author Mathael
*/
public class ExEnsoulResult extends L2GameServerPacket
{
public static final ExEnsoulResult FAILED = new ExEnsoulResult();
private final int _result;
private final SoulCrystalOption[] _commons;
private final SoulCrystalOption _special;
public ExEnsoulResult()
{
_result = 0;
_commons = null;
_special = null;
}
public ExEnsoulResult(int result, SoulCrystalOption[] commons, SoulCrystalOption special)
{
_result = result;
_commons = commons;
_special = special;
}
@Override
protected void writeImpl()
{
writeC(0xFE);
writeH(0x17F);
// Success (Yes or No)
writeC(_result);
// Primary special abilities
int count = 0;
for (SoulCrystalOption sc : _commons)
{
if (sc != null)
{
count++;
}
}
writeC(count);
for (SoulCrystalOption sc : _commons)
{
if (sc != null)
{
writeD(sc.getEffect());
}
}
// Secondary special abilities
writeC(_special != null);
if (_special != null)
{
writeD(_special.getEffect());
}
}
}

View File

@ -0,0 +1,35 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jmobius.gameserver.network.serverpackets.ensoul;
import com.l2jmobius.gameserver.network.serverpackets.L2GameServerPacket;
public class ExShowEnsoulWindow extends L2GameServerPacket
{
public static final ExShowEnsoulWindow STATIC_PACKET = new ExShowEnsoulWindow();
public ExShowEnsoulWindow()
{
}
@Override
protected void writeImpl()
{
writeC(0xFE);
writeD(0x17E);
}
}