mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Retreating/losing a battle should teleport to the nearest anchor
This commit is contained in:
@@ -241,9 +241,15 @@ public class BattleService extends BaseGameService {
|
||||
|
||||
// Teleport to anchor if player has lost/retreated. On official servers, the player party is teleported to the nearest anchor.
|
||||
if (teleportToAnchor) {
|
||||
var anchor = player.getScene().getFloorInfo().getStartAnchorInfo();
|
||||
if (anchor != null) {
|
||||
player.moveTo(anchor.clonePos());
|
||||
var anchorProp = player.getScene().getNearestSpring();
|
||||
if (anchorProp != null && anchorProp.getPropInfo() != null) {
|
||||
var anchor = player.getScene().getFloorInfo().getAnchorInfo(
|
||||
anchorProp.getPropInfo().getAnchorGroupID(),
|
||||
anchorProp.getPropInfo().getAnchorID()
|
||||
);
|
||||
if (anchor != null) {
|
||||
player.moveTo(anchor.clonePos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -367,22 +367,15 @@ public class Player {
|
||||
// Sanity
|
||||
if (this.getScene() == null) return;
|
||||
|
||||
boolean anchorRange = false;
|
||||
|
||||
// Check anchors. We can optimize this later.
|
||||
for (EntityProp anchor : this.getScene().getHealingSprings()) {
|
||||
long dist = getPos().getFast2dDist(anchor.getPos());
|
||||
if (dist > 25_000_000) continue; // 5000^2
|
||||
|
||||
anchorRange = true;
|
||||
break;
|
||||
}
|
||||
EntityProp nearestAnchor = this.getScene().getNearestSpring(25_000_000); // 5000^2
|
||||
boolean isInRange = nearestAnchor != null;
|
||||
|
||||
// Only heal if player isnt already in anchor range
|
||||
if (anchorRange && anchorRange != this.inAnchorRange) {
|
||||
if (isInRange && isInRange != this.inAnchorRange) {
|
||||
this.getCurrentLineup().heal(10000);
|
||||
}
|
||||
this.inAnchorRange = anchorRange;
|
||||
this.inAnchorRange = isInRange;
|
||||
}
|
||||
|
||||
public void moveTo(int entryId, Position pos) {
|
||||
|
||||
@@ -127,6 +127,7 @@ public class Scene {
|
||||
);
|
||||
prop.setInstId(propInfo.getID());
|
||||
prop.setGroupId(group.getId());
|
||||
prop.setPropInfo(propInfo);
|
||||
|
||||
// Hacky fixes
|
||||
if (prop.getPropId() == 1003) {
|
||||
@@ -252,6 +253,36 @@ public class Scene {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nearest spring (Space Anchor) to the player in the scene
|
||||
* @return
|
||||
*/
|
||||
public EntityProp getNearestSpring() {
|
||||
return getNearestSpring(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the nearest spring (Space Anchor) to the player in the scene
|
||||
* @param minDistSq Only checks springs in below this distance
|
||||
* @return
|
||||
*/
|
||||
public EntityProp getNearestSpring(long minDistSq) {
|
||||
EntityProp spring = null;
|
||||
long springDist = 0;
|
||||
|
||||
for (EntityProp prop : this.getHealingSprings()) {
|
||||
long dist = getPlayer().getPos().getFast2dDist(prop.getPos());
|
||||
if (dist > minDistSq) continue;
|
||||
|
||||
if (spring == null || dist < springDist) {
|
||||
spring = prop;
|
||||
springDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return spring;
|
||||
}
|
||||
|
||||
// TODO
|
||||
public void fireTrigger(PropTriggerType type, int param1, int param2) {
|
||||
for (PropTrigger trigger : this.getTriggers()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package emu.lunarcore.game.scene.entity;
|
||||
|
||||
import emu.lunarcore.data.config.PropInfo;
|
||||
import emu.lunarcore.data.excel.PropExcel;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
@@ -23,6 +24,9 @@ public class EntityProp implements GameEntity {
|
||||
private final Position pos;
|
||||
private final Position rot;
|
||||
|
||||
@Setter
|
||||
private PropInfo propInfo;
|
||||
|
||||
public EntityProp(Scene scene, PropExcel excel, Position pos) {
|
||||
this.scene = scene;
|
||||
this.excel = excel;
|
||||
|
||||
Reference in New Issue
Block a user