#pragma once

#include <common/items/all.qh>
#include <common/mutators/mutator/powerups/powerups.qh>
#ifdef SVQC
    // For FL_POWERUP
    #include <common/constants.qh>
    #include <server/items/items.qh>
#endif

#ifdef GAMEQC
MODEL(Shield_ITEM, Item_Model("g_invincible.md3"));
SOUND(Shield, Item_Sound("powerup_shield"));
#endif

#ifdef SVQC
bool autocvar_g_powerups_shield;
float autocvar_g_balance_powerup_invincible_takedamage;
float autocvar_g_balance_powerup_invincible_takeforce;
float autocvar_g_balance_powerup_invincible_time;
void powerup_shield_init(Pickup def, entity item)
{
    if(!autocvar_g_powerups || !autocvar_g_powerups_shield)
        def.spawnflags |= ITEM_FLAG_MUTATORBLOCKED;

    if(!item.invincible_finished)
        item.invincible_finished = (item.count) ? item.count : autocvar_g_balance_powerup_invincible_time;
}
#endif

CLASS(ShieldItem, Powerup)
    ATTRIB(ShieldItem, m_canonical_spawnfunc, string, "item_shield");
#ifdef SVQC
    ATTRIB(ShieldItem, m_iteminit, void(Pickup def, entity item), powerup_shield_init);
#endif
#ifdef GAMEQC
    ATTRIB(ShieldItem, spawnflags, int, ITEM_FLAG_NORMAL);
    ATTRIB(ShieldItem, m_itemid, int, IT_INVINCIBLE);
    ATTRIB(ShieldItem, m_model, Model, MDL_Shield_ITEM);
    ATTRIB(ShieldItem, m_sound, Sound, SND_Shield);
    ATTRIB(ShieldItem, m_glow, bool, true);
    ATTRIB(ShieldItem, m_respawnsound, Sound, SND_SHIELD_RESPAWN);
#endif
    ATTRIB(ShieldItem, netname, string, "invincible");
    ATTRIB(ShieldItem, m_name, string, _("Shield"));
    ATTRIB(ShieldItem, m_icon, string, "shield");
    ATTRIB(ShieldItem, m_color, vector, '1 0 1');
    ATTRIB(ShieldItem, m_waypoint, string, _("Shield"));
    ATTRIB(ShieldItem, m_waypointblink, int, 2);
ENDCLASS(ShieldItem)
REGISTER_ITEM(Shield, NEW(ShieldItem));

SPAWNFUNC_ITEM(item_shield, ITEM_Shield)
SPAWNFUNC_ITEM(item_invincible, ITEM_Shield)

CLASS(ShieldStatusEffect, PowerupStatusEffect)
	ATTRIB(ShieldStatusEffect, netname, string, "invincible"); // NOTE: referring to as invincible so that it matches the powerup item
	ATTRIB(ShieldStatusEffect, m_name, string, _("Shield"));
	ATTRIB(ShieldStatusEffect, m_icon, string, "shield");
ENDCLASS(ShieldStatusEffect)
REGISTER_STATUSEFFECT(Shield, NEW(ShieldStatusEffect));
