feat: add more home mark point (#2323)

This commit is contained in:
hamusuke
2023-08-31 08:32:47 +09:00
committed by GitHub
parent 7049cfdb58
commit e8f4949836
10 changed files with 257 additions and 54 deletions

View File

@@ -4,12 +4,15 @@ import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import emu.grasscutter.data.binout.HomeworldDefaultSaveData;
import emu.grasscutter.net.proto.HomeBlockArrangementInfoOuterClass.HomeBlockArrangementInfo;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
@Entity
@Data
@Builder(builderMethodName = "of")
@@ -77,6 +80,8 @@ public class HomeBlockItem {
.setIsUnlocked(unlocked)
.setComfortValue(calComfort());
this.reassignIfNull();
this.deployFurnitureList.forEach(f -> proto.addDeployFurniureList(f.toProto()));
this.persistentFurnitureList.forEach(f -> proto.addPersistentFurnitureList(f.toProto()));
this.deployAnimalList.forEach(f -> proto.addDeployAnimalList(f.toProto()));
@@ -84,4 +89,26 @@ public class HomeBlockItem {
return proto.build();
}
// TODO add more types (farm field and suite)
public List<? extends HomeMarkPointProtoFactory> getMarkPointProtoFactories() {
this.reassignIfNull();
return Stream.of(this.deployFurnitureList, this.persistentFurnitureList, this.deployNPCList).flatMap(Collection::stream).toList();
}
public void reassignIfNull() {
if (this.deployFurnitureList == null) {
this.deployFurnitureList = List.of();
}
if (this.persistentFurnitureList == null) {
this.persistentFurnitureList = List.of();
}
if (this.deployAnimalList == null) {
this.deployAnimalList = List.of();
}
if (this.deployNPCList == null) {
this.deployNPCList = List.of();
}
}
}

View File

@@ -11,12 +11,24 @@ import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
import java.util.stream.Collectors;
@Entity
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(builderMethodName = "of")
public class HomeFurnitureItem {
public class HomeFurnitureItem implements HomeMarkPointProtoFactory {
public static final int PAIMON_FURNITURE_ID = 368134;
public static final int TELEPORT_FURNITURE_ID = 373501;
public static final Set<Integer> APARTMENT_FURNITURE_ID_SET = GameData.getItemDataMap().values()
.stream()
.filter(itemData -> itemData.getSpecialFurnitureType() == SpecialFurnitureType.Apartment)
.map(ItemData::getId)
.collect(Collectors.toUnmodifiableSet());
int furnitureId;
int guid;
int parentFurnitureIndex;
@@ -56,17 +68,6 @@ 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 ItemData getAsItem() {
return GameData.getItemDataMap().get(this.furnitureId);
}
@@ -79,4 +80,29 @@ public class HomeFurnitureItem {
}
return item.getComfort();
}
@Nullable
@Override
public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto() {
var type = this.adjustByFurnitureId();
if (type == SpecialFurnitureType.NOT_SPECIAL) {
return null;
}
return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder()
.setFurnitureId(this.furnitureId)
.setFurnitureType(type.getValue())
.setPos(this.spawnPos.toProto())
.setGuid(this.guid)
.build();
}
@Override
public SpecialFurnitureType adjustByFurnitureId() {
return switch (this.furnitureId) {
case PAIMON_FURNITURE_ID -> SpecialFurnitureType.Paimon;
case TELEPORT_FURNITURE_ID -> SpecialFurnitureType.TeleportPoint;
default -> APARTMENT_FURNITURE_ID_SET.contains(this.furnitureId) ? SpecialFurnitureType.Apartment : SpecialFurnitureType.NOT_SPECIAL;
};
}
}

View File

@@ -0,0 +1,21 @@
package emu.grasscutter.game.home;
import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass;
import org.jetbrains.annotations.Nullable;
public interface HomeMarkPointProtoFactory {
@Nullable
HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto();
default SpecialFurnitureType adjustByFurnitureId() {
return this.getType();
}
default SpecialFurnitureType getType() {
return SpecialFurnitureType.NOT_SPECIAL;
}
default boolean isProtoConvertible() {
return this.adjustByFurnitureId() != SpecialFurnitureType.NOT_SPECIAL;
}
}

View File

@@ -1,18 +1,23 @@
package emu.grasscutter.game.home;
import dev.morphia.annotations.Entity;
import emu.grasscutter.data.GameData;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass;
import emu.grasscutter.net.proto.HomeMarkPointNPCDataOuterClass;
import emu.grasscutter.net.proto.HomeNpcDataOuterClass;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.Nullable;
@Entity
@Data
@FieldDefaults(level = AccessLevel.PRIVATE)
@Builder(builderMethodName = "of")
public class HomeNPCItem {
public class HomeNPCItem implements HomeMarkPointProtoFactory {
transient int furnitureId;
int avatarId;
Position spawnPos;
Position spawnRot;
@@ -20,19 +25,52 @@ public class HomeNPCItem {
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();
.avatarId(homeNpcData.getAvatarId())
.spawnPos(new Position(homeNpcData.getSpawnPos()))
.spawnRot(new Position(homeNpcData.getSpawnRot()))
.costumeId(homeNpcData.getCostumeId())
.build();
}
public HomeNpcDataOuterClass.HomeNpcData toProto() {
return HomeNpcDataOuterClass.HomeNpcData.newBuilder()
.setAvatarId(avatarId)
.setSpawnPos(spawnPos.toProto())
.setSpawnRot(spawnRot.toProto())
.setCostumeId(costumeId)
.build();
.setAvatarId(avatarId)
.setSpawnPos(spawnPos.toProto())
.setSpawnRot(spawnRot.toProto())
.setCostumeId(costumeId)
.build();
}
public int getFurnitureId() {
if (this.furnitureId == 0) {
var data = GameData.getHomeWorldNPCDataMap().get(this.avatarId);
this.furnitureId = data == null ? -1 : data.getFurnitureID();
}
return this.furnitureId;
}
@Nullable
@Override
public HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData toMarkPointProto() {
return HomeMarkPointFurnitureDataOuterClass.HomeMarkPointFurnitureData.newBuilder()
.setFurnitureId(this.getFurnitureId())
.setFurnitureType(this.getType().getValue())
.setPos(this.spawnPos.toProto())
.setNpcData(HomeMarkPointNPCDataOuterClass.HomeMarkPointNPCData.newBuilder()
.setAvatarId(this.avatarId)
.setCostumeId(this.costumeId)
.build())
.build();
}
@Override
public SpecialFurnitureType getType() {
return SpecialFurnitureType.NPC;
}
@Override
public boolean isProtoConvertible() {
return this.getFurnitureId() > 0;
}
}

View File

@@ -6,13 +6,14 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.binout.HomeworldDefaultSaveData;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.net.proto.HomeSceneArrangementInfoOuterClass.HomeSceneArrangementInfo;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults;
import java.util.Map;
import java.util.stream.Collectors;
@Entity
@Data
@Builder(builderMethodName = "of")
@@ -64,12 +65,16 @@ public class HomeSceneItem {
}
public int getRoomSceneId() {
if (mainHouse == null || mainHouse.getAsItem() == null) {
if (this.isRoom()) {
return 0;
}
return mainHouse.getAsItem().getRoomSceneId();
}
public boolean isRoom() {
return mainHouse == null || mainHouse.getAsItem() == null;
}
public int calComfort() {
return this.blockItems.values().stream().mapToInt(HomeBlockItem::calComfort).sum();
}

View File

@@ -0,0 +1,20 @@
package emu.grasscutter.game.home;
import lombok.Getter;
@Getter
public enum SpecialFurnitureType {
NOT_SPECIAL(-1),
FarmField(2),
TeleportPoint(3),
NPC(5),
Apartment(6),
FurnitureSuite(7),
Paimon(8);
private final int value;
SpecialFurnitureType(int value) {
this.value = value;
}
}