#include "Player/RealPlayer.h"

#include <Battle/Attack.h>
#include <Battle/BattleField.h>
#include <Battle/Defense.h>
#include <Battle/Escape.h>
#include <Ship/Ship.h>

#include <iostream>

std::random_device RealPlayer::_rd{};

RealPlayer::RealPlayer(const std::string& name, std::unique_ptr<Ship>&& ship)
    : _name(name), _ship(std::move(ship)) {}

int RealPlayer::attack(Ship& playerShip) {
    std::uniform_int_distribution<int> dice(0, 20);
    const int res = dice(_seed);
    int input = 0;
    int damage = 0;
    std::cout << "Choose Ammo: 1) Round Shot 2) Chain Shot 3) Grape Shot: ";
    std::cin >> input;

    if (input == 1 && res > 4) {
        damage = 50;
    } else if (input == 2 && res > 7) {
        damage = 80;
    } else if (input == 3 && res > 10) {
        damage = 100;
    } else {
        return 0;
    }

    playerShip.takeDamage(damage);
    return damage;
}

Ship* RealPlayer::chooseEnemyShip(const BattleField& battleField) const {
    // To simplify palyer and enemy has one ship
    return battleField.getEnemyShip();
}

std::unique_ptr<Action> RealPlayer::chooseAction(const BattleField& battleField) const {
    int input = 0;
    std::cout << "Choose Action: 1) Attack 2) Defense 3) Escape: ";
    std::cin >> input;

    if (input == 1) {
        return std::make_unique<Attack>();
    }
    if (input == 3) {
        return std::make_unique<Escape>();
    }

    return std::make_unique<Defense>();
}
