Package utility

Examples of utility.GamePacket


        responseCode = Constants.SMSG_UPDATE_AVG_GAME_SCALE_VOTE;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(avgVote);
        return packet.getBytes();
    }
View Full Code Here


        responseCode = Constants.SMSG_SHOP_UNLOCK;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);

        if (unlockList != null) {
            packet.addShort16((short) unlockList.size());

            for (SpeciesType species : unlockList) {
                packet.addShort16((short) species.getGroupType());

                if (species.getGroupType() == Constants.ORGANISM_TYPE_PLANT) {
                    PlantType plant = (PlantType) species;

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

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

                    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

        responseCode = Constants.SMSG_CREATE_ENV;
    }

    @Override
    public byte[] constructResponseInBytes() {;
        GamePacket packet = new GamePacket(responseCode);
        packet.addInt32(env.getID());
        packet.addShort16((short) env.getRow());
        packet.addShort16((short) env.getColumn());
        packet.addInt32(env.getOwnerID());
        packet.addInt32(env.getEnvironmentScore());

        for (Zone zone : env.getZones()) {
            packet.addShort16((short) zone.getID());
            packet.addShort16((short) zone.getType());

            WaterSource waterSource = zone.getWaterSource();
            packet.addBoolean(waterSource != null);

            if (waterSource != null) {
                packet.addInt32(waterSource.getID());
                packet.addInt32(waterSource.getMaxWater());
                packet.addInt32(waterSource.getWater());
            }
        }

        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_CANCEL_TO_JOIN_GAME;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        if (world != null) {
            if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
                packet.addShort16((short) 0);
                packet.addShort16(status);
            } else if (world.getGameMode() == Constants.GAME_TYPE_PVP) {
                packet.addShort16((short) 1);

                if (world.getEnvironments() != null) {
                    packet.addShort16((short) world.getEnvironments().size());

                    if (world.getGameMode() == Constants.GAME_TYPE_PVP) {
                        for (Environment env : world.getEnvironments()) {
//                            packet.addString(env.getAvatar().getPlayer().getUsername());
                            packet.addShort16((short) env.getRow());
                            packet.addShort16((short) env.getColumn());
                        }
                    } else if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
                        for (Environment env : world.getEnvironments()) {
//                            packet.addString(env.getAvatar().getPlayer().getUsername());
                            packet.addShort16((short) env.getRow());
                            packet.addShort16((short) env.getColumn());
                        }
                    }

//                    for (Environment env : world.getEnvironments()) {
//                        packet.addString(env.getClient().getAvatar().getAvatarType());
//                        packet.addShort16((short) env.getClient().getAvatar().getIsReady());
//                    }

                }
            }
        }

        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_DRINK_WATER;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addInt32(species.getID());

        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_SAVE_EXIT_GAME;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(status);
        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_BIRTH_PLANT;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(status);
        packet.addInt32(plant.getID());
        packet.addString(plant.getSpeciesType().getSpeciesName());
        packet.addShort16((short) plant.getSpeciesType().getModelID());
        packet.addShort16((short) plant.getSpeciesTypeID());
        packet.addInt32(plant.getPlayerID());
        packet.addInt32(plant.getZoneID());
        packet.addShort16((short) plant.getBiomass());
        packet.addFloat(plant.getX());
        packet.addFloat(plant.getY());
        packet.addFloat(plant.getZ());
        packet.addShort16((short) plant.getGroupSize());
        packet.addShort16((short) count);

        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_CURE_PLANT_DISEASE;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(plantID);
        packet.addShort16(diseaseID);
        return packet.getBytes();
    }
View Full Code Here

        responseCode = Constants.SMSG_CREATE_NEW_WORLD;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(status);//status

        if (world.getGameMode() == Constants.GAME_TYPE_PVE) {
            packet.addShort16((short) 1);
        } else if (world.getGameMode() == Constants.GAME_TYPE_PVP) {
            packet.addShort16((short) 2);
        }

        if (status == 0) {
            packet.addInt32(world.getID());
            //world name
            packet.addString(world.getGameName());
            //ecosystem
            packet.addString(world.getEnvType());
            //max player number
            packet.addShort16((short) world.getMaxPlayers());

            //Character name
            packet.addString(charName);
            packet.addFloat(world.getTimeRate());
        }

        return packet.getBytes();

    }
View Full Code Here

        responseCode = Constants.SMSG_BIRTH_ANIMAL;
    }

    @Override
    public byte[] constructResponseInBytes() {
        GamePacket packet = new GamePacket(responseCode);
        packet.addShort16(status);
        packet.addInt32(animal.getID());
        packet.addString(animal.getSpeciesType().getSpeciesName());
        packet.addShort16((short) animal.getSpeciesType().getModelID());
        packet.addShort16((short) animal.getSpeciesTypeID());
        packet.addInt32(animal.getPlayerID());
        packet.addInt32(animal.getZoneID());
        packet.addShort16((short) animal.getBiomass());
        packet.addFloat(animal.getX());
        packet.addFloat(animal.getY());
        packet.addFloat(animal.getZ());
        packet.addShort16((short) animal.getGroupSize());
        packet.addShort16((short) count);

        return packet.getBytes();
    }
View Full Code Here

TOP

Related Classes of utility.GamePacket

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.