Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
ad57bb91
Commit
ad57bb91
authored
Apr 17, 2022
by
Melledy
Browse files
Remove gadgets from world when a player leaves
parent
c919c9c9
Changes
3
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/TeamManager.java
View file @
ad57bb91
...
@@ -2,9 +2,12 @@ package emu.grasscutter.game;
...
@@ -2,9 +2,12 @@ package emu.grasscutter.game;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
dev.morphia.annotations.Transient
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.GenshinConstants
;
import
emu.grasscutter.GenshinConstants
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
import
emu.grasscutter.data.def.AvatarSkillDepotData
;
...
@@ -47,14 +50,14 @@ public class TeamManager {
...
@@ -47,14 +50,14 @@ public class TeamManager {
@Transient
private
TeamInfo
mpTeam
;
@Transient
private
TeamInfo
mpTeam
;
@Transient
private
int
entityId
;
@Transient
private
int
entityId
;
@Transient
private
final
List
<
EntityAvatar
>
avatars
;
@Transient
private
final
List
<
EntityAvatar
>
avatars
;
@Transient
private
final
Lis
t
<
EntityGadget
>
gadgets
;
@Transient
private
final
Se
t
<
EntityGadget
>
gadgets
;
@Transient
private
final
IntSet
teamResonances
;
@Transient
private
final
IntSet
teamResonances
;
@Transient
private
final
IntSet
teamResonancesConfig
;
@Transient
private
final
IntSet
teamResonancesConfig
;
public
TeamManager
()
{
public
TeamManager
()
{
this
.
mpTeam
=
new
TeamInfo
();
this
.
mpTeam
=
new
TeamInfo
();
this
.
avatars
=
new
ArrayList
<>();
this
.
avatars
=
new
ArrayList
<>();
this
.
gadgets
=
new
ArrayLis
t
<>();
this
.
gadgets
=
new
HashSe
t
<>();
this
.
teamResonances
=
new
IntOpenHashSet
();
this
.
teamResonances
=
new
IntOpenHashSet
();
this
.
teamResonancesConfig
=
new
IntOpenHashSet
();
this
.
teamResonancesConfig
=
new
IntOpenHashSet
();
}
}
...
@@ -134,6 +137,10 @@ public class TeamManager {
...
@@ -134,6 +137,10 @@ public class TeamManager {
this
.
entityId
=
entityId
;
this
.
entityId
=
entityId
;
}
}
public
Set
<
EntityGadget
>
getGadgets
()
{
return
gadgets
;
}
public
IntSet
getTeamResonances
()
{
public
IntSet
getTeamResonances
()
{
return
teamResonances
;
return
teamResonances
;
}
}
...
...
src/main/java/emu/grasscutter/game/World.java
View file @
ad57bb91
...
@@ -17,6 +17,7 @@ import emu.grasscutter.game.props.LifeState;
...
@@ -17,6 +17,7 @@ import emu.grasscutter.game.props.LifeState;
import
emu.grasscutter.game.GenshinPlayer.SceneLoadState
;
import
emu.grasscutter.game.GenshinPlayer.SceneLoadState
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityClientGadget
;
import
emu.grasscutter.game.entity.EntityClientGadget
;
import
emu.grasscutter.game.entity.EntityGadget
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult
;
import
emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult
;
import
emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType
;
import
emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType
;
...
@@ -197,6 +198,11 @@ public class World implements Iterable<GenshinPlayer> {
...
@@ -197,6 +198,11 @@ public class World implements Iterable<GenshinPlayer> {
this
.
updatePlayerInfos
(
player
);
this
.
updatePlayerInfos
(
player
);
}
}
// Remove player gadgets
for
(
EntityGadget
gadget
:
player
.
getTeamManager
().
getGadgets
())
{
this
.
removeEntity
(
gadget
);
}
// Disband world if host leaves
// Disband world if host leaves
if
(
getHost
()
==
player
)
{
if
(
getHost
()
==
player
)
{
List
<
GenshinPlayer
>
kicked
=
new
ArrayList
<>(
this
.
getPlayers
());
List
<
GenshinPlayer
>
kicked
=
new
ArrayList
<>(
this
.
getPlayers
());
...
@@ -377,7 +383,8 @@ public class World implements Iterable<GenshinPlayer> {
...
@@ -377,7 +383,8 @@ public class World implements Iterable<GenshinPlayer> {
// Directly add
// Directly add
this
.
addEntityDirectly
(
gadget
);
this
.
addEntityDirectly
(
gadget
);
// Add to owner's gadget list TODO
// Add to owner's gadget list
gadget
.
getOwner
().
getTeamManager
().
getGadgets
().
add
(
gadget
);
// Optimization
// Optimization
if
(
this
.
getPlayerCount
()
==
1
&&
this
.
getPlayers
().
get
(
0
)
==
gadget
.
getOwner
())
{
if
(
this
.
getPlayerCount
()
==
1
&&
this
.
getPlayers
().
get
(
0
)
==
gadget
.
getOwner
())
{
...
@@ -398,7 +405,8 @@ public class World implements Iterable<GenshinPlayer> {
...
@@ -398,7 +405,8 @@ public class World implements Iterable<GenshinPlayer> {
EntityClientGadget
gadget
=
(
EntityClientGadget
)
entity
;
EntityClientGadget
gadget
=
(
EntityClientGadget
)
entity
;
this
.
removeEntityDirectly
(
gadget
);
this
.
removeEntityDirectly
(
gadget
);
// Remove from owner's gadget list TODO
// Remove from owner's gadget list
gadget
.
getOwner
().
getTeamManager
().
getGadgets
().
remove
(
gadget
);
// Optimization
// Optimization
if
(
this
.
getPlayerCount
()
==
1
&&
this
.
getPlayers
().
get
(
0
)
==
gadget
.
getOwner
())
{
if
(
this
.
getPlayerCount
()
==
1
&&
this
.
getPlayers
().
get
(
0
)
==
gadget
.
getOwner
())
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEvtCreateGadgetNotify.java
View file @
ad57bb91
...
@@ -19,6 +19,11 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
...
@@ -19,6 +19,11 @@ public class HandlerEvtCreateGadgetNotify extends PacketHandler {
return
;
return
;
}
}
// Sanity check - dont add duplicate entities
if
(
session
.
getPlayer
().
getWorld
().
getEntityById
(
notify
.
getEntityId
())
!=
null
)
{
return
;
}
// Create entity and summon in world
// Create entity and summon in world
EntityClientGadget
gadget
=
new
EntityClientGadget
(
session
.
getPlayer
().
getWorld
(),
session
.
getPlayer
(),
notify
);
EntityClientGadget
gadget
=
new
EntityClientGadget
(
session
.
getPlayer
().
getWorld
(),
session
.
getPlayer
(),
notify
);
session
.
getPlayer
().
getWorld
().
onPlayerCreateGadget
(
gadget
);
session
.
getPlayer
().
getWorld
().
onPlayerCreateGadget
(
gadget
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment