#include "xstp_inc_jump"
//#include "jump_include"

int CheckValidErf(string sPrefix)
{
    if (sPrefix == "cac" ||
        sPrefix == "hvh" || 
        sPrefix == "mds" || 
        sPrefix == "poe" ||
        sPrefix == "scd" ||
        sPrefix == "ggd" ||
        sPrefix == "bhm")
    {
        return FALSE;
    }
    
    return TRUE;
}

// Function to check if the target is on the hardcoded list of allowed players
int TargetIsOnList(object oTarget)
{
    // Get the username of the target player
    string sPlayerName = GetName(oTarget);

    // Hardcoded list of usernames
    if (sPlayerName == "Renzokuken" ||
        sPlayerName == "XCRs Bitch" ||
       // sPlayerName == "PlayerName3" ||
    //    sPlayerName == "AnotherName")
    {
        return TRUE; // The target is on the list
    }

    return FALSE; // The target is not on the list
}

// Main function for the jump functionality
void main()
{
    object oItem = GetEventParamObject(0);
    object oTarget = GetEventParamObject(1);
    object oUser = GetEventParamObject(2);
    
    // Retrieve the area object where the user is located
    object oArea = GetArea(oUser);

    // Check if XS_NO_JUMP_TOOL is set in this area
    int nNoJumpTool = GetLocalInt(oArea, "XS_NO_JUMP_TOOL");
    if (nNoJumpTool == 1)
    {
        SendMessageToPC(oUser, "The jump tool cannot be used in this area.");
        return;
    }
    
    // Check if the area is from a valid ERF
    string sPrefix = GetResRefErfPrefix(GetResRef(oArea));
    if (!CheckValidErf(sPrefix))
    {
        SendMessageToPC(oUser, "Jumpers can't be used in epic dungeons!");
        return;
    }

    // Check if the target is on the hardcoded list
    if (!TargetIsOnList(oTarget))
    {
        SendMessageToPC(oUser, "The target player is not on the allowed list.");
        return;
    }

    // Check distance between user and target
    if (GetDistanceBetween(oUser, oTarget) > 20.0)
    {
        SendMessageToPC(oUser, "The target is too far away.");
        return;
    }

    // Apply visual effects
    effect eBeam = EffectBeam(VFX_BEAM_CHAIN, oUser, BODY_NODE_CHEST);
    effect eEntangleVFX = EffectVisualEffect(VFX_DUR_ENTANGLE);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBeam, oTarget, 24.0);
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eEntangleVFX, oTarget, 24.0);

    // Immobilize the target
    effect eImmobilize = EffectCutsceneDominated();
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eImmobilize, oTarget, 24.0);

    // Command the target to speak
    AssignCommand(oTarget, ActionSpeakString("[The target is wrapped in rope and being dragged towards the Slut Snatcher's user!]"));

    // Schedule the jump after the immobilization effect has ended
    ActionJumpToObject(oUser);
}
