Commit efa69c00 authored by AnimeGitB's avatar AnimeGitB
Browse files

Change unlocked scenes from lists to sets

parent c3450e89
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -231,25 +230,22 @@ public final class SetPropCommand implements CommandHandler { ...@@ -231,25 +230,22 @@ public final class SetPropCommand implements CommandHandler {
return true; return true;
} }
// List of map areas. Unfortunately, there is no readily available source for them in excels or bins.
final static private List<Integer> sceneAreas = List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,20,21,22,23,24,25,29,100,101,102,103,200,210,300,400,401,402,403);
private boolean unlockMap(Player targetPlayer) { private boolean unlockMap(Player targetPlayer) {
// Unlock. // Unlock.
targetPlayer.setUnlockedScenePoints(new HashMap<>()); GameData.getScenePointsPerScene().forEach((sceneId, scenePoints) -> {
targetPlayer.setUnlockedSceneAreas(new HashMap<>());
for (int sceneId : GameData.getScenePointsPerScene().keySet()) {
// Unlock trans points. // Unlock trans points.
targetPlayer.getUnlockedScenePoints().put(sceneId, new ArrayList<>()); targetPlayer.getUnlockedScenePoints(sceneId).addAll(scenePoints);
targetPlayer.getUnlockedScenePoints().get(sceneId).addAll(GameData.getScenePointsPerScene().get(sceneId));
// Unlock map areas. Unfortunately, there is no readily available source for them in excels or bins. // Unlock map areas.
targetPlayer.getUnlockedSceneAreas().put(sceneId, new ArrayList<>()); targetPlayer.getUnlockedSceneAreas(sceneId).addAll(sceneAreas);
targetPlayer.getUnlockedSceneAreas().get(sceneId).addAll(List.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18,19,20,21,22,23,24,25,29,100,101,102,103,200,210,300,400,401,402,403)); });
}
// Send notify. // Send notify.
int playerScene = targetPlayer.getSceneId(); int playerScene = targetPlayer.getSceneId();
targetPlayer.sendPacket(new PacketScenePointUnlockNotify(playerScene, targetPlayer.getUnlockedScenePoints().get(playerScene))); targetPlayer.sendPacket(new PacketScenePointUnlockNotify(playerScene, targetPlayer.getUnlockedScenePoints(playerScene)));
targetPlayer.sendPacket(new PacketSceneAreaUnlockNotify(playerScene, targetPlayer.getUnlockedSceneAreas().get(playerScene))); targetPlayer.sendPacket(new PacketSceneAreaUnlockNotify(playerScene, targetPlayer.getUnlockedSceneAreas(playerScene)));
return true; return true;
} }
} }
...@@ -80,6 +80,7 @@ import java.time.Instant; ...@@ -80,6 +80,7 @@ import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@Entity(value = "players", useDiscriminator = false) @Entity(value = "players", useDiscriminator = false)
...@@ -111,7 +112,7 @@ public class Player { ...@@ -111,7 +112,7 @@ public class Player {
@Getter private Set<Integer> nameCardList; @Getter private Set<Integer> nameCardList;
@Getter private Set<Integer> flyCloakList; @Getter private Set<Integer> flyCloakList;
@Getter private Set<Integer> costumeList; @Getter private Set<Integer> costumeList;
@Getter private Set<Integer> rewardedLevels; @Getter @Setter private Set<Integer> rewardedLevels;
@Getter @Setter private Set<Integer> realmList; @Getter @Setter private Set<Integer> realmList;
@Getter private Set<Integer> unlockedForgingBlueprints; @Getter private Set<Integer> unlockedForgingBlueprints;
@Getter private Set<Integer> unlockedCombines; @Getter private Set<Integer> unlockedCombines;
...@@ -120,10 +121,10 @@ public class Player { ...@@ -120,10 +121,10 @@ public class Player {
@Getter private Map<Long, ExpeditionInfo> expeditionInfo; @Getter private Map<Long, ExpeditionInfo> expeditionInfo;
@Getter private Map<Integer, Integer> unlockedRecipies; @Getter private Map<Integer, Integer> unlockedRecipies;
@Getter private List<ActiveForgeData> activeForges; @Getter private List<ActiveForgeData> activeForges;
@Getter private Map<Integer,Integer> questGlobalVariables; @Getter private Map<Integer, Integer> questGlobalVariables;
@Getter private Map<Integer, Integer> openStates; @Getter private Map<Integer, Integer> openStates;
@Getter @Setter private Map<Integer, List<Integer>> unlockedSceneAreas; @Getter @Setter private Map<Integer, Set<Integer>> unlockedSceneAreas;
@Getter @Setter private Map<Integer, List<Integer>> unlockedScenePoints; @Getter @Setter private Map<Integer, Set<Integer>> unlockedScenePoints;
@Transient private long nextGuid = 0; @Transient private long nextGuid = 0;
@Transient @Getter @Setter private int peerId; @Transient @Getter @Setter private int peerId;
...@@ -388,6 +389,14 @@ public class Player { ...@@ -388,6 +389,14 @@ public class Player {
return expeditionLimit; return expeditionLimit;
} }
public Set<Integer> getUnlockedSceneAreas(int sceneId) {
return this.unlockedSceneAreas.computeIfAbsent(sceneId, i -> new CopyOnWriteArraySet<>());
}
public Set<Integer> getUnlockedScenePoints(int sceneId) {
return this.unlockedScenePoints.computeIfAbsent(sceneId, i -> new CopyOnWriteArraySet<>());
}
public int getLevel() { public int getLevel() {
return this.getProperty(PlayerProperty.PROP_PLAYER_LEVEL); return this.getProperty(PlayerProperty.PROP_PLAYER_LEVEL);
} }
...@@ -881,10 +890,6 @@ public class Player { ...@@ -881,10 +890,6 @@ public class Player {
return this.birthday.getDay() > 0; return this.birthday.getDay() > 0;
} }
public void setRewardedLevels(Set<Integer> rewardedLevels) {
this.rewardedLevels = rewardedLevels;
}
public SocialDetail.Builder getSocialDetail() { public SocialDetail.Builder getSocialDetail() {
List<SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo> socialShowAvatarInfoList = new ArrayList<>(); List<SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo> socialShowAvatarInfoList = new ArrayList<>();
if (this.isOnline()) { if (this.isOnline()) {
......
...@@ -44,19 +44,8 @@ public class PlayerProgressManager extends BasePlayerDataManager { ...@@ -44,19 +44,8 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// Auto-unlock the first statue and map area, until we figure out how to make // Auto-unlock the first statue and map area, until we figure out how to make
// that particular statue interactable. // that particular statue interactable.
if (!this.player.getUnlockedScenePoints().containsKey(3)) { this.player.getUnlockedScenePoints(3).add(7);
this.player.getUnlockedScenePoints().put(3, new ArrayList<>()); this.player.getUnlockedSceneAreas(3).add(1);
}
if (!this.player.getUnlockedScenePoints().get(3).contains(7)) {
this.player.getUnlockedScenePoints().get(3).add(7);
}
if (!this.player.getUnlockedSceneAreas().containsKey(3)) {
this.player.getUnlockedSceneAreas().put(3, new ArrayList<>());
}
if (!this.player.getUnlockedSceneAreas().get(3).contains(1)) {
this.player.getUnlockedSceneAreas().get(3).add(1);
}
} }
/****************************************************************************************************************** /******************************************************************************************************************
...@@ -211,16 +200,13 @@ public class PlayerProgressManager extends BasePlayerDataManager { ...@@ -211,16 +200,13 @@ public class PlayerProgressManager extends BasePlayerDataManager {
String key = sceneId + "_" + pointId; String key = sceneId + "_" + pointId;
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(key); ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(key);
if (scenePointEntry == null || this.player.getUnlockedScenePoints().getOrDefault(sceneId, List.of()).contains(pointId)) { if (scenePointEntry == null || this.player.getUnlockedScenePoints(sceneId).contains(pointId)) {
this.player.sendPacket(new PacketUnlockTransPointRsp(Retcode.RET_FAIL)); this.player.sendPacket(new PacketUnlockTransPointRsp(Retcode.RET_FAIL));
return; return;
} }
// Add the point to the list of unlocked points for its scene. // Add the point to the list of unlocked points for its scene.
if (!this.player.getUnlockedScenePoints().containsKey(sceneId)) { this.player.getUnlockedScenePoints(sceneId).add(pointId);
this.player.getUnlockedScenePoints().put(sceneId, new ArrayList<>());
}
this.player.getUnlockedScenePoints().get(sceneId).add(pointId);
// Give primogems and Adventure EXP for unlocking. // Give primogems and Adventure EXP for unlocking.
var primos = new GameItem(GameData.getItemDataMap().get(201), 5); var primos = new GameItem(GameData.getItemDataMap().get(201), 5);
...@@ -240,16 +226,8 @@ public class PlayerProgressManager extends BasePlayerDataManager { ...@@ -240,16 +226,8 @@ public class PlayerProgressManager extends BasePlayerDataManager {
} }
public void unlockSceneArea(int sceneId, int areaId) { public void unlockSceneArea(int sceneId, int areaId) {
// Check whether this area is already unlocked.
if (this.player.getUnlockedSceneAreas().getOrDefault(sceneId, List.of()).contains(areaId)) {
return;
}
// Add the area to the list of unlocked areas in its scene. // Add the area to the list of unlocked areas in its scene.
if (!this.player.getUnlockedSceneAreas().containsKey(sceneId)) { this.player.getUnlockedSceneAreas(sceneId).add(areaId);
this.player.getUnlockedSceneAreas().put(sceneId, new ArrayList<>());
}
this.player.getUnlockedSceneAreas().get(sceneId).add(areaId);
// Send packet. // Send packet.
this.player.sendPacket(new PacketSceneAreaUnlockNotify(sceneId, areaId)); this.player.sendPacket(new PacketSceneAreaUnlockNotify(sceneId, areaId));
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
...@@ -17,7 +15,7 @@ public class PacketGetSceneAreaRsp extends BasePacket { ...@@ -17,7 +15,7 @@ public class PacketGetSceneAreaRsp extends BasePacket {
GetSceneAreaRsp p = GetSceneAreaRsp.newBuilder() GetSceneAreaRsp p = GetSceneAreaRsp.newBuilder()
.setSceneId(sceneId) .setSceneId(sceneId)
.addAllAreaIdList(player.getUnlockedSceneAreas().getOrDefault(sceneId, List.of())) .addAllAreaIdList(player.getUnlockedSceneAreas(sceneId))
.addCityInfoList(CityInfo.newBuilder().setCityId(1).setLevel(1).build()) .addCityInfoList(CityInfo.newBuilder().setCityId(1).setLevel(1).build())
.addCityInfoList(CityInfo.newBuilder().setCityId(2).setLevel(1).build()) .addCityInfoList(CityInfo.newBuilder().setCityId(2).setLevel(1).build())
.addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build()) .addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build())
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
...@@ -21,7 +19,7 @@ public class PacketGetScenePointRsp extends BasePacket { ...@@ -21,7 +19,7 @@ public class PacketGetScenePointRsp extends BasePacket {
p.addUnlockedPointList(i); p.addUnlockedPointList(i);
} }
} else { } else {
p.addAllUnlockedPointList(player.getUnlockedScenePoints().getOrDefault(sceneId, List.of())); p.addAllUnlockedPointList(player.getUnlockedScenePoints(sceneId));
} }
for (int i = 1; i < 9; i++) { for (int i = 1; i < 9; i++) {
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneAreaUnlockNotifyOuterClass.SceneAreaUnlockNotify; import emu.grasscutter.net.proto.SceneAreaUnlockNotifyOuterClass.SceneAreaUnlockNotify;
...@@ -17,7 +15,7 @@ public class PacketSceneAreaUnlockNotify extends BasePacket { ...@@ -17,7 +15,7 @@ public class PacketSceneAreaUnlockNotify extends BasePacket {
this.setData(p); this.setData(p);
} }
public PacketSceneAreaUnlockNotify(int sceneId, List<Integer> areaIds) { public PacketSceneAreaUnlockNotify(int sceneId, Iterable<Integer> areaIds) {
super(PacketOpcodes.SceneAreaUnlockNotify); super(PacketOpcodes.SceneAreaUnlockNotify);
SceneAreaUnlockNotify.Builder p = SceneAreaUnlockNotify.newBuilder() SceneAreaUnlockNotify.Builder p = SceneAreaUnlockNotify.newBuilder()
......
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ScenePointUnlockNotifyOuterClass.ScenePointUnlockNotify; import emu.grasscutter.net.proto.ScenePointUnlockNotifyOuterClass.ScenePointUnlockNotify;
...@@ -17,7 +15,7 @@ public class PacketScenePointUnlockNotify extends BasePacket { ...@@ -17,7 +15,7 @@ public class PacketScenePointUnlockNotify extends BasePacket {
this.setData(p); this.setData(p);
} }
public PacketScenePointUnlockNotify(int sceneId, List<Integer> pointIds) { public PacketScenePointUnlockNotify(int sceneId, Iterable<Integer> pointIds) {
super(PacketOpcodes.ScenePointUnlockNotify); super(PacketOpcodes.ScenePointUnlockNotify);
ScenePointUnlockNotify.Builder p = ScenePointUnlockNotify.newBuilder() ScenePointUnlockNotify.Builder p = ScenePointUnlockNotify.newBuilder()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment