#include "nw_i0_plot"

void main() {
    DelayCommand(6.0, DestroyObject(OBJECT_SELF));

    object oPC = GetFirstPC();
    object oArea = GetArea(OBJECT_SELF);
    while (GetIsObjectValid(oPC)) {
        if (GetArea(oPC) == oArea) {
            int nBetOnBlack = GetLocalInt(oPC, "I_BET_ON_BLACK");

            if (nBetOnBlack > 0) {
                // Find the I_CAS_HANDLE item
                object oHandle = GetItemPossessedBy(oPC, "I_CAS_HANDLE");
                if (GetIsObjectValid(oHandle)) {
                    int nCurrentTickets = GetLocalInt(oHandle, "nCAS_TICKET");
                    int nRewardTickets = nBetOnBlack; // Calculation for the reward, modify as needed
                    SetLocalInt(oHandle, "nCAS_TICKET", nCurrentTickets + nRewardTickets);

                    SendMessageToPC(oPC, "Rewarding Tickets for Betting on BLACK: " + IntToString(nRewardTickets) + ". Total Tickets: " + IntToString(nCurrentTickets + nRewardTickets));
                }
                else {
                    SendMessageToPC(oPC, "No valid handle found for rewards.");
                }
            }

            DeleteLocalInt(oPC, "I_BET_ON_RED");
            DeleteLocalInt(oPC, "I_BET_ON_BLACK");
        }
        oPC = GetNextPC();
    }

    object oHandler = GetLocalObject(OBJECT_SELF, "HANDLER");
    ExecuteScript("cas_clear_arena", oHandler);
}
