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