Updated Crystallizable item data.

Adapted from: L2jUnity free files.
This commit is contained in:
MobiusDev
2017-12-19 21:12:43 +00:00
parent 3f9c0c6696
commit 00fc352835
66 changed files with 8262 additions and 1895 deletions

View File

@@ -66,7 +66,7 @@ import com.l2jmobius.gameserver.data.xml.impl.HennaData;
import com.l2jmobius.gameserver.data.xml.impl.HitConditionBonusData;
import com.l2jmobius.gameserver.data.xml.impl.InitialEquipmentData;
import com.l2jmobius.gameserver.data.xml.impl.InitialShortcutData;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystalizationData;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystallizationData;
import com.l2jmobius.gameserver.data.xml.impl.KarmaData;
import com.l2jmobius.gameserver.data.xml.impl.LuckyGameData;
import com.l2jmobius.gameserver.data.xml.impl.MultisellData;
@@ -220,7 +220,7 @@ public class GameServer
EnchantItemGroupsData.getInstance();
EnchantItemData.getInstance();
EnchantItemOptionsData.getInstance();
ItemCrystalizationData.getInstance();
ItemCrystallizationData.getInstance();
OptionData.getInstance();
AugmentationData.getInstance();
EnchantItemHPBonusData.getInstance();

View File

@@ -1,102 +0,0 @@
/*
* 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.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.commons.util.IGameXmlReader;
import com.l2jmobius.gameserver.model.CrystalizationData;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
/**
* @author UnAfraid
*/
public final class ItemCrystalizationData implements IGameXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ItemCrystalizationData.class.getName());
private final Map<Integer, CrystalizationData> _items = new HashMap<>();
protected ItemCrystalizationData()
{
load();
}
@Override
public void load()
{
parseDatapackFile("data/CrystalizableItems.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded: " + _items.size() + " Items");
}
@Override
public void parseDocument(Document doc, File f)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("crystalizable_item".equalsIgnoreCase(d.getNodeName()))
{
final int id = parseInteger(d.getAttributes(), "id");
final CrystalizationData data = new CrystalizationData(id);
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
if ("item".equalsIgnoreCase(c.getNodeName()))
{
final NamedNodeMap attrs = c.getAttributes();
final int itemId = parseInteger(attrs, "id");
final long itemCount = parseLong(attrs, "count");
final double itemChance = parseDouble(attrs, "chance");
data.addItem(new ItemChanceHolder(itemId, itemChance, itemCount));
}
}
_items.put(id, data);
}
}
}
}
}
public CrystalizationData getCrystalization(int itemId)
{
return _items.get(itemId);
}
/**
* Gets the single instance of ItemCrystalizationData.
* @return single instance of ItemCrystalizationData
*/
public static ItemCrystalizationData getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final ItemCrystalizationData _instance = new ItemCrystalizationData();
}
}

View File

@@ -0,0 +1,243 @@
/*
* 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.io.File;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.commons.util.IGameXmlReader;
import com.l2jmobius.gameserver.datatables.ItemTable;
import com.l2jmobius.gameserver.enums.CrystallizationType;
import com.l2jmobius.gameserver.model.holders.CrystallizationDataHolder;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
import com.l2jmobius.gameserver.model.items.L2Armor;
import com.l2jmobius.gameserver.model.items.L2Item;
import com.l2jmobius.gameserver.model.items.L2Weapon;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.items.type.CrystalType;
/**
* @author UnAfraid
*/
public final class ItemCrystallizationData implements IGameXmlReader
{
private static final Logger LOGGER = Logger.getLogger(ItemCrystallizationData.class.getName());
private final Map<CrystalType, Map<CrystallizationType, List<ItemChanceHolder>>> _crystallizationTemplates = new EnumMap<>(CrystalType.class);
private final Map<Integer, CrystallizationDataHolder> _items = new HashMap<>();
protected ItemCrystallizationData()
{
load();
}
@Override
public void load()
{
_crystallizationTemplates.clear();
for (CrystalType crystalType : CrystalType.values())
{
_crystallizationTemplates.put(crystalType, new EnumMap<>(CrystallizationType.class));
}
_items.clear();
parseDatapackFile("data/CrystallizableItems.xml");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _crystallizationTemplates.size() + " crystallization templates.");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _items.size() + " pre-defined crystallizable items.");
// Generate remaining data.
generateCrystallizationData();
}
@Override
public void parseDocument(Document doc, File f)
{
for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
{
if ("list".equalsIgnoreCase(n.getNodeName()))
{
for (Node o = n.getFirstChild(); o != null; o = o.getNextSibling())
{
if ("templates".equalsIgnoreCase(o.getNodeName()))
{
for (Node d = o.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("crystallizable_template".equalsIgnoreCase(d.getNodeName()))
{
final CrystalType crystalType = parseEnum(d.getAttributes(), CrystalType.class, "crystalType");
final CrystallizationType crystallizationType = parseEnum(d.getAttributes(), CrystallizationType.class, "crystallizationType");
final List<ItemChanceHolder> crystallizeRewards = new ArrayList<>();
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
if ("item".equalsIgnoreCase(c.getNodeName()))
{
NamedNodeMap attrs = c.getAttributes();
final int itemId = parseInteger(attrs, "id");
final long itemCount = parseLong(attrs, "count");
final double itemChance = parseDouble(attrs, "chance");
crystallizeRewards.add(new ItemChanceHolder(itemId, itemChance, itemCount));
}
}
_crystallizationTemplates.get(crystalType).put(crystallizationType, crystallizeRewards);
}
}
}
else if ("items".equalsIgnoreCase(o.getNodeName()))
{
for (Node d = o.getFirstChild(); d != null; d = d.getNextSibling())
{
if ("crystallizable_item".equalsIgnoreCase(d.getNodeName()))
{
final int id = parseInteger(d.getAttributes(), "id");
final List<ItemChanceHolder> crystallizeRewards = new ArrayList<>();
for (Node c = d.getFirstChild(); c != null; c = c.getNextSibling())
{
if ("item".equalsIgnoreCase(c.getNodeName()))
{
NamedNodeMap attrs = c.getAttributes();
final int itemId = parseInteger(attrs, "id");
final long itemCount = parseLong(attrs, "count");
final double itemChance = parseDouble(attrs, "chance");
crystallizeRewards.add(new ItemChanceHolder(itemId, itemChance, itemCount));
}
}
_items.put(id, new CrystallizationDataHolder(id, crystallizeRewards));
}
}
}
}
}
}
}
public int getLoadedCrystallizationTemplateCount()
{
return _crystallizationTemplates.size();
}
private List<ItemChanceHolder> calculateCrystallizeRewards(L2Item item, List<ItemChanceHolder> crystallizeRewards)
{
if (crystallizeRewards == null)
{
return null;
}
final List<ItemChanceHolder> rewards = new ArrayList<>();
for (ItemChanceHolder reward : crystallizeRewards)
{
double chance = reward.getChance() * item.getCrystalCount();
long count = reward.getCount();
if (chance > 100.)
{
double countMul = Math.ceil(chance / 100.);
chance /= countMul;
count *= countMul;
}
rewards.add(new ItemChanceHolder(reward.getId(), chance, count));
}
return rewards;
}
private void generateCrystallizationData()
{
final int previousCount = _items.size();
for (L2Item item : ItemTable.getInstance().getAllItems())
{
// Check if the data has not been generated.
if (((item instanceof L2Weapon) || (item instanceof L2Armor)) && item.isCrystallizable() && !_items.containsKey(item.getId()))
{
final List<ItemChanceHolder> holder = _crystallizationTemplates.get(item.getCrystalType()).get((item instanceof L2Weapon) ? CrystallizationType.WEAPON : CrystallizationType.ARMOR);
if (holder != null)
{
_items.put(item.getId(), new CrystallizationDataHolder(item.getId(), calculateCrystallizeRewards(item, holder)));
}
}
}
LOGGER.info(getClass().getSimpleName() + ": Generated " + (_items.size() - previousCount) + " crystallizable items from templates.");
}
public List<ItemChanceHolder> getCrystallizationTemplate(CrystalType crystalType, CrystallizationType crystallizationType)
{
return _crystallizationTemplates.get(crystalType).get(crystallizationType);
}
/**
* @param itemId
* @return {@code CrystallizationData} for unenchanted items (enchanted items just have different crystal count, but same rewards),<br>
* or {@code null} if there is no such data registered.
*/
public CrystallizationDataHolder getCrystallizationData(int itemId)
{
return _items.get(itemId);
}
/**
* @param item to calculate its worth in crystals.
* @return List of {@code ItemChanceHolder} for the rewards with altered crystal count.
*/
public List<ItemChanceHolder> getCrystallizationRewards(L2ItemInstance item)
{
final List<ItemChanceHolder> result = new ArrayList<>();
final CrystallizationDataHolder data = getCrystallizationData(item.getId());
if (data != null)
{
// If there are no crystals on the template, add such.
if (data.getItems().stream().noneMatch(i -> i.getId() == item.getItem().getCrystalItemId()))
{
result.add(new ItemChanceHolder(item.getItem().getCrystalItemId(), 100, item.getCrystalCount()));
}
result.addAll(data.getItems());
}
else
{
// Add basic crystal reward.
result.add(new ItemChanceHolder(item.getItem().getCrystalItemId(), 100, item.getCrystalCount()));
}
return result;
}
/**
* Gets the single instance of ItemCrystalizationData.
* @return single instance of ItemCrystalizationData
*/
public static ItemCrystallizationData getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final ItemCrystallizationData _instance = new ItemCrystallizationData();
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.enums;
import com.l2jmobius.gameserver.model.items.L2Armor;
import com.l2jmobius.gameserver.model.items.L2Item;
import com.l2jmobius.gameserver.model.items.L2Weapon;
/**
* @author Nik
*/
public enum CrystallizationType
{
NONE,
WEAPON,
ARMOR,
ACCESORY;
public static CrystallizationType getByItem(L2Item item)
{
if (item instanceof L2Weapon)
{
return WEAPON;
}
if (item instanceof L2Armor)
{
return ARMOR;
}
switch (item.getBodyPart())
{
case L2Item.SLOT_R_EAR:
case L2Item.SLOT_L_EAR:
case L2Item.SLOT_R_FINGER:
case L2Item.SLOT_L_FINGER:
case L2Item.SLOT_NECK:
case L2Item.SLOT_HAIR:
case L2Item.SLOT_HAIR2:
case L2Item.SLOT_HAIRALL:
{
return ACCESORY;
}
}
return NONE;
}
}

View File

@@ -1,51 +1,45 @@
/*
* 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.model;
import java.util.ArrayList;
import java.util.List;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
/**
* @author UnAfraid
*/
public class CrystalizationData
{
private final int _id;
private final List<ItemChanceHolder> _items = new ArrayList<>();
public CrystalizationData(int id)
{
_id = id;
}
public int getId()
{
return _id;
}
public void addItem(ItemChanceHolder item)
{
_items.add(item);
}
public List<ItemChanceHolder> getItems()
{
return _items;
}
}
/*
* 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.model.holders;
import java.util.Collections;
import java.util.List;
/**
* @author UnAfraid
*/
public class CrystallizationDataHolder
{
private final int _id;
private final List<ItemChanceHolder> _items;
public CrystallizationDataHolder(int id, List<ItemChanceHolder> items)
{
_id = id;
_items = Collections.unmodifiableList(items);
}
public int getId()
{
return _id;
}
public List<ItemChanceHolder> getItems()
{
return Collections.unmodifiableList(_items);
}
}

View File

@@ -16,16 +16,14 @@
*/
package com.l2jmobius.gameserver.network.clientpackets;
import java.util.ArrayList;
import java.util.List;
import com.l2jmobius.Config;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.commons.util.Rnd;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystalizationData;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystallizationData;
import com.l2jmobius.gameserver.enums.PrivateStoreType;
import com.l2jmobius.gameserver.enums.Race;
import com.l2jmobius.gameserver.model.CrystalizationData;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
@@ -110,6 +108,7 @@ public final class RequestCrystallizeItem implements IClientIncomingPacket
if (item.isHeroItem())
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
@@ -122,18 +121,19 @@ public final class RequestCrystallizeItem implements IClientIncomingPacket
final L2ItemInstance itemToRemove = activeChar.getInventory().getItemByObjectId(_objectId);
if ((itemToRemove == null) || itemToRemove.isShadowItem() || itemToRemove.isTimeLimitedItem())
{
client.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
if (!itemToRemove.getItem().isCrystallizable() || (itemToRemove.getItem().getCrystalCount() <= 0) || (itemToRemove.getItem().getCrystalType() == CrystalType.NONE))
{
_log.warning(activeChar.getName() + " (" + activeChar.getObjectId() + ") tried to crystallize " + itemToRemove.getItem().getId());
client.sendPacket(SystemMessageId.THIS_ITEM_CANNOT_BE_CRYSTALLIZED);
return;
}
if (!activeChar.getInventory().canManipulateWithItemId(itemToRemove.getId()))
{
activeChar.sendMessage("You cannot use this item.");
client.sendPacket(SystemMessageId.THIS_ITEM_CANNOT_BE_CRYSTALLIZED);
return;
}
@@ -199,6 +199,13 @@ public final class RequestCrystallizeItem implements IClientIncomingPacket
return;
}
final List<ItemChanceHolder> crystallizationRewards = ItemCrystallizationData.getInstance().getCrystallizationRewards(itemToRemove);
if ((crystallizationRewards == null) || crystallizationRewards.isEmpty())
{
activeChar.sendPacket(SystemMessageId.CRYSTALLIZATION_CANNOT_BE_PROCEEDED_BECAUSE_THERE_ARE_NO_ITEMS_REGISTERED);
return;
}
// activeChar.setInCrystallize(true);
// unequip if needed
@@ -234,19 +241,7 @@ public final class RequestCrystallizeItem implements IClientIncomingPacket
iu.addRemovedItem(removedItem);
activeChar.sendInventoryUpdate(iu);
final int crystalId = itemToRemove.getItem().getCrystalItemId();
final int crystalAmount = itemToRemove.getCrystalCount();
final List<ItemChanceHolder> items = new ArrayList<>();
items.add(new ItemChanceHolder(crystalId, 100, crystalAmount));
final CrystalizationData data = ItemCrystalizationData.getInstance().getCrystalization(itemToRemove.getId());
if (data != null)
{
data.getItems().stream().filter(holder -> (holder.getId() != crystalId)).forEach(items::add);
}
for (ItemChanceHolder holder : items)
for (ItemChanceHolder holder : crystallizationRewards)
{
final double rand = Rnd.nextDouble() * 100;
if (rand < holder.getChance())

View File

@@ -16,14 +16,12 @@
*/
package com.l2jmobius.gameserver.network.clientpackets.crystalization;
import java.util.ArrayList;
import java.util.List;
import com.l2jmobius.Config;
import com.l2jmobius.commons.network.PacketReader;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystalizationData;
import com.l2jmobius.gameserver.data.xml.impl.ItemCrystallizationData;
import com.l2jmobius.gameserver.enums.PrivateStoreType;
import com.l2jmobius.gameserver.model.CrystalizationData;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.holders.ItemChanceHolder;
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
@@ -180,26 +178,17 @@ public class RequestCrystallizeEstimate implements IClientIncomingPacket
return;
}
activeChar.setInCrystallize(true);
// add crystals
final int crystalId = item.getItem().getCrystalItemId();
final int crystalAmount = item.getCrystalCount();
final List<ItemChanceHolder> items = new ArrayList<>();
items.add(new ItemChanceHolder(crystalId, 100, crystalAmount));
final CrystalizationData data = ItemCrystalizationData.getInstance().getCrystalization(item.getId());
if (data != null)
// Show crystallization rewards window.
final List<ItemChanceHolder> crystallizationRewards = ItemCrystallizationData.getInstance().getCrystallizationRewards(item);
if ((crystallizationRewards != null) && !crystallizationRewards.isEmpty())
{
for (ItemChanceHolder holder : data.getItems())
{
if (holder.getId() != crystalId)
{
items.add(holder);
}
}
activeChar.setInCrystallize(true);
client.sendPacket(new ExGetCrystalizingEstimation(crystallizationRewards));
}
else
{
client.sendPacket(SystemMessageId.CRYSTALLIZATION_CANNOT_BE_PROCEEDED_BECAUSE_THERE_ARE_NO_ITEMS_REGISTERED);
}
client.sendPacket(new ExGetCrystalizingEstimation(items));
}
}