use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by ldtteam.
the class CitizenJobHandler method onJobChanged.
/**
* Defines job changes and state changes of the citizen.
*
* @param job the set job.
*/
@Override
public void onJobChanged(@Nullable final IJob<?> job) {
// Model
setModelDependingOnJob(job);
// AI Tasks
for (@NotNull final PrioritizedGoal task : new ArrayList<>(citizen.getTasks().availableGoals)) {
if (task.getGoal() instanceof AbstractAISkeleton) {
citizen.getTasks().removeGoal(task.getGoal());
}
}
citizen.getCitizenData().setIdleAtJob(false);
if (job != null) {
job.addWorkerAIToTaskList(citizen.getTasks());
if (citizen.getTicksExisted() > 0 && citizen.getCitizenColonyHandler().getWorkBuilding() != null && citizen.getDesiredActivity() == DesiredActivity.WORK) {
BlockPosUtil.tryMoveBaseCitizenEntityToXYZ(citizen, citizen.getCitizenColonyHandler().getWorkBuilding().getPosition());
}
// Calculate the number of guards for some advancements
if (job instanceof AbstractJobGuard) {
IColony colony = citizen.getCitizenColonyHandler().getColony();
int guards = ((int) colony.getCitizenManager().getCitizens().stream().filter(citizen -> citizen.getJob() instanceof AbstractJobGuard).count());
AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColony(), player -> AdvancementTriggers.ARMY_POPULATION.trigger(player, guards));
}
job.initEntityValues(citizen);
}
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* AttackEntityEvent handler.
* <p>
* Check, if a player tries to attack an entity.. Deny if: - If the attacking happens in the colony - Player is less than officer to the colony.
*
* @param event ItemEntityPickupEvent
*/
@SubscribeEvent
public void on(final AttackEntityEvent event) {
if (event.getTarget() instanceof MonsterEntity) {
return;
}
@NotNull final PlayerEntity player = EntityUtils.getPlayerOfFakePlayer(event.getPlayer(), event.getPlayer().getCommandSenderWorld());
if (MineColonies.getConfig().getServer().enableColonyProtection.get() && colony.isCoordInColony(player.getCommandSenderWorld(), new BlockPos(player.position()))) {
final Permissions perms = colony.getPermissions();
if (event.getTarget() instanceof EntityCitizen) {
final AbstractEntityCitizen citizen = (AbstractEntityCitizen) event.getTarget();
if (citizen.getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard && perms.hasPermission(event.getPlayer(), Action.GUARDS_ATTACK)) {
return;
}
if (perms.hasPermission(event.getPlayer(), Action.ATTACK_CITIZEN)) {
return;
}
cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_CITIZEN, new BlockPos(event.getTarget().position()));
return;
}
if (!(event.getTarget() instanceof MobEntity) && !perms.hasPermission(event.getPlayer(), Action.ATTACK_ENTITY)) {
cancelEvent(event, event.getPlayer(), colony, Action.ATTACK_ENTITY, new BlockPos(event.getTarget().position()));
}
}
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class EventListener method onUpdateEntityRadar.
@SubscribeEvent
public void onUpdateEntityRadar(@NotNull final EntityRadarUpdateEvent event) {
final WrappedEntity wrapper = event.getWrappedEntity();
final LivingEntity entity = wrapper.getEntityLivingRef().get();
if (entity instanceof AbstractEntityCitizen) {
final boolean isVisitor = entity instanceof VisitorCitizen;
TextComponent jobName;
if (isVisitor) {
if (!JourneymapOptions.getShowVisitors(this.jmap.getOptions())) {
wrapper.setDisable(true);
return;
}
jobName = new TranslationTextComponent(PARTIAL_JOURNEY_MAP_INFO + "visitor");
} else {
final String jobId = entity.getEntityData().get(DATA_JOB);
final JobEntry jobEntry = IJobRegistry.getInstance().getValue(new ResourceLocation(jobId));
final IJob<?> job = jobEntry == null ? null : jobEntry.produceJob(null);
if (job instanceof AbstractJobGuard ? !JourneymapOptions.getShowGuards(this.jmap.getOptions()) : !JourneymapOptions.getShowCitizens(this.jmap.getOptions())) {
wrapper.setDisable(true);
return;
}
jobName = new TranslationTextComponent(jobEntry == null ? PARTIAL_JOURNEY_MAP_INFO + "unemployed" : jobEntry.getTranslationKey());
}
if (JourneymapOptions.getShowColonistTooltip(this.jmap.getOptions())) {
ITextComponent name = entity.getCustomName();
if (name != null) {
wrapper.setEntityToolTips(Arrays.asList(name, jobName.setStyle(JOB_TOOLTIP)));
}
}
final boolean showName = event.getActiveUiState().ui.equals(Context.UI.Minimap) ? JourneymapOptions.getShowColonistNameMinimap(this.jmap.getOptions()) : JourneymapOptions.getShowColonistNameFullscreen(this.jmap.getOptions());
if (!showName) {
wrapper.setCustomName("");
}
if (!isVisitor && JourneymapOptions.getShowColonistTeamColour(this.jmap.getOptions())) {
wrapper.setColor(entity.getTeamColor());
}
} else if (entity instanceof AbstractEntityMinecoloniesMob) {
final JourneymapOptions.RaiderColor color = JourneymapOptions.getRaiderColor(this.jmap.getOptions());
if (JourneymapOptions.RaiderColor.NONE.equals(color)) {
wrapper.setDisable(true);
} else if (!JourneymapOptions.RaiderColor.HOSTILE.equals(color)) {
wrapper.setColor(color.getColor().getValue());
}
}
}
use of com.minecolonies.coremod.colony.jobs.AbstractJobGuard 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.coremod.colony.jobs.AbstractJobGuard in project minecolonies by Minecolonies.
the class CitizenHappinessHandler method getGuardFactor.
/**
* Get the guard security happiness modifier from the colony.
*
* @param colony the colony.
* @return true if so.
*/
private double getGuardFactor(final IColony colony) {
double guards = 1;
double workers = 1;
for (final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
if (citizen.getJob() instanceof AbstractJobGuard) {
guards++;
} else {
workers++;
}
}
return Math.min(guards / (workers * 2 / 3), 2);
}
Aggregations