All pastes #961575 Raw Edit

Mine

public text v1 · immutable
#961575 ·published 2008-03-28 23:56 UTC
rendered paste body
/*
 * 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/>.
 */

/**
 * @author Forsaiken
 */

package net.sf.l2j.gameserver.handler;

import java.io.File;
import java.util.logging.Logger;

import javax.xml.parsers.DocumentBuilderFactory;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.model.L2Skill;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.util.L2FastList;
import net.sf.l2j.util.L2FastMap;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public final class SkillLearnModTable
{
    private static final Logger _log = Logger.getLogger(SkillLearnModTable.class.getName());
    
    private static SkillLearnModTable _instance;
    
    public static SkillLearnModTable getInstance()
    {
        if (_instance == null)
            _instance = new SkillLearnModTable();
        return _instance;
    }
    
    private SkillLearnModTable()
    {
        load();
    }
    
    private L2FastMap<Integer, L2FastList<Integer>> _stackingSkills;
    
    public void load()
    {
        _stackingSkills = new L2FastMap<Integer, L2FastList<Integer>>();
        
        
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setValidating(false);
        factory.setIgnoringComments(true);
        
        File file = new File(Config.DATAPACK_ROOT + "/data/mods/skillstacking.xml");
        if (!file.exists())
        {
            _log.info("The skillstacking.xml file is missing.");
            return;
        }
        
        try
        {
            Document doc = factory.newDocumentBuilder().parse(file);
            for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
            {
                if ("list".equalsIgnoreCase(n.getNodeName()))
                {
                    for (Node na = n.getFirstChild(); na != null; na = na.getNextSibling())
                    {
                        if ("skillgroup".equalsIgnoreCase(na.getNodeName()))
                        {
                            L2FastList<Integer> stackingSkills = new L2FastList<Integer>();
                            for (Node nb = na.getFirstChild(); nb != null; nb = nb.getNextSibling())
                            {
                                if ("skill".equalsIgnoreCase(na.getNodeName()))
                                {
                                    NamedNodeMap attrs = nb.getAttributes();
                                    final int skill_id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
                                    stackingSkills.add(skill_id);
                                }
                            }
                            for (final int skill_id : stackingSkills)
                                _stackingSkills.put(skill_id, stackingSkills);
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
    
    /**
     * Check if the skill_id stack with the players current skills.
     * @param player who wants to learn the skill
     * @param skill_id of the skill the player wants to learn
     * @return false if stacking
     */
    public final boolean isStacking(L2PcInstance player, final int skill_id)
    {
        L2Skill[] skills = player.getAllSkills();
        System.out.println("1");
        if (skills != null)
        {
        	System.out.println("2");
            for (L2Skill skill : skills)
            {
                if (skill != null)
                {
                	System.out.println("3");
                    final int skillId = skill.getId();
                    System.out.println("SkillId: " + skill.getId());
                    if (_stackingSkills.containsKey(skillId))
                    {
                    	System.out.println("4");
                        if (_stackingSkills.get(skillId).contains(skill_id))
                        {
                        	System.out.println("5");
                        	return true;
                        }
                            
                    }
                }
            }
        }
        return false;
    }
}