Реализация мультипрофы

oreh

Свой человек
Участник
Сообщения
48
Розыгрыши
0
Репутация
25
Реакции
9
Баллы
545
Исходники emurt.
Недавно, о чудо, у меня вышла компиляция сборки. Открыл все скрипты, честно скажу радости не было предела.
Ребят подскажите как реализовать мультипрофу, чтобы каждый мог выучить скилы любой другой профы?
В каком скрипте, что изменить?
 
Последнее редактирование:
Исходники emurt.
Недавно, о чудо, у меня вышла компиляция сборки. Открыл все скрипты, честно скажу радости не было придела.
Ребят подскажите как реализовать мультипрофу, чтобы каждый мог выучить скилы любой другой профы?
В каком скрипте, что изменить?
посмотри в других исходах где это есть и начни поиск по конфигам...)
 
  • Мне нравится
Реакции: oreh

    oreh

    Баллов: 1
    За ответ
а в каких есть реализация?
 
Нормальной нет. Писать Самому.
Дописывать парсеры итд.
В правке метода не обойтись.

У лыжи есть реализация классической мультипрофы... И у оверов мульти саб не дописаный.
 
  • Мне нравится
Реакции: oreh
ясно, я такое не осилю пока.
 
попробуй найти разраба этого сайта, у него есть скрипт на мульту 100% он нам писал пару лет назад:)
 
Нормальной нет. Писать Самому.
Дописывать парсеры итд.
В правке метода не обойтись.

У лыжи есть реализация классической мультипрофы... И у оверов мульти саб не дописаный.
какие парсеры) она или есть или ее нет)

править в ядре 3+1 файла, в 4 задаютя рейты на выученные скилы к примеру я у себя поставил х5 и обычно идет х2 по умолчанию (L2Skill.java),

private final int _addCrossLearn; // -1 disable, otherwice SP price for others classes, default 1000
private final float _mulCrossLearn; // multiplay for others classes, default 2
private final float _mulCrossLearnRace; // multiplay for others races, default 2
private final float _mulCrossLearnProf; // multiplay for fighter/mage missmatch, default 3

на мой взгляд лучше всех продумана на сборках l2jx (там черт ногу сломит- в коде, но раз вникнув много полезного можно перенести исходники teon, всем рекомендую данную команду хоть и древняя) именно оттуда и выбирал под свой сервер, открываешь eclipse и поиском ищещь все что нужно ,п.с ставил на акисоподобный исходник
 
Шутник)

я же написал что у l2j (лыжи) есть реализация. Причем самая убогая из тех что я знаю.
Зачем ради мультипрофы брать этот хлам?)
Какая она самая продуманная?) Самая простая, проще некуда.

Лучше же взять тот же лостворлд или емурт, и сделать нормальную реализацию мультипрофы.
 
Последнее редактирование:
Я тут в исходах нарыл SkillTraderManager
Я так понял это продавец скилов?! Как мне его включить ?
SkillTraderManager.java

Код:
package l2p.gameserver.instancemanager;

import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.List;
import l2p.gameserver.data.xml.holder.SkillTradeHolder;
import l2p.gameserver.model.SkillLearn;
import l2p.gameserver.model.base.ClassId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author baltasar
 */
public class SkillTraderManager {

    private static TIntObjectHashMap<List<SkillLearn>> _normalSkillTreeSell = new TIntObjectHashMap<List<SkillLearn>>();

    private static final Logger _log = LoggerFactory.getLogger(SkillTraderManager.class);
    private static SkillTraderManager _instance;

    public static SkillTraderManager getInstance() {
        if (_instance == null) {
            _instance = new SkillTraderManager();
        }

        return _instance;
    }

    public SkillTraderManager() {
        LoadSkillTrade();
    }

    private void LoadSkillTrade() {

        int classID;

        for (ClassId classId : ClassId.VALUES) {
            if (classId.name().startsWith("dummyEntry")) {
                continue;
            }

            classID = classId.getId();

            List<SkillLearn> temp;

            temp = SkillTradeHolder.getInstance().getNormalSkillForLearnsClassId(classID);
            if (temp == null) {
                _log.error("Not found NORMAL skill learn for class " + classID);
                continue;
            }

            ClassId secondparent = classId.getParent(1);
            if (secondparent == classId.getParent(0)) {
                secondparent = null;
            }

            classId = classId.getParent(0);

            while (classId != null) {
                List<SkillLearn> parentList = SkillTradeHolder.getInstance().getNormalSkillForLearnsClassId(classId.getId());
                temp.removeAll(parentList);

                classId = classId.getParent(0);
                if (classId == null && secondparent != null) {
                    classId = secondparent;
                    secondparent = secondparent.getParent(1);
                }
            }
            _normalSkillTreeSell.put(classID, temp);

        }

    }

    public static TIntObjectHashMap<List<SkillLearn>> getAllSkills() {
        return _normalSkillTreeSell;
    }

    public static List<SkillLearn> getSkillForClass(int classId) {
        return _normalSkillTreeSell.get(classId);
    }
}
SkillTradeHolder.java
Код:
package l2p.gameserver.data.xml.holder;

import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import l2p.commons.data.xml.AbstractHolder;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.Skill;
import l2p.gameserver.model.SkillLearn;
import l2p.gameserver.model.base.AcquireType;
import l2p.gameserver.model.base.ClassId;
import l2p.gameserver.model.pledge.Clan;
import l2p.gameserver.model.pledge.SubUnit;

/**
 * @author: VISTALL
 * @date: 20:55/30.11.2010
 */
public final class SkillTradeHolder extends AbstractHolder {

    private static final SkillTradeHolder _instance = new SkillTradeHolder();

    public static SkillTradeHolder getInstance() {
        return _instance;
    }
    //загрузка для менеджера
   
    private TIntObjectHashMap<List<SkillLearn>> _skillTreeSell = new TIntObjectHashMap<List<SkillLearn>>();
   
    // классовые зависимости
    private TIntObjectHashMap<List<SkillLearn>> _normalSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    private TIntObjectHashMap<List<SkillLearn>> _transferSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    // расовые зависимости
    private TIntObjectHashMap<List<SkillLearn>> _fishingSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    private TIntObjectHashMap<List<SkillLearn>> _transformationSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    // без зависимостей
    private List<SkillLearn> _certificationSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _collectionSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _pledgeSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _subUnitSkillTree = new ArrayList<SkillLearn>();

    public int getMinLevelForNewSkill(Player player, AcquireType type) {
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return 0;
                }
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return 0;
                }
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return 0;
                }
                break;
            default:
                return 0;
        }
        int minlevel = 0;
        for (SkillLearn temp : skills) {
            if (temp.getMinLevel() > player.getLevel()) {
                if (minlevel == 0 || temp.getMinLevel() < minlevel) {
                    minlevel = temp.getMinLevel();
                }
            }
        }
        return minlevel;
    }

    public Collection<SkillLearn> getAvailableSkills(Player player, AcquireType type) {
        return getAvailableSkills(player, type, null);
    }

    public Collection<SkillLearn> getAvailableSkills(Player player, AcquireType type, SubUnit subUnit) {
        Collection<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case COLLECTION:
                skills = _collectionSkillTree;
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case TRANSFER_EVA_SAINTS:
            case TRANSFER_SHILLIEN_SAINTS:
            case TRANSFER_CARDINAL:
                skills = _transferSkillTree.get(type.transferClassId());
                if (skills == null) {
                    info("skill tree for class " + type.transferClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                if (player == null) {
                    return skills;
                } else {
                    Map<Integer, SkillLearn> skillLearnMap = new TreeMap<Integer, SkillLearn>();
                    for (SkillLearn temp : skills) {
                        if (temp.getMinLevel() <= player.getLevel()) {
                            int knownLevel = player.getSkillLevel(temp.getId());
                            if (knownLevel == -1) {
                                skillLearnMap.put(temp.getId(), temp);
                            }
                        }
                    }

                    return skillLearnMap.values();
                }
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case CLAN:
                skills = _pledgeSkillTree;
                Collection<Skill> skls = player.getClan().getSkills(); //TODO [VISTALL] придумать другой способ

                return getAvaliableList(skills, skls.toArray(new Skill[skls.size()]), player.getClan().getLevel());
            case SUB_UNIT:
                skills = _subUnitSkillTree;
                Collection<Skill> st = subUnit.getSkills(); //TODO [VISTALL] придумать другой способ

                return getAvaliableList(skills, st.toArray(new Skill[st.size()]), player.getClan().getLevel());
            case CERTIFICATION:
                skills = _certificationSkillTree;
                if (player == null) {
                    return skills;
                } else {
                    return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
                }
            default:
                return Collections.emptyList();
        }
    }

    private Collection<SkillLearn> getAvaliableList(Collection<SkillLearn> skillLearns, Skill[] skills, int level) {
        Map<Integer, SkillLearn> skillLearnMap = new TreeMap<Integer, SkillLearn>();
        for (SkillLearn temp : skillLearns) {
            if (temp.getMinLevel() <= level) {
                boolean knownSkill = false;
                for (int j = 0; j < skills.length && !knownSkill; j++) {
                    if (skills[j].getId() == temp.getId()) {
                        knownSkill = true;
                        if (skills[j].getLevel() == temp.getLevel() - 1) {
                            skillLearnMap.put(temp.getId(), temp);
                        }
                    }
                }
                if (!knownSkill && temp.getLevel() == 1) {
                    skillLearnMap.put(temp.getId(), temp);
                }
            }
        }

        return skillLearnMap.values();
    }

    public SkillLearn getSkillLearn(Player player, int id, int level, AcquireType type) {
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                break;
            case COLLECTION:
                skills = _collectionSkillTree;
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                break;
            case TRANSFER_CARDINAL:
            case TRANSFER_SHILLIEN_SAINTS:
            case TRANSFER_EVA_SAINTS:
                skills = _transferSkillTree.get(player.getActiveClassId());
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                break;
            case CLAN:
                skills = _pledgeSkillTree;
                break;
            case SUB_UNIT:
                skills = _subUnitSkillTree;
                break;
            case CERTIFICATION:
                skills = _certificationSkillTree;
                break;
            default:
                return null;
        }

        if (skills == null) {
            return null;
        }

        for (SkillLearn temp : skills) {
            if (temp.getLevel() == level && temp.getId() == id) {
                return temp;
            }
        }

        return null;
    }

    public boolean isSkillPossible(Player player, Skill skill, AcquireType type) {
        Clan clan = null;
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                break;
            case COLLECTION:
                skills = _collectionSkillTree;
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                break;
            case TRANSFER_CARDINAL:
            case TRANSFER_EVA_SAINTS:
            case TRANSFER_SHILLIEN_SAINTS:
                int transferId = type.transferClassId();
                if (player.getActiveClassId() != transferId) {
                    return false;
                }

                skills = _transferSkillTree.get(transferId);
                break;
            case CLAN:
                clan = player.getClan();
                if (clan == null) {
                    return false;
                }
                skills = _pledgeSkillTree;
                break;
            case SUB_UNIT:
                clan = player.getClan();
                if (clan == null) {
                    return false;
                }

                skills = _subUnitSkillTree;
                break;
            case CERTIFICATION:
                skills = _certificationSkillTree;
                break;
            default:
                return false;
        }

        return isSkillPossible(skills, skill);
    }

    private boolean isSkillPossible(Collection<SkillLearn> skills, Skill skill) {
        for (SkillLearn learn : skills) {
            if (learn.getId() == skill.getId() && learn.getLevel() <= skill.getLevel()) {
                return true;
            }
        }
        return false;
    }

    public boolean isSkillPossible(Player player, Skill skill) {
        for (AcquireType aq : AcquireType.VALUES) {
            if (isSkillPossible(player, skill, aq)) {
                return true;
            }
        }

        return false;
    }

    public List<SkillLearn> getSkillLearnListByItemId(Player player, int itemId) {
        List<SkillLearn> learns = _normalSkillTree.get(player.getActiveClassId());
        if (learns == null) {
            return Collections.emptyList();
        }

        List<SkillLearn> l = new ArrayList<SkillLearn>(1);
        for (SkillLearn $i : learns) {
            if ($i.getItemId() == itemId) {
                l.add($i);
            }
        }

        return l;
    }

    public List<SkillLearn> getAllNormalSkillTreeWithForgottenScrolls() {
        List<SkillLearn> a = new ArrayList<SkillLearn>();
        for (TIntObjectIterator<List<SkillLearn>> i = _normalSkillTree.iterator(); i.hasNext();) {
            i.advance();
            for (SkillLearn learn : i.value()) {
                if (learn.getItemId() > 0 && learn.isClicked()) {
                    a.add(learn);
                }
            }
        }

        return a;
    }

    public void addAllNormalSkillLearns(TIntObjectHashMap<List<SkillLearn>> map) {
        int classID;

        for (ClassId classId : ClassId.VALUES) {
            if (classId.name().startsWith("dummyEntry")) {
                continue;
            }

            classID = classId.getId();

            List<SkillLearn> temp;

            temp = map.get(classID);
            if (temp == null) {
                info("Not found NORMAL skill learn for class " + classID);
                continue;
            }

            _normalSkillTree.put(classId.getId(), temp);
            _skillTreeSell.put(classId.getId(), temp);

            ClassId secondparent = classId.getParent(1);
            if (secondparent == classId.getParent(0)) {
                secondparent = null;
            }

            classId = classId.getParent(0);

            while (classId != null) {
                List<SkillLearn> parentList = _normalSkillTree.get(classId.getId());
                temp.addAll(parentList);

                classId = classId.getParent(0);
                if (classId == null && secondparent != null) {
                    classId = secondparent;
                    secondparent = secondparent.getParent(1);
                }
            }
        }
    }

    public TIntObjectHashMap<List<SkillLearn>> getAllNormalSkillForLearns() {
        return _skillTreeSell;
    }
    public List<SkillLearn> getNormalSkillForLearnsClassId(int classId) {
        return _skillTreeSell.get(classId);
    }

    public void addAllFishingLearns(int race, List<SkillLearn> s) {
        _fishingSkillTree.put(race, s);
    }

    public void addAllTransferLearns(int classId, List<SkillLearn> s) {
        _transferSkillTree.put(classId, s);
    }

    public void addAllTransformationLearns(int race, List<SkillLearn> s) {
        _transformationSkillTree.put(race, s);
    }

    public void addAllCertificationLearns(List<SkillLearn> s) {
        _certificationSkillTree.addAll(s);
    }

    public void addAllCollectionLearns(List<SkillLearn> s) {
        _collectionSkillTree.addAll(s);
    }

    public void addAllSubUnitLearns(List<SkillLearn> s) {
        _subUnitSkillTree.addAll(s);
    }

    public void addAllPledgeLearns(List<SkillLearn> s) {
        _pledgeSkillTree.addAll(s);
    }

    @Override
    public void log() {
       
    }

    @Deprecated
    @Override
    public int size() {
        return 0;
    }

    @Override
    public void clear() {
        _skillTreeSell.clear();
        _normalSkillTree.clear();
        _fishingSkillTree.clear();
        _transferSkillTree.clear();
        _certificationSkillTree.clear();
        _collectionSkillTree.clear();
        _pledgeSkillTree.clear();
        _subUnitSkillTree.clear();
    }

    private int sizeTroveMap(TIntObjectHashMap<List<SkillLearn>> a) {
        int i = 0;
        for (TIntObjectIterator<List<SkillLearn>> iterator = a.iterator(); iterator.hasNext();) {
            iterator.advance();
            i += iterator.value().size();
        }

        return i;
    }
}
SkillTradeParser.java
Код:
apackage l2p.gameserver.data.xml.parser;

import gnu.trove.map.hash.TIntObjectHashMap;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Element;
import l2p.commons.data.xml.AbstractDirParser;
import l2p.gameserver.Config;
import l2p.gameserver.data.xml.holder.SkillTradeHolder;
import l2p.gameserver.model.SkillLearn;

public final class SkillTradeParser extends AbstractDirParser<SkillTradeHolder> {

    private static final SkillTradeParser _instance = new SkillTradeParser();

    public static SkillTradeParser getInstance() {
        return _instance;
    }

    protected SkillTradeParser() {
        super(SkillTradeHolder.getInstance());
    }

    @Override
    public File getXMLDir() {
        return new File(Config.DATAPACK_ROOT, "data/xml/skill_tree/");
    }

    @Override
    public boolean isIgnored(File b) {
        return false;
    }

    @Override
    public String getDTDFileName() {
        return "tree.dtd";
    }

    @Override
    protected void readData(Element rootElement) throws Exception {
        for (Iterator<Element> iterator = rootElement.elementIterator("certification_skill_tree"); iterator.hasNext();) {
            getHolder().addAllCertificationLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("sub_unit_skill_tree"); iterator.hasNext();) {
            getHolder().addAllSubUnitLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("pledge_skill_tree"); iterator.hasNext();) {
            getHolder().addAllPledgeLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("collection_skill_tree"); iterator.hasNext();) {
            getHolder().addAllCollectionLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("fishing_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int race = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllFishingLearns(race, learns);
            }
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("transfer_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int classId = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllTransferLearns(classId, learns);
            }
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("normal_skill_tree"); iterator.hasNext();) {
            TIntObjectHashMap<List<SkillLearn>> map = new TIntObjectHashMap<List<SkillLearn>>();
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int classId = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);

                map.put(classId, learns);
            }

            getHolder().addAllNormalSkillLearns(map);
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("transformation_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int race = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllTransformationLearns(race, learns);
            }
        }
    }

    private List<SkillLearn> parseSkillLearn(Element tree) {
        List<SkillLearn> skillLearns = new ArrayList<SkillLearn>();
        for (Iterator<Element> iterator = tree.elementIterator("skill"); iterator.hasNext();) {
            Element element = iterator.next();

            int id = Integer.parseInt(element.attributeValue("id"));
            int level = Integer.parseInt(element.attributeValue("level"));
            int cost = element.attributeValue("cost") == null ? 0 : Integer.parseInt(element.attributeValue("cost"));
            int min_level = Integer.parseInt(element.attributeValue("min_level"));
            int item_id = element.attributeValue("item_id") == null ? 0 : Integer.parseInt(element.attributeValue("item_id"));
            long item_count = element.attributeValue("item_count") == null ? 1 : Long.parseLong(element.attributeValue("item_count"));
            boolean clicked = element.attributeValue("clicked") != null && Boolean.parseBoolean(element.attributeValue("clicked"));

            skillLearns.add(new SkillLearn(id, level, min_level, cost, item_id, item_count, clicked));
        }

        return skillLearns;
    }
}
 
Я тут в исходах нарыл SkillTraderManager
Я так понял это продавец скилов?! Как мне его включить ?
SkillTraderManager.java

Код:
package l2p.gameserver.instancemanager;

import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.List;
import l2p.gameserver.data.xml.holder.SkillTradeHolder;
import l2p.gameserver.model.SkillLearn;
import l2p.gameserver.model.base.ClassId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
*
* @author baltasar
*/
public class SkillTraderManager {

    private static TIntObjectHashMap<List<SkillLearn>> _normalSkillTreeSell = new TIntObjectHashMap<List<SkillLearn>>();

    private static final Logger _log = LoggerFactory.getLogger(SkillTraderManager.class);
    private static SkillTraderManager _instance;

    public static SkillTraderManager getInstance() {
        if (_instance == null) {
            _instance = new SkillTraderManager();
        }

        return _instance;
    }

    public SkillTraderManager() {
        LoadSkillTrade();
    }

    private void LoadSkillTrade() {

        int classID;

        for (ClassId classId : ClassId.VALUES) {
            if (classId.name().startsWith("dummyEntry")) {
                continue;
            }

            classID = classId.getId();

            List<SkillLearn> temp;

            temp = SkillTradeHolder.getInstance().getNormalSkillForLearnsClassId(classID);
            if (temp == null) {
                _log.error("Not found NORMAL skill learn for class " + classID);
                continue;
            }

            ClassId secondparent = classId.getParent(1);
            if (secondparent == classId.getParent(0)) {
                secondparent = null;
            }

            classId = classId.getParent(0);

            while (classId != null) {
                List<SkillLearn> parentList = SkillTradeHolder.getInstance().getNormalSkillForLearnsClassId(classId.getId());
                temp.removeAll(parentList);

                classId = classId.getParent(0);
                if (classId == null && secondparent != null) {
                    classId = secondparent;
                    secondparent = secondparent.getParent(1);
                }
            }
            _normalSkillTreeSell.put(classID, temp);

        }

    }

    public static TIntObjectHashMap<List<SkillLearn>> getAllSkills() {
        return _normalSkillTreeSell;
    }

    public static List<SkillLearn> getSkillForClass(int classId) {
        return _normalSkillTreeSell.get(classId);
    }
}
SkillTradeHolder.java
Код:
package l2p.gameserver.data.xml.holder;

import gnu.trove.iterator.TIntObjectIterator;
import gnu.trove.map.hash.TIntObjectHashMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import l2p.commons.data.xml.AbstractHolder;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.Skill;
import l2p.gameserver.model.SkillLearn;
import l2p.gameserver.model.base.AcquireType;
import l2p.gameserver.model.base.ClassId;
import l2p.gameserver.model.pledge.Clan;
import l2p.gameserver.model.pledge.SubUnit;

/**
* @author: VISTALL
* @date: 20:55/30.11.2010
*/
public final class SkillTradeHolder extends AbstractHolder {

    private static final SkillTradeHolder _instance = new SkillTradeHolder();

    public static SkillTradeHolder getInstance() {
        return _instance;
    }
    //загрузка для менеджера
 
    private TIntObjectHashMap<List<SkillLearn>> _skillTreeSell = new TIntObjectHashMap<List<SkillLearn>>();
 
    // классовые зависимости
    private TIntObjectHashMap<List<SkillLearn>> _normalSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    private TIntObjectHashMap<List<SkillLearn>> _transferSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    // расовые зависимости
    private TIntObjectHashMap<List<SkillLearn>> _fishingSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    private TIntObjectHashMap<List<SkillLearn>> _transformationSkillTree = new TIntObjectHashMap<List<SkillLearn>>();
    // без зависимостей
    private List<SkillLearn> _certificationSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _collectionSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _pledgeSkillTree = new ArrayList<SkillLearn>();
    private List<SkillLearn> _subUnitSkillTree = new ArrayList<SkillLearn>();

    public int getMinLevelForNewSkill(Player player, AcquireType type) {
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return 0;
                }
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return 0;
                }
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return 0;
                }
                break;
            default:
                return 0;
        }
        int minlevel = 0;
        for (SkillLearn temp : skills) {
            if (temp.getMinLevel() > player.getLevel()) {
                if (minlevel == 0 || temp.getMinLevel() < minlevel) {
                    minlevel = temp.getMinLevel();
                }
            }
        }
        return minlevel;
    }

    public Collection<SkillLearn> getAvailableSkills(Player player, AcquireType type) {
        return getAvailableSkills(player, type, null);
    }

    public Collection<SkillLearn> getAvailableSkills(Player player, AcquireType type, SubUnit subUnit) {
        Collection<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case COLLECTION:
                skills = _collectionSkillTree;
                if (skills == null) {
                    info("skill tree for class " + player.getActiveClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case TRANSFER_EVA_SAINTS:
            case TRANSFER_SHILLIEN_SAINTS:
            case TRANSFER_CARDINAL:
                skills = _transferSkillTree.get(type.transferClassId());
                if (skills == null) {
                    info("skill tree for class " + type.transferClassId() + " is not defined !");
                    return Collections.emptyList();
                }
                if (player == null) {
                    return skills;
                } else {
                    Map<Integer, SkillLearn> skillLearnMap = new TreeMap<Integer, SkillLearn>();
                    for (SkillLearn temp : skills) {
                        if (temp.getMinLevel() <= player.getLevel()) {
                            int knownLevel = player.getSkillLevel(temp.getId());
                            if (knownLevel == -1) {
                                skillLearnMap.put(temp.getId(), temp);
                            }
                        }
                    }

                    return skillLearnMap.values();
                }
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                if (skills == null) {
                    info("skill tree for race " + player.getRace().ordinal() + " is not defined !");
                    return Collections.emptyList();
                }
                return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
            case CLAN:
                skills = _pledgeSkillTree;
                Collection<Skill> skls = player.getClan().getSkills(); //TODO [VISTALL] придумать другой способ

                return getAvaliableList(skills, skls.toArray(new Skill[skls.size()]), player.getClan().getLevel());
            case SUB_UNIT:
                skills = _subUnitSkillTree;
                Collection<Skill> st = subUnit.getSkills(); //TODO [VISTALL] придумать другой способ

                return getAvaliableList(skills, st.toArray(new Skill[st.size()]), player.getClan().getLevel());
            case CERTIFICATION:
                skills = _certificationSkillTree;
                if (player == null) {
                    return skills;
                } else {
                    return getAvaliableList(skills, player.getAllSkillsArray(), player.getLevel());
                }
            default:
                return Collections.emptyList();
        }
    }

    private Collection<SkillLearn> getAvaliableList(Collection<SkillLearn> skillLearns, Skill[] skills, int level) {
        Map<Integer, SkillLearn> skillLearnMap = new TreeMap<Integer, SkillLearn>();
        for (SkillLearn temp : skillLearns) {
            if (temp.getMinLevel() <= level) {
                boolean knownSkill = false;
                for (int j = 0; j < skills.length && !knownSkill; j++) {
                    if (skills[j].getId() == temp.getId()) {
                        knownSkill = true;
                        if (skills[j].getLevel() == temp.getLevel() - 1) {
                            skillLearnMap.put(temp.getId(), temp);
                        }
                    }
                }
                if (!knownSkill && temp.getLevel() == 1) {
                    skillLearnMap.put(temp.getId(), temp);
                }
            }
        }

        return skillLearnMap.values();
    }

    public SkillLearn getSkillLearn(Player player, int id, int level, AcquireType type) {
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                break;
            case COLLECTION:
                skills = _collectionSkillTree;
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                break;
            case TRANSFER_CARDINAL:
            case TRANSFER_SHILLIEN_SAINTS:
            case TRANSFER_EVA_SAINTS:
                skills = _transferSkillTree.get(player.getActiveClassId());
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                break;
            case CLAN:
                skills = _pledgeSkillTree;
                break;
            case SUB_UNIT:
                skills = _subUnitSkillTree;
                break;
            case CERTIFICATION:
                skills = _certificationSkillTree;
                break;
            default:
                return null;
        }

        if (skills == null) {
            return null;
        }

        for (SkillLearn temp : skills) {
            if (temp.getLevel() == level && temp.getId() == id) {
                return temp;
            }
        }

        return null;
    }

    public boolean isSkillPossible(Player player, Skill skill, AcquireType type) {
        Clan clan = null;
        List<SkillLearn> skills;
        switch (type) {
            case NORMAL:
                skills = _normalSkillTree.get(player.getActiveClassId());
                break;
            case COLLECTION:
                skills = _collectionSkillTree;
                break;
            case TRANSFORMATION:
                skills = _transformationSkillTree.get(player.getRace().ordinal());
                break;
            case FISHING:
                skills = _fishingSkillTree.get(player.getRace().ordinal());
                break;
            case TRANSFER_CARDINAL:
            case TRANSFER_EVA_SAINTS:
            case TRANSFER_SHILLIEN_SAINTS:
                int transferId = type.transferClassId();
                if (player.getActiveClassId() != transferId) {
                    return false;
                }

                skills = _transferSkillTree.get(transferId);
                break;
            case CLAN:
                clan = player.getClan();
                if (clan == null) {
                    return false;
                }
                skills = _pledgeSkillTree;
                break;
            case SUB_UNIT:
                clan = player.getClan();
                if (clan == null) {
                    return false;
                }

                skills = _subUnitSkillTree;
                break;
            case CERTIFICATION:
                skills = _certificationSkillTree;
                break;
            default:
                return false;
        }

        return isSkillPossible(skills, skill);
    }

    private boolean isSkillPossible(Collection<SkillLearn> skills, Skill skill) {
        for (SkillLearn learn : skills) {
            if (learn.getId() == skill.getId() && learn.getLevel() <= skill.getLevel()) {
                return true;
            }
        }
        return false;
    }

    public boolean isSkillPossible(Player player, Skill skill) {
        for (AcquireType aq : AcquireType.VALUES) {
            if (isSkillPossible(player, skill, aq)) {
                return true;
            }
        }

        return false;
    }

    public List<SkillLearn> getSkillLearnListByItemId(Player player, int itemId) {
        List<SkillLearn> learns = _normalSkillTree.get(player.getActiveClassId());
        if (learns == null) {
            return Collections.emptyList();
        }

        List<SkillLearn> l = new ArrayList<SkillLearn>(1);
        for (SkillLearn $i : learns) {
            if ($i.getItemId() == itemId) {
                l.add($i);
            }
        }

        return l;
    }

    public List<SkillLearn> getAllNormalSkillTreeWithForgottenScrolls() {
        List<SkillLearn> a = new ArrayList<SkillLearn>();
        for (TIntObjectIterator<List<SkillLearn>> i = _normalSkillTree.iterator(); i.hasNext();) {
            i.advance();
            for (SkillLearn learn : i.value()) {
                if (learn.getItemId() > 0 && learn.isClicked()) {
                    a.add(learn);
                }
            }
        }

        return a;
    }

    public void addAllNormalSkillLearns(TIntObjectHashMap<List<SkillLearn>> map) {
        int classID;

        for (ClassId classId : ClassId.VALUES) {
            if (classId.name().startsWith("dummyEntry")) {
                continue;
            }

            classID = classId.getId();

            List<SkillLearn> temp;

            temp = map.get(classID);
            if (temp == null) {
                info("Not found NORMAL skill learn for class " + classID);
                continue;
            }

            _normalSkillTree.put(classId.getId(), temp);
            _skillTreeSell.put(classId.getId(), temp);

            ClassId secondparent = classId.getParent(1);
            if (secondparent == classId.getParent(0)) {
                secondparent = null;
            }

            classId = classId.getParent(0);

            while (classId != null) {
                List<SkillLearn> parentList = _normalSkillTree.get(classId.getId());
                temp.addAll(parentList);

                classId = classId.getParent(0);
                if (classId == null && secondparent != null) {
                    classId = secondparent;
                    secondparent = secondparent.getParent(1);
                }
            }
        }
    }

    public TIntObjectHashMap<List<SkillLearn>> getAllNormalSkillForLearns() {
        return _skillTreeSell;
    }
    public List<SkillLearn> getNormalSkillForLearnsClassId(int classId) {
        return _skillTreeSell.get(classId);
    }

    public void addAllFishingLearns(int race, List<SkillLearn> s) {
        _fishingSkillTree.put(race, s);
    }

    public void addAllTransferLearns(int classId, List<SkillLearn> s) {
        _transferSkillTree.put(classId, s);
    }

    public void addAllTransformationLearns(int race, List<SkillLearn> s) {
        _transformationSkillTree.put(race, s);
    }

    public void addAllCertificationLearns(List<SkillLearn> s) {
        _certificationSkillTree.addAll(s);
    }

    public void addAllCollectionLearns(List<SkillLearn> s) {
        _collectionSkillTree.addAll(s);
    }

    public void addAllSubUnitLearns(List<SkillLearn> s) {
        _subUnitSkillTree.addAll(s);
    }

    public void addAllPledgeLearns(List<SkillLearn> s) {
        _pledgeSkillTree.addAll(s);
    }

    @Override
    public void log() {
     
    }

    @Deprecated
    @Override
    public int size() {
        return 0;
    }

    @Override
    public void clear() {
        _skillTreeSell.clear();
        _normalSkillTree.clear();
        _fishingSkillTree.clear();
        _transferSkillTree.clear();
        _certificationSkillTree.clear();
        _collectionSkillTree.clear();
        _pledgeSkillTree.clear();
        _subUnitSkillTree.clear();
    }

    private int sizeTroveMap(TIntObjectHashMap<List<SkillLearn>> a) {
        int i = 0;
        for (TIntObjectIterator<List<SkillLearn>> iterator = a.iterator(); iterator.hasNext();) {
            iterator.advance();
            i += iterator.value().size();
        }

        return i;
    }
}
SkillTradeParser.java
Код:
apackage l2p.gameserver.data.xml.parser;

import gnu.trove.map.hash.TIntObjectHashMap;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Element;
import l2p.commons.data.xml.AbstractDirParser;
import l2p.gameserver.Config;
import l2p.gameserver.data.xml.holder.SkillTradeHolder;
import l2p.gameserver.model.SkillLearn;

public final class SkillTradeParser extends AbstractDirParser<SkillTradeHolder> {

    private static final SkillTradeParser _instance = new SkillTradeParser();

    public static SkillTradeParser getInstance() {
        return _instance;
    }

    protected SkillTradeParser() {
        super(SkillTradeHolder.getInstance());
    }

    @Override
    public File getXMLDir() {
        return new File(Config.DATAPACK_ROOT, "data/xml/skill_tree/");
    }

    @Override
    public boolean isIgnored(File b) {
        return false;
    }

    @Override
    public String getDTDFileName() {
        return "tree.dtd";
    }

    @Override
    protected void readData(Element rootElement) throws Exception {
        for (Iterator<Element> iterator = rootElement.elementIterator("certification_skill_tree"); iterator.hasNext();) {
            getHolder().addAllCertificationLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("sub_unit_skill_tree"); iterator.hasNext();) {
            getHolder().addAllSubUnitLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("pledge_skill_tree"); iterator.hasNext();) {
            getHolder().addAllPledgeLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("collection_skill_tree"); iterator.hasNext();) {
            getHolder().addAllCollectionLearns(parseSkillLearn(iterator.next()));
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("fishing_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int race = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllFishingLearns(race, learns);
            }
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("transfer_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int classId = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllTransferLearns(classId, learns);
            }
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("normal_skill_tree"); iterator.hasNext();) {
            TIntObjectHashMap<List<SkillLearn>> map = new TIntObjectHashMap<List<SkillLearn>>();
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("class"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int classId = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);

                map.put(classId, learns);
            }

            getHolder().addAllNormalSkillLearns(map);
        }

        for (Iterator<Element> iterator = rootElement.elementIterator("transformation_skill_tree"); iterator.hasNext();) {
            Element nxt = iterator.next();
            for (Iterator<Element> classIterator = nxt.elementIterator("race"); classIterator.hasNext();) {
                Element classElement = classIterator.next();
                int race = Integer.parseInt(classElement.attributeValue("id"));
                List<SkillLearn> learns = parseSkillLearn(classElement);
                getHolder().addAllTransformationLearns(race, learns);
            }
        }
    }

    private List<SkillLearn> parseSkillLearn(Element tree) {
        List<SkillLearn> skillLearns = new ArrayList<SkillLearn>();
        for (Iterator<Element> iterator = tree.elementIterator("skill"); iterator.hasNext();) {
            Element element = iterator.next();

            int id = Integer.parseInt(element.attributeValue("id"));
            int level = Integer.parseInt(element.attributeValue("level"));
            int cost = element.attributeValue("cost") == null ? 0 : Integer.parseInt(element.attributeValue("cost"));
            int min_level = Integer.parseInt(element.attributeValue("min_level"));
            int item_id = element.attributeValue("item_id") == null ? 0 : Integer.parseInt(element.attributeValue("item_id"));
            long item_count = element.attributeValue("item_count") == null ? 1 : Long.parseLong(element.attributeValue("item_count"));
            boolean clicked = element.attributeValue("clicked") != null && Boolean.parseBoolean(element.attributeValue("clicked"));

            skillLearns.add(new SkillLearn(id, level, min_level, cost, item_id, item_count, clicked));
        }

        return skillLearns;
    }
}
В них еще должен быть сервис на обнуление перса и выдачи итема:) делали нам пару лет назад, не плохая реализация была. скилы можно было покупать и статы +1 после каждого обнуления.
 
  • Мне нравится
Реакции: oreh
Как с этим работать ребят?
jonius, а как он должен называться примерно ?
 
Объясните пожалуйста как мне этот скрипт использовать ? Как привязать к определенному нпц ?
 
не хочет никто с нубом связываться) :Huh::Imd:
 
Назад
Сверху Снизу