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
cd77fb90
Commit
cd77fb90
authored
May 19, 2022
by
Melledy
Browse files
Move gadget/monster creation events to after they are spawned in scene
parent
512021b2
Changes
5
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityGadget.java
View file @
cd77fb90
...
@@ -28,6 +28,8 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
...
@@ -28,6 +28,8 @@ import emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo;
import
emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo
;
import
emu.grasscutter.net.proto.SceneGadgetInfoOuterClass.SceneGadgetInfo
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo
;
import
emu.grasscutter.net.proto.WorktopInfoOuterClass.WorktopInfo
;
import
emu.grasscutter.scripts.constants.EventType
;
import
emu.grasscutter.scripts.data.ScriptArgs
;
import
emu.grasscutter.server.packet.send.PacketGadgetStateNotify
;
import
emu.grasscutter.server.packet.send.PacketGadgetStateNotify
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.ProtoHelper
;
import
emu.grasscutter.utils.ProtoHelper
;
...
@@ -139,6 +141,12 @@ public class EntityGadget extends EntityBaseGadget {
...
@@ -139,6 +141,12 @@ public class EntityGadget extends EntityBaseGadget {
return
null
;
return
null
;
}
}
@Override
public
void
onCreate
()
{
// Lua event
getScene
().
getScriptManager
().
callEvent
(
EventType
.
EVENT_GADGET_CREATE
,
new
ScriptArgs
(
this
.
getConfigId
()));
}
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
...
...
src/main/java/emu/grasscutter/game/entity/EntityMonster.java
View file @
cd77fb90
...
@@ -110,6 +110,12 @@ public class EntityMonster extends GameEntity {
...
@@ -110,6 +110,12 @@ public class EntityMonster extends GameEntity {
this
.
poseId
=
poseId
;
this
.
poseId
=
poseId
;
}
}
@Override
public
void
onCreate
()
{
// Lua event
getScene
().
getScriptManager
().
callEvent
(
EventType
.
EVENT_ANY_MONSTER_LIVE
,
new
ScriptArgs
(
this
.
getConfigId
()));
}
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
if
(
this
.
getSpawnEntry
()
!=
null
)
{
if
(
this
.
getSpawnEntry
()
!=
null
)
{
...
...
src/main/java/emu/grasscutter/game/entity/GameEntity.java
View file @
cd77fb90
...
@@ -108,10 +108,6 @@ public abstract class GameEntity {
...
@@ -108,10 +108,6 @@ public abstract class GameEntity {
this
.
lastMoveReliableSeq
=
lastMoveReliableSeq
;
this
.
lastMoveReliableSeq
=
lastMoveReliableSeq
;
}
}
public
abstract
SceneEntityInfo
toProto
();
public
abstract
void
onDeath
(
int
killerId
);
public
void
setFightProperty
(
FightProperty
prop
,
float
value
)
{
public
void
setFightProperty
(
FightProperty
prop
,
float
value
)
{
this
.
getFightProperties
().
put
(
prop
.
getId
(),
value
);
this
.
getFightProperties
().
put
(
prop
.
getId
(),
value
);
}
}
...
@@ -219,4 +215,21 @@ public abstract class GameEntity {
...
@@ -219,4 +215,21 @@ public abstract class GameEntity {
getScene
().
killEntity
(
this
,
0
);
getScene
().
killEntity
(
this
,
0
);
}
}
}
}
/**
* Called when this entity is added to the world
*/
public
void
onCreate
()
{
}
/**
* Called when this entity dies
* @param killerId Entity id of the entity that killed this entity
*/
public
void
onDeath
(
int
killerId
)
{
}
public
abstract
SceneEntityInfo
toProto
();
}
}
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
cd77fb90
...
@@ -311,6 +311,7 @@ public class Scene {
...
@@ -311,6 +311,7 @@ public class Scene {
private
void
addEntityDirectly
(
GameEntity
entity
)
{
private
void
addEntityDirectly
(
GameEntity
entity
)
{
getEntities
().
put
(
entity
.
getId
(),
entity
);
getEntities
().
put
(
entity
.
getId
(),
entity
);
entity
.
onCreate
();
// Call entity create event
}
}
public
synchronized
void
addEntity
(
GameEntity
entity
)
{
public
synchronized
void
addEntity
(
GameEntity
entity
)
{
...
...
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
cd77fb90
...
@@ -371,9 +371,6 @@ public class SceneScriptManager {
...
@@ -371,9 +371,6 @@ public class SceneScriptManager {
this
.
getScriptMonsterSpawnService
()
this
.
getScriptMonsterSpawnService
()
.
onMonsterCreatedListener
.
forEach
(
action
->
action
.
onNotify
(
entity
));
.
onMonsterCreatedListener
.
forEach
(
action
->
action
.
onNotify
(
entity
));
// Lua event
callEvent
(
EventType
.
EVENT_ANY_MONSTER_LIVE
,
new
ScriptArgs
(
entity
.
getConfigId
()));
return
entity
;
return
entity
;
}
}
...
...
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