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
ae3d9a4d
Commit
ae3d9a4d
authored
Apr 29, 2022
by
Melledy
Browse files
Add a few more functions for the script engine to call
parent
1a5d4cf4
Changes
4
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityMonster.java
View file @
ae3d9a4d
...
@@ -23,6 +23,7 @@ import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo;
...
@@ -23,6 +23,7 @@ import emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.SceneMonsterInfoOuterClass.SceneMonsterInfo
;
import
emu.grasscutter.net.proto.SceneMonsterInfoOuterClass.SceneMonsterInfo
;
import
emu.grasscutter.net.proto.SceneWeaponInfoOuterClass.SceneWeaponInfo
;
import
emu.grasscutter.net.proto.SceneWeaponInfoOuterClass.SceneWeaponInfo
;
import
emu.grasscutter.scripts.constants.EventType
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.ProtoHelper
;
import
emu.grasscutter.utils.ProtoHelper
;
import
it.unimi.dsi.fastutil.ints.Int2FloatMap
;
import
it.unimi.dsi.fastutil.ints.Int2FloatMap
;
...
@@ -115,6 +116,9 @@ public class EntityMonster extends GameEntity {
...
@@ -115,6 +116,9 @@ public class EntityMonster extends GameEntity {
if
(
this
.
getSpawnEntry
()
!=
null
)
{
if
(
this
.
getSpawnEntry
()
!=
null
)
{
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
}
}
if
(
getScene
().
getScriptManager
().
isInit
()
&&
this
.
getGroupId
()
>
0
)
{
getScene
().
getScriptManager
().
callEvent
(
EventType
.
EVENT_ANY_MONSTER_DIE
,
null
);
}
if
(
getScene
().
getChallenge
()
!=
null
&&
getScene
().
getChallenge
().
getGroup
().
id
==
this
.
getGroupId
())
{
if
(
getScene
().
getChallenge
()
!=
null
&&
getScene
().
getChallenge
().
getGroup
().
id
==
this
.
getGroupId
())
{
getScene
().
getChallenge
().
onMonsterDie
(
this
);
getScene
().
getChallenge
().
onMonsterDie
(
this
);
}
}
...
...
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
ae3d9a4d
...
@@ -4,6 +4,7 @@ import java.util.ArrayList;
...
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
javax.script.Bindings
;
import
javax.script.Bindings
;
...
@@ -33,6 +34,7 @@ import emu.grasscutter.scripts.data.SceneInitConfig;
...
@@ -33,6 +34,7 @@ import emu.grasscutter.scripts.data.SceneInitConfig;
import
emu.grasscutter.scripts.data.SceneMonster
;
import
emu.grasscutter.scripts.data.SceneMonster
;
import
emu.grasscutter.scripts.data.SceneSuite
;
import
emu.grasscutter.scripts.data.SceneSuite
;
import
emu.grasscutter.scripts.data.SceneTrigger
;
import
emu.grasscutter.scripts.data.SceneTrigger
;
import
emu.grasscutter.scripts.data.SceneVar
;
import
emu.grasscutter.scripts.data.ScriptArgs
;
import
emu.grasscutter.scripts.data.ScriptArgs
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
;
...
@@ -41,8 +43,9 @@ public class SceneScriptManager {
...
@@ -41,8 +43,9 @@ 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
B
in
dings
binding
s
;
private
f
in
al
Map
<
String
,
LuaValue
>
variable
s
;
private
Bindings
bindings
;
private
SceneConfig
config
;
private
SceneConfig
config
;
private
List
<
SceneBlock
>
blocks
;
private
List
<
SceneBlock
>
blocks
;
private
Int2ObjectOpenHashMap
<
Set
<
SceneTrigger
>>
triggers
;
private
Int2ObjectOpenHashMap
<
Set
<
SceneTrigger
>>
triggers
;
...
@@ -53,6 +56,7 @@ public class SceneScriptManager {
...
@@ -53,6 +56,7 @@ public class SceneScriptManager {
this
.
scriptLib
=
new
ScriptLib
(
this
);
this
.
scriptLib
=
new
ScriptLib
(
this
);
this
.
scriptLibLua
=
CoerceJavaToLua
.
coerce
(
this
.
scriptLib
);
this
.
scriptLibLua
=
CoerceJavaToLua
.
coerce
(
this
.
scriptLib
);
this
.
triggers
=
new
Int2ObjectOpenHashMap
<>();
this
.
triggers
=
new
Int2ObjectOpenHashMap
<>();
this
.
variables
=
new
HashMap
<>();
// TEMPORARY
// TEMPORARY
if
(
this
.
getScene
().
getId
()
<
10
)
{
if
(
this
.
getScene
().
getId
()
<
10
)
{
...
@@ -87,6 +91,10 @@ public class SceneScriptManager {
...
@@ -87,6 +91,10 @@ public class SceneScriptManager {
return
blocks
;
return
blocks
;
}
}
public
Map
<
String
,
LuaValue
>
getVariables
()
{
return
variables
;
}
public
Set
<
SceneTrigger
>
getTriggersByEvent
(
int
eventId
)
{
public
Set
<
SceneTrigger
>
getTriggersByEvent
(
int
eventId
)
{
return
triggers
.
computeIfAbsent
(
eventId
,
e
->
new
HashSet
<>());
return
triggers
.
computeIfAbsent
(
eventId
,
e
->
new
HashSet
<>());
}
}
...
@@ -203,6 +211,9 @@ public class SceneScriptManager {
...
@@ -203,6 +211,9 @@ public class SceneScriptManager {
group
.
triggers
=
ScriptLoader
.
getSerializer
().
toList
(
SceneTrigger
.
class
,
bindings
.
get
(
"triggers"
));
group
.
triggers
=
ScriptLoader
.
getSerializer
().
toList
(
SceneTrigger
.
class
,
bindings
.
get
(
"triggers"
));
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"
));
List
<
SceneVar
>
variables
=
ScriptLoader
.
getSerializer
().
toList
(
SceneVar
.
class
,
bindings
.
get
(
"variables"
));
variables
.
forEach
(
var
->
this
.
getVariables
().
put
(
var
.
name
,
LuaValue
.
valueOf
(
var
.
value
)));
}
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
);
}
}
...
...
src/main/java/emu/grasscutter/scripts/ScriptLib.java
View file @
ae3d9a4d
...
@@ -5,6 +5,7 @@ import java.util.List;
...
@@ -5,6 +5,7 @@ import java.util.List;
import
java.util.Optional
;
import
java.util.Optional
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaValue
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
...
@@ -120,7 +121,7 @@ public class ScriptLib {
...
@@ -120,7 +121,7 @@ public class ScriptLib {
return
0
;
return
0
;
}
}
public
int
AddExtraGroupSuite
(
int
groupId
,
int
param2
)
{
public
int
AddExtraGroupSuite
(
int
groupId
,
int
suite
)
{
SceneGroup
group
=
getSceneScriptManager
().
getGroupById
(
groupId
);
SceneGroup
group
=
getSceneScriptManager
().
getGroupById
(
groupId
);
if
(
group
==
null
||
group
.
monsters
==
null
)
{
if
(
group
==
null
||
group
.
monsters
==
null
)
{
...
@@ -151,8 +152,35 @@ public class ScriptLib {
...
@@ -151,8 +152,35 @@ public class ScriptLib {
return
0
;
return
0
;
}
}
public
int
GetGroupMonsterCountByGroupId
(
int
groupId
)
{
return
(
int
)
getSceneScriptManager
().
getScene
().
getEntities
().
values
().
stream
()
.
filter
(
e
->
e
instanceof
EntityMonster
&&
e
.
getGroupId
()
==
groupId
)
.
count
();
}
public
LuaValue
GetGroupVariableValue
(
String
var
)
{
return
getSceneScriptManager
().
getVariables
().
getOrDefault
(
var
,
LuaValue
.
NIL
);
}
public
LuaValue
ChangeGroupVariableValue
(
String
var
,
LuaValue
value
)
{
getSceneScriptManager
().
getVariables
().
put
(
var
,
value
);
return
LuaValue
.
ZERO
;
}
public
int
RefreshGroup
(
LuaTable
table
)
{
public
int
RefreshGroup
(
LuaTable
table
)
{
// Add group back to suite
// Kill and Respawn?
int
groupId
=
table
.
get
(
"group_id"
).
toint
();
int
suite
=
table
.
get
(
"suite"
).
toint
();
SceneGroup
group
=
getSceneScriptManager
().
getGroupById
(
groupId
);
if
(
group
==
null
||
group
.
monsters
==
null
)
{
return
1
;
}
// TODO just spawn all from group for now
this
.
getSceneScriptManager
().
spawnMonstersInGroup
(
group
);
return
0
;
return
0
;
}
}
...
...
src/main/java/emu/grasscutter/scripts/data/SceneVar.java
0 → 100644
View file @
ae3d9a4d
package
emu.grasscutter.scripts.data
;
public
class
SceneVar
{
public
String
name
;
public
int
value
;
public
boolean
no_refresh
;
}
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