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
ffc1f801
Commit
ffc1f801
authored
Apr 29, 2022
by
Melledy
Browse files
Implement spawning monsters by suite
parent
ae3d9a4d
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
ffc1f801
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
javax.script.Bindings
;
import
javax.script.Bindings
;
import
javax.script.CompiledScript
;
import
javax.script.CompiledScript
;
...
@@ -43,7 +44,7 @@ public class SceneScriptManager {
...
@@ -43,7 +44,7 @@ public class SceneScriptManager {
private
final
Scene
scene
;
private
final
Scene
scene
;
private
final
ScriptLib
scriptLib
;
private
final
ScriptLib
scriptLib
;
private
final
LuaValue
scriptLibLua
;
private
final
LuaValue
scriptLibLua
;
private
final
Map
<
String
,
LuaValue
>
variables
;
private
final
Map
<
String
,
Integer
>
variables
;
private
Bindings
bindings
;
private
Bindings
bindings
;
private
SceneConfig
config
;
private
SceneConfig
config
;
...
@@ -91,7 +92,7 @@ public class SceneScriptManager {
...
@@ -91,7 +92,7 @@ public class SceneScriptManager {
return
blocks
;
return
blocks
;
}
}
public
Map
<
String
,
LuaValue
>
getVariables
()
{
public
Map
<
String
,
Integer
>
getVariables
()
{
return
variables
;
return
variables
;
}
}
...
@@ -212,8 +213,22 @@ public class SceneScriptManager {
...
@@ -212,8 +213,22 @@ public class SceneScriptManager {
group
.
suites
=
ScriptLoader
.
getSerializer
().
toList
(
SceneSuite
.
class
,
bindings
.
get
(
"suites"
));
group
.
suites
=
ScriptLoader
.
getSerializer
().
toList
(
SceneSuite
.
class
,
bindings
.
get
(
"suites"
));
group
.
init_config
=
ScriptLoader
.
getSerializer
().
toObject
(
SceneInitConfig
.
class
,
bindings
.
get
(
"init_config"
));
group
.
init_config
=
ScriptLoader
.
getSerializer
().
toObject
(
SceneInitConfig
.
class
,
bindings
.
get
(
"init_config"
));
// Add variables to suite
List
<
SceneVar
>
variables
=
ScriptLoader
.
getSerializer
().
toList
(
SceneVar
.
class
,
bindings
.
get
(
"variables"
));
List
<
SceneVar
>
variables
=
ScriptLoader
.
getSerializer
().
toList
(
SceneVar
.
class
,
bindings
.
get
(
"variables"
));
variables
.
forEach
(
var
->
this
.
getVariables
().
put
(
var
.
name
,
LuaValue
.
valueOf
(
var
.
value
)));
variables
.
forEach
(
var
->
this
.
getVariables
().
put
(
var
.
name
,
var
.
value
));
// Add monsters to suite TODO optimize
HashMap
<
Integer
,
SceneMonster
>
map
=
(
HashMap
<
Integer
,
SceneMonster
>)
group
.
monsters
.
stream
().
collect
(
Collectors
.
toMap
(
m
->
m
.
config_id
,
m
->
m
));
for
(
SceneSuite
suite
:
group
.
suites
)
{
suite
.
sceneMonsters
=
new
ArrayList
<>(
suite
.
monsters
.
size
());
for
(
int
id
:
suite
.
monsters
)
{
SceneMonster
monster
=
map
.
get
(
id
);
if
(
monster
!=
null
)
{
suite
.
sceneMonsters
.
add
(
monster
);
}
}
}
}
catch
(
ScriptException
e
)
{
}
catch
(
ScriptException
e
)
{
Grasscutter
.
getLogger
().
error
(
"Error loading group "
+
group
.
id
+
" in scene "
+
getScene
().
getId
(),
e
);
Grasscutter
.
getLogger
().
error
(
"Error loading group "
+
group
.
id
+
" in scene "
+
getScene
().
getId
(),
e
);
}
}
...
@@ -244,10 +259,24 @@ public class SceneScriptManager {
...
@@ -244,10 +259,24 @@ public class SceneScriptManager {
}
}
}
}
public
void
spawnMonstersInGroup
(
SceneGroup
group
,
int
suiteIndex
)
{
spawnMonstersInGroup
(
group
,
group
.
getSuiteByIndex
(
suiteIndex
));
}
public
void
spawnMonstersInGroup
(
SceneGroup
group
)
{
public
void
spawnMonstersInGroup
(
SceneGroup
group
)
{
spawnMonstersInGroup
(
group
,
null
);
}
public
void
spawnMonstersInGroup
(
SceneGroup
group
,
SceneSuite
suite
)
{
List
<
SceneMonster
>
monsters
=
group
.
monsters
;
if
(
suite
!=
null
)
{
monsters
=
suite
.
sceneMonsters
;
}
List
<
GameEntity
>
toAdd
=
new
ArrayList
<>();
List
<
GameEntity
>
toAdd
=
new
ArrayList
<>();
for
(
SceneMonster
monster
:
group
.
monsters
)
{
for
(
SceneMonster
monster
:
monsters
)
{
MonsterData
data
=
GameData
.
getMonsterDataMap
().
get
(
monster
.
monster_id
);
MonsterData
data
=
GameData
.
getMonsterDataMap
().
get
(
monster
.
monster_id
);
if
(
data
==
null
)
{
if
(
data
==
null
)
{
...
...
src/main/java/emu/grasscutter/scripts/ScriptLib.java
View file @
ffc1f801
...
@@ -129,7 +129,7 @@ public class ScriptLib {
...
@@ -129,7 +129,7 @@ public class ScriptLib {
}
}
// TODO just spawn all from group for now
// TODO just spawn all from group for now
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
);
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
,
suite
);
return
0
;
return
0
;
}
}
...
@@ -158,11 +158,11 @@ public class ScriptLib {
...
@@ -158,11 +158,11 @@ public class ScriptLib {
.
count
();
.
count
();
}
}
public
LuaValue
GetGroupVariableValue
(
String
var
)
{
public
int
GetGroupVariableValue
(
String
var
)
{
return
getSceneScriptManager
().
getVariables
().
getOrDefault
(
var
,
LuaValue
.
NIL
);
return
getSceneScriptManager
().
getVariables
().
getOrDefault
(
var
,
0
);
}
}
public
LuaValue
ChangeGroupVariableValue
(
String
var
,
LuaValue
value
)
{
public
LuaValue
ChangeGroupVariableValue
(
String
var
,
int
value
)
{
getSceneScriptManager
().
getVariables
().
put
(
var
,
value
);
getSceneScriptManager
().
getVariables
().
put
(
var
,
value
);
return
LuaValue
.
ZERO
;
return
LuaValue
.
ZERO
;
}
}
...
@@ -179,7 +179,7 @@ public class ScriptLib {
...
@@ -179,7 +179,7 @@ public class ScriptLib {
}
}
// TODO just spawn all from group for now
// TODO just spawn all from group for now
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
);
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
,
suite
);
return
0
;
return
0
;
}
}
...
...
src/main/java/emu/grasscutter/scripts/data/SceneGroup.java
View file @
ffc1f801
...
@@ -26,4 +26,8 @@ public class SceneGroup {
...
@@ -26,4 +26,8 @@ public class SceneGroup {
public
boolean
setLoaded
(
boolean
loaded
)
{
public
boolean
setLoaded
(
boolean
loaded
)
{
return
loaded
;
return
loaded
;
}
}
public
SceneSuite
getSuiteByIndex
(
int
index
)
{
return
suites
.
get
(
index
-
1
);
}
}
}
src/main/java/emu/grasscutter/scripts/data/SceneSuite.java
View file @
ffc1f801
...
@@ -5,6 +5,9 @@ import java.util.List;
...
@@ -5,6 +5,9 @@ import java.util.List;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
public
class
SceneSuite
{
public
class
SceneSuite
{
public
List
<
Integer
>
monsters
;
public
List
<
String
>
triggers
;
public
List
<
String
>
triggers
;
public
int
rand_weight
;
public
int
rand_weight
;
public
transient
List
<
SceneMonster
>
sceneMonsters
;
}
}
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