#include "data/scripts/library/spawn.h"

void keyshoot(void Shot, float dx, float dy, float dz, int Time)
{// Shoot projectile only when attack button is held
    void self = getlocalvar("self");
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    int TPhase = getentityvar(self, 0);

    if (playerkeys(iPIndex, 0, "attack") && !(playerkeys(iPIndex, 0, "attack2") ) ){
      if(TPhase != NULL() && TPhase <= openborvariant("elapsed_time") - 2*Time){
        setentityvar(self, 0, NULL());
        TPhase = NULL();
      }
      if (TPhase == NULL()){
        shoot(Shot, dx, dy, dz);
        setentityvar(self, 0, openborvariant("elapsed_time"));
      }
    }
}

void keymissile(void Shot, float dx, float dy, float Vx, float Vy, int Time)
{// Shoot projectile only when attack button is held
    void self = getlocalvar("self");
    int iPIndex = getentityproperty(self,"playerindex"); //Get player index
    int TPhase = getentityvar(self, 0);

    if (playerkeys(iPIndex, 0, "attack2") && !(playerkeys(iPIndex, 0, "attack") ) ){
      if(TPhase != NULL() && TPhase <= openborvariant("elapsed_time") - 2*Time){
        setentityvar(self, 0, NULL());
        TPhase = NULL();
      }
      if (TPhase == NULL()){
        shooter2(Shot, dx, dy, 0, Vx, Vy, 0);
        setentityvar(self, 0, openborvariant("elapsed_time"));
      }
    }
}

void beidle()
{// Go to IDLE animation!
    void self = getlocalvar("self");

    setidle(self, openborconstant("ANI_IDLE"));
}

void dasher( float Vx, float Vy, float Vz )
{// Dash with desired speed!
    void self = getlocalvar("self");
    int dir = getentityproperty(self,"direction");

    if(dir==0){ // Facing left?
      Vx = -Vx ;
    }

    changeentityproperty(self, "velocity", Vx, Vz, Vy); //Move!
}

void degravity(int Ratio)
{// Changes antigravity effect
    void self = getlocalvar("self");
    changeentityproperty(self, "antigravity", Ratio);
}
