npc/animals arrangement & support enter room scene

This commit is contained in:
Akka 2022-06-15 17:20:08 +08:00 committed by Melledy
parent 1c0d869ee5
commit a695d0c33e
9 changed files with 145 additions and 21 deletions

View File

@ -65,6 +65,6 @@ public class GameHome {
player.getSession().send(new PacketPlayerHomeCompInfoNotify(player));
player.getSession().send(new PacketHomeComfortInfoNotify(player));
player.getSession().send(new PacketFurnitureCurModuleArrangeCountNotify());
player.getSession().send(new PacketUnlockedFurnitureFormulaDataNotify());
player.getSession().send(new PacketHomeMarkPointNotify(player, this));
}
}

View File

@ -0,0 +1,37 @@
package emu.grasscutter.game.home;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.HomeAnimalDataOuterClass;
import emu.grasscutter.net.proto.HomeFurnitureDataOuterClass;
import emu.grasscutter.utils.Position;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
@Entity
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(builderMethodName = "of")
public class HomeAnimalItem {
int furnitureId;
Position spawnPos;
Position spawnRot;
public HomeAnimalDataOuterClass.HomeAnimalData toProto(){
return HomeAnimalDataOuterClass.HomeAnimalData.newBuilder()
.setFurnitureId(furnitureId)
.setSpawnPos(spawnPos.toProto())
.setSpawnRot(spawnRot.toProto())
.build();
}
public static HomeAnimalItem parseFrom(HomeAnimalDataOuterClass.HomeAnimalData homeAnimalData) {
return HomeAnimalItem.of()
.furnitureId(homeAnimalData.getFurnitureId())
.spawnPos(new Position(homeAnimalData.getSpawnPos()))
.spawnRot(new Position(homeAnimalData.getSpawnRot()))
.build();
}
}

View File

@ -16,13 +16,12 @@ import java.util.List;
@Builder(builderMethodName = "of")
@FieldDefaults(level = AccessLevel.PRIVATE)
public class HomeBlockItem {
@Id
int blockId;
boolean unlocked;
List<HomeFurnitureItem> deployFurnitureList;
List<HomeAnimalItem> deployAnimalList;
List<HomeNPCItem> deployNPCList;
public void update(HomeBlockArrangementInfo homeBlockArrangementInfo) {
this.blockId = homeBlockArrangementInfo.getBlockId();
@ -30,6 +29,14 @@ public class HomeBlockItem {
this.deployFurnitureList = homeBlockArrangementInfo.getDeployFurniureListList().stream()
.map(HomeFurnitureItem::parseFrom)
.toList();
this.deployAnimalList = homeBlockArrangementInfo.getDeployAnimalListList().stream()
.map(HomeAnimalItem::parseFrom)
.toList();
this.deployNPCList = homeBlockArrangementInfo.getDeployNpcListList().stream()
.map(HomeNPCItem::parseFrom)
.toList();
}
public int calComfort(){
@ -45,6 +52,8 @@ public class HomeBlockItem {
.setComfortValue(calComfort());
this.deployFurnitureList.forEach(f -> proto.addDeployFurniureList(f.toProto()));
this.deployAnimalList.forEach(f -> proto.addDeployAnimalList(f.toProto()));
this.deployNPCList.forEach(f -> proto.addDeployNpcList(f.toProto()));
return proto.build();
}
@ -59,6 +68,8 @@ public class HomeBlockItem {
homeBlock.getFurnitures().stream()
.map(HomeFurnitureItem::parseFrom)
.toList())
.deployAnimalList(List.of())
.deployNPCList(List.of())
.build();
}
}

View File

@ -5,6 +5,7 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.HomeworldDefaultSaveData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.net.proto.HomeFurnitureDataOuterClass;
import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass;
import emu.grasscutter.utils.Position;
import lombok.AccessLevel;
import lombok.Builder;
@ -32,6 +33,16 @@ public class HomeFurnitureItem {
.build();
}
public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto(int type){
return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder()
.setFurnitureId(furnitureId)
.setGuid(guid)
.setFurnitureType(type)
.setPos(spawnPos.toProto())
// TODO NPC and farm
.build();
}
public static HomeFurnitureItem parseFrom(HomeFurnitureDataOuterClass.HomeFurnitureData homeFurnitureData) {
return HomeFurnitureItem.of()
.furnitureId(homeFurnitureData.getFurnitureId())

View File

@ -0,0 +1,39 @@
package emu.grasscutter.game.home;
import dev.morphia.annotations.Entity;
import emu.grasscutter.net.proto.HomeAnimalDataOuterClass;
import emu.grasscutter.net.proto.HomeNpcDataOuterClass;
import emu.grasscutter.utils.Position;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
@Entity
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(builderMethodName = "of")
public class HomeNPCItem {
int avatarId;
Position spawnPos;
Position spawnRot;
int costumeId;
public HomeNpcDataOuterClass.HomeNpcData toProto(){
return HomeNpcDataOuterClass.HomeNpcData.newBuilder()
.setAvatarId(avatarId)
.setSpawnPos(spawnPos.toProto())
.setSpawnRot(spawnRot.toProto())
.setCostumeId(costumeId)
.build();
}
public static HomeNPCItem parseFrom(HomeNpcDataOuterClass.HomeNpcData homeNpcData) {
return HomeNPCItem.of()
.avatarId(homeNpcData.getAvatarId())
.spawnPos(new Position(homeNpcData.getSpawnPos()))
.spawnRot(new Position(homeNpcData.getSpawnRot()))
.costumeId(homeNpcData.getCostumeId())
.build();
}
}

View File

@ -2,6 +2,7 @@ package emu.grasscutter.game.home;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.HomeworldDefaultSaveData;
import emu.grasscutter.net.proto.HomeBasicInfoOuterClass.HomeBasicInfo;
import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo;
@ -45,7 +46,7 @@ public class HomeSceneItem {
for(var blockItem : arrangementInfo.getBlockArrangementInfoListList()){
var block = this.blockItems.get(blockItem.getBlockId());
if(block == null){
System.out.println(111);
Grasscutter.getLogger().warn("Could not found the Home Block {}", blockItem.getBlockId());
continue;
}
block.update(blockItem);
@ -79,6 +80,7 @@ public class HomeSceneItem {
.setBornPos(bornPos.toProto())
.setBornRot(bornRot.toProto())
.setDjinnPos(djinnPos.toProto())
.setIsSetBornPos(true)
.setSceneId(sceneId)
.setTmpVersion(1);

View File

@ -1,11 +1,13 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeSceneJumpReqOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketHomeSceneJumpRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.HomeSceneJumpReq)
public class HandlerHomeSceneJumpReq extends PacketHandler {
@ -20,21 +22,14 @@ public class HandlerHomeSceneJumpReq extends PacketHandler {
var homeScene = home.getHomeSceneItem(realmId);
home.save();
if(req.getIsEnterRoomScene()){
var roomScene = home.getHomeSceneItem(homeScene.getRoomSceneId());
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
homeScene.getRoomSceneId(),
roomScene.getBornPos()
);
}else{
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
realmId,
homeScene.getBornPos()
);
}
Scene scene = session.getPlayer().getWorld().getSceneById(req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId);
Position pos = scene.getScriptManager().getConfig().born_pos;
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
req.getIsEnterRoomScene() ? homeScene.getRoomSceneId() : realmId,
pos
);
session.send(new PacketHomeSceneJumpRsp(req.getIsEnterRoomScene()));
}

View File

@ -30,13 +30,18 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
int realmId = 2000 + session.getPlayer().getCurrentRealmId();
var home = session.getPlayer().getHome();
// prepare the default arrangement for first come in
var homeScene = home.getHomeSceneItem(realmId);
home.save();
Scene scene = session.getPlayer().getWorld().getSceneById(realmId);
Position pos = scene.getScriptManager().getConfig().born_pos;
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
realmId,
homeScene.getBornPos()
pos
);

View File

@ -1,10 +1,14 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.home.GameHome;
import emu.grasscutter.game.home.HomeBlockItem;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeMarkPointNotifyOuterClass;
import emu.grasscutter.net.proto.HomeMarkPointSceneDataOuterClass;
import java.util.Collection;
public class PacketHomeMarkPointNotify extends BasePacket {
@ -13,6 +17,26 @@ public class PacketHomeMarkPointNotify extends BasePacket {
var proto = HomeMarkPointNotifyOuterClass.HomeMarkPointNotify.newBuilder();
for(var moduleId : player.getRealmList()){
var homeScene = home.getHomeSceneItem(moduleId + 2000);
var markPointData = HomeMarkPointSceneDataOuterClass.HomeMarkPointSceneData.newBuilder()
.setModuleId(moduleId)
.setSceneId(moduleId + 2000)
.setTeapotSpiritPos(homeScene.getDjinnPos().toProto());
// Now it only supports the teleport point
// TODO add more types
var marks = homeScene.getBlockItems().values().stream()
.map(HomeBlockItem::getDeployFurnitureList)
.flatMap(Collection::stream)
.filter(i -> i.getFurnitureId() == 373501)
.map(x -> x.toMarkPointProto(3))
.toList();
markPointData.addAllFurnitureList(marks);
proto.addMarkPointDataList(markPointData);
}
this.setData(proto);
}