DialogQuestion(NpcQuestion,Collection,ExplorationPlayer)   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 4
ccs 4
cts 4
cp 1
crap 1
rs 10
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.out.dialog;
21
22
import fr.quatrevieux.araknemu.game.exploration.ExplorationPlayer;
23
import fr.quatrevieux.araknemu.game.exploration.npc.dialog.NpcQuestion;
24
import fr.quatrevieux.araknemu.game.exploration.npc.dialog.Response;
25
26
import java.util.Collection;
27
28
/**
29
 * Send question and responses for a dialog
30
 *
31
 * https://github.com/Emudofus/Dofus/blob/1.29/dofus/aks/Dialog.as#L60
32
 */
33
public final class DialogQuestion {
34
    private final NpcQuestion question;
35
    private final Collection<Response> responses;
36
    private final ExplorationPlayer interlocutor;
37
38 1
    public DialogQuestion(NpcQuestion question, Collection<Response> responses, ExplorationPlayer interlocutor) {
39 1
        this.question = question;
40 1
        this.responses = responses;
41 1
        this.interlocutor = interlocutor;
42 1
    }
43
44
    @Override
45
    public String toString() {
46 1
        final StringBuilder sb = new StringBuilder(64);
47
48 1
        sb.append("DQ").append(question.id());
49
50 1
        boolean first = true;
51 1
        for (Object parameter : question.parameters(interlocutor)) {
52 1
            sb.append(first ? ';' : ',').append(parameter);
53 1
            first = false;
54
        }
55
56 1
        first = true;
57 1
        for (Response response : responses) {
58 1
            sb.append(first ? '|' : ';').append(response.id());
59 1
            first = false;
60 1
        }
61
62 1
        return sb.toString();
63
    }
64
}
65