#include "channel_include"
#include "cas_casinoinc"

// Forward declare if compiled separately.
void LogPotentialAbuse(object oPC, int nCost, int nTokens, int nTokensPurchased, int nTokensSpent, string sGameName);

const float COOLDOWN_SECONDS = 3600.0f; // 2 hours
const string LOC_COOLDOWN = "CAS_SEX_ANNOUNCE_COOLDOWN";

void main()
{
    object oPC = GetLastUsedBy();
    if (!GetIsObjectValid(oPC) || !GetIsPC(oPC)) return;

    // Cooldown check on the placeable itself
    if (GetLocalInt(OBJECT_SELF, LOC_COOLDOWN) == 1)
    {
        SendMessageToPC(oPC, "This announcer is cooling down. Try again later.");
        return;
    }

    // Find the nearest LISTENER to the USER
    object oListener = GetNearestObjectByTag("C_CAS_GLORYLISTEN", oPC, 1);
    if (!GetIsObjectValid(oListener) || GetObjectType(oListener) != OBJECT_TYPE_CREATURE)
    {
        SendMessageToPC(oPC, "No listener is available to send the announcement.");
        return;
    }

    string sMsg = "Someone has entered the gloryhole at the Casino of Coins.";

    // Local broadcast anonymously (no chat source shown)
    BroadcasteMessageToCustomPublicChannel(
        oListener,
        sMsg,
        CHANNEL_CUSTOM_PUBLIC_SEX,
        TRUE // anonymous
    );

    // Cross-server relay using the listener as source (anonymous across servers if supported)
    BroadcastPublicChatMessageOnOtherServers(
        oListener,
        sMsg,
        CHANNEL_CUSTOM_PUBLIC_SEX
    );

    // Staff log: who triggered it
    LogPotentialAbuse(oPC, 0, 0, 0, 0, "ANNOUNCER_SEX_LISTENER");

    // Optional feedback + cooldown
    SendMessageToPC(oPC, "Announcement sent anonymously. Cooldown started. You can only ping once every hour.");
    SetLocalInt(OBJECT_SELF, LOC_COOLDOWN, 1);
    DelayCommand(COOLDOWN_SECONDS, DeleteLocalInt(OBJECT_SELF, LOC_COOLDOWN));
}
