All pastes #400579 Raw Edit

Something

public text v1 · immutable
·published 2007-03-18 19: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 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
 */

/**
 * @author godson
 */


package net.sf.l2j.gameserver.datatables;

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

import net.sf.l2j.L2DatabaseFactory;
/**
 * 
 *
 * @author  Luno
 */
public class GambleTable
{
	private static Logger _log = Logger.getLogger(ArmorSetsTable.class.getName());
	private static GambleTable _instance;
	
	public int gambleRewardItemId[];
	public int gambleRewardCount[];
	public int gambleRewardChance[];
	public int gambleGiftItemId[];
	public int gambleGiftCount[];
	public int gambleGiftChance[];
	
	public static GambleTable getInstance()
	{
		if(_instance == null)
			_instance = new GambleTable();
		return _instance;
	}
	private GambleTable()
	{
		loadData();
	}
	private void loadData()
	{
		Connection con;
		try 
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			PreparedStatement statement_reward = con.prepareStatement("SELECT item_id, type, count, chance FROM gluecksspiel WHERE type=1");
			ResultSet rset_reward = statement_reward.executeQuery();
			PreparedStatement statement_gift = con.prepareStatement("SELECT item_id, type, count, chance FROM gluecksspiel WHERE type=2");
			ResultSet rset_gift = statement_reward.executeQuery();
			
    		rset_reward.last();
    		int rewardRows = rset_reward.getRow();
    		rset_reward.beforeFirst();
			int count_reward = 0;
			
    		rset_gift.last();
    		int giftRows = rset_reward.getRow();
    		rset_gift.beforeFirst();
			int count_gift = 0;
    		
			while(rset_reward.next())
			{
				gambleRewardItemId = new int[rewardRows];
				gambleRewardChance = new int[rewardRows];
				gambleRewardCount = new int[rewardRows];
				
				gambleRewardItemId[count_reward] = rset_reward.getInt("item_id");
				gambleRewardChance[count_reward] = rset_reward.getInt("count");
				gambleRewardCount[count_reward] = rset_reward.getInt("chance");
				
				count_reward++;
			}
			
			while(rset_gift.next())
			{
				gambleGiftItemId = new int[giftRows];
				gambleGiftChance = new int[giftRows];
				gambleGiftCount = new int[giftRows];
				
				gambleGiftItemId[count_reward] = rset_gift.getInt("item_id");
				gambleGiftChance[count_reward] = rset_gift.getInt("count");
				gambleGiftCount[count_reward] = rset_gift.getInt("chance");
				
				count_gift++;
			}
			
			int datatable_size = giftRows + rewardRows;
			_log.config("Gamble Table: Loaded "+datatable_size+" prices.");
			
			rset_reward.close();
			rset_gift.close();
			statement_reward.close();
			statement_gift.close();
			con.close();
		}
		catch (Exception e) 
		{
			_log.severe("Gamble: Error reading Gamble table: " + e);
		}
	}
}