<commit_before>/*
 * Copyright 2017 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.Const;
import org.destinationsol.game.input.AiPilot;
import org.destinationsol.game.input.BeaconDestProvider;
import org.destinationsol.game.input.Pilot;
import org.destinationsol.game.input.UiControlledPilot;
import org.destinationsol.game.item.Gun;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.item.TradeConfig;
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.hulls.HullConfig;

class PlayerCreator {

    private static final int TUTORIAL_MONEY_AMOUNT = 200;
    private static final int SHIP_SPAWN_ANGLE = 0;
    private static final int SHIP_SPAWN_ROTATION_SPEED = 0;
    private static final boolean SHIP_SPAWN_HAS_REPAIRER = true;
    private static final int NUMBER_OF_TUTORIAL_ITEM_ADD_ATTEMPTS = 50;
    private static final float MAX_NUMBER_OF_TUTORIAL_ITEM_GROUPS = 1.5f * Const.ITEM_GROUPS_PER_PAGE;

    Hero createPlayer(ShipConfig shipConfig, boolean shouldSpawnOnGalaxySpawnPosition, RespawnState respawnState, SolGame game, boolean isMouseControl, boolean isNewShip) {
        // If we continue a game, we should spawn from the same position
        Vector2 position = findPlayerSpawnPosition(shipConfig, shouldSpawnOnGalaxySpawnPosition, game);
        game.getCam().setPos(position);

        if (isMouseControl) {
            game.getBeaconHandler().init(game, position);
        }
        Pilot pilot = createPilot(game, isMouseControl);

        float money = grantPlayerMoney(shipConfig, respawnState, game);

        HullConfig hull = findHullConfig(shipConfig, respawnState);

        String items = findItems(shipConfig, respawnState);

        boolean giveAmmo = shouldGiveAmmo(respawnState, isNewShip);
        Hero hero = createHero(position, pilot, money, hull, items, giveAmmo, game);
        addAndEquipItems(hero, respawnState, game);

        // Don't change equipped items across load/respawn
        //AiPilot.reEquip(this, myHero);

        game.getObjectManager().addObjDelayed(hero.getShip());
        game.getObjectManager().resetDelays();
        return hero;
    }

    private void addAndEquipItems(Hero hero, RespawnState respawnState, SolGame game) {
        ItemContainer itemContainer = hero.getItemContainer();
        if (!respawnState.getRespawnItems().isEmpty()) {
            addAndEquipRespawnItems(hero, respawnState, itemContainer, game);
        } else if (game.getTutMan() != null) {<commit_msg>Cleanup and extract hero configuration with creation<commit_after>/*
 * Copyright 2017 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.Const;
import org.destinationsol.game.input.AiPilot;
import org.destinationsol.game.input.BeaconDestProvider;
import org.destinationsol.game.input.Pilot;
import org.destinationsol.game.input.UiControlledPilot;
import org.destinationsol.game.item.Gun;
import org.destinationsol.game.item.ItemContainer;
import org.destinationsol.game.item.SolItem;
import org.destinationsol.game.item.TradeConfig;
import org.destinationsol.game.ship.FarShip;
import org.destinationsol.game.ship.hulls.HullConfig;

class PlayerCreator {

    private static final int TUTORIAL_MONEY_AMOUNT = 200;
    private static final int SHIP_SPAWN_ANGLE = 0;
    private static final int SHIP_SPAWN_ROTATION_SPEED = 0;
    private static final boolean SHIP_SPAWN_HAS_REPAIRER = true;
    private static final int NUMBER_OF_TUTORIAL_ITEM_ADD_ATTEMPTS = 50;
    private static final float MAX_NUMBER_OF_TUTORIAL_ITEM_GROUPS = 1.5f * Const.ITEM_GROUPS_PER_PAGE;

    Hero createPlayer(ShipConfig shipConfig, boolean shouldSpawnOnGalaxySpawnPosition, RespawnState respawnState, SolGame game, boolean isMouseControl, boolean isNewShip) {
        Vector2 position = findPlayerSpawnPosition(shipConfig, shouldSpawnOnGalaxySpawnPosition, game);
        game.getCam().setPos(position);
        if (isMouseControl) {
            game.getBeaconHandler().init(game, position);
        }
        Hero hero = configureAndCreateHero(shipConfig, respawnState, game, isMouseControl, isNewShip, position);
        game.getObjectManager().addObjDelayed(hero.getShip());
        game.getObjectManager().resetDelays();
        return hero;
    }

    private Hero configureAndCreateHero(ShipConfig shipConfig, RespawnState respawnState, SolGame game, boolean isMouseControl, boolean isNewShip, Vector2 position) {
        Pilot pilot = createPilot(game, isMouseControl);
        float money = grantPlayerMoney(shipConfig, respawnState, game);
        HullConfig hull = findHullConfig(shipConfig, respawnState);
        String items = findItems(shipConfig, respawnState);
        boolean giveAmmo = shouldGiveAmmo(respawnState, isNewShip);
        Hero hero = createHero(position, pilot, money, hull, items, giveAmmo, game);
        addAndEquipItems(hero, respawnState, game);
        return hero;
    }

    private void addAndEquipItems(Hero hero, RespawnState respawnState, SolGame game) {
        ItemContainer itemContainer = hero.getItemContainer();
        if (!respawnState.getRespawnItems().isEmpty()) {
            addAndEquipRespawnItems(hero, respawnState, itemContainer, game);
        } else if (game.getTutMan() != null) {
{'fraction_non_alphanumeric': 0.0817108692319485, 'fraction_numerical': 0.005978844090142573, 'mean_word_length': 4.227564102564102, 'pattern_counts': {'":': 0, '<': 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': '1371697', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1916, 'n_words': 506}