Search in sources :

Example 1 with WorkOrderBuildRemoval

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by Minecolonies.

the class AbstractBuilding method removeWorkOrder.

/**
 * Remove the work order for the building.
 * <p>
 * Remove either the upgrade or repair work order
 */
@Override
public void removeWorkOrder() {
    for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
        if (o.getSchematicLocation().equals(getID()) && (o instanceof WorkOrderBuildBuilding || o instanceof WorkOrderBuildRemoval)) {
            colony.getWorkManager().removeWorkOrder(o.getID());
            markDirty();
            final BlockPos buildingPos = o.getClaimedBy();
            final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
            if (building != null) {
                for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
                    for (final ICitizenData citizen : module.getAssignedCitizen()) {
                        building.cancelAllRequestsOfCitizen(citizen);
                    }
                }
            }
            return;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with WorkOrderBuildRemoval

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by Minecolonies.

the class BuildingBuilder method searchWorkOrder.

@Override
public void searchWorkOrder() {
    final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
    if (citizen == null) {
        return;
    }
    final List<WorkOrderBuildDecoration> list = new ArrayList<>();
    list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildRemoval.class, getPosition()));
    // WorkOrderBuildDecoration is the superclass of BuildBuilding and thus returns both
    list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildDecoration.class, getPosition()));
    list.removeIf(order -> order instanceof WorkOrderBuildMiner);
    final WorkOrderBuildDecoration order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
    if (order != null) {
        citizen.getJob(JobBuilder.class).setWorkOrder(order);
        order.setClaimedBy(citizen);
        return;
    }
    if (getManualMode()) {
        return;
    }
    for (final WorkOrderBuildDecoration wo : list) {
        double distanceToBuilder = Double.MAX_VALUE;
        if (wo instanceof WorkOrderBuild && !(wo instanceof WorkOrderBuildRemoval) && !((WorkOrderBuild) wo).canBuild(citizen)) {
            continue;
        }
        for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
            final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
            if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
                continue;
            }
            if (!job.hasWorkOrder() && wo instanceof WorkOrderBuild && ((WorkOrderBuild) wo).canBuild(otherBuilder)) {
                final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getSchematicLocation());
                if (distance < distanceToBuilder) {
                    distanceToBuilder = distance;
                }
            }
        }
        if (citizen.getWorkBuilding().getID().distSqr(wo.getSchematicLocation()) < distanceToBuilder) {
            citizen.getJob(JobBuilder.class).setWorkOrder(wo);
            wo.setClaimedBy(citizen);
            return;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ArrayList(java.util.ArrayList) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) NotNull(org.jetbrains.annotations.NotNull) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 3 with WorkOrderBuildRemoval

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.

the class AbstractBuilding method removeWorkOrder.

/**
 * Remove the work order for the building.
 * <p>
 * Remove either the upgrade or repair work order
 */
@Override
public void removeWorkOrder() {
    for (@NotNull final WorkOrderBuild o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuild.class)) {
        if (o.getSchematicLocation().equals(getID()) && (o instanceof WorkOrderBuildBuilding || o instanceof WorkOrderBuildRemoval)) {
            colony.getWorkManager().removeWorkOrder(o.getID());
            markDirty();
            final BlockPos buildingPos = o.getClaimedBy();
            final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
            if (building != null) {
                for (final AbstractAssignedCitizenModule module : building.getModules(AbstractAssignedCitizenModule.class)) {
                    for (final ICitizenData citizen : module.getAssignedCitizen()) {
                        building.cancelAllRequestsOfCitizen(citizen);
                    }
                }
            }
            return;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with WorkOrderBuildRemoval

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.

the class AbstractBuilding method requestWorkOrder.

/**
 * Adds work orders to the {@link Colony#getWorkManager()}.
 *
 * @param level   Desired level.
 * @param builder the assigned builder.
 */
protected void requestWorkOrder(final int level, final BlockPos builder, final boolean removal) {
    for (@NotNull final WorkOrderBuildBuilding o : colony.getWorkManager().getWorkOrdersOfType(WorkOrderBuildBuilding.class)) {
        if (o.getSchematicLocation().equals(getID())) {
            return;
        }
    }
    WorkOrderBuild workOrder;
    if (removal) {
        if (!canDeconstruct()) {
            LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.cantdeconstruct");
            return;
        }
        workOrder = new WorkOrderBuildRemoval(this, level);
    } else {
        workOrder = new WorkOrderBuildBuilding(this, level);
    }
    if (!removal && !canBeBuiltByBuilder(level) && !workOrder.canBeResolved(colony, level)) {
        LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
        return;
    }
    if (workOrder.tooFarFromAnyBuilder(colony, level) && builder.equals(BlockPos.ZERO)) {
        LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuilderstoofar");
        return;
    }
    if (getCorners().getA().getY() >= MAX_BUILD_HEIGHT || getCorners().getB().getY() >= MAX_BUILD_HEIGHT) {
        LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoohigh");
        return;
    } else if (getPosition().getY() <= MIN_BUILD_HEIGHT) {
        LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildtoolow");
        return;
    }
    if (!builder.equals(BlockPos.ZERO)) {
        final IBuilding building = colony.getBuildingManager().getBuilding(builder);
        if (building instanceof AbstractBuildingStructureBuilder && (building.getBuildingLevel() >= level || canBeBuiltByBuilder(level))) {
            workOrder.setClaimedBy(builder);
        } else {
            LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "entity.builder.messagebuildernecessary", Integer.toString(level));
            return;
        }
    }
    colony.getWorkManager().addWorkOrder(workOrder, false);
    colony.getProgressManager().progressWorkOrderPlacement(workOrder);
    if (workOrder.getID() != 0) {
        LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.workorderadded", workOrder.getDisplayName(), colony.getName(), workOrder.getSchematicLocation().getX(), workOrder.getSchematicLocation().getY(), workOrder.getSchematicLocation().getZ());
    }
    markDirty();
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkOrderBuildBuilding(com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with WorkOrderBuildRemoval

use of com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval in project minecolonies by ldtteam.

the class BuildingBuilder method searchWorkOrder.

@Override
public void searchWorkOrder() {
    final ICitizenData citizen = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
    if (citizen == null) {
        return;
    }
    final List<WorkOrderBuildDecoration> list = new ArrayList<>();
    list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildRemoval.class, getPosition()));
    // WorkOrderBuildDecoration is the superclass of BuildBuilding and thus returns both
    list.addAll(getColony().getWorkManager().getOrderedList(WorkOrderBuildDecoration.class, getPosition()));
    list.removeIf(order -> order instanceof WorkOrderBuildMiner);
    final WorkOrderBuildDecoration order = list.stream().filter(w -> w.getClaimedBy() != null && w.getClaimedBy().equals(getPosition())).findFirst().orElse(null);
    if (order != null) {
        citizen.getJob(JobBuilder.class).setWorkOrder(order);
        order.setClaimedBy(citizen);
        return;
    }
    if (getManualMode()) {
        return;
    }
    for (final WorkOrderBuildDecoration wo : list) {
        double distanceToBuilder = Double.MAX_VALUE;
        if (wo instanceof WorkOrderBuild && !(wo instanceof WorkOrderBuildRemoval) && !((WorkOrderBuild) wo).canBuild(citizen)) {
            continue;
        }
        for (@NotNull final ICitizenData otherBuilder : getColony().getCitizenManager().getCitizens()) {
            final JobBuilder job = otherBuilder.getJob(JobBuilder.class);
            if (job == null || otherBuilder.getWorkBuilding() == null || citizen.getId() == otherBuilder.getId()) {
                continue;
            }
            if (!job.hasWorkOrder() && wo instanceof WorkOrderBuild && ((WorkOrderBuild) wo).canBuild(otherBuilder)) {
                final double distance = otherBuilder.getWorkBuilding().getID().distSqr(wo.getSchematicLocation());
                if (distance < distanceToBuilder) {
                    distanceToBuilder = distance;
                }
            }
        }
        if (citizen.getWorkBuilding().getID().distSqr(wo.getSchematicLocation()) < distanceToBuilder) {
            citizen.getJob(JobBuilder.class).setWorkOrder(wo);
            wo.setClaimedBy(citizen);
            return;
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ArrayList(java.util.ArrayList) JobBuilder(com.minecolonies.coremod.colony.jobs.JobBuilder) ICitizenData(com.minecolonies.api.colony.ICitizenData) WorkOrderBuildRemoval(com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval) NotNull(org.jetbrains.annotations.NotNull) WorkOrderBuildMiner(com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Aggregations

WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)6 WorkOrderBuildRemoval (com.minecolonies.coremod.colony.workorders.WorkOrderBuildRemoval)6 NotNull (org.jetbrains.annotations.NotNull)6 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 WorkOrderBuildBuilding (com.minecolonies.coremod.colony.workorders.WorkOrderBuildBuilding)4 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)2 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)2 JobBuilder (com.minecolonies.coremod.colony.jobs.JobBuilder)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 WorkOrderBuildMiner (com.minecolonies.coremod.colony.workorders.WorkOrderBuildMiner)2 ArrayList (java.util.ArrayList)2 BlockPos (net.minecraft.util.math.BlockPos)2