//
// Created by main on 21-10-22.
//

#ifndef FUGG_ACTION_H
#define FUGG_ACTION_H

#include "../Client.h"

namespace fugg {
    class Action {

    public:
        enum class State : unsigned char {
            Running,
            Failed,
            Succeeded
        };

        virtual State evaluate(Client &client) = 0;
    };

    class StatefulAction : Action {
        virtual State start() = 0;
        virtual State run() = 0;
        virtual State stop() = 0;
    };


    class ActionAttack : Action {
        const flyff::MoverID target_id;

    public:
        explicit ActionAttack(flyff::MoverID id) : target_id(id) { }

        State evaluate(Client &client) override {
            const auto& target = client.get_mover(target_id);

            if(!target) return State::Failed;

            if(client.player->selected_target != target_id) {
                client.player->selected_target = target_id;
                client.send_set_target(target_id);
            }

            if(client.player->move_toward_target != target_id) {
                client.player->move_toward_target = target_id;
                client.send_interact_target(1);
            }

            return State::Succeeded;
        };
    };
};


#endif //FUGG_ACTION_H
