Retreating/losing a battle should teleport to the nearest anchor

This commit is contained in:
Melledy
2023-10-07 19:46:15 -07:00
parent 380ec3dbc7
commit acdcbf8829
4 changed files with 49 additions and 15 deletions

View File

@@ -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. // Teleport to anchor if player has lost/retreated. On official servers, the player party is teleported to the nearest anchor.
if (teleportToAnchor) { if (teleportToAnchor) {
var anchor = player.getScene().getFloorInfo().getStartAnchorInfo(); var anchorProp = player.getScene().getNearestSpring();
if (anchor != null) { if (anchorProp != null && anchorProp.getPropInfo() != null) {
player.moveTo(anchor.clonePos()); var anchor = player.getScene().getFloorInfo().getAnchorInfo(
anchorProp.getPropInfo().getAnchorGroupID(),
anchorProp.getPropInfo().getAnchorID()
);
if (anchor != null) {
player.moveTo(anchor.clonePos());
}
} }
} }

View File

@@ -367,22 +367,15 @@ public class Player {
// Sanity // Sanity
if (this.getScene() == null) return; if (this.getScene() == null) return;
boolean anchorRange = false;
// Check anchors. We can optimize this later. // Check anchors. We can optimize this later.
for (EntityProp anchor : this.getScene().getHealingSprings()) { EntityProp nearestAnchor = this.getScene().getNearestSpring(25_000_000); // 5000^2
long dist = getPos().getFast2dDist(anchor.getPos()); boolean isInRange = nearestAnchor != null;
if (dist > 25_000_000) continue; // 5000^2
anchorRange = true;
break;
}
// Only heal if player isnt already in anchor range // Only heal if player isnt already in anchor range
if (anchorRange && anchorRange != this.inAnchorRange) { if (isInRange && isInRange != this.inAnchorRange) {
this.getCurrentLineup().heal(10000); this.getCurrentLineup().heal(10000);
} }
this.inAnchorRange = anchorRange; this.inAnchorRange = isInRange;
} }
public void moveTo(int entryId, Position pos) { public void moveTo(int entryId, Position pos) {

View File

@@ -127,6 +127,7 @@ public class Scene {
); );
prop.setInstId(propInfo.getID()); prop.setInstId(propInfo.getID());
prop.setGroupId(group.getId()); prop.setGroupId(group.getId());
prop.setPropInfo(propInfo);
// Hacky fixes // Hacky fixes
if (prop.getPropId() == 1003) { if (prop.getPropId() == 1003) {
@@ -252,6 +253,36 @@ public class Scene {
return true; 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 // TODO
public void fireTrigger(PropTriggerType type, int param1, int param2) { public void fireTrigger(PropTriggerType type, int param1, int param2) {
for (PropTrigger trigger : this.getTriggers()) { for (PropTrigger trigger : this.getTriggers()) {

View File

@@ -1,5 +1,6 @@
package emu.lunarcore.game.scene.entity; package emu.lunarcore.game.scene.entity;
import emu.lunarcore.data.config.PropInfo;
import emu.lunarcore.data.excel.PropExcel; import emu.lunarcore.data.excel.PropExcel;
import emu.lunarcore.game.enums.PropState; import emu.lunarcore.game.enums.PropState;
import emu.lunarcore.game.scene.Scene; import emu.lunarcore.game.scene.Scene;
@@ -23,6 +24,9 @@ public class EntityProp implements GameEntity {
private final Position pos; private final Position pos;
private final Position rot; private final Position rot;
@Setter
private PropInfo propInfo;
public EntityProp(Scene scene, PropExcel excel, Position pos) { public EntityProp(Scene scene, PropExcel excel, Position pos) {
this.scene = scene; this.scene = scene;
this.excel = excel; this.excel = excel;