#include "Mover.h"

#include "../../Neuz.h"

namespace flyff {
    uint64_t Mover::Buff::get_time_remaining() const {
        const auto &neuz = Neuz::instance();

        if (time_instantiated == 0)
            return 0;

        auto elapsed =
                (neuz.maybe_login_time +
                 ((neuz.current_time + time_instantiated * -1000) - neuz.start_time)) /
                1000;

        if (elapsed <= time_total) {
            return time_total - elapsed;
        }

        return 0;
    }

    bool Mover::is_in_combat(uint32_t millis) const {
        const auto &neuz = flyff::Neuz::instance();
        // 10 seconds
        return neuz.current_time - last_combat < (millis * 1000);
    }

    static const Mover::ParameterValue PARAMETER_HASH = 0x41c64e6d;

    Mover::ParameterValue Mover::get_change_param(ParamID index) const {
        static const Mover::ParameterValue CHANGED_STAT_HASH = 0x7af81861U;
        auto id = static_cast<uint32_t>(index);

        return changed_parameters[id] ^ adj_param ^ id * PARAMETER_HASH + CHANGED_STAT_HASH;
    }

    Mover::ParameterValue Mover::get_adjust_param(ParamID index) const {
        static const Mover::ParameterValue ADJUSTED_STAT_HASH = 0x471b3592U;
        auto id = static_cast<uint32_t>(index);
        // Find these values in CMover::Init
        return adjusted_parameters[id] ^ adj_param ^ id * PARAMETER_HASH + ADJUSTED_STAT_HASH;
    }
};  // namespace flyff