Search in sources :

Example 1 with BuildingGuardTower

use of com.minecolonies.coremod.colony.buildings.BuildingGuardTower in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method getRandomBuilding.

/**
     * Gets a random building from his colony.
     *
     * @return a random blockPos.
     */
private BlockPos getRandomBuilding() {
    if (worker.getColony() == null || getOwnBuilding() == null) {
        return worker.getPosition();
    }
    final Collection<AbstractBuilding> buildingList = worker.getColony().getBuildings().values();
    final Object[] buildingArray = buildingList.toArray();
    final int random = worker.getRandom().nextInt(buildingArray.length);
    final AbstractBuilding building = (AbstractBuilding) buildingArray[random];
    if (building instanceof BuildingGuardTower || BlockPosUtil.getDistance2D(building.getLocation(), this.getOwnBuilding().getLocation()) > ((BuildingGuardTower) getOwnBuilding()).getPatrolDistance()) {
        return this.getOwnBuilding().getLocation();
    }
    return building.getLocation();
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 2 with BuildingGuardTower

use of com.minecolonies.coremod.colony.buildings.BuildingGuardTower in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method checkIfExecute.

/**
     * Checks if the worker is in a state where he can execute well.
     *
     * @return true if so.
     */
private boolean checkIfExecute() {
    final AbstractBuilding building = getOwnBuilding();
    if (!(building instanceof BuildingGuardTower)) {
        return true;
    }
    if (!((BuildingGuardTower) building).shallRetrieveOnLowHealth()) {
        return false;
    }
    if (worker.getHealth() > 2) {
        return false;
    }
    worker.isWorkerAtSiteWithMove(building.getLocation(), PATH_CLOSE);
    return true;
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 3 with BuildingGuardTower

use of com.minecolonies.coremod.colony.buildings.BuildingGuardTower in project minecolonies by Minecolonies.

the class AbstractEntityAIGuard method patrol.

/**
     * Lets the guard patrol inside the colony area searching for mobs.
     *
     * @return the next state to go.
     */
protected AIState patrol() {
    worker.setAIMoveSpeed(1);
    final AbstractBuilding building = getOwnBuilding();
    if (building instanceof BuildingGuardTower) {
        if (currentPathTarget == null || BlockPosUtil.getDistance2D(building.getColony().getCenter(), currentPathTarget) > Configurations.workingRangeTownHall + Configurations.townHallPadding || currentPathTarget.getY() < 2) {
            return getNextPatrollingTarget((BuildingGuardTower) building);
        }
        if (worker.isWorkerAtSiteWithMove(currentPathTarget, PATH_CLOSE) || ((BuildingGuardTower) building).getTask().equals(BuildingGuardTower.Task.FOLLOW)) {
            return getNextPatrollingTarget((BuildingGuardTower) building);
        }
    }
    return AIState.GUARD_SEARCH_TARGET;
}
Also used : BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with BuildingGuardTower

use of com.minecolonies.coremod.colony.buildings.BuildingGuardTower in project minecolonies by Minecolonies.

the class GuardTaskMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final GuardTaskMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        //Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final BuildingGuardTower building = colony.getBuilding(message.buildingId, BuildingGuardTower.class);
        if (building != null) {
            if (message.job != -1) {
                building.setJob(BuildingGuardTower.GuardJob.values()[message.job]);
            }
            building.setAssignManually(message.assignmentMode);
            building.setPatrolManually(message.patrollingMode);
            building.setRetrieveOnLowHealth(message.retrieval);
            building.setTask(BuildingGuardTower.Task.values()[message.task]);
            if (building.getTask().equals(BuildingGuardTower.Task.FOLLOW)) {
                building.setPlayerToFollow(player);
            }
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with BuildingGuardTower

use of com.minecolonies.coremod.colony.buildings.BuildingGuardTower in project minecolonies by Minecolonies.

the class ItemScepterGuard method handleItemUsage.

/**
     * Handles the usage of the item.
     *
     * @param worldIn  the world it is used in.
     * @param pos      the position.
     * @param compound the compound.
     * @param playerIn the player using it.
     * @return if it has been successful.
     */
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
    final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
    if (colony == null) {
        return EnumActionResult.FAIL;
    }
    final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
    final AbstractBuilding hut = colony.getBuilding(guardTower);
    if (hut == null || !(hut instanceof BuildingGuardTower)) {
        return EnumActionResult.FAIL;
    }
    if (BlockPosUtil.getDistance2D(pos, guardTower) > ((BuildingGuardTower) hut).getPatrolDistance()) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
        return EnumActionResult.FAIL;
    }
    final BuildingGuardTower.Task task = BuildingGuardTower.Task.values()[compound.getInteger("task")];
    final CitizenData citizen = ((BuildingGuardTower) hut).getWorker();
    String name = "";
    if (citizen != null) {
        name = " " + citizen.getName();
    }
    if (task.equals(BuildingGuardTower.Task.GUARD)) {
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
        ((BuildingGuardTower) hut).setGuardTarget(pos);
        playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
    } else {
        if (!compound.hasKey(TAG_LAST_POS)) {
            ((BuildingGuardTower) hut).resetPatrolTargets();
        }
        ((BuildingGuardTower) hut).addPatrolTargets(pos);
        LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
    }
    BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
    return EnumActionResult.SUCCESS;
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildingGuardTower (com.minecolonies.coremod.colony.buildings.BuildingGuardTower)5 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)4 Colony (com.minecolonies.coremod.colony.Colony)2 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 BlockPos (net.minecraft.util.math.BlockPos)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1