Add option "all" for UnlockMap and change the default behavior for "/prop unlockmap on" (#2196)

* Do not unlock unnecessary scene points during '/prop unlockmap on'

* Format code [skip actions]

* Backup scenePoints since we might modify it

* Format code [skip actions]

* Add 'all' for UnlockMap

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
iTruth 2023-06-10 01:31:11 +08:00 committed by GitHub
parent 4093420c90
commit 1ed89598ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import emu.grasscutter.server.packet.send.PacketScenePointUnlockNotify;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.IntStream;
@Command(
@ -107,6 +108,7 @@ public final class SetPropCommand implements CommandHandler {
case "on", "true" -> 1;
case "off", "false" -> 0;
case "toggle" -> -1;
case "all" -> -2;
default -> Integer.parseInt(valueStr);
};
} catch (NumberFormatException ignored) {
@ -126,7 +128,7 @@ public final class SetPropCommand implements CommandHandler {
sender, targetPlayer, prop.pseudoProp, value);
case SET_OPENSTATE -> this.setOpenState(targetPlayer, value, 1);
case UNSET_OPENSTATE -> this.setOpenState(targetPlayer, value, 0);
case UNLOCK_MAP -> unlockMap(targetPlayer);
case UNLOCK_MAP -> unlockMap(targetPlayer, value);
default -> targetPlayer.setProperty(prop.prop, value);
};
@ -217,13 +219,30 @@ public final class SetPropCommand implements CommandHandler {
return true;
}
private boolean unlockMap(Player targetPlayer) {
private boolean unlockMap(Player targetPlayer, int value) {
// Unlock.
GameData.getScenePointsPerScene()
.forEach(
(sceneId, scenePoints) -> {
// Unlock trans points.
targetPlayer.getUnlockedScenePoints(sceneId).addAll(scenePoints);
if (value == -2) {
// Unlock trans points.
targetPlayer.getUnlockedScenePoints(sceneId).addAll(scenePoints);
} else {
var scenePointsBackup = new CopyOnWriteArrayList<>(scenePoints);
for (var p : scenePointsBackup) {
var scenePointEentry = GameData.getScenePointEntryById(sceneId, p);
var pointData = scenePointEentry.getPointData();
boolean forbidSimpleUnlock = pointData.isForbidSimpleUnlock();
boolean sceneBuildingPointLocked =
pointData.getType().equals("SceneBuildingPoint") && !pointData.isUnlocked();
if (forbidSimpleUnlock || sceneBuildingPointLocked) scenePointsBackup.remove(p);
}
// Unlock trans points.
targetPlayer.getUnlockedScenePoints(sceneId).addAll(scenePointsBackup);
}
// Unlock map areas.
targetPlayer.getUnlockedSceneAreas(sceneId).addAll(sceneAreas);

View File

@ -19,6 +19,8 @@ public final class PointData {
@Getter private Position pos;
@Getter private Position rot;
@Getter private Position size;
@Getter private boolean forbidSimpleUnlock;
@Getter private boolean unlocked;
@SerializedName(
value = "dungeonIds",