Change unlocked scenes from lists to sets

This commit is contained in:
AnimeGitB 2022-08-16 14:25:02 +09:30
parent c3450e8905
commit efa69c007d
7 changed files with 31 additions and 60 deletions

View File

@ -1,6 +1,5 @@
package emu.grasscutter.command.commands;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -231,25 +230,22 @@ public final class SetPropCommand implements CommandHandler {
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) {
// Unlock.
targetPlayer.setUnlockedScenePoints(new HashMap<>());
targetPlayer.setUnlockedSceneAreas(new HashMap<>());
for (int sceneId : GameData.getScenePointsPerScene().keySet()) {
GameData.getScenePointsPerScene().forEach((sceneId, scenePoints) -> {
// Unlock trans points.
targetPlayer.getUnlockedScenePoints().put(sceneId, new ArrayList<>());
targetPlayer.getUnlockedScenePoints().get(sceneId).addAll(GameData.getScenePointsPerScene().get(sceneId));
targetPlayer.getUnlockedScenePoints(sceneId).addAll(scenePoints);
// Unlock map areas. Unfortunately, there is no readily available source for them in excels or bins.
targetPlayer.getUnlockedSceneAreas().put(sceneId, new ArrayList<>());
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));
}
// Unlock map areas.
targetPlayer.getUnlockedSceneAreas(sceneId).addAll(sceneAreas);
});
// Send notify.
int playerScene = targetPlayer.getSceneId();
targetPlayer.sendPacket(new PacketScenePointUnlockNotify(playerScene, targetPlayer.getUnlockedScenePoints().get(playerScene)));
targetPlayer.sendPacket(new PacketSceneAreaUnlockNotify(playerScene, targetPlayer.getUnlockedSceneAreas().get(playerScene)));
targetPlayer.sendPacket(new PacketScenePointUnlockNotify(playerScene, targetPlayer.getUnlockedScenePoints(playerScene)));
targetPlayer.sendPacket(new PacketSceneAreaUnlockNotify(playerScene, targetPlayer.getUnlockedSceneAreas(playerScene)));
return true;
}
}

View File

@ -80,6 +80,7 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.LinkedBlockingQueue;
@Entity(value = "players", useDiscriminator = false)
@ -111,7 +112,7 @@ public class Player {
@Getter private Set<Integer> nameCardList;
@Getter private Set<Integer> flyCloakList;
@Getter private Set<Integer> costumeList;
@Getter private Set<Integer> rewardedLevels;
@Getter @Setter private Set<Integer> rewardedLevels;
@Getter @Setter private Set<Integer> realmList;
@Getter private Set<Integer> unlockedForgingBlueprints;
@Getter private Set<Integer> unlockedCombines;
@ -120,10 +121,10 @@ public class Player {
@Getter private Map<Long, ExpeditionInfo> expeditionInfo;
@Getter private Map<Integer, Integer> unlockedRecipies;
@Getter private List<ActiveForgeData> activeForges;
@Getter private Map<Integer,Integer> questGlobalVariables;
@Getter private Map<Integer, Integer> questGlobalVariables;
@Getter private Map<Integer, Integer> openStates;
@Getter @Setter private Map<Integer, List<Integer>> unlockedSceneAreas;
@Getter @Setter private Map<Integer, List<Integer>> unlockedScenePoints;
@Getter @Setter private Map<Integer, Set<Integer>> unlockedSceneAreas;
@Getter @Setter private Map<Integer, Set<Integer>> unlockedScenePoints;
@Transient private long nextGuid = 0;
@Transient @Getter @Setter private int peerId;
@ -388,6 +389,14 @@ public class Player {
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() {
return this.getProperty(PlayerProperty.PROP_PLAYER_LEVEL);
}
@ -881,10 +890,6 @@ public class Player {
return this.birthday.getDay() > 0;
}
public void setRewardedLevels(Set<Integer> rewardedLevels) {
this.rewardedLevels = rewardedLevels;
}
public SocialDetail.Builder getSocialDetail() {
List<SocialShowAvatarInfoOuterClass.SocialShowAvatarInfo> socialShowAvatarInfoList = new ArrayList<>();
if (this.isOnline()) {

View File

@ -44,19 +44,8 @@ public class PlayerProgressManager extends BasePlayerDataManager {
// Auto-unlock the first statue and map area, until we figure out how to make
// that particular statue interactable.
if (!this.player.getUnlockedScenePoints().containsKey(3)) {
this.player.getUnlockedScenePoints().put(3, new ArrayList<>());
}
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);
}
this.player.getUnlockedScenePoints(3).add(7);
this.player.getUnlockedSceneAreas(3).add(1);
}
/******************************************************************************************************************
@ -211,16 +200,13 @@ public class PlayerProgressManager extends BasePlayerDataManager {
String key = sceneId + "_" + pointId;
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));
return;
}
// Add the point to the list of unlocked points for its scene.
if (!this.player.getUnlockedScenePoints().containsKey(sceneId)) {
this.player.getUnlockedScenePoints().put(sceneId, new ArrayList<>());
}
this.player.getUnlockedScenePoints().get(sceneId).add(pointId);
this.player.getUnlockedScenePoints(sceneId).add(pointId);
// Give primogems and Adventure EXP for unlocking.
var primos = new GameItem(GameData.getItemDataMap().get(201), 5);
@ -240,16 +226,8 @@ public class PlayerProgressManager extends BasePlayerDataManager {
}
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.
if (!this.player.getUnlockedSceneAreas().containsKey(sceneId)) {
this.player.getUnlockedSceneAreas().put(sceneId, new ArrayList<>());
}
this.player.getUnlockedSceneAreas().get(sceneId).add(areaId);
this.player.getUnlockedSceneAreas(sceneId).add(areaId);
// Send packet.
this.player.sendPacket(new PacketSceneAreaUnlockNotify(sceneId, areaId));

View File

@ -1,7 +1,5 @@
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
@ -17,7 +15,7 @@ public class PacketGetSceneAreaRsp extends BasePacket {
GetSceneAreaRsp p = GetSceneAreaRsp.newBuilder()
.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(2).setLevel(1).build())
.addCityInfoList(CityInfo.newBuilder().setCityId(3).setLevel(1).build())

View File

@ -1,7 +1,5 @@
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
@ -21,7 +19,7 @@ public class PacketGetScenePointRsp extends BasePacket {
p.addUnlockedPointList(i);
}
} else {
p.addAllUnlockedPointList(player.getUnlockedScenePoints().getOrDefault(sceneId, List.of()));
p.addAllUnlockedPointList(player.getUnlockedScenePoints(sceneId));
}
for (int i = 1; i < 9; i++) {

View File

@ -1,7 +1,5 @@
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneAreaUnlockNotifyOuterClass.SceneAreaUnlockNotify;
@ -17,7 +15,7 @@ public class PacketSceneAreaUnlockNotify extends BasePacket {
this.setData(p);
}
public PacketSceneAreaUnlockNotify(int sceneId, List<Integer> areaIds) {
public PacketSceneAreaUnlockNotify(int sceneId, Iterable<Integer> areaIds) {
super(PacketOpcodes.SceneAreaUnlockNotify);
SceneAreaUnlockNotify.Builder p = SceneAreaUnlockNotify.newBuilder()

View File

@ -1,7 +1,5 @@
package emu.grasscutter.server.packet.send;
import java.util.List;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.ScenePointUnlockNotifyOuterClass.ScenePointUnlockNotify;
@ -17,7 +15,7 @@ public class PacketScenePointUnlockNotify extends BasePacket {
this.setData(p);
}
public PacketScenePointUnlockNotify(int sceneId, List<Integer> pointIds) {
public PacketScenePointUnlockNotify(int sceneId, Iterable<Integer> pointIds) {
super(PacketOpcodes.ScenePointUnlockNotify);
ScenePointUnlockNotify.Builder p = ScenePointUnlockNotify.newBuilder()