Search in sources :

Example 91 with ICitizenData

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);
}
Also used : Skill(com.minecolonies.api.entity.citizen.Skill) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 92 with ICitizenData

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));
    }
}
Also used : Skill(com.minecolonies.api.entity.citizen.Skill) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 93 with ICitizenData

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);
            }
        }
    }
}
Also used : ICitizenData(com.minecolonies.api.colony.ICitizenData) StackList(com.minecolonies.api.colony.requestsystem.requestable.StackList) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)

Example 94 with ICitizenData

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();
}
Also used : ArrayList(java.util.ArrayList) ICitizenData(com.minecolonies.api.colony.ICitizenData) ItemStack(net.minecraft.item.ItemStack) StudyItem(com.minecolonies.api.entity.ai.util.StudyItem)

Example 95 with ICitizenData

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();
}
Also used : AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)180 NotNull (org.jetbrains.annotations.NotNull)49 BlockPos (net.minecraft.util.math.BlockPos)47 IColony (com.minecolonies.api.colony.IColony)46 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)33 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)31 ItemStack (net.minecraft.item.ItemStack)28 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)23 PlayerEntity (net.minecraft.entity.player.PlayerEntity)23 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)18 Colony (com.minecolonies.coremod.colony.Colony)16 ArrayList (java.util.ArrayList)16 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)13 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12