Unverified Commit 4da4c03e authored by hamusuke's avatar hamusuke Committed by GitHub
Browse files

feat: unlock homeworld bgm and set homeworld bgm. (#1844)

* will be able to change home bgm.

* feat: unlock homeworld bgm and set homeworld bgm.

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

* Update GameHome.java

* Get default unlocked home bgms from HomeWorldBgmData

* fix: duplicate home items by sending packet
parent 98ac42a6
......@@ -118,6 +118,7 @@ public class GameData {
@Getter private static final Int2ObjectMap<BlossomRefreshExcelConfigData> blossomRefreshExcelConfigDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<OpenStateData> openStateDataMap = new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<HomeWorldBgmData> homeWorldBgmDataMap = new Int2ObjectOpenHashMap<>();
// Cache
private static Map<Integer, List<Integer>> fetters = new HashMap<>();
......
package emu.grasscutter.data.excels;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.experimental.FieldDefaults;
@Getter
@FieldDefaults(level = AccessLevel.PRIVATE)
@ResourceType(name = {"HomeWorldBgmExcelConfigData.json"})
public class HomeWorldBgmData extends GameResource {
@SerializedName(value = "homeBgmId", alternate = "MJJENLEBKEF")
private int homeBgmId;
private boolean isDefaultUnlock;
private boolean NBIDHGOOCKD;
private boolean JJMNJMCCOKP;
private int cityId;
private int sortOrder;
private String GEGHMJBJMGB;
@SerializedName(value = "bgmNameTextMapHash", alternate = "LMLNBMJFFML")
private long bgmNameTextMapHash;
@Override
public int getId() {
return this.homeBgmId;
}
}
......@@ -15,7 +15,9 @@ import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@Entity(value = "homes", useDiscriminator = false)
......@@ -34,6 +36,7 @@ public class GameHome {
int exp;
List<FurnitureMakeSlotItem> furnitureMakeSlotItemList;
ConcurrentHashMap<Integer, HomeSceneItem> sceneMap;
Set<Integer> unlockedHomeBgmList;
public void save(){
DatabaseHelper.saveHome(this);
......@@ -72,9 +75,33 @@ public class GameHome {
player.getSession().send(new PacketHomeComfortInfoNotify(player));
player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify());
player.getSession().send(new PacketHomeMarkPointNotify(player));
player.getSession().send(new PacketUnlockedHomeBgmNotify(player));
}
public HomeWorldLevelData getLevelData(){
return GameData.getHomeWorldLevelDataMap().get(level);
}
public void addUnlockedHomeBgm(int homeBgmId) {
getUnlockedHomeBgmList().add(homeBgmId);
save();
}
public Set<Integer> getUnlockedHomeBgmListInfo() {
var list = getUnlockedHomeBgmList();
if (list == null) {
list = new HashSet<>();
addAllDefaultUnlockedBgmIds(list);
setUnlockedHomeBgmList(list);
save();
}
return list;
}
private void addAllDefaultUnlockedBgmIds(Set<Integer> list) {
GameData.getHomeWorldBgmDataMap().int2ObjectEntrySet().stream()
.filter(entry -> entry.getValue().isDefaultUnlock())
.forEach(entry -> list.add(entry.getIntKey()));
}
}
......@@ -25,6 +25,7 @@ public class HomeSceneItem {
Position bornPos;
Position bornRot;
Position djinnPos;
int homeBgmId;
HomeFurnitureItem mainHouse;
int tmpVersion;
public static HomeSceneItem parseFrom(HomeworldDefaultSaveData defaultItem, int sceneId) {
......@@ -55,6 +56,7 @@ public class HomeSceneItem {
this.bornPos = new Position(arrangementInfo.getBornPos());
this.bornRot = new Position(arrangementInfo.getBornRot());
this.djinnPos = new Position(arrangementInfo.getDjinnPos());
this.homeBgmId = arrangementInfo.getUnk2700BJHAMKKECEI();
this.mainHouse = HomeFurnitureItem.parseFrom(arrangementInfo.getMainHouse());
this.tmpVersion = arrangementInfo.getTmpVersion();
}
......@@ -82,6 +84,7 @@ public class HomeSceneItem {
.setDjinnPos(djinnPos.toProto())
.setIsSetBornPos(true)
.setSceneId(sceneId)
.setUnk2700BJHAMKKECEI(homeBgmId)
.setTmpVersion(tmpVersion);
if(mainHouse != null){
......
......@@ -833,6 +833,17 @@ public class InventorySystem extends BaseGameSystem {
break;
}
break;
case MATERIAL_BGM:
ItemUseData use = itemData.getItemUse().get(0);
if (use.getUseOp() == ItemUseOp.ITEM_USE_UNLOCK_HOME_BGM) {
int bgmId = Integer.parseInt(use.getUseParam()[0]);
player.getInventory().removeItem(useItem, 1);
player.sendPacket(new PacketUnlockHomeBgmNotify(bgmId));
player.getHome().addUnlockedHomeBgm(bgmId);
player.sendPacket(new PacketUnlockedHomeBgmNotify(player));
return useItem;
}
break;
default:
break;
}
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.Unk2700BEDLIGJANCJClientReq;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketChangeHomeBgmNotify;
import emu.grasscutter.server.packet.send.PacketChangeHomeBgmRsp;
import emu.grasscutter.server.packet.send.PacketUnlockedHomeBgmNotify;
@Opcodes(PacketOpcodes.Unk2700_BEDLIGJANCJ_ClientReq)
public class HandlerChangeHomeBgmReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
var req = Unk2700BEDLIGJANCJClientReq.Unk2700_BEDLIGJANCJ_ClientReq.parseFrom(payload);
int homeBgmId = req.getUnk2700BJHAMKKECEI();
var home = session.getPlayer().getHome();
if (!home.getUnlockedHomeBgmListInfo().contains(homeBgmId)) {
home.addUnlockedHomeBgm(homeBgmId);
session.send(new PacketUnlockedHomeBgmNotify(session.getPlayer()));
}
home.getHomeSceneItem(session.getPlayer().getSceneId()).setHomeBgmId(homeBgmId);
home.save();
session.send(new PacketChangeHomeBgmNotify(homeBgmId));
session.send(new PacketChangeHomeBgmRsp());
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.Unk2700FJEHHCPCBLGServerNotify;
public class PacketChangeHomeBgmNotify extends BasePacket {
public PacketChangeHomeBgmNotify(int homeBgmId) {
super(PacketOpcodes.Unk2700_FJEHHCPCBLG_ServerNotify);
var notify = Unk2700FJEHHCPCBLGServerNotify.Unk2700_FJEHHCPCBLG_ServerNotify.newBuilder()
.setUnk2700BJHAMKKECEI(homeBgmId)
.build();
this.setData(notify);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.Unk2700OGHMHELMBNNServerRsp;
public class PacketChangeHomeBgmRsp extends BasePacket {
public PacketChangeHomeBgmRsp() {
super(PacketOpcodes.Unk2700_OGHMHELMBNN_ServerRsp);
var rsp = Unk2700OGHMHELMBNNServerRsp.Unk2700_OGHMHELMBNN_ServerRsp.newBuilder()
.setRetcode(0)
.build();
this.setData(rsp);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.Unk2700MEBFPBDNPGOServerNotify;
public class PacketUnlockHomeBgmNotify extends BasePacket {
public PacketUnlockHomeBgmNotify(int homeBgmId) {
super(PacketOpcodes.Unk2700_MEBFPBDNPGO_ServerNotify);
var notify = Unk2700MEBFPBDNPGOServerNotify.Unk2700_MEBFPBDNPGO_ServerNotify.newBuilder()
.addUnk2700ELJPLMIHNIP(homeBgmId)
.build();
this.setData(notify);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.Unk2700LOHBMOKOPLHServerNotify;
public class PacketUnlockedHomeBgmNotify extends BasePacket {
public PacketUnlockedHomeBgmNotify(Player player) {
super(PacketOpcodes.Unk2700_LOHBMOKOPLH_ServerNotify);
if (player.getRealmList() == null) {
return;
}
var unlocked = player.getHome().getUnlockedHomeBgmListInfo();
var notify = Unk2700LOHBMOKOPLHServerNotify.Unk2700_LOHBMOKOPLH_ServerNotify.newBuilder()
.addAllUnk2700KMEKMNONMGE(unlocked)
.build();
this.setData(notify);
}
}
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