Search in sources :

Example 6 with Skill

use of com.minecolonies.api.entity.citizen.Skill in project minecolonies by ldtteam.

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 7 with Skill

use of com.minecolonies.api.entity.citizen.Skill in project minecolonies by ldtteam.

the class CitizenData method deserializeNBT.

@Override
public void deserializeNBT(final CompoundNBT nbtTagCompound) {
    name = nbtTagCompound.getString(TAG_NAME);
    female = nbtTagCompound.getBoolean(TAG_FEMALE);
    paused = nbtTagCompound.getBoolean(TAG_PAUSED);
    isChild = nbtTagCompound.getBoolean(TAG_CHILD);
    textureId = nbtTagCompound.getInt(TAG_TEXTURE);
    if (nbtTagCompound.getAllKeys().contains(TAG_SUFFIX)) {
        textureSuffix = nbtTagCompound.getString(TAG_SUFFIX);
    } else {
        textureSuffix = SUFFIXES.get(random.nextInt(SUFFIXES.size()));
    }
    lastPosition = BlockPosUtil.read(nbtTagCompound, TAG_POS);
    if (nbtTagCompound.contains(TAG_RESPAWN_POS)) {
        nextRespawnPos = BlockPosUtil.read(nbtTagCompound, TAG_RESPAWN_POS);
    }
    citizenSkillHandler.read(nbtTagCompound.getCompound(TAG_NEW_SKILLS));
    saturation = nbtTagCompound.getDouble(TAG_SATURATION);
    if (nbtTagCompound.getAllKeys().contains("job")) {
        setJob(IJobDataManager.getInstance().createFrom(this, nbtTagCompound.getCompound("job")));
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_INVENTORY)) {
        final ListNBT nbttaglist = nbtTagCompound.getList(TAG_INVENTORY, 10);
        this.inventory.read(nbttaglist);
        this.inventory.setHeldItem(Hand.MAIN_HAND, nbtTagCompound.getInt(TAG_HELD_ITEM_SLOT));
        this.inventory.setHeldItem(Hand.OFF_HAND, nbtTagCompound.getInt(TAG_OFFHAND_HELD_ITEM_SLOT));
    }
    if (name.isEmpty()) {
        name = generateName(random, isFemale(), getColony());
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_ASLEEP)) {
        bedPos = BlockPosUtil.read(nbtTagCompound, TAG_BEDS);
        isAsleep = nbtTagCompound.getBoolean(TAG_ASLEEP);
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_JUST_ATE)) {
        justAte = nbtTagCompound.getBoolean(TAG_JUST_ATE);
    }
    // Citizen chat options.
    if (nbtTagCompound.getAllKeys().contains(TAG_CHAT_OPTIONS)) {
        final ListNBT handlerTagList = nbtTagCompound.getList(TAG_CHAT_OPTIONS, Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < handlerTagList.size(); ++i) {
            final ServerCitizenInteraction handler = (ServerCitizenInteraction) MinecoloniesAPIProxy.getInstance().getInteractionResponseHandlerDataManager().createFrom(this, handlerTagList.getCompound(i).getCompound(TAG_CHAT_OPTION));
            citizenChatOptions.put(handler.getInquiry(), handler);
        }
    }
    this.citizenHappinessHandler.read(nbtTagCompound);
    this.citizenMournHandler.read(nbtTagCompound);
    if (nbtTagCompound.getAllKeys().contains(TAG_LEVEL_MAP) && !nbtTagCompound.getAllKeys().contains(TAG_NEW_SKILLS)) {
        citizenSkillHandler.init((int) citizenHappinessHandler.getHappiness(getColony()));
        final Map<String, Integer> levels = new HashMap<>();
        final ListNBT levelTagList = nbtTagCompound.getList(TAG_LEVEL_MAP, Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < levelTagList.size(); ++i) {
            final CompoundNBT levelExperienceAtJob = levelTagList.getCompound(i);
            final String jobName = levelExperienceAtJob.getString(TAG_NAME);
            final int level = Math.min(levelExperienceAtJob.getInt(TAG_LEVEL), MAX_CITIZEN_LEVEL);
            levels.put(jobName, level);
        }
        for (final Map.Entry<String, Integer> entry : levels.entrySet()) {
            final Skill primary = Skill.values()[random.nextInt(Skill.values().length)];
            final Skill secondary = Skill.values()[random.nextInt(Skill.values().length)];
            citizenSkillHandler.incrementLevel(primary, entry.getValue() / 2);
            citizenSkillHandler.incrementLevel(secondary, entry.getValue() / 4);
        }
    }
    this.idle = nbtTagCompound.getBoolean(TAG_IDLE);
    final String parentA = nbtTagCompound.getString(TAG_PARENT_A);
    final String parentB = nbtTagCompound.getString(TAG_PARENT_B);
    this.parents = new Tuple<>(parentA, parentB);
    @NotNull final ListNBT siblingsNBT = nbtTagCompound.getList(TAG_SIBLINGS, Constants.NBT.TAG_INT);
    for (int i = 0; i < siblingsNBT.size(); i++) {
        siblings.add(siblingsNBT.getInt(i));
    }
    @NotNull final ListNBT childrenNBT = nbtTagCompound.getList(TAG_CHILDREN, Constants.NBT.TAG_INT);
    for (int i = 0; i < childrenNBT.size(); i++) {
        children.add(childrenNBT.getInt(i));
    }
    partner = nbtTagCompound.getInt(TAG_PARTNER);
    this.isWorking = nbtTagCompound.getBoolean(TAG_ACTIVE);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) NotNull(org.jetbrains.annotations.NotNull) ListNBT(net.minecraft.nbt.ListNBT) Skill(com.minecolonies.api.entity.citizen.Skill) ServerCitizenInteraction(com.minecolonies.coremod.colony.interactionhandling.ServerCitizenInteraction)

Example 8 with Skill

use of com.minecolonies.api.entity.citizen.Skill 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 9 with Skill

use of com.minecolonies.api.entity.citizen.Skill in project minecolonies by Minecolonies.

the class CitizenData method deserializeNBT.

@Override
public void deserializeNBT(final CompoundNBT nbtTagCompound) {
    name = nbtTagCompound.getString(TAG_NAME);
    female = nbtTagCompound.getBoolean(TAG_FEMALE);
    paused = nbtTagCompound.getBoolean(TAG_PAUSED);
    isChild = nbtTagCompound.getBoolean(TAG_CHILD);
    textureId = nbtTagCompound.getInt(TAG_TEXTURE);
    if (nbtTagCompound.getAllKeys().contains(TAG_SUFFIX)) {
        textureSuffix = nbtTagCompound.getString(TAG_SUFFIX);
    } else {
        textureSuffix = SUFFIXES.get(random.nextInt(SUFFIXES.size()));
    }
    lastPosition = BlockPosUtil.read(nbtTagCompound, TAG_POS);
    if (nbtTagCompound.contains(TAG_RESPAWN_POS)) {
        nextRespawnPos = BlockPosUtil.read(nbtTagCompound, TAG_RESPAWN_POS);
    }
    citizenSkillHandler.read(nbtTagCompound.getCompound(TAG_NEW_SKILLS));
    saturation = nbtTagCompound.getDouble(TAG_SATURATION);
    if (nbtTagCompound.getAllKeys().contains("job")) {
        setJob(IJobDataManager.getInstance().createFrom(this, nbtTagCompound.getCompound("job")));
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_INVENTORY)) {
        final ListNBT nbttaglist = nbtTagCompound.getList(TAG_INVENTORY, 10);
        this.inventory.read(nbttaglist);
        this.inventory.setHeldItem(Hand.MAIN_HAND, nbtTagCompound.getInt(TAG_HELD_ITEM_SLOT));
        this.inventory.setHeldItem(Hand.OFF_HAND, nbtTagCompound.getInt(TAG_OFFHAND_HELD_ITEM_SLOT));
    }
    if (name.isEmpty()) {
        name = generateName(random, isFemale(), getColony());
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_ASLEEP)) {
        bedPos = BlockPosUtil.read(nbtTagCompound, TAG_BEDS);
        isAsleep = nbtTagCompound.getBoolean(TAG_ASLEEP);
    }
    if (nbtTagCompound.getAllKeys().contains(TAG_JUST_ATE)) {
        justAte = nbtTagCompound.getBoolean(TAG_JUST_ATE);
    }
    // Citizen chat options.
    if (nbtTagCompound.getAllKeys().contains(TAG_CHAT_OPTIONS)) {
        final ListNBT handlerTagList = nbtTagCompound.getList(TAG_CHAT_OPTIONS, Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < handlerTagList.size(); ++i) {
            final ServerCitizenInteraction handler = (ServerCitizenInteraction) MinecoloniesAPIProxy.getInstance().getInteractionResponseHandlerDataManager().createFrom(this, handlerTagList.getCompound(i).getCompound(TAG_CHAT_OPTION));
            citizenChatOptions.put(handler.getInquiry(), handler);
        }
    }
    this.citizenHappinessHandler.read(nbtTagCompound);
    this.citizenMournHandler.read(nbtTagCompound);
    if (nbtTagCompound.getAllKeys().contains(TAG_LEVEL_MAP) && !nbtTagCompound.getAllKeys().contains(TAG_NEW_SKILLS)) {
        citizenSkillHandler.init((int) citizenHappinessHandler.getHappiness(getColony()));
        final Map<String, Integer> levels = new HashMap<>();
        final ListNBT levelTagList = nbtTagCompound.getList(TAG_LEVEL_MAP, Constants.NBT.TAG_COMPOUND);
        for (int i = 0; i < levelTagList.size(); ++i) {
            final CompoundNBT levelExperienceAtJob = levelTagList.getCompound(i);
            final String jobName = levelExperienceAtJob.getString(TAG_NAME);
            final int level = Math.min(levelExperienceAtJob.getInt(TAG_LEVEL), MAX_CITIZEN_LEVEL);
            levels.put(jobName, level);
        }
        for (final Map.Entry<String, Integer> entry : levels.entrySet()) {
            final Skill primary = Skill.values()[random.nextInt(Skill.values().length)];
            final Skill secondary = Skill.values()[random.nextInt(Skill.values().length)];
            citizenSkillHandler.incrementLevel(primary, entry.getValue() / 2);
            citizenSkillHandler.incrementLevel(secondary, entry.getValue() / 4);
        }
    }
    this.idle = nbtTagCompound.getBoolean(TAG_IDLE);
    final String parentA = nbtTagCompound.getString(TAG_PARENT_A);
    final String parentB = nbtTagCompound.getString(TAG_PARENT_B);
    this.parents = new Tuple<>(parentA, parentB);
    @NotNull final ListNBT siblingsNBT = nbtTagCompound.getList(TAG_SIBLINGS, Constants.NBT.TAG_INT);
    for (int i = 0; i < siblingsNBT.size(); i++) {
        siblings.add(siblingsNBT.getInt(i));
    }
    @NotNull final ListNBT childrenNBT = nbtTagCompound.getList(TAG_CHILDREN, Constants.NBT.TAG_INT);
    for (int i = 0; i < childrenNBT.size(); i++) {
        children.add(childrenNBT.getInt(i));
    }
    partner = nbtTagCompound.getInt(TAG_PARTNER);
    this.isWorking = nbtTagCompound.getBoolean(TAG_ACTIVE);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) NotNull(org.jetbrains.annotations.NotNull) ListNBT(net.minecraft.nbt.ListNBT) Skill(com.minecolonies.api.entity.citizen.Skill) ServerCitizenInteraction(com.minecolonies.coremod.colony.interactionhandling.ServerCitizenInteraction)

Example 10 with Skill

use of com.minecolonies.api.entity.citizen.Skill in project minecolonies by Minecolonies.

the class WindowHireWorker method onOpened.

/**
 * Called when the GUI has been opened. Will fill the fields and lists.
 */
@Override
public void onOpened() {
    updateCitizens();
    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).off();
    citizenList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return citizens.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            @NotNull final ICitizenDataView citizen = citizens.get(index);
            final Button isPaused = rowPane.findPaneOfTypeByID(BUTTON_PAUSE, Button.class);
            if (selectedModule.canAssign(citizen) && !selectedModule.isFull() && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).on();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else if ((selectedModule.isFull()) && !selectedModule.getAssignedCitizens().contains(citizen.getId())) {
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                isPaused.off();
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_DONE, Button.class).off();
                rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).on();
                if ((!selectedModule.getColony().isManualHiring() && selectedModule.getHiringMode() == HiringMode.DEFAULT) || (selectedModule.getHiringMode() == HiringMode.AUTO)) {
                    rowPane.findPaneOfTypeByID(BUTTON_FIRE, Button.class).disable();
                    findPaneOfTypeByID(AUTO_HIRE_WARN, Text.class).on();
                }
                isPaused.on();
                isPaused.setText(LanguageHandler.format(citizen.isPaused() ? COM_MINECOLONIES_COREMOD_GUI_HIRE_UNPAUSE : COM_MINECOLONIES_COREMOD_GUI_HIRE_PAUSE));
            }
            if (citizen.isPaused()) {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).on();
            } else {
                rowPane.findPaneOfTypeByID(BUTTON_RESTART, Button.class).off();
            }
            final StringTextComponent intermString = new StringTextComponent(" ");
            final TextBuilder textBuilder = PaneBuilders.textBuilder();
            textBuilder.append(new StringTextComponent(""));
            int skillCount = citizen.getCitizenSkillHandler().getSkills().entrySet().size();
            final Skill primary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getPrimarySkill() : null;
            final Skill secondary = selectedModule instanceof WorkerBuildingModuleView ? ((WorkerBuildingModuleView) selectedModule).getSecondarySkill() : null;
            for (final Map.Entry<Skill, Tuple<Integer, Double>> entry : citizen.getCitizenSkillHandler().getSkills().entrySet()) {
                final String skillName = entry.getKey().name().toLowerCase(Locale.US);
                final int skillLevel = entry.getValue().getA();
                final Style skillStyle = createColor(primary, secondary, entry.getKey());
                textBuilder.append(new TranslationTextComponent("com.minecolonies.coremod.gui.citizen.skills." + skillName).setStyle(skillStyle));
                textBuilder.append(new StringTextComponent(": " + skillLevel).setStyle(skillStyle));
                if (--skillCount > 0) {
                    textBuilder.append(intermString);
                }
            }
            // finish the current line
            textBuilder.newLine();
            rowPane.findPaneOfTypeByID(CITIZEN_LABEL, Text.class).setText((citizen.getJob().isEmpty() ? "" : LanguageHandler.format(citizen.getJob()) + ": ") + citizen.getName());
            rowPane.findPaneOfTypeByID(ATTRIBUTES_LABEL, Text.class).setText(textBuilder.getText());
        }
    });
    jobList.setDataProvider(new ScrollingList.DataProvider() {

        @Override
        public int getElementCount() {
            return moduleViews.size();
        }

        @Override
        public void updateElement(final int index, @NotNull final Pane rowPane) {
            final JobEntry entry = moduleViews.get(index).getJobEntry();
            final Button button = rowPane.findPaneOfTypeByID(BUTTON_JOB, Button.class);
            button.setText(new TranslationTextComponent(entry.getTranslationKey()));
            if (entry.equals(selectedModule.getJobEntry())) {
                button.disable();
            } else {
                button.enable();
            }
        }
    });
}
Also used : Text(com.ldtteam.blockout.controls.Text) WorkerBuildingModuleView(com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView) Pane(com.ldtteam.blockout.Pane) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) Skill(com.minecolonies.api.entity.citizen.Skill) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) TextBuilder(com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder) Button(com.ldtteam.blockout.controls.Button) Style(net.minecraft.util.text.Style) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) ICitizenDataView(com.minecolonies.api.colony.ICitizenDataView) ScrollingList(com.ldtteam.blockout.views.ScrollingList)

Aggregations

Skill (com.minecolonies.api.entity.citizen.Skill)16 Text (com.ldtteam.blockout.controls.Text)6 Pane (com.ldtteam.blockout.Pane)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)4 WorkerBuildingModuleView (com.minecolonies.coremod.colony.buildings.moduleviews.WorkerBuildingModuleView)4 Map (java.util.Map)4 CompoundNBT (net.minecraft.nbt.CompoundNBT)4 ListNBT (net.minecraft.nbt.ListNBT)4 Tuple (net.minecraft.util.Tuple)4 NotNull (org.jetbrains.annotations.NotNull)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 TextBuilder (com.ldtteam.blockout.controls.AbstractTextBuilder.TextBuilder)2 Button (com.ldtteam.blockout.controls.Button)2 Image (com.ldtteam.blockout.controls.Image)2 ScrollingList (com.ldtteam.blockout.views.ScrollingList)2 ICitizenDataView (com.minecolonies.api.colony.ICitizenDataView)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)2 JobEntry (com.minecolonies.api.colony.jobs.registry.JobEntry)2 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)2