Search in sources :

Example 66 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class CitizenData method generateName.

/**
 * Generates a random name from a set of names.
 *
 * @param rand Random object.
 * @param female the gender
 * @param colony the colony.
 * @return Name of the citizen.
 */
public static String generateName(@NotNull final Random rand, final boolean female, final IColony colony) {
    String citizenName;
    final String firstName;
    final String middleInitial;
    final String lastName;
    if (female) {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
    } else {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
    }
    middleInitial = String.valueOf(getRandomLetter(rand));
    lastName = getRandomElement(rand, MineColonies.getConfig().getServer().lastNames.get().toArray(new String[0]));
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        // For now, don't include middle names, as their rules (and presence) vary heavily by region.
        citizenName = String.format("%s %s", lastName, firstName);
    } else {
        if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
            citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
        } else {
            citizenName = String.format("%s %s", firstName, lastName);
        }
    }
    // Check whether there's already a citizen with this name
    for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        if (citizen != null && citizen.getName().equals(citizenName)) {
            // Oops - recurse this function and try again
            citizenName = generateName(rand, female, colony);
            break;
        }
    }
    return citizenName;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 67 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class CitizenData method generateName.

/**
 * Generates a random name considering both parent names.
 *
 * @param rand Random object.
 */
public void generateName(@NotNull final Random rand, final String firstParentName, final String secondParentName) {
    String nameA = firstParentName;
    String nameB = secondParentName;
    String citizenName;
    final String firstName;
    final String middleInitial;
    final String lastName;
    if (firstParentName == null || firstParentName.isEmpty()) {
        nameA = generateName(rand, rand.nextBoolean(), colony);
    }
    if (secondParentName == null || secondParentName.isEmpty()) {
        nameB = generateName(rand, rand.nextBoolean(), colony);
    }
    final String[] firstParentNameSplit = nameA.split(" ");
    final String[] secondParentNameSplit = nameB.split(" ");
    int lastNameIndex = 1;
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        lastNameIndex = 0;
    } else if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
        lastNameIndex = 2;
    }
    if (random.nextBoolean()) {
        middleInitial = firstParentNameSplit[lastNameIndex].substring(0, 1);
        lastName = secondParentNameSplit[lastNameIndex];
    } else {
        middleInitial = secondParentNameSplit[lastNameIndex].substring(0, 1);
        lastName = firstParentNameSplit[lastNameIndex];
    }
    if (female) {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().femaleFirstNames.get().toArray(new String[0]));
    } else {
        firstName = getRandomElement(rand, MineColonies.getConfig().getServer().maleFirstNames.get().toArray(new String[0]));
    }
    if (MineColonies.getConfig().getServer().useEasternNameOrder.get()) {
        // For now, don't include middle names, as their rules (and presence) vary heavily by region.
        citizenName = String.format("%s %s", lastName, firstName);
    } else {
        if (MineColonies.getConfig().getServer().useMiddleInitial.get()) {
            citizenName = String.format("%s %s. %s", firstName, middleInitial, lastName);
        } else {
            citizenName = String.format("%s %s", firstName, lastName);
        }
    }
    // Check whether there's already a citizen with this name
    for (final ICitizenData citizen : this.getColony().getCitizenManager().getCitizens()) {
        if (citizen != null && citizen.getName().equals(citizenName)) {
            // Oops - recurse this function and try again
            generateName(rand, firstParentName, secondParentName);
            return;
        }
    }
    this.name = citizenName;
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 68 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class ItemScrollGuardHelp method onItemUseSuccess.

@Override
protected ItemStack onItemUseSuccess(final ItemStack itemStack, final World world, final ServerPlayerEntity player) {
    final IColony colony = getColony(itemStack);
    final BlockPos buildingPos = BlockPosUtil.read(itemStack.getTag(), TAG_BUILDING_POS);
    final IBuilding building = colony.getBuildingManager().getBuilding(buildingPos);
    if (!(building instanceof AbstractBuildingGuards)) {
        MessageUtils.format(TOOL_GUARD_SCROLL_NO_GUARD_BUILDING).sendTo(player);
        return itemStack;
    }
    itemStack.shrink(1);
    final List<ICitizenData> guards = new ArrayList<>(building.getAllAssignedCitizen());
    if (world.random.nextInt(10) == 0 || colony.getWorld() != world) {
        // Fail
        final LlamaEntity entity = EntityType.LLAMA.create(world);
        entity.setPos(player.getX(), player.getY(), player.getZ());
        world.addFreshEntity(entity);
        player.displayClientMessage(new TranslationTextComponent("minecolonies.scroll.failed" + (world.random.nextInt(FAIL_RESPONSES_TOTAL) + 1)).setStyle(Style.EMPTY.withColor(TextFormatting.GOLD)), true);
        SoundUtils.playSoundForPlayer(player, SoundEvents.EVOKER_CAST_SPELL, 0.5f, 1.0f);
        return itemStack;
    } else {
        for (final ICitizenData citizenData : guards) {
            final AbstractJobGuard job = citizenData.getJob(AbstractJobGuard.class);
            if (job != null && job.getWorkerAI() != null && !((AbstractEntityAIGuard) job.getWorkerAI()).hasTool()) {
                continue;
            }
            if (citizenData.getEntity().isPresent()) {
                if (citizenData.getEntity().get().getCitizenDiseaseHandler().isSick()) {
                    continue;
                }
                citizenData.getEntity().get().remove();
            }
            colony.getCitizenManager().spawnOrCreateCivilian(citizenData, world, player.blockPosition(), true);
            citizenData.setNextRespawnPosition(buildingPos);
            ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.FOLLOW);
            ((AbstractBuildingGuards) building).setPlayerToFollow(player);
            final FollowModeSetting grouping = ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.FOLLOW_MODE);
            if (grouping.getValue().equals(FollowModeSetting.LOOSE)) {
                grouping.trigger();
            }
            citizenData.setSaturation(100);
            colony.getPackageManager().addCloseSubscriber(player);
            if (job != null && job.getWorkerAI() != null) {
                final long spawnTime = world.getGameTime() + TICKS_SECOND * 900;
                // Timed despawn
                job.getWorkerAI().registerTarget(new AIOneTimeEventTarget(() -> {
                    if (world.getGameTime() - spawnTime > 0) {
                        ((AbstractBuildingGuards) building).getSetting(AbstractBuildingGuards.GUARD_TASK).set(GuardTaskSetting.PATROL);
                        citizenData.getEntity().ifPresent(Entity::remove);
                        colony.getPackageManager().removeCloseSubscriber(player);
                        return true;
                    }
                    return false;
                }, AIWorkerState.DECIDE));
            }
        }
        SoundUtils.playSoundForPlayer(player, SoundEvents.UI_TOAST_CHALLENGE_COMPLETE, 0.3f, 1.0f);
    }
    return itemStack;
}
Also used : AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ArrayList(java.util.ArrayList) AIOneTimeEventTarget(com.minecolonies.api.entity.ai.statemachine.AIOneTimeEventTarget) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) LlamaEntity(net.minecraft.entity.passive.horse.LlamaEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) BlockPos(net.minecraft.util.math.BlockPos) FollowModeSetting(com.minecolonies.coremod.colony.buildings.modules.settings.FollowModeSetting)

Example 69 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class HireFireMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ICitizenData citizen = colony.getCitizenManager().getCivilian(citizenID);
    citizen.setPaused(false);
    if (hire) {
        building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).assignCitizen(citizen);
    } else {
        building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).removeCitizen(citizen);
    }
}
Also used : AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IColony(com.minecolonies.api.colony.IColony) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 70 with ICitizenData

use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.

the class RegisteredStructureManager method removeBuilding.

@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
    if (buildings.containsKey(building.getID())) {
        final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
        for (final IBuilding tbuilding : buildings.values()) {
            if (tbuilding != building) {
                builder.put(tbuilding.getID(), tbuilding);
            }
        }
        buildings = builder.build();
        for (final ServerPlayerEntity player : subscribers) {
            Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
        }
        Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
    }
    if (building instanceof BuildingTownHall) {
        townHall = null;
    } else if (building instanceof BuildingWareHouse) {
        wareHouses.remove(building);
    } else if (building instanceof BuildingMysticalSite) {
        mysticalSites.remove(building);
    }
    // Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
    for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        citizen.onRemoveBuilding(building);
        building.cancelAllRequestsOfCitizen(citizen);
    }
    colony.getRequestManager().onProviderRemovedFromColony(building);
    colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
    colony.getCitizenManager().calculateMaxCitizens();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12