// cas_fishstart.nss
#include "cas_fishinc"

void main()
{
    object oPC = GetLastUsedBy();

    if (!GetIsPC(oPC) || GetIsDM(oPC))
        return;

    object oToken = GetItemPossessedBy(oPC, TOKEN_TAG);
    if (!GetIsObjectValid(oToken))
    {
        SendMessageToPC(oPC, "You need a casino token to play.");
        return;
    }

    int nDifficulty = GetLocalInt(oToken, VAR_DIFFICULTY);
    if (nDifficulty < 1 || nDifficulty > 3)
    {
        SendMessageToPC(oPC, "You must set a difficulty before playing.");
        return;
    }

    if (GetLocalInt(oPC, "MATH_GAME_ACTIVE"))
    {
        SendMessageToPC(oPC, "Game already running. Use the spear on your fish.");
        return;
    }

    // Start game state
    int nTarget = Random(100);
       SetLocalInt(oPC, "MATH_GAME_TARGET", nTarget);
    SetLocalInt(oPC, "MATH_GAME_CURRENT", 0);
    SetLocalInt(oPC, "MATH_GAME_ACTIVE", 1);

    // Track what started the game (so spear-on-table cancels)
    CasFish_SetGameStarter(oPC, OBJECT_SELF);

    // 90 second time limit
    DelayCommand(GAME_DURATION_SECONDS, CasFish_Timeout(oPC));


    // Give spear + hook event
    CasFish_GiveAndRegisterSpear(oPC);

    // Spawn initial fish
    int i;
    for (i = 0; i < DESIRED_FISH_COUNT; i++)
    {
        CasFish_SpawnFishForPlayer(oPC);
    }
}
