#include "../H/player.h"

Mob::Mob(){}

Mob::Mob(const Vector3f & position, float Damage, int Armour) : m_pos(position), m_damage(Damage), m_armour(Armour)
{
    m_health = 100.f * Armour;
}

void Mob::SetPosition (Vector3f delta){
    m_pos.x = delta.x;
    m_pos.y = delta.y;
    m_pos.z = delta.z;
}

void Mob::Move(Player p1){
    double speed = 0.1;
    Vector3f p1pos = p1.Position();
    if (p1pos.x >= m_pos.x){
        m_pos.x += speed;
    }
    if (p1pos.x < m_pos.x){
        m_pos.x -= speed;
    }
    if (p1pos.y >= m_pos.y){
        m_pos.y += speed;
    }
    if (p1pos.y < m_pos.y){
        m_pos.y -= speed;
    }
    if (p1pos.z >= m_pos.z){
        m_pos.z += speed;
    }
    if (p1pos.z < m_pos.z){
        m_pos.z -= speed;
    }
}

Vector3f Mob::Position(){
    return m_pos;
}

void Mob::Damage(Player& p1){
    p1.setHealth(p1.Health() - m_damage);
}

float Mob::GetDamage(){
    return m_damage;
}

float Mob::Health(){
    return m_health;
}

void Mob::setHealth(float health){
    m_health = health;
}

void Mob::RenderMob()
{
    //around1
    glBegin(GL_TRIANGLES);
        glNormal3f(0, 1, 0);
        
        glTexCoord2f(0, 0);
        glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);

        glTexCoord2f(1, 0);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);

        glTexCoord2f(1, 1);
        glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);
    glEnd();
    
    //around2
    glBegin(GL_TRIANGLES);
        glNormal3f(0, 1, 0);
        
        glTexCoord2f(0, 0);
        glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);

        glTexCoord2f(1, 0);
        glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);

        glTexCoord2f(1, 1);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);
    glEnd();

    //around3
    glBegin(GL_TRIANGLES);
        glNormal3f(0, 1, 0);
        
        glTexCoord2f(0, 0);
        glVertex3f(m_pos.x, m_pos.y + .5f, m_pos.z);

        glTexCoord2f(1, 0);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);

        glTexCoord2f(1, 1);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);
    glEnd();

    //bottom 
    glBegin(GL_TRIANGLES);
        glNormal3f(0, -1, 0);
        
        glTexCoord2f(0, 0);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z - .5f);

        glTexCoord2f(1, 0);
        glVertex3f(m_pos.x - .5f, m_pos.y - .5f, m_pos.z + .5f);

        glTexCoord2f(1, 1);
        glVertex3f(m_pos.x + .5f, m_pos.y - .5f, m_pos.z + .5f);
    glEnd();
}

bool Mob::isNull(){
    if (m_pos.x == 0 && m_pos.y == 0 && m_pos.z == 0 && m_damage == 0 && m_armour == 0)
        return true;
    return false;
}

int Mob::GetArmour(){
    return m_armour;
}

bool Mob::isEqual(Mob mob){
    Vector3f v = mob.Position();
    if (m_pos.x == v.x && m_pos.y == v.y && m_pos.z == v.z && m_damage == mob.GetDamage() && m_armour == mob.GetArmour())
        return true;
    return false;
}