<commit_before>package io.luna.game.model.mob;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import io.luna.LunaContext;
import io.luna.game.model.EntityType;
import io.luna.game.model.Position;
import io.luna.game.model.def.NpcCombatDefinition;
import io.luna.game.model.def.NpcDefinition;
import io.luna.game.model.mob.block.UpdateFlagSet.UpdateFlag;

import java.util.Optional;

/**
 * A model representing a non-player-controlled mob.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class Npc extends Mob {

    /**
     * The base identifier. The one the class was created with.
     */
    private final int id;

    /**
     * The definition.
     */
    private NpcDefinition definition;

    /**
     * The combat definition.
     */
    private Optional<NpcCombatDefinition> combatDefinition;

    /**
     * The transformation identifier.
     */
    private Optional<Integer> transformId = Optional.empty();

    /**
     * Creates a new {@link Npc}.
     *
     * @param context The context instance.
     * @param id The identifier.
     * @param position The position.
     */
    public Npc(LunaContext context, int id, Position position) {
        super(context, EntityType.NPC);
        this.id = id; // Base identifier, for resetting transformations.

        // Set definition values.
        definition = NpcDefinition.ALL.retrieve(id);
        combatDefinition = NpcCombatDefinition.ALL.get(id);

        // Set skill levels.
        setSkills();

        // Set position.
        setPosition(position);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).
                add("index", getIndex()).
                add("name", definition.getName()).
                add("id", getId()).toString();
    }


    @Override
    public int size() {
        return definition.getSize();
    }

    @Override
    public void reset() {
        transformId = Optional.empty();
    }

    @Override
    public int getCombatLevel() {
        return combatDefinition.map(NpcCombatDefinition::getLevel).orElse(0);
    }

    @Override
    public int getTotalHealth() {
        return combatDefinition.map(NpcCombatDefinition::getHitpoints).orElse(0);
    }

    @Override
    public void transform(int id) {
        definition = NpcDefinition.ALL.retrieve(id);
        combatDefinition = NpcCombatDefinition.ALL.get(id);
        transformId = Optional.of(id);
        setSkills();
        updateFlags.flag(UpdateFlag.TRANSFORM);
    }

    @Override
    public void resetTransform() {<commit_msg>Ensure that NPCs with no health have it set to -1.<commit_after>package io.luna.game.model.mob;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import io.luna.LunaContext;
import io.luna.game.model.EntityType;
import io.luna.game.model.Position;
import io.luna.game.model.def.NpcCombatDefinition;
import io.luna.game.model.def.NpcDefinition;
import io.luna.game.model.mob.block.UpdateFlagSet.UpdateFlag;

import java.util.Optional;

/**
 * A model representing a non-player-controlled mob.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class Npc extends Mob {

    /**
     * The base identifier. The one the class was created with.
     */
    private final int id;

    /**
     * The definition.
     */
    private NpcDefinition definition;

    /**
     * The combat definition.
     */
    private Optional<NpcCombatDefinition> combatDefinition;

    /**
     * The transformation identifier.
     */
    private Optional<Integer> transformId = Optional.empty();

    /**
     * Creates a new {@link Npc}.
     *
     * @param context The context instance.
     * @param id The identifier.
     * @param position The position.
     */
    public Npc(LunaContext context, int id, Position position) {
        super(context, EntityType.NPC);
        this.id = id; // Base identifier, for resetting transformations.

        // Set definition values.
        definition = NpcDefinition.ALL.retrieve(id);
        combatDefinition = NpcCombatDefinition.ALL.get(id);

        // Set skill levels.
        setSkills();

        // Set position.
        setPosition(position);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).
                add("index", getIndex()).
                add("name", definition.getName()).
                add("id", getId()).toString();
    }


    @Override
    public int size() {
        return definition.getSize();
    }

    @Override
    public void reset() {
        transformId = Optional.empty();
    }

    @Override
    public int getCombatLevel() {
        return combatDefinition.map(NpcCombatDefinition::getLevel).orElse(0);
    }

    @Override
    public int getTotalHealth() {
        return combatDefinition.map(NpcCombatDefinition::getHitpoints).orElse(-1);
    }

    @Override
    public void transform(int id) {
        definition = NpcDefinition.ALL.retrieve(id);
        combatDefinition = NpcCombatDefinition.ALL.get(id);
        transformId = Optional.of(id);
        setSkills();
        updateFlags.flag(UpdateFlag.TRANSFORM);
    }

    @Override
    public void resetTransform() {
{'fraction_non_alphanumeric': 0.11370539104024298, 'fraction_numerical': 0.0024677296886864084, 'mean_word_length': 2.5126666666666666, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264948', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1490, 'n_words': 346}