fix: unlocking home bgm doesn't work. (#1886)

* fix: unlocking home bgm doesn't work.

* Update src/main/java/emu/grasscutter/game/home/GameHome.java

Co-authored-by: Luke H-W <Birdulon@users.noreply.github.com>

Co-authored-by: Luke H-W <Birdulon@users.noreply.github.com>
This commit is contained in:
hamusuke 2022-10-23 13:38:17 +09:00 committed by GitHub
parent 54ad108a14
commit 8b520b3883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import emu.grasscutter.data.excels.HomeWorldLevelData;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
@ -20,6 +21,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Entity(value = "homes", useDiscriminator = false)
@Data
@ -57,6 +59,7 @@ public class GameHome {
.ownerUid(uid)
.level(1)
.sceneMap(new ConcurrentHashMap<>())
.unlockedHomeBgmList(new HashSet<>())
.build();
}
@ -93,7 +96,7 @@ public class GameHome {
}
public boolean addUnlockedHomeBgm(int homeBgmId) {
if (getUnlockedHomeBgmList().add(homeBgmId)) return false;
if (!getUnlockedHomeBgmList().add(homeBgmId)) return false;
var player = this.getPlayer();
player.sendPacket(new PacketUnlockHomeBgmNotify(homeBgmId));
@ -102,20 +105,22 @@ public class GameHome {
return true;
}
public Set<Integer> getUnlockedHomeBgmListInfo() {
public Set<Integer> getUnlockedHomeBgmList() {
if (this.unlockedHomeBgmList == null) {
this.unlockedHomeBgmList = new HashSet<>();
addAllDefaultUnlockedBgmIds(this.unlockedHomeBgmList);
}
if (this.unlockedHomeBgmList.addAll(getDefaultUnlockedHomeBgmIds())) {
save();
}
return this.unlockedHomeBgmList;
}
private void addAllDefaultUnlockedBgmIds(Set<Integer> list) {
GameData.getHomeWorldBgmDataMap().forEach((id, data) -> {
if (data.isDefaultUnlock())
list.add(id);
});
private Set<Integer> getDefaultUnlockedHomeBgmIds() {
return GameData.getHomeWorldBgmDataMap().int2ObjectEntrySet().stream()
.filter(e -> e.getValue().isDefaultUnlock())
.map(Int2ObjectMap.Entry::getIntKey)
.collect(Collectors.toUnmodifiableSet());
}
}

View File

@ -17,7 +17,6 @@ public class HandlerChangeHomeBgmReq extends PacketHandler {
int homeBgmId = req.getUnk2700BJHAMKKECEI();
var home = session.getPlayer().getHome();
home.addUnlockedHomeBgm(homeBgmId); // Not sure if this is sane
home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId);
home.save();

View File

@ -13,7 +13,7 @@ public class PacketUnlockedHomeBgmNotify extends BasePacket {
return;
}
var unlocked = player.getHome().getUnlockedHomeBgmListInfo();
var unlocked = player.getHome().getUnlockedHomeBgmList();
var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder()
.addAllUnk2700KMEKMNONMGE(unlocked)