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.inventory; |
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.ObjectAdded; |
25
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.ObjectDeleted; |
26
|
|
|
import fr.quatrevieux.araknemu.game.item.inventory.event.ObjectQuantityChanged; |
27
|
|
|
import fr.quatrevieux.araknemu.game.player.GamePlayer; |
28
|
|
|
import fr.quatrevieux.araknemu.game.player.characteristic.event.CharacteristicsChanged; |
29
|
|
|
import fr.quatrevieux.araknemu.game.player.event.GameJoined; |
30
|
|
|
import fr.quatrevieux.araknemu.network.game.out.object.InventoryWeight; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Send inventory weight when inventory operations or characteristics changes occurs |
34
|
|
|
*/ |
35
|
|
|
public final class SendWeight implements EventsSubscriber { |
36
|
|
|
private final GamePlayer player; |
37
|
|
|
|
38
|
1 |
|
public SendWeight(GamePlayer player) { |
39
|
1 |
|
this.player = player; |
40
|
1 |
|
} |
41
|
|
|
|
42
|
|
|
@Override |
43
|
|
|
public Listener[] listeners() { |
44
|
1 |
|
return new Listener[] { |
45
|
1 |
|
new Listener<GameJoined>() { |
46
|
|
|
@Override |
47
|
|
|
public void on(GameJoined event) { |
48
|
1 |
|
send(); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
@Override |
52
|
|
|
public Class<GameJoined> event() { |
53
|
1 |
|
return GameJoined.class; |
54
|
|
|
} |
55
|
|
|
}, |
56
|
1 |
|
new Listener<CharacteristicsChanged>() { |
57
|
|
|
@Override |
58
|
|
|
public void on(CharacteristicsChanged event) { |
59
|
1 |
|
send(); |
60
|
1 |
|
} |
61
|
|
|
|
62
|
|
|
@Override |
63
|
|
|
public Class<CharacteristicsChanged> event() { |
64
|
1 |
|
return CharacteristicsChanged.class; |
65
|
|
|
} |
66
|
|
|
}, |
67
|
1 |
|
new Listener<ObjectQuantityChanged>() { |
68
|
|
|
@Override |
69
|
|
|
public void on(ObjectQuantityChanged event) { |
70
|
1 |
|
send(); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
@Override |
74
|
|
|
public Class<ObjectQuantityChanged> event() { |
75
|
1 |
|
return ObjectQuantityChanged.class; |
76
|
|
|
} |
77
|
|
|
}, |
78
|
1 |
|
new Listener<ObjectAdded>() { |
79
|
|
|
@Override |
80
|
|
|
public void on(ObjectAdded event) { |
81
|
1 |
|
send(); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
@Override |
85
|
|
|
public Class<ObjectAdded> event() { |
86
|
1 |
|
return ObjectAdded.class; |
87
|
|
|
} |
88
|
|
|
}, |
89
|
1 |
|
new Listener<ObjectDeleted>() { |
90
|
|
|
@Override |
91
|
|
|
public void on(ObjectDeleted event) { |
92
|
1 |
|
send(); |
93
|
1 |
|
} |
94
|
|
|
|
95
|
|
|
@Override |
96
|
|
|
public Class<ObjectDeleted> event() { |
97
|
1 |
|
return ObjectDeleted.class; |
98
|
|
|
} |
99
|
|
|
}, |
100
|
|
|
}; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
private void send() { |
104
|
1 |
|
player.inventory().refreshWeight(); |
105
|
1 |
|
player.send(new InventoryWeight(player)); |
106
|
1 |
|
} |
107
|
|
|
} |
108
|
|
|
|