mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 06:31:26 +00:00
fix: sync home avatar costume (#2326)
This commit is contained in:
parent
6fc4859f31
commit
0db69882a3
@ -1,17 +1,23 @@
|
||||
package emu.grasscutter.game.avatar;
|
||||
|
||||
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.game.entity.EntityAvatar;
|
||||
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.packet.send.*;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import it.unimi.dsi.fastutil.longs.*;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarChangeCostumeNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketAvatarFlycloakChangeNotify;
|
||||
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> {
|
||||
private final Int2ObjectMap<Avatar> avatars;
|
||||
@ -114,11 +120,14 @@ public class AvatarStorage extends BasePlayerManager implements Iterable<Avatar>
|
||||
entity =
|
||||
EntityCreationEvent.call(
|
||||
EntityAvatar.class, new Class<?>[] {Avatar.class}, new Object[] {avatar});
|
||||
getPlayer().sendPacket(new PacketAvatarChangeCostumeNotify(entity));
|
||||
getPlayer().getWorld().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
|
||||
} else {
|
||||
getPlayer().getScene().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
|
||||
getPlayer().getWorld().broadcastPacket(new PacketAvatarChangeCostumeNotify(entity));
|
||||
}
|
||||
|
||||
// Notify costume change to HomeWorld
|
||||
this.getPlayer().getHome().onPlayerChangedAvatarCostume(avatar);
|
||||
|
||||
// Done
|
||||
return true;
|
||||
}
|
||||
|
@ -6,11 +6,14 @@ import emu.grasscutter.data.GameData;
|
||||
import emu.grasscutter.data.excels.HomeWorldLevelData;
|
||||
import emu.grasscutter.data.excels.scene.SceneData;
|
||||
import emu.grasscutter.database.DatabaseHelper;
|
||||
import emu.grasscutter.game.avatar.Avatar;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.SceneType;
|
||||
import emu.grasscutter.server.packet.send.*;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import lombok.*;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
@ -102,6 +105,24 @@ public class GameHome {
|
||||
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
|
||||
public void onClaimReward(Player player) {
|
||||
player.getSession().send(new PacketPlayerHomeCompInfoNotify(player));
|
||||
|
@ -3,8 +3,12 @@ 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.*;
|
||||
import lombok.*;
|
||||
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;
|
||||
|
||||
@ -24,7 +28,6 @@ public class HomeNPCItem implements HomeMarkPointProtoFactory {
|
||||
.avatarId(homeNpcData.getAvatarId())
|
||||
.spawnPos(new Position(homeNpcData.getSpawnPos()))
|
||||
.spawnRot(new Position(homeNpcData.getSpawnRot()))
|
||||
.costumeId(homeNpcData.getCostumeId())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user