public short buyOrganism(int organism_type, int player_id, int species_id, int amount, int zone_id, float xCoor, float yCoor) {
Player player = GameServer.getInstance().getActivePlayer(player_id);
Avatar avatar = player.getAvatar();
if (avatar != null) {
SpeciesType species = null;
if (organism_type == Constants.ORGANISM_TYPE_PLANT) {
species = GameServer.getInstance().getPlantType(species_id);
} else if (organism_type == Constants.ORGANISM_TYPE_ANIMAL) {
species = GameServer.getInstance().getAnimalType(species_id);
}
boolean canBuy = avatar.spendCash(species.getCost());
if (canBuy) {
GameServer.getInstance().updateCash(player, 0);
Zone zone = zones.get(zone_id);
if (zone != null) {
Organism organism = createOrganism(species_id, amount);
for (int node_id : organism.getSpeciesType().getNodeList()) {
zone.addNewNode(node_id, amount * organism.getSpeciesType().getNodeAmount(node_id));
}
createOrganismByResponse(organism, organism.getGroupSize(), zone_id, Constants.CREATE_STATUS_PURCHASE, xCoor, yCoor, Constants.CREATE_USER);
try {
if (organism_type == Constants.ORGANISM_TYPE_PLANT) {
PlantStatDAO.insertPlantStat(organism.getID(), species_id, currentMonth, "Purchase", world.getEnvByUserID(player_id).getEnvironmentScore(), null, player_id, zone_id);
} else if (organism_type == Constants.ORGANISM_TYPE_ANIMAL) {
AnimalStatDAO.insertAnimalStat(organism.getID(), species_id, currentMonth, "Purchase", world.getEnvByUserID(player_id).getEnvironmentScore(), null, player_id, zone_id);
}
for (int node_id : species.getNodeList()) {
UserActionsDAO.createAction(zone.getManipulationID(), zone.getCurrentTimeStep(), 0, node_id, GameServer.getInstance().getSpeciesTypeByNodeID(node_id).getAvgBiomass() * organism.getGroupSize());
}
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
GameServer.getInstance().updateExperience(player, species.getCost() * 2);
return 0;
}
}
}