use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIEatTask method waitForFood.
/**
* Wander around the placeToPath a bit while waiting for the cook to deliver food. After waiting for a certain time, get the food yourself.
*
* @return the next state to go to.
*/
private EatingState waitForFood() {
final ICitizenData citizenData = citizen.getCitizenData();
final IColony colony = citizenData.getColony();
restaurantPos = colony.getBuildingManager().getBestBuilding(citizen, BuildingCook.class);
if (restaurantPos == null) {
return SEARCH_RESTAURANT;
}
if (!colony.getBuildingManager().getBuilding(restaurantPos).isInBuilding(citizen.blockPosition())) {
return GO_TO_RESTAURANT;
}
eatPos = findPlaceToEat();
if (eatPos != null) {
return GO_TO_EAT_POS;
}
if (hasFood()) {
return EAT;
}
return WAIT_FOR_FOOD;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIWorkNether method checkHeal.
/**
* Checks the citizens health status and heals the citizen if necessary.
*/
private float checkHeal(AbstractEntityCitizen citizen) {
ICitizenData citizenData = citizen.getCitizenData();
double healAmount = 0D;
if (citizen.getHealth() < citizen.getMaxHealth()) {
final double limitDecrease = citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATLIMIT);
if (citizenData.getSaturation() >= FULL_SATURATION + limitDecrease) {
healAmount = 2 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION));
} else if (citizenData.getSaturation() < LOW_SATURATION) {
return (float) healAmount;
} else {
healAmount = 1 * (1.0 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(REGENERATION));
}
citizen.heal((float) healAmount);
if (healAmount > 0.1D) {
citizenData.markDirty();
}
}
return (float) healAmount;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method freeCure.
/**
* Do free cure magic.
*
* @return the next state to go to.
*/
private IAIState freeCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
progressTicks = 0;
return FREE_CURE;
}
progressTicks++;
if (progressTicks < MAX_PROGRESS_TICKS) {
Network.getNetwork().sendToTrackingEntity(new StreamParticleEffectMessage(worker.position().add(0, 2, 0), citizen.position(), ParticleTypes.HEART, progressTicks % MAX_PROGRESS_TICKS, MAX_PROGRESS_TICKS), worker);
Network.getNetwork().sendToTrackingEntity(new CircleParticleEffectMessage(worker.position().add(0, 2, 0), ParticleTypes.HEART, progressTicks), worker);
return getState();
}
progressTicks = 0;
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
citizen.getCitizenDiseaseHandler().cure();
currentPatient.setState(Patient.PatientState.TREATED);
currentPatient = null;
return DECIDE;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method requestCure.
/**
* Request the cure for a given patient.
*
* @return the next state to go to.
*/
private IAIState requestCure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = building.getColony().getCitizenManager().getCivilian(currentPatient.getId());
if (data == null || !data.getEntity().isPresent() || !data.getEntity().get().getCitizenDiseaseHandler().isSick()) {
currentPatient = null;
return DECIDE;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
if (walkToBlock(citizen.blockPosition())) {
return REQUEST_CURE;
}
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
if (diseaseName.isEmpty()) {
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
final ImmutableList<IRequest<? extends Stack>> list = building.getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
final ImmutableList<IRequest<? extends Stack>> completed = building.getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem) && !InventoryUtils.hasItemInItemHandler(building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), cure::sameItem)) {
boolean hasRequest = false;
for (final IRequest<? extends Stack> request : list) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
for (final IRequest<? extends Stack> request : completed) {
if (request.getRequest().getStack().sameItem(cure)) {
hasRequest = true;
break;
}
}
if (!hasRequest) {
worker.getCitizenData().createRequestAsync(new Stack(cure, REQUEST_COUNT, 1));
}
}
}
currentPatient.setState(Patient.PatientState.REQUESTED);
currentPatient = null;
return DECIDE;
}
use of com.minecolonies.api.colony.ICitizenData 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