use of com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY in project minecolonies by ldtteam.
the class EntityAIWorkHealer method cure.
/**
* Give a citizen the cure.
*
* @return the next state to go to.
*/
private IAIState cure() {
if (currentPatient == null) {
return DECIDE;
}
final ICitizenData data = getOwnBuilding().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(data.getEntity().get().blockPosition())) {
return CURE;
}
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
if (diseaseName.isEmpty()) {
currentPatient = null;
citizen.heal(10);
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
citizen.markDirty();
return DECIDE;
}
if (!hasCureInInventory(disease, worker.getInventoryCitizen())) {
if (hasCureInInventory(disease, getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
for (final ItemStack cure : disease.getCure()) {
if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), 1);
return GATHERING_REQUIRED_MATERIALS;
}
}
}
currentPatient = null;
return DECIDE;
}
if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
for (final ItemStack cure : disease.getCure()) {
if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
if (InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
currentPatient = null;
return DECIDE;
}
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(worker.getInventoryCitizen(), cure::sameItem, cure.getCount(), citizen.getInventoryCitizen());
}
}
}
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
currentPatient.setState(Patient.PatientState.TREATED);
currentPatient = null;
return DECIDE;
}
use of com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY in project minecolonies by ldtteam.
the class EntityAIWorkHealer method decide.
/**
* Decide what to do next. Check if all patients are up date, else update their states. Then check if there is any patient we can cure or request things for.
*
* @return the next state to go to.
*/
private IAIState decide() {
if (walkToBuilding()) {
return DECIDE;
}
final BuildingHospital hospital = getOwnBuilding();
for (final AbstractEntityCitizen citizen : WorldUtil.getEntitiesWithinBuilding(world, AbstractEntityCitizen.class, getOwnBuilding(), cit -> cit.getCitizenDiseaseHandler().isSick())) {
hospital.checkOrCreatePatientFile(citizen.getCivilianID());
}
for (final Patient patient : hospital.getPatients()) {
final ICitizenData data = hospital.getColony().getCitizenManager().getCivilian(patient.getId());
if (data == null || !data.getEntity().isPresent() || (data.getEntity().isPresent() && !data.getEntity().get().getCitizenDiseaseHandler().isSick())) {
hospital.removePatientFile(patient);
continue;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
@Nullable final Disease disease = diseaseName.isEmpty() ? null : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
if (patient.getState() == Patient.PatientState.NEW) {
this.currentPatient = patient;
return REQUEST_CURE;
}
if (patient.getState() == Patient.PatientState.REQUESTED) {
if (disease == null) {
this.currentPatient = patient;
return CURE;
}
if (testRandomCureChance()) {
this.currentPatient = patient;
return FREE_CURE;
}
if (!InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
if (hasCureInInventory(disease, worker.getInventoryCitizen()) || hasCureInInventory(disease, getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
this.currentPatient = patient;
return CURE;
}
final ImmutableList<IRequest<? extends Stack>> list = getOwnBuilding().getOpenRequestsOfType(worker.getCitizenData().getId(), TypeToken.of(Stack.class));
final ImmutableList<IRequest<? extends Stack>> completed = getOwnBuilding().getCompletedRequestsOfType(worker.getCitizenData(), TypeToken.of(Stack.class));
for (final ItemStack cure : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName).getCure()) {
if (!InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), cure::sameItem)) {
if (InventoryUtils.getItemCountInItemHandler(getOwnBuilding().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), stack -> stack.sameItem(cure)) >= cure.getCount()) {
needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), cure.getCount());
return GATHERING_REQUIRED_MATERIALS;
}
boolean hasCureRequested = false;
for (final IRequest<? extends Stack> request : list) {
if (request.getRequest().getStack().sameItem(cure)) {
hasCureRequested = true;
break;
}
}
for (final IRequest<? extends Stack> request : completed) {
if (request.getRequest().getStack().sameItem(cure)) {
hasCureRequested = true;
break;
}
}
if (!hasCureRequested) {
patient.setState(Patient.PatientState.NEW);
break;
}
}
}
} else {
data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
}
}
if (patient.getState() == Patient.PatientState.TREATED) {
if (disease == null) {
this.currentPatient = patient;
return CURE;
}
if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
patient.setState(Patient.PatientState.NEW);
return DECIDE;
}
}
}
for (final PlayerEntity player : WorldUtil.getEntitiesWithinBuilding(world, PlayerEntity.class, getOwnBuilding(), player -> player.getHealth() < player.getMaxHealth() - 10 - (2 * getOwnBuilding().getBuildingLevel()))) {
playerToHeal = player;
return CURE_PLAYER;
}
final ICitizenData data = getOwnBuilding().getColony().getCitizenManager().getRandomCitizen();
if (data.getEntity().isPresent() && data.getEntity().get().getHealth() < 10.0 && BlockPosUtil.getDistance2D(data.getEntity().get().blockPosition(), getOwnBuilding().getPosition()) < getOwnBuilding().getBuildingLevel() * 40) {
remotePatient = data;
return WANDER;
}
return DECIDE;
}
use of com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method decide.
/**
* Decide what to do next. Check if all patients are up date, else update their states. Then check if there is any patient we can cure or request things for.
*
* @return the next state to go to.
*/
private IAIState decide() {
if (walkToBuilding()) {
return DECIDE;
}
final BuildingHospital hospital = building;
for (final AbstractEntityCitizen citizen : WorldUtil.getEntitiesWithinBuilding(world, AbstractEntityCitizen.class, building, cit -> cit.getCitizenDiseaseHandler().isSick())) {
hospital.checkOrCreatePatientFile(citizen.getCivilianID());
}
for (final Patient patient : hospital.getPatients()) {
final ICitizenData data = hospital.getColony().getCitizenManager().getCivilian(patient.getId());
if (data == null || !data.getEntity().isPresent() || (data.getEntity().isPresent() && !data.getEntity().get().getCitizenDiseaseHandler().isSick())) {
hospital.removePatientFile(patient);
continue;
}
final EntityCitizen citizen = (EntityCitizen) data.getEntity().get();
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
@Nullable final Disease disease = diseaseName.isEmpty() ? null : IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
if (patient.getState() == Patient.PatientState.NEW) {
this.currentPatient = patient;
return REQUEST_CURE;
}
if (patient.getState() == Patient.PatientState.REQUESTED) {
if (disease == null) {
this.currentPatient = patient;
return CURE;
}
if (testRandomCureChance()) {
this.currentPatient = patient;
return FREE_CURE;
}
if (!InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
if (hasCureInInventory(disease, worker.getInventoryCitizen()) || hasCureInInventory(disease, building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
this.currentPatient = patient;
return CURE;
}
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)) {
if (InventoryUtils.getItemCountInItemHandler(building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null), stack -> stack.sameItem(cure)) >= cure.getCount()) {
needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), cure.getCount());
return GATHERING_REQUIRED_MATERIALS;
}
boolean hasCureRequested = false;
for (final IRequest<? extends Stack> request : list) {
if (request.getRequest().getStack().sameItem(cure)) {
hasCureRequested = true;
break;
}
}
for (final IRequest<? extends Stack> request : completed) {
if (request.getRequest().getStack().sameItem(cure)) {
hasCureRequested = true;
break;
}
}
if (!hasCureRequested) {
patient.setState(Patient.PatientState.NEW);
break;
}
}
}
} else {
data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
}
}
if (patient.getState() == Patient.PatientState.TREATED) {
if (disease == null) {
this.currentPatient = patient;
return CURE;
}
if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
patient.setState(Patient.PatientState.NEW);
return DECIDE;
}
}
}
for (final PlayerEntity player : WorldUtil.getEntitiesWithinBuilding(world, PlayerEntity.class, building, player -> player.getHealth() < player.getMaxHealth() - 10 - (2 * building.getBuildingLevel()))) {
playerToHeal = player;
return CURE_PLAYER;
}
final ICitizenData data = building.getColony().getCitizenManager().getRandomCitizen();
if (data.getEntity().isPresent() && data.getEntity().get().getHealth() < 10.0 && BlockPosUtil.getDistance2D(data.getEntity().get().blockPosition(), building.getPosition()) < building.getBuildingLevel() * 40) {
remotePatient = data;
return WANDER;
}
return DECIDE;
}
use of com.minecolonies.api.util.constant.TranslationConstants.PATIENT_FULL_INVENTORY in project minecolonies by Minecolonies.
the class EntityAIWorkHealer method cure.
/**
* Give a citizen the cure.
*
* @return the next state to go to.
*/
private IAIState cure() {
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(data.getEntity().get().blockPosition())) {
return CURE;
}
final String diseaseName = citizen.getCitizenDiseaseHandler().getDisease();
final Disease disease = IColonyManager.getInstance().getCompatibilityManager().getDisease(diseaseName);
if (diseaseName.isEmpty()) {
currentPatient = null;
citizen.heal(10);
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
citizen.markDirty();
return DECIDE;
}
if (!hasCureInInventory(disease, worker.getInventoryCitizen())) {
if (hasCureInInventory(disease, building.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).orElseGet(null))) {
for (final ItemStack cure : disease.getCure()) {
if (InventoryUtils.getItemCountInItemHandler(worker.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
needsCurrently = new Tuple<>(stack -> stack.sameItem(cure), 1);
return GATHERING_REQUIRED_MATERIALS;
}
}
}
currentPatient = null;
return DECIDE;
}
if (!hasCureInInventory(disease, citizen.getInventoryCitizen())) {
for (final ItemStack cure : disease.getCure()) {
if (InventoryUtils.getItemCountInItemHandler(citizen.getInventoryCitizen(), stack -> stack.sameItem(cure)) < cure.getCount()) {
if (InventoryUtils.isItemHandlerFull(citizen.getInventoryCitizen())) {
data.triggerInteraction(new StandardInteraction(new TranslationTextComponent(PATIENT_FULL_INVENTORY), ChatPriority.BLOCKING));
currentPatient = null;
return DECIDE;
}
InventoryUtils.transferXOfFirstSlotInItemHandlerWithIntoNextFreeSlotInItemHandler(worker.getInventoryCitizen(), cure::sameItem, cure.getCount(), citizen.getInventoryCitizen());
}
}
}
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
currentPatient.setState(Patient.PatientState.TREATED);
currentPatient = null;
return DECIDE;
}
Aggregations