Unhardcoded elemental attribute data.
This commit is contained in:
@@ -60,6 +60,7 @@ import org.l2jmobius.gameserver.data.xml.CombinationItemsData;
|
||||
import org.l2jmobius.gameserver.data.xml.CubicData;
|
||||
import org.l2jmobius.gameserver.data.xml.DailyMissionData;
|
||||
import org.l2jmobius.gameserver.data.xml.DoorData;
|
||||
import org.l2jmobius.gameserver.data.xml.ElementalAttributeData;
|
||||
import org.l2jmobius.gameserver.data.xml.EnchantItemData;
|
||||
import org.l2jmobius.gameserver.data.xml.EnchantItemGroupsData;
|
||||
import org.l2jmobius.gameserver.data.xml.EnchantItemHPBonusData;
|
||||
@@ -262,6 +263,7 @@ public class GameServer
|
||||
EnchantItemGroupsData.getInstance();
|
||||
EnchantItemData.getInstance();
|
||||
EnchantItemOptionsData.getInstance();
|
||||
ElementalAttributeData.getInstance();
|
||||
ItemCrystallizationData.getInstance();
|
||||
OptionData.getInstance();
|
||||
VariationData.getInstance();
|
||||
|
@@ -14,34 +14,30 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model;
|
||||
package org.l2jmobius.gameserver.data.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.util.IXmlReader;
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.data.ItemTable;
|
||||
import org.l2jmobius.gameserver.enums.AttributeType;
|
||||
import org.l2jmobius.gameserver.enums.ElementalItemType;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.holders.ElementalItemHolder;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
|
||||
public class Elementals
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ElementalAttributeData implements IXmlReader
|
||||
{
|
||||
private static final Map<Integer, ElementalItems> TABLE = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
for (ElementalItems item : ElementalItems.values())
|
||||
{
|
||||
TABLE.put(item._itemId, item);
|
||||
}
|
||||
}
|
||||
|
||||
protected static final byte NONE = -1;
|
||||
protected static final byte FIRE = 0;
|
||||
protected static final byte WATER = 1;
|
||||
protected static final byte WIND = 2;
|
||||
protected static final byte EARTH = 3;
|
||||
protected static final byte HOLY = 4;
|
||||
protected static final byte DARK = 5;
|
||||
private static final Map<Integer, ElementalItemHolder> ELEMENTAL_ITEMS = new HashMap<>();
|
||||
|
||||
public static final int FIRST_WEAPON_BONUS = 20;
|
||||
public static final int NEXT_WEAPON_BONUS = 5;
|
||||
@@ -97,100 +93,63 @@ public class Elementals
|
||||
};
|
||||
/* @formatter:on */
|
||||
|
||||
public enum ElementalItemType
|
||||
protected ElementalAttributeData()
|
||||
{
|
||||
Stone(3),
|
||||
StoneSuper(3),
|
||||
Crystal(6),
|
||||
CrystalSuper(6),
|
||||
Jewel(9),
|
||||
Energy(12);
|
||||
|
||||
public int _maxLevel;
|
||||
|
||||
ElementalItemType(int maxLevel)
|
||||
{
|
||||
_maxLevel = maxLevel;
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
public enum ElementalItems
|
||||
@Override
|
||||
public void load()
|
||||
{
|
||||
fireStone(FIRE, 9546, ElementalItemType.Stone, 0),
|
||||
waterStone(WATER, 9547, ElementalItemType.Stone, 0),
|
||||
windStone(WIND, 9549, ElementalItemType.Stone, 0),
|
||||
earthStone(EARTH, 9548, ElementalItemType.Stone, 0),
|
||||
divineStone(HOLY, 9551, ElementalItemType.Stone, 0),
|
||||
darkStone(DARK, 9550, ElementalItemType.Stone, 0),
|
||||
|
||||
fireRoughtore(FIRE, 10521, ElementalItemType.Stone, 0),
|
||||
waterRoughtore(WATER, 10522, ElementalItemType.Stone, 0),
|
||||
windRoughtore(WIND, 10524, ElementalItemType.Stone, 0),
|
||||
earthRoughtore(EARTH, 10523, ElementalItemType.Stone, 0),
|
||||
divineRoughtore(HOLY, 10526, ElementalItemType.Stone, 0),
|
||||
darkRoughtore(DARK, 10525, ElementalItemType.Stone, 0),
|
||||
|
||||
fireCrystal(FIRE, 9552, ElementalItemType.Crystal, 0),
|
||||
waterCrystal(WATER, 9553, ElementalItemType.Crystal, 0),
|
||||
windCrystal(WIND, 9555, ElementalItemType.Crystal, 0),
|
||||
earthCrystal(EARTH, 9554, ElementalItemType.Crystal, 0),
|
||||
divineCrystal(HOLY, 9557, ElementalItemType.Crystal, 0),
|
||||
darkCrystal(DARK, 9556, ElementalItemType.Crystal, 0),
|
||||
|
||||
fireJewel(FIRE, 9558, ElementalItemType.Jewel, 0),
|
||||
waterJewel(WATER, 9559, ElementalItemType.Jewel, 0),
|
||||
windJewel(WIND, 9561, ElementalItemType.Jewel, 0),
|
||||
earthJewel(EARTH, 9560, ElementalItemType.Jewel, 0),
|
||||
divineJewel(HOLY, 9563, ElementalItemType.Jewel, 0),
|
||||
darkJewel(DARK, 9562, ElementalItemType.Jewel, 0),
|
||||
|
||||
fireEnergy(FIRE, 9564, ElementalItemType.Energy, 0),
|
||||
waterEnergy(WATER, 9565, ElementalItemType.Energy, 0),
|
||||
windEnergy(WIND, 9567, ElementalItemType.Energy, 0),
|
||||
earthEnergy(EARTH, 9566, ElementalItemType.Energy, 0),
|
||||
divineEnergy(HOLY, 9569, ElementalItemType.Energy, 0),
|
||||
darkEnergy(DARK, 9568, ElementalItemType.Energy, 0);
|
||||
|
||||
public byte _element;
|
||||
public int _itemId;
|
||||
public ElementalItemType _type;
|
||||
public int _fixedPower;
|
||||
|
||||
ElementalItems(byte element, int itemId, ElementalItemType type, int fixedPower)
|
||||
{
|
||||
_element = element;
|
||||
_itemId = itemId;
|
||||
_type = type;
|
||||
_fixedPower = fixedPower;
|
||||
}
|
||||
ELEMENTAL_ITEMS.clear();
|
||||
parseDatapackFile("data/ElementalAttributeData.xml");
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + ELEMENTAL_ITEMS.size() + " elemental attribute items.");
|
||||
}
|
||||
|
||||
public static byte getItemElement(int itemId)
|
||||
@Override
|
||||
public void parseDocument(Document doc, File f)
|
||||
{
|
||||
final ElementalItems item = TABLE.get(itemId);
|
||||
forEach(doc, "list", listNode -> forEach(listNode, "item", itemNode ->
|
||||
{
|
||||
final StatSet set = new StatSet(parseAttributes(itemNode));
|
||||
|
||||
final int id = set.getInt("id");
|
||||
if (ItemTable.getInstance().getTemplate(id) == null)
|
||||
{
|
||||
LOGGER.info(getClass().getSimpleName() + ": Could not find item with id " + id + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
ELEMENTAL_ITEMS.put(id, new ElementalItemHolder(id, set.getEnum("elemental", AttributeType.class), set.getEnum("type", ElementalItemType.class), set.getInt("power", 0)));
|
||||
}));
|
||||
}
|
||||
|
||||
public AttributeType getItemElement(int itemId)
|
||||
{
|
||||
final ElementalItemHolder item = ELEMENTAL_ITEMS.get(itemId);
|
||||
if (item != null)
|
||||
{
|
||||
return item._element;
|
||||
return item.getElement();
|
||||
}
|
||||
return NONE;
|
||||
return AttributeType.NONE;
|
||||
}
|
||||
|
||||
public static ElementalItems getItemElemental(int itemId)
|
||||
public ElementalItemHolder getItemElemental(int itemId)
|
||||
{
|
||||
return TABLE.get(itemId);
|
||||
return ELEMENTAL_ITEMS.get(itemId);
|
||||
}
|
||||
|
||||
public static int getMaxElementLevel(int itemId)
|
||||
public int getMaxElementLevel(int itemId)
|
||||
{
|
||||
final ElementalItems item = TABLE.get(itemId);
|
||||
final ElementalItemHolder item = ELEMENTAL_ITEMS.get(itemId);
|
||||
if (item != null)
|
||||
{
|
||||
return item._type._maxLevel;
|
||||
return item.getType().getMaxLevel();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static boolean isSuccess(ItemInstance item, int stoneId)
|
||||
public boolean isSuccess(ItemInstance item, int stoneId)
|
||||
{
|
||||
int row = -1;
|
||||
int column = -1;
|
||||
@@ -228,29 +187,29 @@ public class Elementals
|
||||
}
|
||||
}
|
||||
|
||||
switch (TABLE.get(stoneId)._type)
|
||||
switch (ELEMENTAL_ITEMS.get(stoneId).getType())
|
||||
{
|
||||
case Stone:
|
||||
case STONE:
|
||||
{
|
||||
column = item.isWeapon() ? 0 : 1;
|
||||
break;
|
||||
}
|
||||
case Crystal:
|
||||
case CRYSTAL:
|
||||
{
|
||||
column = item.isWeapon() ? 2 : 3;
|
||||
break;
|
||||
}
|
||||
case StoneSuper:
|
||||
case STONE_SUPER:
|
||||
{
|
||||
column = item.isWeapon() ? 4 : 5;
|
||||
break;
|
||||
}
|
||||
case CrystalSuper:
|
||||
case CRYSTAL_SUPER:
|
||||
{
|
||||
column = item.isWeapon() ? 6 : 7;
|
||||
break;
|
||||
}
|
||||
case Jewel:
|
||||
case JEWEL:
|
||||
{
|
||||
column = item.isWeapon() ? 8 : 9;
|
||||
break;
|
||||
@@ -262,4 +221,14 @@ public class Elementals
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ElementalAttributeData getInstance()
|
||||
{
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final ElementalAttributeData INSTANCE = new ElementalAttributeData();
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.enums;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public enum ElementalItemType
|
||||
{
|
||||
STONE(3),
|
||||
STONE_SUPER(3),
|
||||
CRYSTAL(6),
|
||||
CRYSTAL_SUPER(6),
|
||||
JEWEL(9),
|
||||
ENERGY(12);
|
||||
|
||||
private int _maxLevel;
|
||||
|
||||
ElementalItemType(int maxLevel)
|
||||
{
|
||||
_maxLevel = maxLevel;
|
||||
}
|
||||
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return _maxLevel;
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.holders;
|
||||
|
||||
import org.l2jmobius.gameserver.enums.AttributeType;
|
||||
import org.l2jmobius.gameserver.enums.ElementalItemType;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
*/
|
||||
public class ElementalItemHolder
|
||||
{
|
||||
private final int _itemId;
|
||||
private final AttributeType _element;
|
||||
private final ElementalItemType _type;
|
||||
private final int _power;
|
||||
|
||||
public ElementalItemHolder(int itemId, AttributeType element, ElementalItemType type, int power)
|
||||
{
|
||||
_itemId = itemId;
|
||||
_element = element;
|
||||
_type = type;
|
||||
_power = power;
|
||||
}
|
||||
|
||||
public int getItemId()
|
||||
{
|
||||
return _itemId;
|
||||
}
|
||||
|
||||
public AttributeType getElement()
|
||||
{
|
||||
return _element;
|
||||
}
|
||||
|
||||
public ElementalItemType getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
public int getPower()
|
||||
{
|
||||
return _power;
|
||||
}
|
||||
}
|
@@ -18,11 +18,12 @@ package org.l2jmobius.gameserver.network.clientpackets;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.data.xml.ElementalAttributeData;
|
||||
import org.l2jmobius.gameserver.enums.AttributeType;
|
||||
import org.l2jmobius.gameserver.enums.PrivateStoreType;
|
||||
import org.l2jmobius.gameserver.model.Elementals;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.actor.request.EnchantItemAttributeRequest;
|
||||
import org.l2jmobius.gameserver.model.holders.ElementalItemHolder;
|
||||
import org.l2jmobius.gameserver.model.items.enchant.attribute.AttributeHolder;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.network.GameClient;
|
||||
@@ -132,7 +133,7 @@ public class RequestExEnchantItemAttribute implements IClientIncomingPacket
|
||||
|
||||
final int stoneId = stone.getId();
|
||||
final long count = Math.min(stone.getCount(), _count);
|
||||
AttributeType elementToAdd = AttributeType.findByClientId(Elementals.getItemElement(stoneId));
|
||||
AttributeType elementToAdd = ElementalAttributeData.getInstance().getItemElement(stoneId);
|
||||
// Armors have the opposite element
|
||||
if (item.isArmor())
|
||||
{
|
||||
@@ -296,7 +297,7 @@ public class RequestExEnchantItemAttribute implements IClientIncomingPacket
|
||||
return -1;
|
||||
}
|
||||
|
||||
final boolean success = Elementals.isSuccess(item, stone.getId());
|
||||
final boolean success = ElementalAttributeData.getInstance().isSuccess(item, stone.getId());
|
||||
if (success)
|
||||
{
|
||||
item.setAttribute(new AttributeHolder(elementToAdd, newPower), false);
|
||||
@@ -307,7 +308,7 @@ public class RequestExEnchantItemAttribute implements IClientIncomingPacket
|
||||
|
||||
public int getLimit(ItemInstance item, int sotneId)
|
||||
{
|
||||
final Elementals.ElementalItems elementItem = Elementals.getItemElemental(sotneId);
|
||||
final ElementalItemHolder elementItem = ElementalAttributeData.getInstance().getItemElemental(sotneId);
|
||||
if (elementItem == null)
|
||||
{
|
||||
return 0;
|
||||
@@ -315,30 +316,30 @@ public class RequestExEnchantItemAttribute implements IClientIncomingPacket
|
||||
|
||||
if (item.isWeapon())
|
||||
{
|
||||
return Elementals.WEAPON_VALUES[elementItem._type._maxLevel];
|
||||
return ElementalAttributeData.WEAPON_VALUES[elementItem.getType().getMaxLevel()];
|
||||
}
|
||||
return Elementals.ARMOR_VALUES[elementItem._type._maxLevel];
|
||||
return ElementalAttributeData.ARMOR_VALUES[elementItem.getType().getMaxLevel()];
|
||||
}
|
||||
|
||||
public int getPowerToAdd(int stoneId, int oldValue, ItemInstance item)
|
||||
{
|
||||
if (Elementals.getItemElement(stoneId) != -1)
|
||||
if (ElementalAttributeData.getInstance().getItemElement(stoneId) != AttributeType.NONE)
|
||||
{
|
||||
if (Elementals.getItemElemental(stoneId)._fixedPower > 0)
|
||||
if (ElementalAttributeData.getInstance().getItemElemental(stoneId).getPower() > 0)
|
||||
{
|
||||
return Elementals.getItemElemental(stoneId)._fixedPower;
|
||||
return ElementalAttributeData.getInstance().getItemElemental(stoneId).getPower();
|
||||
}
|
||||
if (item.isWeapon())
|
||||
{
|
||||
if (oldValue == 0)
|
||||
{
|
||||
return Elementals.FIRST_WEAPON_BONUS;
|
||||
return ElementalAttributeData.FIRST_WEAPON_BONUS;
|
||||
}
|
||||
return Elementals.NEXT_WEAPON_BONUS;
|
||||
return ElementalAttributeData.NEXT_WEAPON_BONUS;
|
||||
}
|
||||
else if (item.isArmor())
|
||||
{
|
||||
return Elementals.ARMOR_BONUS;
|
||||
return ElementalAttributeData.ARMOR_BONUS;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
@@ -20,8 +20,8 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.l2jmobius.commons.network.PacketWriter;
|
||||
import org.l2jmobius.gameserver.data.xml.ElementalAttributeData;
|
||||
import org.l2jmobius.gameserver.enums.AttributeType;
|
||||
import org.l2jmobius.gameserver.model.Elementals;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
|
||||
import org.l2jmobius.gameserver.network.OutgoingPackets;
|
||||
@@ -41,12 +41,12 @@ public class ExChooseInventoryAttributeItem implements IClientOutgoingPacket
|
||||
{
|
||||
_itemId = stone.getDisplayId();
|
||||
_count = stone.getCount();
|
||||
_atribute = AttributeType.findByClientId(Elementals.getItemElement(_itemId));
|
||||
_atribute = ElementalAttributeData.getInstance().getItemElement(_itemId);
|
||||
if (_atribute == AttributeType.NONE)
|
||||
{
|
||||
throw new IllegalArgumentException("Undefined Atribute item: " + stone);
|
||||
}
|
||||
_level = Elementals.getMaxElementLevel(_itemId);
|
||||
_level = ElementalAttributeData.getInstance().getMaxElementLevel(_itemId);
|
||||
|
||||
// Register only items that can be put an attribute stone/crystal
|
||||
for (ItemInstance item : player.getInventory().getItems())
|
||||
|
Reference in New Issue
Block a user