#include "burstGun.hpp"
#include "../entity/bullet.hpp"
#include "../world.hpp"
#include <window.h>

namespace game::equipment {

BurstGun::BurstGun() noexcept: Weapon(0.04, 8, 25)
{
    this->remainShots = 3;
    this->fullReloadTime = 0;
};

void BurstGun::Update() noexcept
{
    if (this->reloadTime > 0) {
        this->reloadTime -= window::deltaTime;

        if (this->reloadTime <= 0) {

            if (!this->remainShots) {
                this->remainShots = 3;
            }

            this->reloadTime = 0;
        }
    }

    if (this->fullReloadTime > 0) {
        this->fullReloadTime -= window::deltaTime;

        if (this->fullReloadTime <= 0) {
            this->remainShots = 3;
            this->fullReloadTime = 0;
        }
    }
}

void BurstGun::Shoot(const vec2f &position, bool direction, World *world, bool forced) noexcept
{
    if (this->reloadTime > 0) {
        return;
    }

    this->remainShots--;

    this->fullReloadTime = this->cooldown * 5;

    if (!this->remainShots) {
        this->reloadTime = this->fullReloadTime;
    } else {
        this->reloadTime = this->cooldown;
    }

    float damage = this->damage;

    if (forced) {
        damage *= 2;
    }

    if (direction) {
        new entity::Bullet(world, position, this->bulletSpeed, 180, damage);
    } else {
        new entity::Bullet(world, position, this->bulletSpeed, 0, damage);
    }


}


}
