void ApplyEffectAtWaypoint(string sWaypointTag, int nVFX)
{
    object oWaypoint = GetObjectByTag(sWaypointTag);
    if(GetIsObjectValid(oWaypoint))
    {
        location lWaypoint = GetLocation(oWaypoint);
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(nVFX), lWaypoint);
    }
}

void SpawnBoss()
{
    CreateObject(OBJECT_TYPE_CREATURE, "cas_chris_them", GetLocation(GetWaypointByTag("CAS_WP_THEOASIS")));
}


const int REQUIRED_SYMBOLS = 7;


void main()
{
    object oPlaceable = OBJECT_SELF;
    int nSymbolCount = 0;
   

    // Check each item in the placeable's inventory
    object oItem = GetFirstItemInInventory(oPlaceable);
    while(GetIsObjectValid(oItem))
    {
        if(GetLocalInt(oItem, "SYMBOLOFTHEM") == 1)
        {
            nSymbolCount++;
        }
        oItem = GetNextItemInInventory(oPlaceable);
    }

    if(nSymbolCount != REQUIRED_SYMBOLS)
    {
        // Not enough symbols, inform the player
        int nSymbolsNeeded = REQUIRED_SYMBOLS - nSymbolCount;
        SpeakString("The offerings are insufficient... bring forth " + IntToString(nSymbolsNeeded) + " more symbols of Them to prove thy devotion.");
    }
    else
    {
        // Remove all items
        oItem = GetFirstItemInInventory(oPlaceable);
        while(GetIsObjectValid(oItem))
        {
            DestroyObject(oItem);
            oItem = GetNextItemInInventory(oPlaceable);
        }

        // Apply VFX to waypoints
        ApplyEffectAtWaypoint("WP_CAS_VFX8", 1087);
        DelayCommand(1.0, ApplyEffectAtWaypoint("WP_CAS_VFX1", 1146));
        DelayCommand(2.0, ApplyEffectAtWaypoint("WP_CAS_VFX2", 1147));
        DelayCommand(3.0, ApplyEffectAtWaypoint("WP_CAS_VFX3", 1148));
        DelayCommand(4.0, ApplyEffectAtWaypoint("WP_CAS_VFX4", 1149));
        DelayCommand(5.0, ApplyEffectAtWaypoint("WP_CAS_VFX5", 1150));
        DelayCommand(6.0, ApplyEffectAtWaypoint("WP_CAS_VFX6", 1151));
        DelayCommand(7.0, ApplyEffectAtWaypoint("WP_CAS_VFX7", 1152));

        // Spawn the creature
        DelayCommand(8.0, SpawnBoss());
    }
}
