use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CitizenExperienceHandler method addExperience.
@Override
public void addExperience(final double xp) {
final IBuilding home = citizen.getCitizenColonyHandler().getHomeBuilding();
final double citizenHutLevel = home == null ? 0 : home.getBuildingLevel();
final ICitizenData data = citizen.getCitizenData();
final IBuilding workBuilding = data.getWorkBuilding();
if (workBuilding == null || !workBuilding.hasModule(WorkerBuildingModule.class)) {
return;
}
final double workBuildingLevel = workBuilding.getBuildingLevel();
final double buildingXPModifier = 1 + (workBuildingLevel + citizenHutLevel) / 10;
double localXp = xp * buildingXPModifier;
final double saturation = citizen.getCitizenData().getSaturation();
final int intelligenceLevel = data.getCitizenSkillHandler().getLevel(Skill.Intelligence);
localXp += localXp * (intelligenceLevel / 100.0);
if (saturation <= 0) {
return;
}
localXp *= (1 + citizen.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(LEVELING));
localXp = citizen.getCitizenItemHandler().applyMending(localXp);
final WorkerBuildingModule module = workBuilding.getModuleMatching(WorkerBuildingModule.class, m -> m.getAssignedCitizen().contains(data));
final Skill primary = module.getPrimarySkill();
final Skill secondary = module.getSecondarySkill();
data.getCitizenSkillHandler().addXpToSkill(primary, localXp, data);
data.getCitizenSkillHandler().addXpToSkill(primary.getComplimentary(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
data.getCitizenSkillHandler().removeXpFromSkill(primary.getAdverse(), localXp / (100.0 / PRIMARY_DEPENDENCY_SHARE), data);
data.getCitizenSkillHandler().addXpToSkill(secondary, localXp / 2.0, data);
data.getCitizenSkillHandler().addXpToSkill(secondary.getComplimentary(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
data.getCitizenSkillHandler().removeXpFromSkill(secondary.getAdverse(), localXp / (100.0 / SECONDARY_DEPENDENCY_SHARE), data);
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CitizenSkillHandler method init.
@Override
public void init(@NotNull final IColony colony, @Nullable final ICitizenData firstParent, @Nullable final ICitizenData secondParent, final Random rand) {
ICitizenData roleModelA;
ICitizenData roleModelB;
if (firstParent == null) {
roleModelA = colony.getCitizenManager().getRandomCitizen();
} else {
roleModelA = firstParent;
}
if (secondParent == null) {
roleModelB = colony.getCitizenManager().getRandomCitizen();
} else {
roleModelB = secondParent;
}
final int levelCap = (int) colony.getOverallHappiness();
init(levelCap);
final int bonusPoints = 25 + rand.nextInt(25);
int totalPoints = 0;
for (final Skill skill : Skill.values()) {
final int firstRoleModelLevel = roleModelA.getCitizenSkillHandler().getSkills().get(skill).getA();
final int secondRoleModelLevel = roleModelB.getCitizenSkillHandler().getSkills().get(skill).getA();
totalPoints += firstRoleModelLevel + secondRoleModelLevel;
}
for (final Skill skill : Skill.values()) {
final double firstRoleModelLevel = roleModelA.getCitizenSkillHandler().getSkills().get(skill).getA();
final double secondRoleModelLevel = roleModelB.getCitizenSkillHandler().getSkills().get(skill).getA();
int newPoints = (int) (((firstRoleModelLevel + secondRoleModelLevel) / totalPoints) * bonusPoints);
skillMap.put(skill, new Tuple<>(skillMap.get(skill).getA() + newPoints, 0.0D));
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIWorkNether method attemptToEat.
/**
* Attempt to eat to restore some saturation
*/
protected void attemptToEat() {
final IDeliverable edible = new StackList(getEdiblesList(), "Edible Food", 1);
final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, edible::matches);
final ICitizenData citizenData = worker.getCitizenData();
if (slot > -1) {
final ItemStack stack = worker.getInventoryCitizen().getStackInSlot(slot);
final Food itemFood = stack.getItem().getFoodProperties();
final double satIncrease = itemFood.getNutrition() * (1.0 + worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SATURATION));
citizenData.increaseSaturation(satIncrease / 2.0);
citizenData.getInventory().extractItem(slot, 1, false);
final ItemStack containerItem = stack.getContainerItem();
if (containerItem != null && !(containerItem.getItem() instanceof AirItem)) {
if (citizenData.getInventory().isFull()) {
InventoryUtils.spawnItemStack(worker.level, worker.getX(), worker.getY(), worker.getZ(), containerItem);
} else {
InventoryUtils.addItemStackToItemHandler(worker.getItemHandlerCitizen(), containerItem);
}
}
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class EntityAIStudy method study.
/**
* The AI task for the student to study. For this he should walk between the different bookcase hit them once and then stand around for a while.
*
* @return the next IAIState.
*/
private IAIState study() {
final ICitizenData data = worker.getCitizenData();
if (studyPos == null) {
studyPos = building.getRandomBookShelf();
}
if (walkToBlock(studyPos)) {
setDelay(WALK_DELAY);
return getState();
}
// Search for Items to use to study
final List<StudyItem> currentItems = new ArrayList<>();
for (final StudyItem curItem : building.getStudyItems()) {
final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(worker, itemStack -> !ItemStackUtils.isEmpty(itemStack) && itemStack.getItem() == curItem.getItem());
if (slot != -1) {
curItem.setSlot(slot);
currentItems.add(curItem);
}
}
// Create a new Request for items
if (currentItems.isEmpty()) {
// Default levelup
data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE, data);
worker.setItemInHand(Hand.MAIN_HAND, ItemStackUtils.EMPTY);
for (final StudyItem studyItem : building.getStudyItems()) {
final int bSlot = InventoryUtils.findFirstSlotInProviderWith(building, studyItem.getItem());
if (bSlot > -1) {
if (walkToBuilding()) {
setDelay(WALK_DELAY);
return getState();
}
takeItemStackFromProvider(building, bSlot);
} else {
checkIfRequestForItemExistOrCreateAsync(new ItemStack(studyItem.getItem(), studyItem.getBreakPct() / 10 > 0 ? studyItem.getBreakPct() / 10 : 1));
}
}
} else // Use random item
{
final StudyItem chosenItem = currentItems.get(world.random.nextInt(currentItems.size()));
worker.setItemInHand(Hand.MAIN_HAND, new ItemStack(chosenItem.getItem(), 1));
data.getCitizenSkillHandler().tryLevelUpIntelligence(world.random, ONE_IN_X_CHANCE * (100D / chosenItem.getSkillIncreasePct()), data);
// Break item rand
if (world.random.nextInt(100) <= chosenItem.getBreakPct()) {
data.getInventory().extractItem(chosenItem.getSlot(), 1, false);
}
}
worker.decreaseSaturationForAction();
studyPos = null;
setDelay(STUDY_DELAY);
return getState();
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AbstractBuildingGuards method startPatrolNext.
/**
* Starts the patrol to the next point
*/
private void startPatrolNext() {
getNextPatrolTarget(true);
patrolTimer = 5;
for (final ICitizenData curguard : getAllAssignedCitizen()) {
if (curguard.getEntity().isPresent()) {
if (curguard.getEntity().get().getCitizenJobHandler().getColonyJob() instanceof AbstractJobGuard) {
((AbstractEntityAIGuard<?, ?>) curguard.getEntity().get().getCitizenJobHandler().getColonyJob().getWorkerAI()).setNextPatrolTarget(lastPatrolPoint);
}
}
}
arrivedAtPatrol.clear();
}
Aggregations