Skip to content

Commit

Permalink
Change unlocked scenes from lists to sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdulon committed Aug 18, 2022
1 parent c3450e8 commit efa69c0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 60 deletions.
22 changes: 9 additions & 13 deletions src/main/java/emu/grasscutter/command/commands/SetPropCommand.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -231,25 +230,22 @@ private boolean setOpenState(Player targetPlayer, int state, int value) {
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;
}
}
21 changes: 13 additions & 8 deletions src/main/java/emu/grasscutter/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -388,6 +389,14 @@ public int getExpeditionLimit() {
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);
}
Expand Down Expand Up @@ -881,10 +890,6 @@ public boolean hasBirthday() {
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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,8 @@ public void onPlayerLogin() {

// 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);
}

/******************************************************************************************************************
Expand Down Expand Up @@ -211,16 +200,13 @@ public void unlockTransPoint(int sceneId, int pointId, boolean isStatue) {
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);
Expand All @@ -240,16 +226,8 @@ public void unlockTransPoint(int sceneId, int pointId, boolean isStatue) {
}

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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +15,7 @@ public PacketGetSceneAreaRsp(Player player, int sceneId) {

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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +19,7 @@ public PacketGetScenePointRsp(Player player, int sceneId) {
p.addUnlockedPointList(i);
}
} else {
p.addAllUnlockedPointList(player.getUnlockedScenePoints().getOrDefault(sceneId, List.of()));
p.addAllUnlockedPointList(player.getUnlockedScenePoints(sceneId));
}

for (int i = 1; i < 9; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +15,7 @@ public PacketSceneAreaUnlockNotify(int sceneId, int areaId) {
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +15,7 @@ public PacketScenePointUnlockNotify(int sceneId, int pointId) {
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()
Expand Down

0 comments on commit efa69c0

Please sign in to comment.