|
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.game.listener.player.exchange; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.core.event.EventsSubscriber; |
|
23
|
|
|
import fr.quatrevieux.araknemu.core.event.Listener; |
|
24
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.KamasChanged; |
|
25
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.ObjectAdded; |
|
26
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.ObjectDeleted; |
|
27
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.ObjectQuantityChanged; |
|
28
|
|
|
import fr.quatrevieux.araknemu.game.world.util.Sender; |
|
29
|
|
|
import fr.quatrevieux.araknemu.network.game.out.exchange.movement.storage.StorageKamas; |
|
30
|
|
|
import fr.quatrevieux.araknemu.network.game.out.exchange.movement.storage.StorageObject; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Send packets for storage's change |
|
34
|
|
|
*/ |
|
35
|
|
|
public final class SendStoragePackets implements EventsSubscriber { |
|
36
|
|
|
private final Sender output; |
|
37
|
|
|
|
|
38
|
1 |
|
public SendStoragePackets(Sender output) { |
|
39
|
1 |
|
this.output = output; |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
@Override |
|
43
|
|
|
public Listener[] listeners() { |
|
44
|
1 |
|
return new Listener[] { |
|
45
|
1 |
|
new Listener<ObjectAdded>() { |
|
46
|
|
|
@Override |
|
47
|
|
|
public void on(ObjectAdded event) { |
|
48
|
1 |
|
output.send(new StorageObject(event.entry())); |
|
49
|
1 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
@Override |
|
52
|
|
|
public Class<ObjectAdded> event() { |
|
53
|
1 |
|
return ObjectAdded.class; |
|
54
|
|
|
} |
|
55
|
|
|
}, |
|
56
|
|
|
|
|
57
|
1 |
|
new Listener<ObjectDeleted>() { |
|
58
|
|
|
@Override |
|
59
|
|
|
public void on(ObjectDeleted event) { |
|
60
|
1 |
|
output.send(new StorageObject(event.entry())); |
|
61
|
1 |
|
} |
|
62
|
|
|
|
|
63
|
|
|
@Override |
|
64
|
|
|
public Class<ObjectDeleted> event() { |
|
65
|
1 |
|
return ObjectDeleted.class; |
|
66
|
|
|
} |
|
67
|
|
|
}, |
|
68
|
|
|
|
|
69
|
1 |
|
new Listener<ObjectQuantityChanged>() { |
|
70
|
|
|
@Override |
|
71
|
|
|
public void on(ObjectQuantityChanged event) { |
|
72
|
1 |
|
output.send(new StorageObject(event.entry())); |
|
73
|
1 |
|
} |
|
74
|
|
|
|
|
75
|
|
|
@Override |
|
76
|
|
|
public Class<ObjectQuantityChanged> event() { |
|
77
|
1 |
|
return ObjectQuantityChanged.class; |
|
78
|
|
|
} |
|
79
|
|
|
}, |
|
80
|
|
|
|
|
81
|
1 |
|
new Listener<KamasChanged>() { |
|
82
|
|
|
@Override |
|
83
|
|
|
public void on(KamasChanged event) { |
|
84
|
1 |
|
output.send(new StorageKamas(event.newQuantity())); |
|
85
|
1 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
@Override |
|
88
|
|
|
public Class<KamasChanged> event() { |
|
89
|
1 |
|
return KamasChanged.class; |
|
90
|
|
|
} |
|
91
|
|
|
}, |
|
92
|
|
|
}; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|