// TMW2 Script
// Author: Jesusalva
// Workers from Worker Day.

001-5,23,73,0	script	Soren	NPC_CONSTR_WORKER,{
    mesn;
    mesq l("You can get @@ anywhere, although here is a little easier to get.", getitemlink(Pearl));
    next;
    mesn;
    mesq l("You can trade them for quite nice items with my friend over there.");
    close;
}

001-5,75,69,0	script	Simon	NPC_CONSTR_WORKER,{
    function alreadyFinished;
    .@year=getq(SQuest_WorkerDay);
    .@day=getq3(SQuest_WorkerDay);
    if (.@year != gettime(GETTIME_YEAR)-2000 ||
        .@day != gettime(GETTIME_DAYOFMONTH))
            setq SQuest_WorkerDay,
                 gettime(GETTIME_YEAR)-2000, 0, gettime(GETTIME_DAYOFMONTH);

    // Main Loop
    do
    {
    .@attempts=getq2(SQuest_WorkerDay);
    if (.@attempts > BaseLevel/10)
        alreadyFinished();

    mesn;
    mesq l("Hey dude. During this event you can trade one @@ for more... useful items.", getitemlink(.Item));
    mesc l("Attempts for today: %d/%d", .@attempts, BaseLevel/10);
    if (countitem(.Item) == 0)
        close;
    next;
    select(
        l("12x Strange Coins"),
        l("2x Snake Egg"),
        l("2x Bronze Gift"),
        l("1600 GP"),
        rif(countitem(.Item) >= 2, l("Trade 2 %s for a Silver Gift + a Bronze Gift", getitemname(.Item))),
        l("Nothing right now.")
    );
    switch (@menu) {
        case 1:
            delitem .Item, 1;
            getitem StrangeCoin, 12;
            setq2 SQuest_WorkerDay, .@attempts+1;
            break;
        case 2:
            delitem .Item, 1;
            getitem SnakeEgg, 2;
            setq2 SQuest_WorkerDay, .@attempts+1;
            break;
        case 3:
            delitem .Item, 1;
            getitem BronzeGift, 2;
            setq2 SQuest_WorkerDay, .@attempts+1;
            break;
        case 4:
            delitem .Item, 1;
            Zeny=Zeny+1600;
            setq2 SQuest_WorkerDay, .@attempts+1;
            break;
        case 5:
            delitem .Item, 2;
            getitem SilverGift, 1;
            getitem BronzeGift, 1;
            setq2 SQuest_WorkerDay, .@attempts+1;
            break;

    }

    } while (@menu < 6);
    close;

function alreadyFinished {
    mesc l("I already got enough %s, thank you.", getitemlink(.Item)), 1;
    close;
}

OnInit:
    .Item=Pearl;
    .distance=4;
    end;
}