fix: sync home avatar costume (#2326)

This commit is contained in:
hamusuke 2023-09-02 09:31:55 +09:00 committed by GitHub
parent 6fc4859f31
commit 0db69882a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 12 deletions

View File

@ -1,17 +1,23 @@
package emu.grasscutter.game.avatar; package emu.grasscutter.game.avatar;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.avatar.*; import emu.grasscutter.data.excels.avatar.AvatarData;
import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.inventory.GameItem; import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.player.*; import emu.grasscutter.game.player.BasePlayerManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.entity.EntityCreationEvent; import emu.grasscutter.server.event.entity.EntityCreationEvent;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeNotify;
import it.unimi.dsi.fastutil.ints.*; import emu.grasscutter.server.packet.send.PacketAvatarFlycloakChangeNotify;
import it.unimi.dsi.fastutil.longs.*; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.*; import java.util.Iterator;
import java.util.List;
public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar> { public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar> {
private final Int2ObjectMap<Avatar> avatars; private final Int2ObjectMap<Avatar> avatars;
@ -114,11 +120,14 @@ public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar>
entity = entity =
EntityCreationEvent.call( EntityCreationEvent.call(
EntityAvatar.class, new Class<?>[] {Avatar.class}, new Object[] {avatar}); EntityAvatar.class, new Class<?>[] {Avatar.class}, new Object[] {avatar});
getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity)); getPlayer().getWorld().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
} else { } else {
getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity)); getPlayer().getWorld().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
} }
// Notify costume change to HomeWorld
this.getPlayer().getHome().onPlayerChangedAvatarCostume(avatar);
// Done // Done
return true; return true;
} }

View File

@ -6,11 +6,14 @@ import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.HomeWorldLevelData; import emu.grasscutter.data.excels.HomeWorldLevelData;
import emu.grasscutter.data.excels.scene.SceneData; import emu.grasscutter.data.excels.scene.SceneData;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.props.SceneType;
import emu.grasscutter.server.packet.send.*; import emu.grasscutter.server.packet.send.*;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.*; import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.FieldDefaults; import lombok.experimental.FieldDefaults;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
@ -102,6 +105,24 @@ public class GameHome {
player.getSession().send(new PacketHomeResourceNotify(player)); player.getSession().send(new PacketHomeResourceNotify(player));
} }
public void onPlayerChangedAvatarCostume(Avatar avatar) {
var world = this.player.getServer().getHomeWorldOrCreate(this.player);
world.broadcastPacket(new PacketHomeAvatarCostumeChangeNotify(avatar.getAvatarId(), avatar.getCostume()));
this.sceneMap.values().stream()
.map(HomeSceneItem::getBlockItems)
.map(Map::values)
.flatMap(Collection::stream)
.map(HomeBlockItem::getDeployNPCList)
.flatMap(Collection::stream)
.filter(homeNPCItem -> homeNPCItem.getAvatarId() == avatar.getAvatarId())
.forEach(homeNPCItem -> homeNPCItem.setCostumeId(avatar.getCostume()));
this.save();
world.getPlayers().forEach(player -> player.sendPacket(new PacketHomeMarkPointNotify(player)));
}
// Tell the client the reward is claimed or realm unlocked // Tell the client the reward is claimed or realm unlocked
public void onClaimReward(Player player) { public void onClaimReward(Player player) {
player.getSession().send(new PacketPlayerHomeCompInfoNotify(player)); player.getSession().send(new PacketPlayerHomeCompInfoNotify(player));

View File

@ -3,8 +3,12 @@ package emu.grasscutter.game.home;
import dev.morphia.annotations.Entity; import dev.morphia.annotations.Entity;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.game.world.Position; import emu.grasscutter.game.world.Position;
import emu.grasscutter.net.proto.*; import emu.grasscutter.net.proto.HomeMarkPointFurnitureDataOuterClass;
import lombok.*; 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 lombok.experimental.FieldDefaults;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -24,7 +28,6 @@ public class HomeNPCItem implements HomeMarkPointProtoFactory {
.avatarId(homeNpcData.getAvatarId()) .avatarId(homeNpcData.getAvatarId())
.spawnPos(new Position(homeNpcData.getSpawnPos())) .spawnPos(new Position(homeNpcData.getSpawnPos()))
.spawnRot(new Position(homeNpcData.getSpawnRot())) .spawnRot(new Position(homeNpcData.getSpawnRot()))
.costumeId(homeNpcData.getCostumeId())
.build(); .build();
} }

View File

@ -0,0 +1,15 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.HomeAvatarCostumeChangeNotifyOuterClass;
public class PacketHomeAvatarCostumeChangeNotify extends BasePacket {
public PacketHomeAvatarCostumeChangeNotify(int avatarId, int costumeId) {
super(PacketOpcodes.HomeAvatarCostumeChangeNotify);
this.setData(HomeAvatarCostumeChangeNotifyOuterClass.HomeAvatarCostumeChangeNotify.newBuilder()
.setAvatarId(avatarId)
.setCostumeId(costumeId));
}
}