Parser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse(String) 0 7 1
A code() 0 3 1
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * Araknemu is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2019 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.network.game.in.exchange.store;
21
22
import fr.quatrevieux.araknemu.core.network.parser.Packet;
23
import fr.quatrevieux.araknemu.core.network.parser.PacketTokenizer;
24
import fr.quatrevieux.araknemu.core.network.parser.ParsePacketException;
25
import fr.quatrevieux.araknemu.core.network.parser.SinglePacketParser;
26
import org.checkerframework.checker.index.qual.Positive;
27
import org.checkerframework.common.value.qual.MinLen;
28
29
/**
30
 * Request for buy an item from a store (NPC or player)
31
 *
32
 * https://github.com/Emudofus/Dofus/blob/1.29/dofus/aks/Exchange.as#L74
33
 */
34
public final class BuyRequest implements Packet {
35
    private final int itemId;
36
    private final @Positive int quantity;
37
38 1
    public BuyRequest(int itemId, @Positive int quantity) {
39 1
        this.itemId = itemId;
40 1
        this.quantity = quantity;
41 1
    }
42
43
    /**
44
     * The item id
45
     *
46
     * Note: for an NPC, this is the item template id, whereas for player it's the item entry id
47
     */
48
    public int itemId() {
49 1
        return itemId;
50
    }
51
52
    /**
53
     * The buy quantity
54
     */
55
    public @Positive int quantity() {
56 1
        return quantity;
57
    }
58
59 1
    public static final class Parser implements SinglePacketParser<BuyRequest> {
60
        @Override
61
        public BuyRequest parse(String input) throws ParsePacketException {
62 1
            final PacketTokenizer tokenizer = tokenize(input, '|');
63
64 1
            return new BuyRequest(
65 1
                tokenizer.nextInt(),
66 1
                tokenizer.nextPositiveInt()
67
            );
68
        }
69
70
        @Override
71
        public @MinLen(2) String code() {
72 1
            return "EB";
73
        }
74
    }
75
}
76