mirror of
https://github.com/Melledy/LunarCore.git
synced 2026-02-04 15:05:07 +01:00
Handle player death
This commit is contained in:
@@ -14,6 +14,9 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class FloorInfo {
|
public class FloorInfo {
|
||||||
private int FloorID;
|
private int FloorID;
|
||||||
|
private int StartGroupID;
|
||||||
|
private int StartAnchorID;
|
||||||
|
|
||||||
@SerializedName(value = "GroupList")
|
@SerializedName(value = "GroupList")
|
||||||
private List<FloorGroupSimpleInfo> SimpleGroupList;
|
private List<FloorGroupSimpleInfo> SimpleGroupList;
|
||||||
|
|
||||||
@@ -29,6 +32,10 @@ public class FloorInfo {
|
|||||||
this.unlockedCheckpoints = new ArrayList<>();
|
this.unlockedCheckpoints = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnchorInfo getStartAnchorInfo() {
|
||||||
|
return getAnchorInfo(StartGroupID, StartAnchorID);
|
||||||
|
}
|
||||||
|
|
||||||
public AnchorInfo getAnchorInfo(int groupId, int anchorId) {
|
public AnchorInfo getAnchorInfo(int groupId, int anchorId) {
|
||||||
GroupInfo group = this.getGroups().get(groupId);
|
GroupInfo group = this.getGroups().get(groupId);
|
||||||
if (group == null) return null;
|
if (group == null) return null;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public class BattleService extends BaseGameService {
|
|||||||
// Create battle and add npc monsters to it
|
// Create battle and add npc monsters to it
|
||||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), stages);
|
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), stages);
|
||||||
battle.getNpcMonsters().addAll(monsters);
|
battle.getNpcMonsters().addAll(monsters);
|
||||||
|
|
||||||
// Add weakness buff to battle
|
// Add weakness buff to battle
|
||||||
if (isPlayerCaster) {
|
if (isPlayerCaster) {
|
||||||
GameAvatar avatar = player.getLineupManager().getCurrentLeaderAvatar();
|
GameAvatar avatar = player.getLineupManager().getCurrentLeaderAvatar();
|
||||||
@@ -116,6 +117,7 @@ public class BattleService extends BaseGameService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set battle and send rsp packet
|
// Set battle and send rsp packet
|
||||||
player.setBattle(battle);
|
player.setBattle(battle);
|
||||||
player.sendPacket(new PacketSceneCastSkillScRsp(battle));
|
player.sendPacket(new PacketSceneCastSkillScRsp(battle));
|
||||||
@@ -175,10 +177,33 @@ public class BattleService extends BaseGameService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get battle object
|
// Get battle object and setup variables
|
||||||
Battle battle = player.getBattle();
|
Battle battle = player.getBattle();
|
||||||
|
int minimumHp = 0;
|
||||||
|
boolean teleportToAnchor = false;
|
||||||
|
|
||||||
// Set health/energy
|
// Handle result
|
||||||
|
switch (result) {
|
||||||
|
case BATTLE_END_WIN -> {
|
||||||
|
// Remove monsters from the map - Could optimize it a little better
|
||||||
|
for (var monster : battle.getNpcMonsters()) {
|
||||||
|
player.getScene().removeEntity(monster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case BATTLE_END_LOSE -> {
|
||||||
|
// Set avatar hp to 20% if the player's party is downed
|
||||||
|
minimumHp = 2000;
|
||||||
|
teleportToAnchor = true;
|
||||||
|
}
|
||||||
|
case BATTLE_END_QUIT -> {
|
||||||
|
teleportToAnchor = true;
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set health/energy for player avatars
|
||||||
for (var battleAvatar : battleAvatars) {
|
for (var battleAvatar : battleAvatars) {
|
||||||
GameAvatar avatar = player.getAvatarById(battleAvatar.getId());
|
GameAvatar avatar = player.getAvatarById(battleAvatar.getId());
|
||||||
if (avatar == null) continue;
|
if (avatar == null) continue;
|
||||||
@@ -187,19 +212,19 @@ public class BattleService extends BaseGameService {
|
|||||||
int currentHp = (int) Math.round((prop.getLeftHp() / prop.getMaxHp()) * 100);
|
int currentHp = (int) Math.round((prop.getLeftHp() / prop.getMaxHp()) * 100);
|
||||||
int currentSp = (int) prop.getLeftSp() * 100;
|
int currentSp = (int) prop.getLeftSp() * 100;
|
||||||
|
|
||||||
//avatar.setCurrentHp(currentHp);
|
avatar.setCurrentHp(Math.max(currentHp, minimumHp));
|
||||||
avatar.setCurrentSp(currentSp);
|
avatar.setCurrentSp(Math.max(currentSp, 0));
|
||||||
avatar.save();
|
avatar.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync with player
|
// Sync with player
|
||||||
player.sendPacket(new PacketSyncLineupNotify(battle.getLineup()));
|
player.sendPacket(new PacketSyncLineupNotify(battle.getLineup()));
|
||||||
|
|
||||||
// Delete enemies if the player won
|
// Teleport to anchor if player has lost/retreated. On official servers, the player party is teleported to the nearest anchor.
|
||||||
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
if (teleportToAnchor) {
|
||||||
// Could optimize it a little better
|
var anchor = player.getScene().getFloorInfo().getStartAnchorInfo();
|
||||||
for (var monster : battle.getNpcMonsters()) {
|
if (anchor != null) {
|
||||||
player.getScene().removeEntity(monster);
|
player.moveTo(anchor.clonePos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import emu.lunarcore.server.packet.SessionState;
|
|||||||
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
||||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||||
import emu.lunarcore.server.packet.send.PacketRevcMsgScNotify;
|
import emu.lunarcore.server.packet.send.PacketRevcMsgScNotify;
|
||||||
|
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
||||||
import emu.lunarcore.util.Position;
|
import emu.lunarcore.util.Position;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -305,6 +306,16 @@ public class Player {
|
|||||||
this.battle = battle;
|
this.battle = battle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void moveTo(int entryId, Position pos) {
|
||||||
|
this.entryId = entryId;
|
||||||
|
this.moveTo(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void moveTo(Position pos) {
|
||||||
|
this.getPos().set(pos);
|
||||||
|
this.sendPacket(new PacketSceneEntityMoveScNotify(this));
|
||||||
|
}
|
||||||
|
|
||||||
public void enterScene(int entryId, int teleportId, boolean sendPacket) {
|
public void enterScene(int entryId, int teleportId, boolean sendPacket) {
|
||||||
// Get map entrance excel
|
// Get map entrance excel
|
||||||
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import lombok.Getter;
|
|||||||
public class Scene {
|
public class Scene {
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final MazePlaneExcel excel;
|
private final MazePlaneExcel excel;
|
||||||
|
private final FloorInfo floorInfo;
|
||||||
private final int planeId;
|
private final int planeId;
|
||||||
private final int floorId;
|
private final int floorId;
|
||||||
private int entryId;
|
private int entryId;
|
||||||
@@ -67,7 +68,7 @@ public class Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn monsters
|
// Spawn monsters
|
||||||
FloorInfo floorInfo = GameData.getFloorInfo(this.planeId, this.floorId);
|
this.floorInfo = GameData.getFloorInfo(this.planeId, this.floorId);
|
||||||
if (floorInfo == null) return;
|
if (floorInfo == null) return;
|
||||||
|
|
||||||
for (GroupInfo group : floorInfo.getGroups().values()) {
|
for (GroupInfo group : floorInfo.getGroups().values()) {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package emu.lunarcore.server.packet.send;
|
||||||
|
|
||||||
|
import emu.lunarcore.game.player.Player;
|
||||||
|
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
|
||||||
|
import emu.lunarcore.proto.SceneEntityMoveScNotifyOuterClass.SceneEntityMoveScNotify;
|
||||||
|
import emu.lunarcore.proto.VectorOuterClass.Vector;
|
||||||
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
|
|
||||||
|
public class PacketSceneEntityMoveScNotify extends BasePacket {
|
||||||
|
|
||||||
|
public PacketSceneEntityMoveScNotify(Player player) {
|
||||||
|
super(CmdId.SceneEntityMoveScNotify);
|
||||||
|
|
||||||
|
var data = SceneEntityMoveScNotify.newInstance()
|
||||||
|
.setEntryId(player.getEntryId())
|
||||||
|
.setMotion(MotionInfo.newInstance().setPos(player.getPos().toProto()).setRot(Vector.newInstance()));
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user