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
886c2e2f
Commit
886c2e2f
authored
Jul 24, 2022
by
KingRainbow44
Browse files
Add `EntityDeathEvent` and implementations
parent
a13725b1
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/entity/EntityAvatar.java
View file @
886c2e2f
...
@@ -30,6 +30,7 @@ import emu.grasscutter.net.proto.SceneAvatarInfoOuterClass.SceneAvatarInfo;
...
@@ -30,6 +30,7 @@ import emu.grasscutter.net.proto.SceneAvatarInfoOuterClass.SceneAvatarInfo;
import
emu.grasscutter.net.proto.SceneEntityAiInfoOuterClass.SceneEntityAiInfo
;
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.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.server.event.player.PlayerMoveEvent
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropChangeReasonNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
...
@@ -108,12 +109,16 @@ public class EntityAvatar extends GameEntity {
...
@@ -108,12 +109,16 @@ public class EntityAvatar extends GameEntity {
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
this
.
killedType
=
PlayerDieType
.
PLAYER_DIE_TYPE_KILL_BY_MONSTER
;
this
.
killedType
=
PlayerDieType
.
PLAYER_DIE_TYPE_KILL_BY_MONSTER
;
this
.
killedBy
=
killerId
;
this
.
killedBy
=
killerId
;
clearEnergy
(
ChangeEnergyReason
.
CHANGE_ENERGY_REASON_NONE
);
clearEnergy
(
ChangeEnergyReason
.
CHANGE_ENERGY_REASON_NONE
);
}
}
public
void
onDeath
(
PlayerDieType
dieType
,
int
killerId
)
{
public
void
onDeath
(
PlayerDieType
dieType
,
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
this
.
killedType
=
dieType
;
this
.
killedType
=
dieType
;
this
.
killedBy
=
killerId
;
this
.
killedBy
=
killerId
;
clearEnergy
(
ChangeEnergyReason
.
CHANGE_ENERGY_REASON_NONE
);
clearEnergy
(
ChangeEnergyReason
.
CHANGE_ENERGY_REASON_NONE
);
...
...
src/main/java/emu/grasscutter/game/entity/EntityBaseGadget.java
View file @
886c2e2f
...
@@ -8,11 +8,11 @@ public abstract class EntityBaseGadget extends GameEntity {
...
@@ -8,11 +8,11 @@ public abstract class EntityBaseGadget extends GameEntity {
public
EntityBaseGadget
(
Scene
scene
)
{
public
EntityBaseGadget
(
Scene
scene
)
{
super
(
scene
);
super
(
scene
);
}
}
public
abstract
int
getGadgetId
();
public
abstract
int
getGadgetId
();
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
}
}
}
}
src/main/java/emu/grasscutter/game/entity/EntityClientGadget.java
View file @
886c2e2f
...
@@ -3,7 +3,6 @@ package emu.grasscutter.game.entity;
...
@@ -3,7 +3,6 @@ package emu.grasscutter.game.entity;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.game.world.Scene
;
import
emu.grasscutter.game.world.World
;
import
emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo
;
import
emu.grasscutter.net.proto.AbilitySyncStateInfoOuterClass.AbilitySyncStateInfo
;
import
emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair
;
import
emu.grasscutter.net.proto.AnimatorParameterValueInfoPairOuterClass.AnimatorParameterValueInfoPair
;
import
emu.grasscutter.net.proto.ClientGadgetInfoOuterClass
;
import
emu.grasscutter.net.proto.ClientGadgetInfoOuterClass
;
...
@@ -11,7 +10,6 @@ import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityIn
...
@@ -11,7 +10,6 @@ import emu.grasscutter.net.proto.EntityAuthorityInfoOuterClass.EntityAuthorityIn
import
emu.grasscutter.net.proto.EntityClientDataOuterClass.EntityClientData
;
import
emu.grasscutter.net.proto.EntityClientDataOuterClass.EntityClientData
;
import
emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo
;
import
emu.grasscutter.net.proto.EntityRendererChangedInfoOuterClass.EntityRendererChangedInfo
;
import
emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify
;
import
emu.grasscutter.net.proto.EvtCreateGadgetNotifyOuterClass.EvtCreateGadgetNotify
;
import
emu.grasscutter.net.proto.GadgetClientParamOuterClass.GadgetClientParam
;
import
emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo
;
import
emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo
;
import
emu.grasscutter.net.proto.PropPairOuterClass.PropPair
;
import
emu.grasscutter.net.proto.PropPairOuterClass.PropPair
;
import
emu.grasscutter.net.proto.ProtEntityTypeOuterClass.ProtEntityType
;
import
emu.grasscutter.net.proto.ProtEntityTypeOuterClass.ProtEntityType
;
...
@@ -25,10 +23,10 @@ import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
...
@@ -25,10 +23,10 @@ import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
public
class
EntityClientGadget
extends
EntityBaseGadget
{
public
class
EntityClientGadget
extends
EntityBaseGadget
{
private
final
Player
owner
;
private
final
Player
owner
;
private
final
Position
pos
;
private
final
Position
pos
;
private
final
Position
rot
;
private
final
Position
rot
;
private
int
configId
;
private
int
configId
;
private
int
campId
;
private
int
campId
;
private
int
campType
;
private
int
campType
;
...
@@ -37,7 +35,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -37,7 +35,7 @@ public class EntityClientGadget extends EntityBaseGadget {
private
boolean
asyncLoad
;
private
boolean
asyncLoad
;
private
int
originalOwnerEntityId
;
private
int
originalOwnerEntityId
;
public
EntityClientGadget
(
Scene
scene
,
Player
player
,
EvtCreateGadgetNotify
notify
)
{
public
EntityClientGadget
(
Scene
scene
,
Player
player
,
EvtCreateGadgetNotify
notify
)
{
super
(
scene
);
super
(
scene
);
this
.
owner
=
player
;
this
.
owner
=
player
;
...
@@ -59,20 +57,20 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -59,20 +57,20 @@ public class EntityClientGadget extends EntityBaseGadget {
this
.
originalOwnerEntityId
=
this
.
ownerEntityId
;
this
.
originalOwnerEntityId
=
this
.
ownerEntityId
;
}
}
}
}
@Override
@Override
public
int
getGadgetId
()
{
public
int
getGadgetId
()
{
return
configId
;
return
configId
;
}
}
public
Player
getOwner
()
{
public
Player
getOwner
()
{
return
owner
;
return
owner
;
}
}
public
int
getCampId
()
{
public
int
getCampId
()
{
return
campId
;
return
campId
;
}
}
public
int
getCampType
()
{
public
int
getCampType
()
{
return
campType
;
return
campType
;
}
}
...
@@ -80,7 +78,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -80,7 +78,7 @@ public class EntityClientGadget extends EntityBaseGadget {
public
int
getOwnerEntityId
()
{
public
int
getOwnerEntityId
()
{
return
ownerEntityId
;
return
ownerEntityId
;
}
}
public
int
getTargetEntityId
()
{
public
int
getTargetEntityId
()
{
return
targetEntityId
;
return
targetEntityId
;
}
}
...
@@ -95,7 +93,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -95,7 +93,7 @@ public class EntityClientGadget extends EntityBaseGadget {
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
}
}
@Override
@Override
...
@@ -124,7 +122,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -124,7 +122,7 @@ public class EntityClientGadget extends EntityBaseGadget {
.
setAiInfo
(
SceneEntityAiInfo
.
newBuilder
().
setIsAiOpen
(
true
).
setBornPos
(
Vector
.
newBuilder
()))
.
setAiInfo
(
SceneEntityAiInfo
.
newBuilder
().
setIsAiOpen
(
true
).
setBornPos
(
Vector
.
newBuilder
()))
.
setBornPos
(
Vector
.
newBuilder
())
.
setBornPos
(
Vector
.
newBuilder
())
.
build
();
.
build
();
SceneEntityInfo
.
Builder
entityInfo
=
SceneEntityInfo
.
newBuilder
()
SceneEntityInfo
.
Builder
entityInfo
=
SceneEntityInfo
.
newBuilder
()
.
setEntityId
(
getId
())
.
setEntityId
(
getId
())
.
setEntityType
(
ProtEntityType
.
PROT_ENTITY_TYPE_GADGET
)
.
setEntityType
(
ProtEntityType
.
PROT_ENTITY_TYPE_GADGET
)
...
@@ -133,13 +131,13 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -133,13 +131,13 @@ public class EntityClientGadget extends EntityBaseGadget {
.
setEntityClientData
(
EntityClientData
.
newBuilder
())
.
setEntityClientData
(
EntityClientData
.
newBuilder
())
.
setEntityAuthorityInfo
(
authority
)
.
setEntityAuthorityInfo
(
authority
)
.
setLifeState
(
1
);
.
setLifeState
(
1
);
PropPair
pair
=
PropPair
.
newBuilder
()
PropPair
pair
=
PropPair
.
newBuilder
()
.
setType
(
PlayerProperty
.
PROP_LEVEL
.
getId
())
.
setType
(
PlayerProperty
.
PROP_LEVEL
.
getId
())
.
setPropValue
(
ProtoHelper
.
newPropValue
(
PlayerProperty
.
PROP_LEVEL
,
1
))
.
setPropValue
(
ProtoHelper
.
newPropValue
(
PlayerProperty
.
PROP_LEVEL
,
1
))
.
build
();
.
build
();
entityInfo
.
addPropList
(
pair
);
entityInfo
.
addPropList
(
pair
);
ClientGadgetInfoOuterClass
.
ClientGadgetInfo
clientGadget
=
ClientGadgetInfoOuterClass
.
ClientGadgetInfo
.
newBuilder
()
ClientGadgetInfoOuterClass
.
ClientGadgetInfo
clientGadget
=
ClientGadgetInfoOuterClass
.
ClientGadgetInfo
.
newBuilder
()
.
setCampId
(
this
.
getCampId
())
.
setCampId
(
this
.
getCampId
())
.
setCampType
(
this
.
getCampType
())
.
setCampType
(
this
.
getCampType
())
...
@@ -147,7 +145,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -147,7 +145,7 @@ public class EntityClientGadget extends EntityBaseGadget {
.
setTargetEntityId
(
this
.
getTargetEntityId
())
.
setTargetEntityId
(
this
.
getTargetEntityId
())
.
setAsyncLoad
(
this
.
isAsyncLoad
())
.
setAsyncLoad
(
this
.
isAsyncLoad
())
.
build
();
.
build
();
SceneGadgetInfo
.
Builder
gadgetInfo
=
SceneGadgetInfo
.
newBuilder
()
SceneGadgetInfo
.
Builder
gadgetInfo
=
SceneGadgetInfo
.
newBuilder
()
.
setGadgetId
(
this
.
getGadgetId
())
.
setGadgetId
(
this
.
getGadgetId
())
.
setOwnerEntityId
(
this
.
getOwnerEntityId
())
.
setOwnerEntityId
(
this
.
getOwnerEntityId
())
...
@@ -157,7 +155,7 @@ public class EntityClientGadget extends EntityBaseGadget {
...
@@ -157,7 +155,7 @@ public class EntityClientGadget extends EntityBaseGadget {
.
setAuthorityPeerId
(
this
.
getOwner
().
getPeerId
());
.
setAuthorityPeerId
(
this
.
getOwner
().
getPeerId
());
entityInfo
.
setGadget
(
gadgetInfo
);
entityInfo
.
setGadget
(
gadgetInfo
);
return
entityInfo
.
build
();
return
entityInfo
.
build
();
}
}
}
}
src/main/java/emu/grasscutter/game/entity/EntityGadget.java
View file @
886c2e2f
...
@@ -175,6 +175,8 @@ public class EntityGadget extends EntityBaseGadget {
...
@@ -175,6 +175,8 @@ public class EntityGadget extends EntityBaseGadget {
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
if
(
this
.
getSpawnEntry
()
!=
null
)
{
if
(
this
.
getSpawnEntry
()
!=
null
)
{
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
}
}
...
...
src/main/java/emu/grasscutter/game/entity/EntityMonster.java
View file @
886c2e2f
...
@@ -158,6 +158,8 @@ public class EntityMonster extends GameEntity {
...
@@ -158,6 +158,8 @@ public class EntityMonster extends GameEntity {
@Override
@Override
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
super
.
onDeath
(
killerId
);
// Invoke super class's onDeath() method.
if
(
this
.
getSpawnEntry
()
!=
null
)
{
if
(
this
.
getSpawnEntry
()
!=
null
)
{
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
this
.
getScene
().
getDeadSpawnedEntities
().
add
(
getSpawnEntry
());
}
}
...
...
src/main/java/emu/grasscutter/game/entity/GameEntity.java
View file @
886c2e2f
...
@@ -15,6 +15,7 @@ import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
...
@@ -15,6 +15,7 @@ import emu.grasscutter.net.proto.MotionInfoOuterClass.MotionInfo;
import
emu.grasscutter.net.proto.MotionStateOuterClass.MotionState
;
import
emu.grasscutter.net.proto.MotionStateOuterClass.MotionState
;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.SceneEntityInfoOuterClass.SceneEntityInfo
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.net.proto.VectorOuterClass.Vector
;
import
emu.grasscutter.server.event.entity.EntityDeathEvent
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify
;
import
emu.grasscutter.utils.Position
;
import
emu.grasscutter.utils.Position
;
import
it.unimi.dsi.fastutil.ints.Int2FloatMap
;
import
it.unimi.dsi.fastutil.ints.Int2FloatMap
;
...
@@ -262,7 +263,9 @@ public abstract class GameEntity {
...
@@ -262,7 +263,9 @@ public abstract class GameEntity {
* @param killerId Entity id of the entity that killed this entity
* @param killerId Entity id of the entity that killed this entity
*/
*/
public
void
onDeath
(
int
killerId
)
{
public
void
onDeath
(
int
killerId
)
{
// Invoke entity death event.
EntityDeathEvent
event
=
new
EntityDeathEvent
(
this
,
killerId
);
event
.
call
();
}
}
public
abstract
SceneEntityInfo
toProto
();
public
abstract
SceneEntityInfo
toProto
();
...
...
src/main/java/emu/grasscutter/server/event/entity/EntityDeathEvent.java
0 → 100644
View file @
886c2e2f
package
emu.grasscutter.server.event.entity
;
import
emu.grasscutter.game.entity.GameEntity
;
import
emu.grasscutter.server.event.types.EntityEvent
;
import
emu.grasscutter.utils.Location
;
import
lombok.Getter
;
import
javax.annotation.Nullable
;
public
final
class
EntityDeathEvent
extends
EntityEvent
{
@Getter
private
final
Location
deathLocation
;
@Getter
@Nullable
private
final
GameEntity
killer
;
public
EntityDeathEvent
(
GameEntity
entity
,
int
killerId
)
{
super
(
entity
);
this
.
deathLocation
=
new
Location
(
entity
.
getScene
(),
entity
.
getPosition
());
this
.
killer
=
entity
.
getScene
().
getEntityById
(
killerId
);
}
}
\ No newline at end of file
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