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
6f43c076
Commit
6f43c076
authored
Apr 21, 2022
by
Yazawazi
Committed by
GitHub
Apr 21, 2022
Browse files
teleports
parent
19572f46
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/GenshinData.java
View file @
6f43c076
...
...
@@ -8,6 +8,7 @@ import emu.grasscutter.Grasscutter;
import
emu.grasscutter.utils.Utils
;
import
emu.grasscutter.data.custom.AbilityEmbryoEntry
;
import
emu.grasscutter.data.custom.OpenConfigEntry
;
import
emu.grasscutter.data.custom.ScenePointEntry
;
import
emu.grasscutter.data.def.*
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
...
...
@@ -18,6 +19,7 @@ public class GenshinData {
private
static
final
Int2ObjectMap
<
String
>
abilityHashes
=
new
Int2ObjectOpenHashMap
<>();
private
static
final
Map
<
String
,
AbilityEmbryoEntry
>
abilityEmbryos
=
new
HashMap
<>();
private
static
final
Map
<
String
,
OpenConfigEntry
>
openConfigEntries
=
new
HashMap
<>();
private
static
final
Map
<
String
,
ScenePointEntry
>
scenePointEntries
=
new
HashMap
<>();
// ExcelConfigs
private
static
final
Int2ObjectMap
<
PlayerLevelData
>
playerLevelDataMap
=
new
Int2ObjectOpenHashMap
<>();
...
...
@@ -82,6 +84,10 @@ public class GenshinData {
return
openConfigEntries
;
}
public
static
Map
<
String
,
ScenePointEntry
>
getScenePointEntries
()
{
return
scenePointEntries
;
}
public
static
Int2ObjectMap
<
AvatarData
>
getAvatarDataMap
()
{
return
avatarDataMap
;
}
...
...
src/main/java/emu/grasscutter/data/ResourceLoader.java
View file @
6f43c076
...
...
@@ -10,11 +10,15 @@ import java.util.regex.Pattern;
import
emu.grasscutter.utils.Utils
;
import
org.reflections.Reflections
;
import
com.google.gson.JsonElement
;
import
com.google.gson.reflect.TypeToken
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.common.PointData
;
import
emu.grasscutter.data.common.ScenePointConfig
;
import
emu.grasscutter.data.custom.AbilityEmbryoEntry
;
import
emu.grasscutter.data.custom.OpenConfigEntry
;
import
emu.grasscutter.data.custom.ScenePointEntry
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
public
class
ResourceLoader
{
...
...
@@ -42,6 +46,7 @@ public class ResourceLoader {
loadOpenConfig
();
// Load resources
loadResources
();
loadScenePoints
();
// Process into depots
GenshinDepot
.
load
();
// Custom - TODO move this somewhere else
...
...
@@ -121,6 +126,45 @@ public class ResourceLoader {
}
}
private
static
void
loadScenePoints
()
{
Pattern
pattern
=
Pattern
.
compile
(
"(?<=scene)(.*?)(?=_point.json)"
);
File
folder
=
new
File
(
Grasscutter
.
getConfig
().
RESOURCE_FOLDER
+
"BinOutPut/Scene/Point"
);
List
<
ScenePointEntry
>
scenePointList
=
new
ArrayList
<>();
for
(
File
file
:
folder
.
listFiles
())
{
ScenePointConfig
config
=
null
;
Integer
sceneId
=
null
;
Matcher
matcher
=
pattern
.
matcher
(
file
.
getName
());
if
(
matcher
.
find
())
{
sceneId
=
Integer
.
parseInt
(
matcher
.
group
(
1
));
}
else
{
continue
;
}
try
(
FileReader
fileReader
=
new
FileReader
(
file
))
{
config
=
Grasscutter
.
getGsonFactory
().
fromJson
(
fileReader
,
ScenePointConfig
.
class
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
continue
;
}
if
(
config
.
points
==
null
)
{
continue
;
}
for
(
Map
.
Entry
<
String
,
JsonElement
>
entry
:
config
.
points
.
entrySet
())
{
PointData
pointData
=
Grasscutter
.
getGsonFactory
().
fromJson
(
entry
.
getValue
(),
PointData
.
class
);
ScenePointEntry
sl
=
new
ScenePointEntry
(
sceneId
+
"_"
+
entry
.
getKey
(),
pointData
);
scenePointList
.
add
(
sl
);
}
for
(
ScenePointEntry
entry
:
scenePointList
)
{
GenshinData
.
getScenePointEntries
().
put
(
entry
.
getName
(),
entry
);
}
}
}
private
static
void
loadAbilityEmbryos
()
{
// Read from cached file if exists
File
embryoCache
=
new
File
(
Grasscutter
.
getConfig
().
DATA_FOLDER
+
"AbilityEmbryos.json"
);
...
...
src/main/java/emu/grasscutter/data/common/PointData.java
0 → 100644
View file @
6f43c076
package
emu.grasscutter.data.common
;
public
class
PointData
{
private
pos
tranPos
;
public
pos
getTranPos
()
{
return
tranPos
;
}
public
void
setTranPos
(
pos
tranPos
)
{
this
.
tranPos
=
tranPos
;
}
public
class
pos
{
private
float
x
;
private
float
y
;
private
float
z
;
public
float
getX
()
{
return
x
;
}
public
void
setX
(
float
x
)
{
this
.
x
=
x
;
}
public
float
getY
()
{
return
y
;
}
public
void
setY
(
float
y
)
{
this
.
y
=
y
;
}
public
float
getZ
()
{
return
z
;
}
public
void
setZ
(
float
z
)
{
this
.
z
=
z
;
}
}
}
src/main/java/emu/grasscutter/data/common/ScenePointConfig.java
0 → 100644
View file @
6f43c076
package
emu.grasscutter.data.common
;
import
com.google.gson.JsonObject
;
public
class
ScenePointConfig
{
public
JsonObject
points
;
public
JsonObject
getPoints
()
{
return
points
;
}
public
void
setPoints
(
JsonObject
Points
)
{
points
=
Points
;
}
}
src/main/java/emu/grasscutter/data/custom/ScenePointEntry.java
0 → 100644
View file @
6f43c076
package
emu.grasscutter.data.custom
;
import
emu.grasscutter.data.common.PointData
;
public
class
ScenePointEntry
{
private
String
name
;
private
PointData
pointData
;
public
ScenePointEntry
(
String
name
,
PointData
pointData
)
{
this
.
name
=
name
;
this
.
pointData
=
pointData
;
}
public
String
getName
()
{
return
name
;
}
public
PointData
getPointData
()
{
return
pointData
;
}
}
src/main/java/emu/grasscutter/game/World.java
View file @
6f43c076
...
...
@@ -206,6 +206,25 @@ public class World implements Iterable<GenshinPlayer> {
public
void
deregisterScene
(
GenshinScene
scene
)
{
this
.
getScenes
().
remove
(
scene
.
getId
());
}
public
boolean
forceTransferPlayerToScene
(
GenshinPlayer
player
,
int
sceneId
,
Position
pos
)
{
// Forces the client to reload the scene map to prevent the player from falling off the map.
if
(
GenshinData
.
getSceneDataMap
().
get
(
sceneId
)
==
null
)
{
return
false
;
}
if
(
player
.
getScene
()
!=
null
)
{
player
.
getScene
().
removePlayer
(
player
);
}
GenshinScene
scene
=
this
.
getSceneById
(
sceneId
);
scene
.
addPlayer
(
player
);
player
.
getPos
().
set
(
pos
);
// Teleport packet
player
.
sendPacket
(
new
PacketPlayerEnterSceneNotify
(
player
,
EnterType
.
EnterSelf
,
EnterReason
.
TransPoint
,
sceneId
,
pos
));
return
true
;
}
public
boolean
transferPlayerToScene
(
GenshinPlayer
player
,
int
sceneId
,
Position
pos
)
{
if
(
player
.
getScene
().
getId
()
==
sceneId
||
GenshinData
.
getSceneDataMap
().
get
(
sceneId
)
==
null
)
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerSceneTransToPointReq.java
0 → 100644
View file @
6f43c076
package
emu.grasscutter.server.packet.recv
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp
;
@Opcodes
(
PacketOpcodes
.
SceneTransToPointReq
)
public
class
HandlerSceneTransToPointReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
SceneTransToPointReq
req
=
SceneTransToPointReq
.
parseFrom
(
payload
);
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketSceneTransToPointRsp.java
0 → 100644
View file @
6f43c076
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.custom.ScenePointEntry
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp
;
import
emu.grasscutter.utils.Position
;
public
class
PacketSceneTransToPointRsp
extends
GenshinPacket
{
public
PacketSceneTransToPointRsp
(
GenshinPlayer
player
,
int
pointId
,
int
sceneId
)
{
super
(
PacketOpcodes
.
SceneTransToPointRsp
);
String
code
=
sceneId
+
"_"
+
pointId
;
ScenePointEntry
scenePointEntry
=
GenshinData
.
getScenePointEntries
().
get
(
code
);
float
x
=
scenePointEntry
.
getPointData
().
getTranPos
().
getX
();
float
y
=
scenePointEntry
.
getPointData
().
getTranPos
().
getY
();
float
z
=
scenePointEntry
.
getPointData
().
getTranPos
().
getZ
();
player
.
getPos
().
set
(
new
Position
(
x
,
y
,
z
));
player
.
getWorld
().
forceTransferPlayerToScene
(
player
,
sceneId
,
player
.
getPos
());
SceneTransToPointRsp
proto
=
SceneTransToPointRsp
.
newBuilder
()
.
setRetcode
(
0
)
.
setPointId
(
pointId
)
.
setSceneId
(
sceneId
)
.
build
();
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