mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 06:31:26 +00:00
Remove gadgets from world when a player leaves
This commit is contained in:
parent
c919c9c9eb
commit
ad57bb91df
@ -2,9 +2,12 @@ package emu.grasscutter.game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import dev.morphia.annotations.Transient;
|
||||
import emu.grasscutter.GenshinConstants;
|
||||
import emu.grasscutter.data.def.AvatarSkillDepotData;
|
||||
@ -47,14 +50,14 @@ public class TeamManager {
|
||||
@Transient private TeamInfo mpTeam;
|
||||
@Transient private int entityId;
|
||||
@Transient private final List<EntityAvatar> avatars;
|
||||
@Transient private final List<EntityGadget> gadgets;
|
||||
@Transient private final Set<EntityGadget> gadgets;
|
||||
@Transient private final IntSet teamResonances;
|
||||
@Transient private final IntSet teamResonancesConfig;
|
||||
|
||||
public TeamManager() {
|
||||
this.mpTeam = new TeamInfo();
|
||||
this.avatars = new ArrayList<>();
|
||||
this.gadgets = new ArrayList<>();
|
||||
this.gadgets = new HashSet<>();
|
||||
this.teamResonances = new IntOpenHashSet();
|
||||
this.teamResonancesConfig = new IntOpenHashSet();
|
||||
}
|
||||
@ -134,6 +137,10 @@ public class TeamManager {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public Set<EntityGadget> getGadgets() {
|
||||
return gadgets;
|
||||
}
|
||||
|
||||
public IntSet getTeamResonances() {
|
||||
return teamResonances;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import emu.grasscutter.game.props.LifeState;
|
||||
import emu.grasscutter.game.GenshinPlayer.SceneLoadState;
|
||||
import emu.grasscutter.game.entity.EntityAvatar;
|
||||
import emu.grasscutter.game.entity.EntityClientGadget;
|
||||
import emu.grasscutter.game.entity.EntityGadget;
|
||||
import emu.grasscutter.net.packet.GenshinPacket;
|
||||
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
|
||||
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
|
||||
@ -197,6 +198,11 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
this.updatePlayerInfos(player);
|
||||
}
|
||||
|
||||
// Remove player gadgets
|
||||
for (EntityGadget gadget : player.getTeamManager().getGadgets()) {
|
||||
this.removeEntity(gadget);
|
||||
}
|
||||
|
||||
// Disband world if host leaves
|
||||
if (getHost() == player) {
|
||||
List<GenshinPlayer> kicked = new ArrayList<>(this.getPlayers());
|
||||
@ -377,7 +383,8 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
// Directly add
|
||||
this.addEntityDirectly(gadget);
|
||||
|
||||
// Add to owner's gadget list TODO
|
||||
// Add to owner's gadget list
|
||||
gadget.getOwner().getTeamManager().getGadgets().add(gadget);
|
||||
|
||||
// Optimization
|
||||
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
|
||||
@ -398,7 +405,8 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
EntityClientGadget gadget = (EntityClientGadget) entity;
|
||||
this.removeEntityDirectly(gadget);
|
||||
|
||||
// Remove from owner's gadget list TODO
|
||||
// Remove from owner's gadget list
|
||||
gadget.getOwner().getTeamManager().getGadgets().remove(gadget);
|
||||
|
||||
// Optimization
|
||||
if (this.getPlayerCount() == 1 && this.getPlayers().get(0) == gadget.getOwner()) {
|
||||
|
@ -19,6 +19,11 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
// Sanity check - dont add duplicate entities
|
||||
if (session.getPlayer().getWorld().getEntityById(notify.getEntityId()) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create entity and summon in world
|
||||
EntityClientGadget gadget = new EntityClientGadget(session.getPlayer().getWorld(), session.getPlayer(), notify);
|
||||
session.getPlayer().getWorld().onPlayerCreateGadget(gadget);
|
||||
|
Loading…
Reference in New Issue
Block a user