Search in sources :

Example 1 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule in project minecolonies by ldtteam.

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 2 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule 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 3 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule in project minecolonies by Minecolonies.

the class BuildingLumberjack method bonemealFungi.

/**
 * Returns early if no worker is assigned Iterates over the nether tree position list If position is a fungus, grows it depending on worker's level If the block has changed,
 * removes the position from the list and returns early If the position is not a fungus, removes the position from the list
 */
private void bonemealFungi() {
    final WorkerBuildingModule module = getFirstModuleOccurance(WorkerBuildingModule.class);
    final ICitizenData data = getFirstModuleOccurance(WorkerBuildingModule.class).getFirstCitizen();
    if (data == null) {
        return;
    }
    final int modifier = Math.max(0, Math.min(FUNGI_MODIFIER, 100));
    for (Iterator<BlockPos> iterator = netherTrees.iterator(); iterator.hasNext(); ) {
        final BlockPos pos = iterator.next();
        final World world = colony.getWorld();
        if (WorldUtil.isBlockLoaded(world, pos)) {
            final BlockState blockState = world.getBlockState(pos);
            final Block block = blockState.getBlock();
            if (block == Blocks.CRIMSON_FUNGUS || block == Blocks.WARPED_FUNGUS) {
                int threshold = modifier + (int) Math.ceil(data.getCitizenSkillHandler().getLevel(module.getPrimarySkill()) * (1 - ((float) modifier / 100)));
                final int rand = world.getRandom().nextInt(100);
                if (rand < threshold) {
                    final IGrowable growable = (IGrowable) block;
                    if (growable.isValidBonemealTarget(world, pos, blockState, world.isClientSide)) {
                        if (!world.isClientSide) {
                            if (growable.isBonemealSuccess(world, world.random, pos, blockState)) {
                                growable.performBonemeal((ServerWorld) world, world.random, pos, blockState);
                                return;
                            }
                        }
                    }
                }
            } else {
                iterator.remove();
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) IGrowable(net.minecraft.block.IGrowable) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World)

Example 4 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule in project minecolonies by Minecolonies.

the class BuildingUniversity method onColonyTick.

@Override
public void onColonyTick(@NotNull final IColony colony) {
    super.onColonyTick(colony);
    final List<ILocalResearch> inProgress = colony.getResearchManager().getResearchTree().getResearchInProgress();
    final WorkerBuildingModule module = getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == ModJobs.researcher);
    int i = 1;
    for (final ILocalResearch research : inProgress) {
        if (i > module.getAssignedCitizen().size()) {
            return;
        }
        for (final ICitizenData data : getAllAssignedCitizen()) {
            data.getCitizenSkillHandler().addXpToSkill(module.getSecondarySkill(), 25.0, data);
        }
        if (colony.getResearchManager().getResearchTree().getResearch(research.getBranch(), research.getId()).research(colony.getResearchManager().getResearchEffects(), colony.getResearchManager().getResearchTree())) {
            onSuccess(research);
        }
        i++;
    }
}
Also used : ILocalResearch(com.minecolonies.api.research.ILocalResearch) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 5 with WorkerBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule in project minecolonies by ldtteam.

the class BuildingUniversity method onColonyTick.

@Override
public void onColonyTick(@NotNull final IColony colony) {
    super.onColonyTick(colony);
    final List<ILocalResearch> inProgress = colony.getResearchManager().getResearchTree().getResearchInProgress();
    final WorkerBuildingModule module = getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == ModJobs.researcher);
    int i = 1;
    for (final ILocalResearch research : inProgress) {
        if (i > module.getAssignedCitizen().size()) {
            return;
        }
        for (final ICitizenData data : getAllAssignedCitizen()) {
            data.getCitizenSkillHandler().addXpToSkill(module.getSecondarySkill(), 25.0, data);
        }
        if (colony.getResearchManager().getResearchTree().getResearch(research.getBranch(), research.getId()).research(colony.getResearchManager().getResearchEffects(), colony.getResearchManager().getResearchTree())) {
            onSuccess(research);
        }
        i++;
    }
}
Also used : ILocalResearch(com.minecolonies.api.research.ILocalResearch) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)6 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 Skill (com.minecolonies.api.entity.citizen.Skill)2 ILocalResearch (com.minecolonies.api.research.ILocalResearch)2 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 IGrowable (net.minecraft.block.IGrowable)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2