123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /*
- * Copyright (C) 2004-2015 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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.
- *
- * L2J Server 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.l2jserver.gameserver.data.xml.impl;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.EnumMap;
- import java.util.List;
- import java.util.Map;
- import org.w3c.dom.Document;
- import org.w3c.dom.Node;
- import com.l2jserver.gameserver.datatables.ItemTable;
- import com.l2jserver.gameserver.enums.StatFunction;
- import com.l2jserver.gameserver.model.items.L2Item;
- import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
- import com.l2jserver.gameserver.model.items.type.CrystalType;
- import com.l2jserver.gameserver.model.stats.Stats;
- import com.l2jserver.gameserver.model.stats.functions.FuncTemplate;
- import com.l2jserver.util.data.xml.IXmlReader;
- /**
- * This class holds the Enchant HP Bonus Data.
- * @author MrPoke, Zoey76
- */
- public class EnchantItemHPBonusData implements IXmlReader
- {
- private final Map<CrystalType, List<Integer>> _armorHPBonuses = new EnumMap<>(CrystalType.class);
-
- private static final float FULL_ARMOR_MODIFIER = 1.5f; // TODO: Move it to config!
-
- /**
- * Instantiates a new enchant hp bonus data.
- */
- protected EnchantItemHPBonusData()
- {
- load();
- }
-
- @Override
- public void load()
- {
- _armorHPBonuses.clear();
- parseDatapackFile("data/stats/enchantHPBonus.xml");
- LOGGER.info("{}: Loaded {} Enchant HP Bonuses.", getClass().getSimpleName(), _armorHPBonuses.size());
- }
-
- @Override
- public void parseDocument(Document doc)
- {
- 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 ("enchantHP".equalsIgnoreCase(d.getNodeName()))
- {
- final List<Integer> bonuses = new ArrayList<>(12);
- for (Node e = d.getFirstChild(); e != null; e = e.getNextSibling())
- {
- if ("bonus".equalsIgnoreCase(e.getNodeName()))
- {
- bonuses.add(Integer.parseInt(e.getTextContent()));
- }
- }
- _armorHPBonuses.put(parseEnum(d.getAttributes(), CrystalType.class, "grade"), bonuses);
- }
- }
- }
- }
-
- if (!_armorHPBonuses.isEmpty())
- {
- final ItemTable it = ItemTable.getInstance();
- // Armors
- final Collection<Integer> armorIds = it.getAllArmorsId();
- for (Integer itemId : armorIds)
- {
- L2Item item = it.getTemplate(itemId);
- if ((item != null) && (item.getCrystalType() != CrystalType.NONE))
- {
- switch (item.getBodyPart())
- {
- case L2Item.SLOT_CHEST:
- case L2Item.SLOT_FEET:
- case L2Item.SLOT_GLOVES:
- case L2Item.SLOT_HEAD:
- case L2Item.SLOT_LEGS:
- case L2Item.SLOT_BACK:
- case L2Item.SLOT_FULL_ARMOR:
- case L2Item.SLOT_UNDERWEAR:
- case L2Item.SLOT_L_HAND:
- case L2Item.SLOT_BELT:
- item.attach(new FuncTemplate(null, null, StatFunction.ENCHANTHP.getName(), -1, Stats.MAX_HP, 0));
- break;
- default:
- break;
- }
- }
- }
- }
- }
-
- /**
- * Gets the HP bonus.
- * @param item the item
- * @return the HP bonus
- */
- public final int getHPBonus(L2ItemInstance item)
- {
- final List<Integer> values = _armorHPBonuses.get(item.getItem().getItemGradeSPlus());
- if ((values == null) || values.isEmpty() || (item.getOlyEnchantLevel() <= 0))
- {
- return 0;
- }
-
- final int bonus = values.get(Math.min(item.getOlyEnchantLevel(), values.size()) - 1);
- if (item.getItem().getBodyPart() == L2Item.SLOT_FULL_ARMOR)
- {
- return (int) (bonus * FULL_ARMOR_MODIFIER);
- }
- return bonus;
- }
-
- /**
- * Gets the single instance of EnchantHPBonusData.
- * @return single instance of EnchantHPBonusData
- */
- public static final EnchantItemHPBonusData getInstance()
- {
- return SingletonHolder._instance;
- }
-
- private static class SingletonHolder
- {
- protected static final EnchantItemHPBonusData _instance = new EnchantItemHPBonusData();
- }
- }
|