Commit 818bfb8c authored by KingRainbow44's avatar KingRainbow44
Browse files

Add `PlayerTeamDeathEvent` and implementations

parent 886c2e2f
...@@ -20,6 +20,7 @@ import emu.grasscutter.net.packet.PacketOpcodes; ...@@ -20,6 +20,7 @@ import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType; import emu.grasscutter.net.proto.EnterTypeOuterClass.EnterType;
import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState; import emu.grasscutter.net.proto.MotionStateOuterClass.MotionState;
import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType; import emu.grasscutter.net.proto.PlayerDieTypeOuterClass.PlayerDieType;
import emu.grasscutter.server.event.player.PlayerTeamDeathEvent;
import emu.grasscutter.server.packet.send.PacketAvatarDieAnimationEndRsp; import emu.grasscutter.server.packet.send.PacketAvatarDieAnimationEndRsp;
import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketAvatarFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
...@@ -76,7 +77,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -76,7 +77,7 @@ public class TeamManager extends BasePlayerDataManager {
} }
public World getWorld() { public World getWorld() {
return getPlayer().getWorld(); return this.getPlayer().getWorld();
} }
public Map<Integer, TeamInfo> getTeams() { public Map<Integer, TeamInfo> getTeams() {
...@@ -123,7 +124,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -123,7 +124,7 @@ public class TeamManager extends BasePlayerDataManager {
} }
public long getCurrentCharacterGuid() { public long getCurrentCharacterGuid() {
return getCurrentAvatarEntity().getAvatar().getGuid(); return this.getCurrentAvatarEntity().getAvatar().getGuid();
} }
public TeamInfo getCurrentTeamInfo() { public TeamInfo getCurrentTeamInfo() {
...@@ -166,20 +167,20 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -166,20 +167,20 @@ public class TeamManager extends BasePlayerDataManager {
} }
public EntityAvatar getCurrentAvatarEntity() { public EntityAvatar getCurrentAvatarEntity() {
return getActiveTeam().get(currentCharacterIndex); return this.getActiveTeam().get(currentCharacterIndex);
} }
public boolean isSpawned() { public boolean isSpawned() {
return getPlayer().getScene() != null && getPlayer().getScene().getEntities().containsKey(getCurrentAvatarEntity().getId()); return this.getPlayer().getScene() != null && this.getPlayer().getScene().getEntities().containsKey(this.getCurrentAvatarEntity().getId());
} }
public int getMaxTeamSize() { public int getMaxTeamSize() {
if (getPlayer().isInMultiplayer()) { if (this.getPlayer().isInMultiplayer()) {
int max = GAME_OPTIONS.avatarLimits.multiplayerTeam; int max = GAME_OPTIONS.avatarLimits.multiplayerTeam;
if (getPlayer().getWorld().getHost() == this.getPlayer()) { if (this.getPlayer().getWorld().getHost() == this.getPlayer()) {
return Math.max(1, (int) Math.ceil(max / (double) getWorld().getPlayerCount())); return Math.max(1, (int) Math.ceil(max / (double) this.getWorld().getPlayerCount()));
} }
return Math.max(1, (int) Math.floor(max / (double) getWorld().getPlayerCount())); return Math.max(1, (int) Math.floor(max / (double) this.getWorld().getPlayerCount()));
} }
return GAME_OPTIONS.avatarLimits.singlePlayerTeam; return GAME_OPTIONS.avatarLimits.singlePlayerTeam;
...@@ -191,14 +192,14 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -191,14 +192,14 @@ public class TeamManager extends BasePlayerDataManager {
* Returns true if there is space to add the number of avatars to the team. * Returns true if there is space to add the number of avatars to the team.
*/ */
public boolean canAddAvatarsToTeam(TeamInfo team, int avatars) { public boolean canAddAvatarsToTeam(TeamInfo team, int avatars) {
return team.size() + avatars <= getMaxTeamSize(); return team.size() + avatars <= this.getMaxTeamSize();
} }
/** /**
* Returns true if there is space to add to the team. * Returns true if there is space to add to the team.
*/ */
public boolean canAddAvatarToTeam(TeamInfo team) { public boolean canAddAvatarToTeam(TeamInfo team) {
return canAddAvatarsToTeam(team, 1); return this.canAddAvatarsToTeam(team, 1);
} }
/** /**
...@@ -209,7 +210,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -209,7 +210,7 @@ public class TeamManager extends BasePlayerDataManager {
if (this.useTemporarilyTeamIndex != -1) { if (this.useTemporarilyTeamIndex != -1) {
return false; return false;
} }
return canAddAvatarsToTeam(this.getCurrentTeamInfo(), avatars); return this.canAddAvatarsToTeam(this.getCurrentTeamInfo(), avatars);
} }
/** /**
...@@ -217,7 +218,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -217,7 +218,7 @@ public class TeamManager extends BasePlayerDataManager {
* If the current team is temporary, returns false. * If the current team is temporary, returns false.
*/ */
public boolean canAddAvatarToCurrentTeam() { public boolean canAddAvatarToCurrentTeam() {
return canAddAvatarsToCurrentTeam(1); return this.canAddAvatarsToCurrentTeam(1);
} }
/** /**
...@@ -226,7 +227,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -226,7 +227,7 @@ public class TeamManager extends BasePlayerDataManager {
* If some can not be added, returns false and does not add any. * If some can not be added, returns false and does not add any.
*/ */
public boolean addAvatarsToTeam(TeamInfo team, Collection<Avatar> avatars) { public boolean addAvatarsToTeam(TeamInfo team, Collection<Avatar> avatars) {
if (!canAddAvatarsToTeam(team, avatars.size())) { if (!this.canAddAvatarsToTeam(team, avatars.size())) {
return false; return false;
} }
...@@ -237,20 +238,20 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -237,20 +238,20 @@ public class TeamManager extends BasePlayerDataManager {
if (this.getPlayer().isInMultiplayer()) { if (this.getPlayer().isInMultiplayer()) {
if (team.equals(this.getMpTeam())) { if (team.equals(this.getMpTeam())) {
// MP team Packet // MP team Packet
this.updateTeamEntities(new PacketChangeMpTeamAvatarRsp(getPlayer(), team)); this.updateTeamEntities(new PacketChangeMpTeamAvatarRsp(this.getPlayer(), team));
} }
} else { } else {
// SP team update packet // SP team update packet
getPlayer().sendPacket(new PacketAvatarTeamUpdateNotify(getPlayer())); this.getPlayer().sendPacket(new PacketAvatarTeamUpdateNotify(this.getPlayer()));
int teamId = this.getTeamId(team); int teamId = this.getTeamId(team);
if (teamId != -1) { if (teamId != -1) {
// This is one of the player's teams // This is one of the player's teams
// Update entites // Update entites
if (teamId == this.getCurrentTeamId()) { if (teamId == this.getCurrentTeamId()) {
this.updateTeamEntities(new PacketSetUpAvatarTeamRsp(getPlayer(), teamId, team)); this.updateTeamEntities(new PacketSetUpAvatarTeamRsp(this.getPlayer(), teamId, team));
} else { } else {
getPlayer().sendPacket(new PacketSetUpAvatarTeamRsp(getPlayer(), teamId, team)); this.getPlayer().sendPacket(new PacketSetUpAvatarTeamRsp(this.getPlayer(), teamId, team));
} }
} }
} }
...@@ -263,7 +264,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -263,7 +264,7 @@ public class TeamManager extends BasePlayerDataManager {
* Returns true if successful. * Returns true if successful.
*/ */
public boolean addAvatarToTeam(TeamInfo team, Avatar avatar) { public boolean addAvatarToTeam(TeamInfo team, Avatar avatar) {
return addAvatarsToTeam(team, Collections.singleton(avatar)); return this.addAvatarsToTeam(team, Collections.singleton(avatar));
} }
/** /**
...@@ -276,7 +277,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -276,7 +277,7 @@ public class TeamManager extends BasePlayerDataManager {
if (this.useTemporarilyTeamIndex != -1) { if (this.useTemporarilyTeamIndex != -1) {
return false; return false;
} }
return addAvatarsToTeam(this.getCurrentTeamInfo(), avatars); return this.addAvatarsToTeam(this.getCurrentTeamInfo(), avatars);
} }
/** /**
...@@ -285,7 +286,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -285,7 +286,7 @@ public class TeamManager extends BasePlayerDataManager {
* Returns true if successful. * Returns true if successful.
*/ */
public boolean addAvatarToCurrentTeam(Avatar avatar) { public boolean addAvatarToCurrentTeam(Avatar avatar) {
return addAvatarsToCurrentTeam(Collections.singleton(avatar)); return this.addAvatarsToCurrentTeam(Collections.singleton(avatar));
} }
private void updateTeamResonances() { private void updateTeamResonances() {
...@@ -294,7 +295,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -294,7 +295,7 @@ public class TeamManager extends BasePlayerDataManager {
this.getTeamResonances().clear(); this.getTeamResonances().clear();
this.getTeamResonancesConfig().clear(); this.getTeamResonancesConfig().clear();
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
AvatarSkillDepotData skillData = entity.getAvatar().getAvatarData().getSkillDepot(); AvatarSkillDepotData skillData = entity.getAvatar().getAvatarData().getSkillDepot();
if (skillData != null) { if (skillData != null) {
map.addTo(skillData.getElementType().getValue(), 1); map.addTo(skillData.getElementType().getValue(), 1);
...@@ -329,7 +330,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -329,7 +330,7 @@ public class TeamManager extends BasePlayerDataManager {
Int2ObjectMap<EntityAvatar> existingAvatars = new Int2ObjectOpenHashMap<>(); Int2ObjectMap<EntityAvatar> existingAvatars = new Int2ObjectOpenHashMap<>();
int prevSelectedAvatarIndex = -1; int prevSelectedAvatarIndex = -1;
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
existingAvatars.put(entity.getAvatar().getAvatarId(), entity); existingAvatars.put(entity.getAvatar().getAvatarId(), entity);
} }
...@@ -348,7 +349,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -348,7 +349,7 @@ public class TeamManager extends BasePlayerDataManager {
prevSelectedAvatarIndex = i; prevSelectedAvatarIndex = i;
} }
} else { } else {
entity = new EntityAvatar(getPlayer().getScene(), getPlayer().getAvatars().getAvatarById(avatarId)); entity = new EntityAvatar(this.getPlayer().getScene(), this.getPlayer().getAvatars().getAvatarById(avatarId));
} }
this.getActiveTeam().add(entity); this.getActiveTeam().add(entity);
...@@ -356,7 +357,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -356,7 +357,7 @@ public class TeamManager extends BasePlayerDataManager {
// Unload removed entities // Unload removed entities
for (EntityAvatar entity : existingAvatars.values()) { for (EntityAvatar entity : existingAvatars.values()) {
getPlayer().getScene().removeEntity(entity); this.getPlayer().getScene().removeEntity(entity);
entity.getAvatar().save(); entity.getAvatar().save();
} }
...@@ -368,33 +369,33 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -368,33 +369,33 @@ public class TeamManager extends BasePlayerDataManager {
this.currentCharacterIndex = prevSelectedAvatarIndex; this.currentCharacterIndex = prevSelectedAvatarIndex;
// Update team resonances // Update team resonances
updateTeamResonances(); this.updateTeamResonances();
// Packets // Packets
getPlayer().getWorld().broadcastPacket(new PacketSceneTeamUpdateNotify(getPlayer())); this.getPlayer().getWorld().broadcastPacket(new PacketSceneTeamUpdateNotify(this.getPlayer()));
// Skill charges packet - Yes, this is official server behavior as of 2.6.0 // Skill charges packet - Yes, this is official server behavior as of 2.6.0
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) { if (entity.getAvatar().getSkillExtraChargeMap().size() > 0) {
getPlayer().sendPacket(new PacketAvatarSkillInfoNotify(entity.getAvatar())); this.getPlayer().sendPacket(new PacketAvatarSkillInfoNotify(entity.getAvatar()));
} }
} }
// Run callback // Run callback
if (responsePacket != null) { if (responsePacket != null) {
getPlayer().sendPacket(responsePacket); this.getPlayer().sendPacket(responsePacket);
} }
// Check if character changed // Check if character changed
if (currentEntity != getCurrentAvatarEntity()) { if (currentEntity != this.getCurrentAvatarEntity()) {
// Remove and Add // Remove and Add
getPlayer().getScene().replaceEntity(currentEntity, getCurrentAvatarEntity()); this.getPlayer().getScene().replaceEntity(currentEntity, this.getCurrentAvatarEntity());
} }
} }
public synchronized void setupAvatarTeam(int teamId, List<Long> list) { public synchronized void setupAvatarTeam(int teamId, List<Long> list) {
// Sanity checks // Sanity checks
if (list.size() == 0 || list.size() > getMaxTeamSize() || getPlayer().isInMultiplayer()) { if (list.size() == 0 || list.size() > this.getMaxTeamSize() || this.getPlayer().isInMultiplayer()) {
return; return;
} }
...@@ -407,7 +408,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -407,7 +408,7 @@ public class TeamManager extends BasePlayerDataManager {
// Set team data // Set team data
LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>(); LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
for (Long aLong : list) { for (Long aLong : list) {
Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(aLong); Avatar avatar = this.getPlayer().getAvatars().getAvatarByGuid(aLong);
if (avatar == null || newTeam.contains(avatar)) { if (avatar == null || newTeam.contains(avatar)) {
// Should never happen // Should never happen
return; return;
...@@ -422,7 +423,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -422,7 +423,7 @@ public class TeamManager extends BasePlayerDataManager {
public void setupMpTeam(List<Long> list) { public void setupMpTeam(List<Long> list) {
// Sanity checks // Sanity checks
if (list.size() == 0 || list.size() > getMaxTeamSize() || !getPlayer().isInMultiplayer()) { if (list.size() == 0 || list.size() > this.getMaxTeamSize() || !this.getPlayer().isInMultiplayer()) {
return; return;
} }
...@@ -431,7 +432,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -431,7 +432,7 @@ public class TeamManager extends BasePlayerDataManager {
// Set team data // Set team data
LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>(); LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
for (Long aLong : list) { for (Long aLong : list) {
Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(aLong); Avatar avatar = this.getPlayer().getAvatars().getAvatarByGuid(aLong);
if (avatar == null || newTeam.contains(avatar)) { if (avatar == null || newTeam.contains(avatar)) {
// Should never happen // Should never happen
return; return;
...@@ -447,14 +448,14 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -447,14 +448,14 @@ public class TeamManager extends BasePlayerDataManager {
public void setupTemporaryTeam(List<List<Long>> guidList) { public void setupTemporaryTeam(List<List<Long>> guidList) {
this.temporaryTeam = guidList.stream().map(list -> { this.temporaryTeam = guidList.stream().map(list -> {
// Sanity checks // Sanity checks
if (list.size() == 0 || list.size() > getMaxTeamSize()) { if (list.size() == 0 || list.size() > this.getMaxTeamSize()) {
return null; return null;
} }
// Set team data // Set team data
LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>(); LinkedHashSet<Avatar> newTeam = new LinkedHashSet<>();
for (Long aLong : list) { for (Long aLong : list) {
Avatar avatar = getPlayer().getAvatars().getAvatarByGuid(aLong); Avatar avatar = this.getPlayer().getAvatars().getAvatarByGuid(aLong);
if (avatar == null || newTeam.contains(avatar)) { if (avatar == null || newTeam.contains(avatar)) {
// Should never happen // Should never happen
return null; return null;
...@@ -474,7 +475,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -474,7 +475,7 @@ public class TeamManager extends BasePlayerDataManager {
public void useTemporaryTeam(int index) { public void useTemporaryTeam(int index) {
this.useTemporarilyTeamIndex = index; this.useTemporarilyTeamIndex = index;
updateTeamEntities(null); this.updateTeamEntities(null);
} }
public void cleanTemporaryTeam() { public void cleanTemporaryTeam() {
...@@ -485,11 +486,11 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -485,11 +486,11 @@ public class TeamManager extends BasePlayerDataManager {
this.useTemporarilyTeamIndex = -1; this.useTemporarilyTeamIndex = -1;
this.temporaryTeam = null; this.temporaryTeam = null;
updateTeamEntities(null); this.updateTeamEntities(null);
} }
public synchronized void setCurrentTeam(int teamId) { public synchronized void setCurrentTeam(int teamId) {
// //
if (getPlayer().isInMultiplayer()) { if (this.getPlayer().isInMultiplayer()) {
return; return;
} }
...@@ -514,7 +515,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -514,7 +515,7 @@ public class TeamManager extends BasePlayerDataManager {
teamInfo.setName(teamName); teamInfo.setName(teamName);
// Packet // Packet
getPlayer().sendPacket(new PacketChangeTeamNameRsp(teamId, teamName)); this.getPlayer().sendPacket(new PacketChangeTeamNameRsp(teamId, teamName));
} }
public synchronized void changeAvatar(long guid) { public synchronized void changeAvatar(long guid) {
...@@ -526,10 +527,10 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -526,10 +527,10 @@ public class TeamManager extends BasePlayerDataManager {
EntityAvatar newEntity = null; EntityAvatar newEntity = null;
int index = -1; int index = -1;
for (int i = 0; i < getActiveTeam().size(); i++) { for (int i = 0; i < this.getActiveTeam().size(); i++) {
if (guid == getActiveTeam().get(i).getAvatar().getGuid()) { if (guid == this.getActiveTeam().get(i).getAvatar().getGuid()) {
index = i; index = i;
newEntity = getActiveTeam().get(i); newEntity = this.getActiveTeam().get(i);
} }
} }
...@@ -544,8 +545,8 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -544,8 +545,8 @@ public class TeamManager extends BasePlayerDataManager {
oldEntity.setMotionState(MotionState.MOTION_STATE_STANDBY); oldEntity.setMotionState(MotionState.MOTION_STATE_STANDBY);
// Remove and Add // Remove and Add
getPlayer().getScene().replaceEntity(oldEntity, newEntity); this.getPlayer().getScene().replaceEntity(oldEntity, newEntity);
getPlayer().sendPacket(new PacketChangeAvatarRsp(guid)); this.getPlayer().sendPacket(new PacketChangeAvatarRsp(guid));
} }
public void onAvatarDie(long dieGuid) { public void onAvatarDie(long dieGuid) {
...@@ -562,7 +563,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -562,7 +563,7 @@ public class TeamManager extends BasePlayerDataManager {
// Died in water. Do not replace // Died in water. Do not replace
// The official server has skipped this notify and will just respawn the team immediately after the animation. // The official server has skipped this notify and will just respawn the team immediately after the animation.
// TODO: Perhaps find a way to get vanilla experience? // TODO: Perhaps find a way to get vanilla experience?
getPlayer().sendPacket(new PacketWorldPlayerDieNotify(dieType, killedBy)); this.getPlayer().sendPacket(new PacketWorldPlayerDieNotify(dieType, killedBy));
} else { } else {
// Replacement avatar // Replacement avatar
EntityAvatar replacement = null; EntityAvatar replacement = null;
...@@ -579,20 +580,24 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -579,20 +580,24 @@ public class TeamManager extends BasePlayerDataManager {
if (replacement == null) { if (replacement == null) {
// No more living team members... // No more living team members...
getPlayer().sendPacket(new PacketWorldPlayerDieNotify(dieType, killedBy)); this.getPlayer().sendPacket(new PacketWorldPlayerDieNotify(dieType, killedBy));
// Invoke player team death event.
PlayerTeamDeathEvent event = new PlayerTeamDeathEvent(this.getPlayer(),
this.getActiveTeam().get(this.getCurrentCharacterIndex()));
event.call();
} else { } else {
// Set index and spawn replacement member // Set index and spawn replacement member
this.setCurrentCharacterIndex(replaceIndex); this.setCurrentCharacterIndex(replaceIndex);
getPlayer().getScene().addEntity(replacement); this.getPlayer().getScene().addEntity(replacement);
} }
} }
// Response packet // Response packet
getPlayer().sendPacket(new PacketAvatarDieAnimationEndRsp(deadAvatar.getId(), 0)); this.getPlayer().sendPacket(new PacketAvatarDieAnimationEndRsp(deadAvatar.getId(), 0));
} }
public boolean reviveAvatar(Avatar avatar) { public boolean reviveAvatar(Avatar avatar) {
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
if (entity.getAvatar() == avatar) { if (entity.getAvatar() == avatar) {
if (entity.isAlive()) { if (entity.isAlive()) {
return false; return false;
...@@ -602,8 +607,8 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -602,8 +607,8 @@ public class TeamManager extends BasePlayerDataManager {
FightProperty.FIGHT_PROP_CUR_HP, FightProperty.FIGHT_PROP_CUR_HP,
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .1f entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .1f
); );
getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP)); this.getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP));
getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); this.getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
return true; return true;
} }
} }
...@@ -612,7 +617,7 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -612,7 +617,7 @@ public class TeamManager extends BasePlayerDataManager {
} }
public boolean healAvatar(Avatar avatar, int healRate, int healAmount) { public boolean healAvatar(Avatar avatar, int healRate, int healAmount) {
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
if (entity.getAvatar() == avatar) { if (entity.getAvatar() == avatar) {
if (!entity.isAlive()) { if (!entity.isAlive()) {
return false; return false;
...@@ -627,8 +632,8 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -627,8 +632,8 @@ public class TeamManager extends BasePlayerDataManager {
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP)
) )
); );
getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP)); this.getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP));
getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); this.getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
return true; return true;
} }
} }
...@@ -646,29 +651,29 @@ public class TeamManager extends BasePlayerDataManager { ...@@ -646,29 +651,29 @@ public class TeamManager extends BasePlayerDataManager {
player.getStaminaManager().stopSustainedStaminaHandler(); // prevent drowning immediately after respawn player.getStaminaManager().stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
// Revive all team members // Revive all team members
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
entity.setFightProperty( entity.setFightProperty(
FightProperty.FIGHT_PROP_CUR_HP, FightProperty.FIGHT_PROP_CUR_HP,
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .4f entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .4f
); );
getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP)); this.getPlayer().sendPacket(new PacketAvatarFightPropUpdateNotify(entity.getAvatar(), FightProperty.FIGHT_PROP_CUR_HP));
getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); this.getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
} }
// Teleport player // Teleport player
getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(getPlayer(), EnterType.ENTER_TYPE_SELF, EnterReason.Revival, 3, GameConstants.START_POSITION)); this.getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(this.getPlayer(), EnterType.ENTER_TYPE_SELF, EnterReason.Revival, 3, GameConstants.START_POSITION));
// Set player position // Set player position
player.setSceneId(3); player.setSceneId(3);
player.getPosition().set(GameConstants.START_POSITION); player.getPosition().set(GameConstants.START_POSITION);
// Packets // Packets
getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp)); this.getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
} }
public void saveAvatars() { public void saveAvatars() {
// Save all avatars from active team // Save all avatars from active team
for (EntityAvatar entity : getActiveTeam()) { for (EntityAvatar entity : this.getActiveTeam()) {
entity.getAvatar().save(); entity.getAvatar().save();
} }
} }
......
package emu.grasscutter.server.event.player;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.event.types.PlayerEvent;
import lombok.Getter;
/**
* This event is invoked when the ENTIRE TEAM dies.
* To listen for one player death, use {@link emu.grasscutter.server.event.entity.EntityDeathEvent}.
*/
public final class PlayerTeamDeathEvent extends PlayerEvent {
@Getter private final EntityAvatar selectedAvatar;
public PlayerTeamDeathEvent(Player player, EntityAvatar selectedAvatar) {
super(player);
this.selectedAvatar = selectedAvatar;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment