Package model

Examples of model.AnimalType


            connection = DAO.getDataSource().getConnection();
            pstmt = connection.prepareStatement(query);
            ResultSet rs = pstmt.executeQuery();

            while (rs.next()) {
                AnimalType animal = new AnimalType(rs.getInt("animal_type_id"));
                animal.setSpeciesName(rs.getString("species_name"));
                animal.setCost(rs.getInt("cost"));
                animal.setDescription(rs.getString("description"));
                animal.setCategory(rs.getString("category"));
                animal.setAvgBiomass(rs.getInt("max_biomass"));
                animal.setWaterBiomassLoss(rs.getInt("water_biomass_loss"));
                animal.setDietType(rs.getShort("diet_type"));
                animal.setWaterNeedFrequency(rs.getInt("water_need_frequency"));
                animal.setMetabolism(rs.getFloat("metabolism"));

                String[] nodeList = rs.getString("node_list").split(",");

                int[] newNodeList = new int[nodeList.length];
                HashMap<Integer, Integer> nodeAmountList = new HashMap<Integer, Integer>();

                for (int i = 0; i < nodeList.length; i++) {
                    String[] nodePair = nodeList[i].split(":");

                    newNodeList[i] = Integer.parseInt(nodePair[0]);

                    if (nodePair.length == 1) {
                        nodeAmountList.put(newNodeList[i], 1);
                    } else {
                        nodeAmountList.put(newNodeList[i], Integer.parseInt(nodePair[1]));
                    }
                }

                animal.setNodeList(newNodeList);
                animal.setNodeAmountList(nodeAmountList);

                animal.setTrophicLevel(rs.getFloat("trophic_level"));
                animal.setModelID(rs.getInt("model_id"));
                animal.setMass(rs.getInt("mass"));
                animal.setMovtForce(rs.getInt("movt_force"));
                animal.setMaxForce(rs.getInt("max_force"));
                animal.setHealChance(rs.getFloat("heal_chance"));
                animal.setAnimalCategory(rs.getString("animal_category"));
                animal.setGroupCapacity(rs.getInt("group_capacity"));

                animalList.add(animal);
            }

            rs.close();
            pstmt.close();

            HashMap<Integer, List<Integer>> cPredatorMap = CarnivoreDAO.getPreyToPredatorTable();
            HashMap<Integer, List<Integer>> cPreyMap = CarnivoreDAO.getPredatorToPreyTable();
            HashMap<Integer, List<Integer>> hPreyMap = HerbivoreDAO.getPredatorToPreyTable();

            for (AnimalType animal : animalList) {
                int animal_id = animal.getID();

                if (cPredatorMap.containsKey(animal_id)) {
                    for (int predator_id : cPredatorMap.get(animal_id)) {
                        animal.addPredatorID(predator_id, Constants.ORGANISM_TYPE_ANIMAL);
                    }
                }

                if (cPreyMap.containsKey(animal_id)) {
                    for (int prey_id : cPreyMap.get(animal_id)) {
                        animal.addPreyID(prey_id, Constants.ORGANISM_TYPE_ANIMAL);
                    }
                }

                if (hPreyMap.containsKey(animal_id)) {
                    for (int prey_id : hPreyMap.get(animal_id)) {
                        animal.addPreyID(prey_id, Constants.ORGANISM_TYPE_PLANT);
                    }
                }
            }
        } finally {
            if (connection != null) {
View Full Code Here


                    packet.addString(predatorList);
                    packet.addInt32(plant.getModelID());
                    packet.addInt32((int) plant.getAvgBiomass());
                } else if (species.getGroupType() == Constants.ORGANISM_TYPE_ANIMAL) {
                    AnimalType animal = (AnimalType) species;

                    packet.addShort16((short) animal.getID());
                    packet.addString(animal.getSpeciesName());
                    packet.addString(animal.getDescription());
                    packet.addString(animal.getCategory());
                    packet.addShort16((short) animal.getCost());

                    String predatorList = "";
                    for (SpeciesType predator : animal.getPredatorList(Constants.ORGANISM_TYPE_ANIMAL)) {
                        predatorList += predator.getSpeciesName() + ", ";
                    }
                    if (predatorList.endsWith(", ")) {
                        predatorList = predatorList.substring(0, predatorList.lastIndexOf(","));
                    }

                    String preyList = "";
                    for (SpeciesType prey : animal.getPreyList(Constants.ORGANISM_TYPE_ANIMAL)) {
                        preyList += prey.getSpeciesName() + ", ";
                    }
                    for (SpeciesType prey : animal.getPreyList(Constants.ORGANISM_TYPE_PLANT)) {
                        preyList += prey.getSpeciesName() + ", ";
                    }
                    if (preyList.endsWith(", ")) {
                        preyList = preyList.substring(0, preyList.lastIndexOf(","));
                    }

                    packet.addString(predatorList);
                    packet.addString(preyList);

                    packet.addShort16((short) animal.getAvgBiomass());
                    packet.addShort16((short) animal.getMass());
                    packet.addShort16((short) animal.getMovtForce());
                    packet.addShort16((short) animal.getMaxForce());
                    packet.addInt32(animal.getModelID());
                    packet.addString(animal.getAnimalCategory());
                }
            }
        }

        return packet.getBytes();
View Full Code Here

            while (rs.next()) {
                String[] tempList = rs.getString("items").split(",");

                for (String item_id : tempList) {
                    AnimalType animal = GameServer.getInstance().getAnimalType(Integer.parseInt(item_id));

                    if (type.isEmpty() || animal.getDescription().equalsIgnoreCase(type)) {
                        shopList.add(animal);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of model.AnimalType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.