All pastes #24355 Raw Edit

Stuff

public java v1 · immutable
#24355 ·published 2005-10-01 09:46 UTC
rendered paste body
package net.sf.l2j.gameserver.model;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.LineNumberReader;import java.util.ArrayList;import java.util.HashMap;import java.util.StringTokenizer;import java.util.logging.Logger;import net.sf.l2j.Config;public class L2Manor{    private static Logger _log = Logger.getLogger(L2Manor.class.getName());    private static final L2Manor _instance = new L2Manor();        private L2Manor()    {        _seeds = new HashMap<Integer,SeedData>();        parseData();                //Seeds data, TODO: move to datapack        // partially moved/*        _seeds.put(5016,new SeedData(10,5073)); // Seed: Dark Coda, Type1: stem,100 Type2: braided hemp,500 Manufactured: Gludio,Oren        _seeds.put(5017,new SeedData(13,5068)); // Seed: Red Coda,  Type1: Type2: Manufactured:        _seeds.put(5018,new SeedData(16,5065)); // Seed: Chilly Coda,  Type1: Type2: Manufactured:        _seeds.put(5019,new SeedData(19,5067)); // Seed: Blue Coda,  Type1: Type2: Manufactured:        _seeds.put(5020,new SeedData(22,5069)); // Seed: Golden Coda,  Type1: Type2: Manufactured:        _seeds.put(5021,new SeedData(25,5071)); // Seed: Lute Coda,  Type1: Type2: Manufactured:        _seeds.put(5022,new SeedData(28,5070)); // Seed: Desert Coda,  Type1: Type2: Manufactured:        _seeds.put(5028,new SeedData(31,5078)); // Seed: Red Cobol,  Type1: Type2: Manufactured:        _seeds.put(5034,new SeedData(34,5075)); // Seed: Chilly Cobol,  Type1: Type2: Manufactured:        _seeds.put(5023,new SeedData(37,5077)); // Seed: Blue Cobol,  Type1: Type2: Manufactured:        _seeds.put(5036,new SeedData(40,5082)); // Seed: Thorn Cobol,  Type1: Type2: Manufactured:        _seeds.put(5037,new SeedData(43,5079)); // Seed: Golden Cobol,  Type1: Type2: Manufactured:        _seeds.put(5038,new SeedData(46,5084)); // Seed: Great Cobol,  Type1: Type2: Manufactured:        _seeds.put(5056,new SeedData(49,5088)); // Seed: Red Codran,  Type1: Type2: Manufactured:        _seeds.put(5049,new SeedData(50,5091)); // Seed: Sea Codran,  Type1: Type2: Manufactured:        _seeds.put(5057,new SeedData(52,5085)); // Seed: Chilly Codran,  Type1: Type2: Manufactured:        _seeds.put(5058,new SeedData(55,5087)); // Seed: Blue Codran,  Type1: Type2: Manufactured:        _seeds.put(5059,new SeedData(58,5092)); // Seed: Twin Codran,  Type1: Type2: Manufactured:        _seeds.put(5060,new SeedData(61,5094)); // Seed: Great Codran,  Type1: Type2: Manufactured:        _seeds.put(5061,new SeedData(64,5090)); // Seed: Desert Codran,  Type1: Type2: Manufactured:*/     }        public static L2Manor getInstance()    {        return _instance;    }        /**     * Returns seed level     * used to calculate 'planting' probability     * @param seedId     * @return     */    public int getSeedLevel(int seedId)    {        SeedData seed = _seeds.get(seedId);                if(seed != null)            return seed._level;        return -1;    }        /**     * Return crop id for seed     * Used do determine reward while harvesting mob     * @param seedId     * @return     */    public int getCropType(int seedId)    {        SeedData seed = _seeds.get(seedId);        if(seed != null)            return seed._crop;        return -1;    }        /**     * Return reward itemId for selected crop     * used by ManorManager     * @param cropId - crop     * @param type - reward type, type1 or type2     * @return     */    public synchronized int getRewardItem(int cropId,int type)    {        for(SeedData seed : _seeds.values())        {            if(seed._crop == cropId)            {                return seed.getReward(type);            }        }                return -1;            }    /**     * returns reward amount for crop     * used by manor manager     * @param cropId - crop id     * @param type - reward type, type1 or type2     * @return     */    public synchronized int getRewardAmount(int cropId,int type)    {        for(SeedData seed : _seeds.values())        {            if(seed._crop == cropId)            {                return seed.getRewardAmount(type);            }        }                return -1;    }        /**     * Return all crops which can be purchased in given castle     * @param castleId     * @return     */    public ArrayList<Integer> getCropForCastle(int castleId)    {        ArrayList<Integer> crops =  new ArrayList<Integer>();                for(SeedData seed : _seeds.values())        {            switch(castleId)            {                //TODO: change to valid enums after CastleInstance commit                case 5:     // Aden Castle                    if(seed._AD == 1)                        crops.add(seed._crop);                    break;                case 1:     // Gludio Castle                    if(seed._GL == 1)                        crops.add(seed._crop);                    break;            }        }                return crops;    }        //TODO: add setX/getX functionality    private class SeedData    {        public SeedData(int level,int crop)        {            _level = level;            _crop = crop;        }                public void setData(int id, int t1, int t2, int t1a, int t2a, int gl, int di, int gi, int or, int ad, int in)        {            _id = id;               // Seed id            _type1 = t1;            // Type I reward id            _type2 = t2;            // Type II reward id            _type1amount = t1a;     // Type I reward amount            _type2amount = t2a;     // Type II reward amount            _GL = gl;               // Can be produced/sold in Gludio castle            _DI = di;               // Can be produced/sold in Dion castle            _GI = gi;               // Can be produced/sold in Giran castle            _OR = or;               // Can be produced/sold in Oren castle            _AD = ad;               // Can be produced/sold in Aden castle            _IN = in;               // Can be produced/sold in Innadril castle        }                public int getReward(int type)        {            switch(type)            {                case 0:                    return 0;  // no reward                case 1:                    return _type1;                case 2:                    return _type2;                default :                    return 0;   // no reward by-default            }        }                public int getRewardAmount(int type)        {            if(type == 1)                return _type1amount;            return _type2amount;                    }                public int _id;        public int _level;        public int _crop;        private int _type1;        private int _type2;        private int _type1amount;        private int _type2amount;        public int _GL;        public int _DI;        public int _GI;        public int _OR;        public int _AD;        public int _IN;    }            private void parseData() {        LineNumberReader lnr = null;        try        {            File seedData = new File(Config.DATAPACK_ROOT, "data/seeds.csv");            lnr = new LineNumberReader(new BufferedReader(new FileReader(seedData)));            String line = null;            while ((line = lnr.readLine()) != null)            {                if (line.trim().length() == 0 || line.startsWith("#"))                {                    continue;                }                SeedData seed = parseList(line);                _seeds.put(seed._id, seed);                         }            _log.config("L2Manor: Loaded " + _seeds.size() + " seeds");        }        catch (FileNotFoundException e)        {            _initialized = false;            _log.warning("seeds.csv is missing in data folder");        }        catch (Exception e)        {            _initialized = false;            _log.warning("error while loading seeds: " + e);        }        finally        {            try            {                lnr.close();            }            catch (Exception e1)            {            }        }    }    private SeedData parseList(String line)    {                StringTokenizer st = new StringTokenizer(line, ";");        int seedId = Integer.parseInt(st.nextToken());  // seed id        int level = Integer.parseInt(st.nextToken());   // seed level        int cropId = Integer.parseInt(st.nextToken());  // crop id        int type1R = Integer.parseInt(st.nextToken());  // type I reward        int type1A = Integer.parseInt(st.nextToken());  // type I reward amount        int type2R = Integer.parseInt(st.nextToken());  // type II reward        int type2A = Integer.parseInt(st.nextToken());  // type II reward amount        int GL = Integer.parseInt(st.nextToken());      // can be produced/sold in Gludio castle        int DI = Integer.parseInt(st.nextToken());      // can be produced/sold in Dion castle        int GI = Integer.parseInt(st.nextToken());      // can be produced/sold in Giran castle        int OR = Integer.parseInt(st.nextToken());      // can be produced/sold in Oren castle        int AD = Integer.parseInt(st.nextToken());      // can be produced/sold in Aden castle        int IN = Integer.parseInt(st.nextToken());      // can be produced/sold in Innadril castle        SeedData seed = new SeedData(level,cropId);        seed.setData(seedId,type1R,type2R,type1A,type2A,GL,DI,GI,OR,AD,IN);                return seed;    }        private static HashMap<Integer,SeedData> _seeds;    private static boolean _initialized = false;}