|
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.exploration; |
|
21
|
|
|
|
|
22
|
|
|
import fr.quatrevieux.araknemu.game.exploration.event.RestrictionsChanged; |
|
23
|
|
|
import fr.quatrevieux.araknemu.game.exploration.map.ExplorationMap; |
|
24
|
|
|
import fr.quatrevieux.araknemu.util.BitSet; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Handle exploration player restrictions |
|
28
|
|
|
*/ |
|
29
|
|
|
public final class Restrictions { |
|
30
|
1 |
|
public static enum Restriction { |
|
31
|
|
|
/** Value : 1 */ |
|
32
|
1 |
|
DENY_ASSAULT, |
|
33
|
|
|
/** Value : 2 */ |
|
34
|
1 |
|
DENY_CHALLENGE, |
|
35
|
|
|
/** Value : 4 */ |
|
36
|
1 |
|
DENY_EXCHANGE, |
|
37
|
|
|
/** Value : 8 */ |
|
38
|
1 |
|
DENY_ATTACK, |
|
39
|
|
|
/** Value : 16 */ |
|
40
|
1 |
|
FORCE_WALK, |
|
41
|
|
|
/** Value : 32 */ |
|
42
|
1 |
|
IS_SLOW, |
|
43
|
|
|
/** Value : 64 */ |
|
44
|
1 |
|
DENY_CREATURE_MODE, |
|
45
|
|
|
/** Value : 128 */ |
|
46
|
1 |
|
IS_TOMB, |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
private static final LocalToExplorationMapping[] LOCAL_TO_EXPLORATION_MAPPING = new LocalToExplorationMapping[] { |
|
50
|
|
|
new LocalToExplorationMapping(fr.quatrevieux.araknemu.game.player.Restrictions::canAssault, Restriction.DENY_ASSAULT), |
|
51
|
|
|
new LocalToExplorationMapping(fr.quatrevieux.araknemu.game.player.Restrictions::canChallenge, Restriction.DENY_CHALLENGE), |
|
52
|
|
|
new LocalToExplorationMapping(fr.quatrevieux.araknemu.game.player.Restrictions::canAttack, Restriction.DENY_ATTACK), |
|
53
|
|
|
new LocalToExplorationMapping(fr.quatrevieux.araknemu.game.player.Restrictions::canExchange, Restriction.DENY_EXCHANGE), |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
private final ExplorationPlayer player; |
|
57
|
|
|
private final BitSet<Restriction> set; |
|
58
|
|
|
|
|
59
|
1 |
|
public Restrictions(ExplorationPlayer player) { |
|
60
|
1 |
|
this.player = player; |
|
61
|
1 |
|
this.set = new BitSet<>(); |
|
62
|
1 |
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the integer value of restrictions |
|
66
|
|
|
*/ |
|
67
|
|
|
public int toInt() { |
|
68
|
1 |
|
return set.toInt(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Check if the player can be assaulted (alignment fight) |
|
73
|
|
|
*/ |
|
74
|
|
|
public boolean canAssault() { |
|
75
|
1 |
|
return !set.check(Restriction.DENY_ASSAULT); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Check if the can ask a duel to the player |
|
80
|
|
|
*/ |
|
81
|
|
|
public boolean canChallenge() { |
|
82
|
1 |
|
return !set.check(Restriction.DENY_CHALLENGE); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Check if exchange is allowed with this player |
|
87
|
|
|
*/ |
|
88
|
|
|
public boolean canExchange() { |
|
89
|
1 |
|
return !set.check(Restriction.DENY_EXCHANGE); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Check if the player (mutant) can be attacked |
|
94
|
|
|
*/ |
|
95
|
|
|
public boolean canAttack() { |
|
96
|
1 |
|
return !set.check(Restriction.DENY_ATTACK); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Check if the player is forced to walk (run is denied) |
|
101
|
|
|
*/ |
|
102
|
|
|
public boolean forceWalk() { |
|
103
|
1 |
|
return set.check(Restriction.FORCE_WALK); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Check if the player is move slowly |
|
108
|
|
|
*/ |
|
109
|
|
|
public boolean isSlow() { |
|
110
|
1 |
|
return set.check(Restriction.IS_SLOW); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Check if the player is a tomb |
|
115
|
|
|
*/ |
|
116
|
|
|
public boolean isTomb() { |
|
117
|
1 |
|
return set.check(Restriction.IS_TOMB); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Refresh the exploration restrictions according to the local player restrictions |
|
122
|
|
|
*/ |
|
123
|
|
|
public void refresh() { |
|
124
|
1 |
|
final fr.quatrevieux.araknemu.game.player.Restrictions localRestrictions = player.player().restrictions(); |
|
125
|
1 |
|
final ExplorationMap map = player.map(); |
|
126
|
|
|
|
|
127
|
1 |
|
boolean hasChanged = false; |
|
128
|
|
|
|
|
129
|
1 |
|
for (LocalToExplorationMapping mapping : LOCAL_TO_EXPLORATION_MAPPING) { |
|
130
|
1 |
|
if (!mapping.checker.check(localRestrictions)) { |
|
131
|
1 |
|
hasChanged |= set.set(mapping.restriction); |
|
132
|
|
|
} else { |
|
133
|
1 |
|
hasChanged |= set.unset(mapping.restriction); |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
1 |
|
if (hasChanged && map != null) { |
|
138
|
1 |
|
map.dispatch(new RestrictionsChanged(player, this)); |
|
139
|
|
|
} |
|
140
|
1 |
|
} |
|
141
|
|
|
|
|
142
|
|
|
private static final class LocalToExplorationMapping { |
|
143
|
|
|
private final Checker checker; |
|
144
|
|
|
private final Restriction restriction; |
|
145
|
|
|
|
|
146
|
1 |
|
public LocalToExplorationMapping(Checker checker, Restriction restriction) { |
|
147
|
1 |
|
this.checker = checker; |
|
148
|
1 |
|
this.restriction = restriction; |
|
149
|
1 |
|
} |
|
150
|
|
|
|
|
151
|
|
|
interface Checker { |
|
152
|
|
|
public boolean check(fr.quatrevieux.araknemu.game.player.Restrictions restrictions); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|