Search in sources :

Example 1 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class HireFireMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final HireFireMessage 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;
        }
        if (message.hire) {
            final CitizenData citizen = colony.getCitizen(message.citizenID);
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
        } else {
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Example 2 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method attemptResolve.

@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
    if (manager.getColony().getWorld().isRemote) {
        return null;
    }
    final Colony colony = (Colony) manager.getColony();
    // We can do an instant get here, since we are already filtering on anything that has no entity.
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
        BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
        // We can do an instant get here, since we are already filtering on anything that has no entity.
        BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
        return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
    }))).orElse(null);
    if (freeDeliveryMan == null) {
        return null;
    }
    final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
    job.addRequest(request.getToken());
    return Lists.newArrayList();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BlockPos(net.minecraft.util.math.BlockPos) TypeToken(com.google.common.reflect.TypeToken) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Log(com.minecolonies.blockout.Log) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Nullable(org.jetbrains.annotations.Nullable) CitizenData(com.minecolonies.coremod.colony.CitizenData) List(java.util.List) Lists(com.google.common.collect.Lists) MineColonies(com.minecolonies.coremod.MineColonies) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method canResolve.

@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends Delivery> requestToCheck) {
    if (manager.getColony().getWorld().isRemote) {
        return false;
    }
    final Colony colony = (Colony) manager.getColony();
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> requestToCheck.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).findFirst().orElse(null);
    return freeDeliveryMan != null;
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BlockPos(net.minecraft.util.math.BlockPos) TypeToken(com.google.common.reflect.TypeToken) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Log(com.minecolonies.blockout.Log) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Nullable(org.jetbrains.annotations.Nullable) CitizenData(com.minecolonies.coremod.colony.CitizenData) List(java.util.List) Lists(com.google.common.collect.Lists) MineColonies(com.minecolonies.coremod.MineColonies) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Example 4 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class StandardPlayerRequestResolver method resolve.

@Nullable
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest request) throws RuntimeException {
    final IColony colony = manager.getColony();
    if (colony instanceof Colony) {
        if (Configurations.requestSystem.creativeResolve && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get() instanceof AbstractBuilding) {
            final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get();
            final Optional<CitizenData> citizenDataOptional = building.getCitizenForRequest(request.getToken());
            final List<ItemStack> resolvablestacks = request.getDisplayStacks();
            if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
                final ItemStack resolveStack = resolvablestacks.get(0);
                resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
                final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizenDataOptional.get().getInventory()), resolveStack);
                if (ItemStackUtils.isEmpty(remainingItemStack)) {
                    manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
                    return;
                }
            }
        }
        final List<EntityPlayer> players = new ArrayList<>(((Colony) colony).getMessageEntityPlayers());
        final EntityPlayer owner = ServerUtils.getPlayerFromUUID(colony.getWorld(), ((Colony) colony).getPermissions().getOwner());
        final TextComponentString colonyDescription = new TextComponentString(colony.getName() + ":");
        if (manager.getColony().getWorld().isDaytime()) {
            if (owner != null) {
                players.remove(owner);
                LanguageHandler.sendPlayerMessage(owner, "com.minecolonies.requestsystem.playerresolver", request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
            }
            LanguageHandler.sendPlayersMessage(players, "com.minecolonies.requestsystem.playerresolver", colonyDescription.getFormattedText() + " " + request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
        }
    }
    assignedRequests.add(request.getToken());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CitizenData

use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.

the class CitizenManager method deserializeCitizen.

private CitizenData deserializeCitizen(@NotNull final NBTTagCompound compound) {
    final CitizenData data = CitizenData.createFromNBT(compound, colony);
    topCitizenId = Math.max(topCitizenId, data.getId());
    return data;
}
Also used : CitizenData(com.minecolonies.coremod.colony.CitizenData)

Aggregations

CitizenData (com.minecolonies.coremod.colony.CitizenData)29 BlockPos (net.minecraft.util.math.BlockPos)15 Colony (com.minecolonies.coremod.colony.Colony)14 NotNull (org.jetbrains.annotations.NotNull)9 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)7 Nullable (org.jetbrains.annotations.Nullable)7 TextComponentString (net.minecraft.util.text.TextComponentString)6 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)4 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)3 MineColonies (com.minecolonies.coremod.MineColonies)3 JobDeliveryman (com.minecolonies.coremod.colony.jobs.JobDeliveryman)3 ItemStack (net.minecraft.item.ItemStack)3 Lists (com.google.common.collect.Lists)2 TypeToken (com.google.common.reflect.TypeToken)2 IColony (com.minecolonies.api.colony.IColony)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequestManager (com.minecolonies.api.colony.requestsystem.manager.IRequestManager)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)2 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)2