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
7f2de4fa
Commit
7f2de4fa
authored
Apr 20, 2022
by
Melledy
Browse files
Fix player location updates in co-op
parent
b9876fc0
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
7f2de4fa
...
...
@@ -31,6 +31,7 @@ import emu.grasscutter.net.proto.OnlinePlayerInfoOuterClass.OnlinePlayerInfo;
import
emu.grasscutter.net.proto.PlayerApplyEnterMpReasonOuterClass.PlayerApplyEnterMpReason
;
import
emu.grasscutter.net.proto.PlayerLocationInfoOuterClass.PlayerLocationInfo
;
import
emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail
;
import
emu.grasscutter.net.proto.WorldPlayerLocationInfoOuterClass.WorldPlayerLocationInfo
;
import
emu.grasscutter.server.game.GameServer
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketAbilityInvocationsNotify
;
...
...
@@ -49,9 +50,11 @@ import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
import
emu.grasscutter.server.packet.send.PacketPlayerPropNotify
;
import
emu.grasscutter.server.packet.send.PacketPlayerStoreNotify
;
import
emu.grasscutter.server.packet.send.PacketPrivateChatNotify
;
import
emu.grasscutter.server.packet.send.PacketScenePlayerLocationNotify
;
import
emu.grasscutter.server.packet.send.PacketSetNameCardRsp
;
import
emu.grasscutter.server.packet.send.PacketStoreWeightLimitNotify
;
import
emu.grasscutter.server.packet.send.PacketUnlockNameCardNotify
;
import
emu.grasscutter.server.packet.send.PacketWorldPlayerLocationNotify
;
import
emu.grasscutter.server.packet.send.PacketWorldPlayerRTTNotify
;
import
emu.grasscutter.utils.Position
;
...
...
@@ -101,6 +104,7 @@ public class GenshinPlayer {
@Transient
private
int
enterSceneToken
;
@Transient
private
SceneLoadState
sceneState
;
@Transient
private
boolean
hasSentAvatarDataNotify
;
@Transient
private
long
nextSendPlayerLocTime
=
0
;
@Transient
private
final
Int2ObjectMap
<
CoopRequest
>
coopRequests
;
@Transient
private
final
InvokeHandler
<
CombatInvokeEntry
>
combatInvokeHandler
;
...
...
@@ -654,6 +658,13 @@ public class GenshinPlayer {
return
social
;
}
public
WorldPlayerLocationInfo
getWorldPlayerLocationInfo
()
{
return
WorldPlayerLocationInfo
.
newBuilder
()
.
setSceneId
(
this
.
getSceneId
())
.
setPlayerLoc
(
this
.
getPlayerLocationInfo
())
.
build
();
}
public
PlayerLocationInfo
getPlayerLocationInfo
()
{
return
PlayerLocationInfo
.
newBuilder
()
.
setUid
(
this
.
getUid
())
...
...
@@ -679,9 +690,22 @@ public class GenshinPlayer {
}
// Ping
if
(
this
.
getWorld
()
!=
null
)
{
this
.
sendPacket
(
new
PacketWorldPlayerRTTNotify
(
this
.
getWorld
()));
// Player ping
// RTT notify - very important to send this often
this
.
sendPacket
(
new
PacketWorldPlayerRTTNotify
(
this
.
getWorld
()));
// Update player locations if in multiplayer every 5 seconds
long
time
=
System
.
currentTimeMillis
();
if
(
this
.
getWorld
().
isMultiplayer
()
&&
this
.
getScene
()
!=
null
&&
time
>
nextSendPlayerLocTime
)
{
this
.
sendPacket
(
new
PacketWorldPlayerLocationNotify
(
this
.
getWorld
()));
this
.
sendPacket
(
new
PacketScenePlayerLocationNotify
(
this
.
getScene
()));
this
.
resetSendPlayerLocTime
();
}
}
}
public
void
resetSendPlayerLocTime
()
{
this
.
nextSendPlayerLocTime
=
System
.
currentTimeMillis
()
+
5000
;
}
@PostLoad
private
void
onLoad
()
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerEnterSceneDoneReq.java
View file @
7f2de4fa
...
...
@@ -31,8 +31,11 @@ public class HandlerEnterSceneDoneReq extends PacketHandler {
// Locations
session
.
send
(
new
PacketWorldPlayerLocationNotify
(
session
.
getPlayer
().
getWorld
()));
session
.
send
(
new
PacketScenePlayerLocationNotify
(
session
.
getPlayer
()));
session
.
send
(
new
PacketScenePlayerLocationNotify
(
session
.
getPlayer
()
.
getScene
()
));
session
.
send
(
new
PacketWorldPlayerRTTNotify
(
session
.
getPlayer
().
getWorld
()));
// Reset timer for sending player locations
session
.
getPlayer
().
resetSendPlayerLocTime
();
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketScenePlayerLocationNotify.java
View file @
7f2de4fa
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinScene
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.ScenePlayerLocationNotifyOuterClass.ScenePlayerLocationNotify
;
public
class
PacketScenePlayerLocationNotify
extends
GenshinPacket
{
public
PacketScenePlayerLocationNotify
(
Genshin
Player
player
)
{
public
PacketScenePlayerLocationNotify
(
Genshin
Scene
scene
)
{
super
(
PacketOpcodes
.
ScenePlayerLocationNotify
);
ScenePlayerLocationNotify
.
Builder
proto
=
ScenePlayerLocationNotify
.
newBuilder
()
.
setSceneId
(
player
.
getScene
Id
());
.
setSceneId
(
scene
.
get
Id
());
for
(
GenshinPlayer
p
:
player
.
getWorld
()
.
getPlayers
())
{
for
(
GenshinPlayer
p
:
scene
.
getPlayers
())
{
proto
.
addPlayerLocList
(
p
.
getPlayerLocationInfo
());
}
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketWorldPlayerLocationNotify.java
View file @
7f2de4fa
...
...
@@ -14,7 +14,7 @@ public class PacketWorldPlayerLocationNotify extends GenshinPacket {
WorldPlayerLocationNotify
.
Builder
proto
=
WorldPlayerLocationNotify
.
newBuilder
();
for
(
GenshinPlayer
p
:
world
.
getPlayers
())
{
proto
.
addPlayerLocList
(
p
.
getPlayerLocationInfo
());
proto
.
addPlayerLocList
(
p
.
get
World
PlayerLocationInfo
());
}
this
.
setData
(
proto
);
...
...
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