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();
}
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;
}
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;
}
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);
}
}
}
}
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;
}
Aggregations