/
tofu
/
l2interlude
Обзор
Документация
Войти
/
tofu
/
l2interlude
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/main/java/com/l2jserver/gameserver/datatables/SkillData.java
165 строк
5 KB
Zoey76
Copyright Update
01 янв 2025, 07:57
01 янв 2025, 07:57
16130a5
Код
Авторство
О чём код?
/* * Copyright © 2004-2025 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.datatables; import static com.l2jserver.gameserver.config.Configuration.general; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.l2jserver.gameserver.data.xml.impl.SkillTreesData; import com.l2jserver.gameserver.engines.DocumentEngine; import com.l2jserver.gameserver.model.skills.Skill; /** * Skill data. */ public final class SkillData { private static final Logger LOG = LoggerFactory.getLogger(SkillData.class); private final Map<Integer, Skill> _skills = new HashMap<>(); private final Map<Integer, Integer> _skillMaxLevel = new HashMap<>(); private final Set<Integer> _enchantable = new HashSet<>(); protected SkillData() { load(); } public void reload() { load(); // Reload Skill Tree as well. SkillTreesData.getInstance().load(); } private void load() { final var start = System.currentTimeMillis(); final var temp = DocumentEngine.getInstance().loadAllSkills(); _skills.clear(); _skills.putAll(temp); _skillMaxLevel.clear(); _enchantable.clear(); for (Skill skill : _skills.values()) { final int skillId = skill.getId(); final int skillLvl = skill.getLevel(); if (skillLvl > 99) { _enchantable.add(skillId); continue; } // only non-enchanted skills final int maxLvl = getMaxLevel(skillId); if (skillLvl > maxLvl) { _skillMaxLevel.put(skillId, skillLvl); } } LOG.info("Loaded {} skill templates from XML files in {}ms.", _skills.size(), System.currentTimeMillis() - start); } /** * Provides the skill hash * @param skill The L2Skill to be hashed * @return getSkillHashCode(skill.getId(), skill.getLevel()) */ public static int getSkillHashCode(Skill skill) { return getSkillHashCode(skill.getId(), skill.getLevel()); } /** * Centralized method for easier change of the hashing sys * @param skillId The Skill Id * @param skillLevel The Skill Level * @return The Skill hash number */ public static int getSkillHashCode(int skillId, int skillLevel) { return (skillId * 1021) + skillLevel; } public Skill getSkill(int skillId, int level) { final Skill result = _skills.get(getSkillHashCode(skillId, level)); if (result != null) { return result; } // skill/level not found, fix for transformation scripts final int maxLvl = getMaxLevel(skillId); // requested level too high if ((maxLvl > 0) && (level > maxLvl)) { if (general().debug()) { LOG.warn("Call to unexisting skill level Id {} requested level {} max level {}!", skillId, level, maxLvl); } return _skills.get(getSkillHashCode(skillId, maxLvl)); } LOG.warn("No skill info found for skill Id {} and skill level {}!", skillId, level); return null; } public int getMaxLevel(int skillId) { final Integer maxLevel = _skillMaxLevel.get(skillId); return maxLevel != null ? maxLevel : 0; } /** * Verifies if the given skill ID correspond to an enchantable skill. * @param skillId the skill ID * @return {@code true} if the skill is enchantable, {@code false} otherwise */ public boolean isEnchantable(int skillId) { return _enchantable.contains(skillId); } /** * @param addNoble * @param hasCastle * @return an array with siege skills. If addNoble == true, will add also Advanced headquarters. */ public Skill[] getSiegeSkills(boolean addNoble, boolean hasCastle) { Skill[] temp = new Skill[2 + (addNoble ? 1 : 0) + (hasCastle ? 2 : 0)]; int i = 0; temp[i++] = _skills.get(SkillData.getSkillHashCode(246, 1)); temp[i++] = _skills.get(SkillData.getSkillHashCode(247, 1)); if (addNoble) { temp[i++] = _skills.get(SkillData.getSkillHashCode(326, 1)); } if (hasCastle) { temp[i++] = _skills.get(SkillData.getSkillHashCode(844, 1)); temp[i] = _skills.get(SkillData.getSkillHashCode(845, 1)); } return temp; } public static SkillData getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final SkillData _instance = new SkillData(); } }