<commit_before>/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.destinationsol.game;

import com.badlogic.gdx.math.Vector2;
import org.destinationsol.GameOptions;
import org.destinationsol.assets.audio.OggMusicManager;
import org.destinationsol.common.SolException;
import org.destinationsol.game.console.commands.PositionCommandHandler;
import org.destinationsol.game.input.Pilot;
import org.destinationsol.game.item.Armor;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.Shield;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.ShipAbility;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.game.ship.hulls.Hull;

/**
 * A wrapper class for the Hero, that handles the normal and transcendent ships transparently.
 */
public class Hero {
    private SolShip shipHero;
    private StarPort.Transcendent transcendentHero;
    private ItemContainer mercs;
    private FarShip transcendentHeroShip;
    private boolean isTranscendent;
    private boolean isDead;

    public Hero(SolShip shipHero, SolGame solGame) {
        if (shipHero == null) {
            throw new SolException("Something is trying to create the hero when there is no ship linked to him.");
        }
        setSolShip(shipHero, solGame);
    }

    public void initialise() {
        if (!Console.getInstance().getDefaultInputHandler().commandExists("position")) {
            Console.getInstance().getDefaultInputHandler().registerCommand("position", new PositionCommandHandler(this));
        } else {
            ((PositionCommandHandler) Console.getInstance().getDefaultInputHandler().getRegisteredCommand("position")).hero = this;
        }
    }

    public void setTranscendent(StarPort.Transcendent transcendentHero) {
        this.transcendentHero = transcendentHero;
        transcendentHeroShip = transcendentHero.getShip();
        isTranscendent = true;
    }

    public void setSolShip(SolShip hero, SolGame solGame) {
        isDead = false;
        if (hero != shipHero) {
            mercs = new ItemContainer();
        }
        this.shipHero = hero;
        isTranscendent = false;
        if (shipHero.getTradeContainer() != null) {
            throw new SolException("Hero is not supposed to have TradeContainer.");
        }
        GameOptions options = solGame.getSolApplication().getOptions();
        solGame.getSolApplication().getMusicManager().registerModuleMusic(hero.getHull().getHullConfig().getInternalName().split(":")[0], options);
        solGame.getSolApplication().getMusicManager().playMusic(OggMusicManager.GAME_MUSIC_SET, options);
    }

    public boolean isTranscendent() {
        return isTranscendent;
    }

    public boolean isNonTranscendent() {
        return !isTranscendent;
    }

    public Pilot getPilot() {
        return isTranscendent ? transcendentHeroShip.getPilot() : shipHero.getPilot();
    }

    public SolShip getShip() {
        if (isTranscendent) {
            throw new SolException("Something is trying to get a SolShip hero while the hero is in Transcendent state.");
        }
        return shipHero;
    }

    public SolShip getShipUnchecked() {
        return shipHero;
    }

    public StarPort.Transcendent getTranscendentHero() {
        if (!isTranscendent) {<commit_msg>Trying to fix unit test<commit_after>/*
 * Copyright 2018 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.destinationsol.game;

import com.badlogic.gdx.math.Vector2;
import org.destinationsol.GameOptions;
import org.destinationsol.assets.audio.OggMusicManager;
import org.destinationsol.common.SolException;
import org.destinationsol.game.console.commands.PositionCommandHandler;
import org.destinationsol.game.input.Pilot;
import org.destinationsol.game.item.Armor;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.Shield;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.ShipAbility;
import org.destinationsol.game.ship.SolShip;
import org.destinationsol.game.ship.hulls.Hull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A wrapper class for the Hero, that handles the normal and transcendent ships transparently.
 */
public class Hero {
    private SolShip shipHero;
    private StarPort.Transcendent transcendentHero;
    private ItemContainer mercs;
    private FarShip transcendentHeroShip;
    private boolean isTranscendent;
    private boolean isDead;

    public Hero(SolShip shipHero, SolGame solGame) {
        if (shipHero == null) {
            throw new SolException("Something is trying to create the hero when there is no ship linked to him.");
        }
        setSolShip(shipHero, solGame);
    }

    public void initialise() {
        if (!Console.getInstance().getDefaultInputHandler().commandExists("position")) {
            Console.getInstance().getDefaultInputHandler().registerCommand("position", new PositionCommandHandler(this));
        } else {
            ((PositionCommandHandler) Console.getInstance().getDefaultInputHandler().getRegisteredCommand("position")).hero = this;
        }
    }

    public void setTranscendent(StarPort.Transcendent transcendentHero) {
        this.transcendentHero = transcendentHero;
        transcendentHeroShip = transcendentHero.getShip();
        isTranscendent = true;
    }

    public void setSolShip(SolShip hero, SolGame solGame) {
        isDead = false;
        if (hero != shipHero) {
            mercs = new ItemContainer();
        }
        this.shipHero = hero;
        isTranscendent = false;
        if (shipHero.getTradeContainer() != null) {
            throw new SolException("Hero is not supposed to have TradeContainer.");
        }
        GameOptions options = solGame.getSolApplication().getOptions();
        //Satisfying unit tests
        if(hero.getHull().getHullConfig().getInternalName() != null)
            solGame.getSolApplication().getMusicManager().registerModuleMusic(hero.getHull().getHullConfig().getInternalName().split(":")[0], options);
        solGame.getSolApplication().getMusicManager().playMusic(OggMusicManager.GAME_MUSIC_SET, options);
    }

    public boolean isTranscendent() {
        return isTranscendent;
    }

    public boolean isNonTranscendent() {
        return !isTranscendent;
    }

    public Pilot getPilot() {
        return isTranscendent ? transcendentHeroShip.getPilot() : shipHero.getPilot();
    }

    public SolShip getShip() {
        if (isTranscendent) {
            throw new SolException("Something is trying to get a SolShip hero while the hero is in Transcendent state.");
        }
        return shipHero;
    }

    public SolShip getShipUnchecked() {
        return shipHero;
    }

    public StarPort.Transcendent getTranscendentHero() {
        if (!isTranscendent) {
{'fraction_non_alphanumeric': 0.09232494393222028, 'fraction_numerical': 0.00274109145277847, 'mean_word_length': 3.4644048943270302, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2887282', 'n_tokens_mistral': 2257, 'n_tokens_neox': 2232, 'n_words': 581}