//
// Created by Dan Crosby on 5/17/20.
//

#include "MeteorStartCommandFactory.hpp"

#include "src/main/cpp/net/eagle0/shardok/library/commands/MeteorStartCommand.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/util/MeteorRangeCoords.hpp"

namespace shardok {

auto MeteorStartCommandFactory::AddAvailableMeteorStartCommands(
        CommandList &existingCommands,
        const Unit *unit,
        const ActionPoints remainingActionPoints,
        const HexMap *map,
        const Coords &currentPosition) const -> void {
    if (!unit->has_attached_hero()) return;
    if (unit->attached_hero().profession_info().profession() !=
        net::eagle0::shardok::storage::fb::Profession_MAGE)
        return;
    if (unit->attached_hero().vigor() < settings.Backing().minimum_vigor_for_meteor()) return;
    if (unit->attached_hero().profession_info().meteor_cast_state() !=
        net::eagle0::shardok::storage::fb::MultiroundMagicState_NONE)
        return;
    if (!settings.GetBattalionType(unit->battalion().type())->allowsCasting) return;
    if (!settings.ActionCostFor(settings.Backing().meteor_start_action_point_cost())
                 .IsPossible(remainingActionPoints))
        return;

    existingCommands.emplace_back(std::make_shared<MeteorStartCommand>(
            settings.ActionCostFor(settings.Backing().meteor_start_action_point_cost()),
            settings,
            unit->player_id(),
            unit->unit_id(),
            CoordsInMeteorRange(map, currentPosition, settings)));
}
void MeteorStartCommandFactory::AddAvailableCommands(
        CommandList &commands,
        const CommandFactory::CommandParams &params) const {
    AddAvailableMeteorStartCommands(
            commands,
            params.unit,
            params.remainingActionPoints,
            params.hexMap,
            params.position);
}

}  // namespace shardok
