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
de8b0be3
Commit
de8b0be3
authored
May 26, 2022
by
ImmuState
Committed by
Melledy
May 26, 2022
Browse files
Introduce a simpler way to get the original owner of an EntityClientGadget
parent
fa90e37d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java
View file @
de8b0be3
...
@@ -35,6 +35,8 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -35,6 +35,8 @@ public class EntityClientGadget extends EntityBaseGadget {
private
int
ownerEntityId
;
private
int
ownerEntityId
;
private
int
targetEntityId
;
private
int
targetEntityId
;
private
boolean
asyncLoad
;
private
boolean
asyncLoad
;
private
int
originalOwnerEntityId
;
public
EntityClientGadget
(
Scene
scene
,
Player
player
,
EvtCreateGadgetNotify
notify
)
{
public
EntityClientGadget
(
Scene
scene
,
Player
player
,
EvtCreateGadgetNotify
notify
)
{
super
(
scene
);
super
(
scene
);
...
@@ -48,6 +50,14 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -48,6 +50,14 @@ public class EntityClientGadget extends EntityBaseGadget {
this
.
ownerEntityId
=
notify
.
getPropOwnerEntityId
();
this
.
ownerEntityId
=
notify
.
getPropOwnerEntityId
();
this
.
targetEntityId
=
notify
.
getTargetEntityId
();
this
.
targetEntityId
=
notify
.
getTargetEntityId
();
this
.
asyncLoad
=
notify
.
getIsAsyncLoad
();
this
.
asyncLoad
=
notify
.
getIsAsyncLoad
();
GameEntity
owner
=
scene
.
getEntityById
(
this
.
ownerEntityId
);
if
(
owner
instanceof
EntityClientGadget
ownerGadget
)
{
this
.
originalOwnerEntityId
=
ownerGadget
.
getOriginalOwnerEntityId
();
}
else
{
this
.
originalOwnerEntityId
=
this
.
ownerEntityId
;
}
}
}
@Override
@Override
...
@@ -79,6 +89,10 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -79,6 +89,10 @@ public class EntityClientGadget extends EntityBaseGadget {
return
this
.
asyncLoad
;
return
this
.
asyncLoad
;
}
}
public
int
getOriginalOwnerEntityId
()
{
return
this
.
originalOwnerEntityId
;
}
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
...
...
src/main/java/emu/grasscutter/game/managers/EnergyManager/EnergyManager.java
View file @
de8b0be3
...
@@ -88,7 +88,7 @@ public class EnergyManager {
...
@@ -88,7 +88,7 @@ public class EnergyManager {
// or it can be an `EntityClientGadget`, owned (some way up the owner hierarchy) by the avatar
// or it can be an `EntityClientGadget`, owned (some way up the owner hierarchy) by the avatar
// that cast the skill.
// that cast the skill.
int
res
=
0
;
int
res
=
0
;
// Try to get the invoking entity from the scene.
// Try to get the invoking entity from the scene.
GameEntity
entity
=
player
.
getScene
().
getEntityById
(
invokeEntityId
);
GameEntity
entity
=
player
.
getScene
().
getEntityById
(
invokeEntityId
);
...
@@ -98,13 +98,10 @@ public class EnergyManager {
...
@@ -98,13 +98,10 @@ public class EnergyManager {
if
(!(
entity
instanceof
EntityClientGadget
))
{
if
(!(
entity
instanceof
EntityClientGadget
))
{
res
=
invokeEntityId
;
res
=
invokeEntityId
;
}
}
// If the entity is a `EntityClientGadget`, we need to
"walk up" the owner hierarchy,
// If the entity is a `EntityClientGadget`, we need to
find the ID of the original
//
until the owner is no longer a gadget. This should then be the ID of the casting avatar
.
//
owner of that gadget
.
else
{
else
{
while
(
entity
instanceof
EntityClientGadget
gadget
)
{
res
=
((
EntityClientGadget
)
entity
).
getOriginalOwnerEntityId
();
res
=
gadget
.
getOwnerEntityId
();
entity
=
player
.
getScene
().
getEntityById
(
gadget
.
getOwnerEntityId
());
}
}
}
return
res
;
return
res
;
...
@@ -139,9 +136,9 @@ public class EnergyManager {
...
@@ -139,9 +136,9 @@ public class EnergyManager {
.
findFirst
();
.
findFirst
();
// Bug: invokes twice sometimes, Ayato, Keqing
// Bug: invokes twice sometimes, Ayato, Keqing
// Amber not getting element properly
// ToDo: deal with press, hold difference. deal with charge(Beidou, Yunjin)
// ToDo: deal with press, hold difference. deal with charge(Beidou, Yunjin)
if
(
avatarEntity
.
isPresent
())
{
if
(
avatarEntity
.
isPresent
())
{
Grasscutter
.
getLogger
().
info
(
"Found entity: {}"
,
avatarEntity
.
get
());
Avatar
avatar
=
avatarEntity
.
get
().
getAvatar
();
Avatar
avatar
=
avatarEntity
.
get
().
getAvatar
();
if
(
avatar
!=
null
)
{
if
(
avatar
!=
null
)
{
...
...
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