All pastes #728970 Raw Edit

MagicGem

public text v1 · immutable
·published 2007-10-07 15:22 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 2, 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package net.sf.l2j.gameserver.datatables;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Logger;

import javolution.util.FastList;

import net.sf.l2j.gameserver.model.L2Skill;


public class MagicGemSkillTable
{
	private static Logger _log = Logger.getLogger(MagicGemSkillTable.class.getName());
	private static MagicGemSkillTable _instance;
    private List<L2Skill> _mageSkillsTree;
    private List<L2Skill> _fighterSkillsTree;
	
	public static MagicGemSkillTable getInstance()
    {
        if (_instance == null)
            _instance = new MagicGemSkillTable();
        
        return _instance;
    }
	
	private MagicGemSkillTable()
	{
		reload();
	}
	
	public void reload()
	{
		java.sql.Connection con = null;
		
		int count1 = 0;
		int count2 = 0;
		
		try
		{
			_mageSkillsTree  = new FastList<L2Skill>();
			_fighterSkillsTree = new FastList<L2Skill>();
			
			PreparedStatement statement = con.prepareStatement("SELECT skill_id, level, ismage, FROM magicgem_skill_trees ORDER BY skill_id, level");
			ResultSet skilltree = statement.executeQuery();
			
			while (skilltree.next())
			{
				int id = skilltree.getInt("skill_id");
				int lvl = skilltree.getInt("level");
				
				if (skilltree.getInt("ismage") == 1)
					_fighterSkillsTree.add(SkillTable.getInstance().getInfo(id, lvl));
				else
					_mageSkillsTree.add(SkillTable.getInstance().getInfo(id, lvl));
			}
			skilltree.close();
			statement.close();
			count1 = _fighterSkillsTree.size();
			count2 = _mageSkillsTree.size();
			
		}
		catch (Exception e)
		{
			
		}
		finally
		{
			try { con.close(); } catch (Exception e) {}
		}
		_log.config("MagicGemSkillTable: Loaded " + count1 + " Fighter Buffs.");
		_log.config("MagicGemSkillTable: Loaded " + count2 + " Mage Buffs.");
	}
	
	public List<L2Skill> getMageSkills()
	{
		return _mageSkillsTree;
	}
	
	public List<L2Skill> getFighterSkills()
	{
		return _fighterSkillsTree;
	}
}