summaryrefslogtreecommitdiff
path: root/npc/boss/manamarket.txt
blob: c3c5bc219091bdd1e64f10ca211daf31ae834723 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// TMW2 Scripts.
// Author:
//  Jesusalva
// Description:
//  ManaMarket sketch

boss,41,41,0	script	ManaMarket	NPC_TEDDYGIRL,{
    function MMCooldown;
    function MMBuy;
    function MMBuyMenu;

    if (!is_staff()) end;
    mesn;
    mesq l("Hello! How can I help you?");
    if (MM_DELAY > gettimetick(2)) close;
    next;
    select
        l("Buy"),
        l("Sell"),
        l("Nothing");
    mes "";
    if (@menu == 1)
        MMBuy();
    close;


// Set the cooldown value to the same as interserver value
function MMCooldown {
    MM_DELAY=gettimetick(2)+300;
    return;
}

// MMBuy(page=0)
function MMBuy {
    .@p=getarg(0,0);
    .@v=MMBuyMenu(.@p);

    // Special results
    switch (.@v) {
        case -1:
            return;
        case -2:
            // FIXME
            MMBuy(.@p+1);
            break;
        default:
            break;
    }

    .@it=$@MM_nameid[.@v];
    // Can't buy stuff you already have
    if (countitem(.@it)) {
        mesn;
        mesq l("You already have this.");
        return;
    }


    // Report
    mesn;
    mesq l("Purchase %02d %s for %d GP?",
            $@MM_amount[.@v], getitemlink(.@it), $@MM_price[.@v]);
    next;
    if (askyesno() == ASK_YES) {
        // TODO: Check if still in stock
        mesn;
        mesq l("Sorry. The arrays can't have zeros.");
        // getitem2
    }
    return;
}

// MMBuyMenu ( page=0 )
function MMBuyMenu {
    deletearray @mm_menu$;
    setarray @mm_menu$, l("Cancel"), "-1";
    .@pg=getarg(0, 0);
    .@limit=min(getarraysize($@MM_id), (.@pg+1)*20);

    // Prepare the information array
    for (.@i=.@pg*20; .@i < .@limit; .@i++) {
        //@mm_menu$+=getitemname($@MM_nameid[.@i])+":";
        array_push(@mm_menu$, getitemname($@MM_nameid[.@i]));
        array_push(@mm_menu$, str(.@i));
    }

    // Still more pages
    if (.@limit < getarraysize($@MM_id)) {
        array_push(@mm_menu$, "Next Page >>");
        array_push(@mm_menu$, "-2");
    }

    // Handle input
    menuint2(@mm_menu$);
    deletearray @mm_menu$;
    return @menuret;
}

OnInit:
    .distance=6;
    .sex = G_FEMALE;

    // Load ManaMarket (max 100 entries)
	.@nb = query_sql("SELECT `id`, `account_id`, `price`, `expire_time`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `opt_idx0`, `opt_val0`, `opt_idx1`, `opt_val1`, `opt_idx2`, `opt_val2`, `opt_idx3`, `opt_val3`, `opt_idx4`, `opt_val4` FROM `manamarket` ORDER BY `id` DESC LIMIT 100", $@MM_id, $@MM_account_id, $@MM_price, $@MM_expire_time, $@MM_nameid, $@MM_amount, $@MM_equip, $@MM_identify, $@MM_refine, $@MM_attribute, $@MM_card0, $@MM_card1, $@MM_card2, $@MM_card3, $@MM_opt_idx0, $@MM_opt_val0, $@MM_opt_idx1, $@MM_opt_val1, $@MM_opt_idx2, $@MM_opt_val2, $@MM_opt_idx3, $@MM_opt_val3, $@MM_opt_idx4, $@MM_opt_val4);
    end;
}