mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 05:44:36 +01:00
Implement auto-heal from space anchors
Currently there is no limit to how much they heal
This commit is contained in:
@@ -6,8 +6,8 @@ import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
public class PropInfo extends ObjectInfo {
|
||||
public float RotX;
|
||||
public float RotZ;
|
||||
private float RotX;
|
||||
private float RotZ;
|
||||
private int MappingInfoID;
|
||||
private int AnchorGroupID;
|
||||
private int AnchorID;
|
||||
|
||||
@@ -2,6 +2,7 @@ package emu.lunarcore.data.excel;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import emu.lunarcore.game.enums.PropType;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -9,6 +10,7 @@ import lombok.Getter;
|
||||
public class PropExcel extends GameResource {
|
||||
private int ID;
|
||||
private String JsonPath;
|
||||
private PropType PropType;
|
||||
|
||||
private transient boolean recoverHp;
|
||||
private transient boolean recoverMp;
|
||||
@@ -28,5 +30,8 @@ public class PropExcel extends GameResource {
|
||||
this.recoverHp = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Clear for optimization
|
||||
this.JsonPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
39
src/main/java/emu/lunarcore/game/enums/PropType.java
Normal file
39
src/main/java/emu/lunarcore/game/enums/PropType.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package emu.lunarcore.game.enums;
|
||||
|
||||
public enum PropType {
|
||||
PROP_NONE (0),
|
||||
PROP_ORDINARY (1),
|
||||
PROP_SUMMON (2),
|
||||
PROP_DESTRUCT (3),
|
||||
PROP_SPRING (4),
|
||||
PROP_PLATFORM (5),
|
||||
PROP_TREASURE_CHEST (6),
|
||||
PROP_MATERIAL_ZONE (7),
|
||||
PROP_COCOON (8),
|
||||
PROP_MAPPINGINFO (9),
|
||||
PROP_PUZZLES (10),
|
||||
PROP_ELEVATOR (11),
|
||||
PROP_NO_REWARD_DESTRUCT (12),
|
||||
PROP_LIGHT (13),
|
||||
PROP_ROGUE_DOOR (14),
|
||||
PROP_ROGUE_OBJECT (15),
|
||||
PROP_ROGUE_CHEST (16),
|
||||
PROP_TELEVISION (17),
|
||||
PROP_RELIC (18),
|
||||
PROP_ELEMENT (19),
|
||||
PROP_ROGUE_HIDDEN_DOOR (20),
|
||||
PROP_PERSPECTIVE_WALL (21),
|
||||
PROP_MAZE_PUZZLE (22),
|
||||
PROP_MAZE_DECAL (23),
|
||||
PROP_ROGUE_REWARD_OBJECT (24),
|
||||
PROP_MAP_ROTATION_CHARGER (25),
|
||||
PROP_MAP_ROTATION_VOLUME (26),
|
||||
PROP_MAP_ROTATION_SWITCHER (27),
|
||||
PROP_BOXMAN_BINDED (28);
|
||||
|
||||
private final int val;
|
||||
|
||||
private PropType(int value) {
|
||||
this.val = value;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import emu.lunarcore.game.battle.Battle;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
import emu.lunarcore.game.inventory.Inventory;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
import emu.lunarcore.game.scene.entity.EntityProp;
|
||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||
@@ -72,6 +73,7 @@ public class Player {
|
||||
|
||||
// Etc
|
||||
@Setter private transient boolean paused;
|
||||
private transient boolean inAnchorRange;
|
||||
private transient int nextBattleId;
|
||||
|
||||
// Player managers
|
||||
@@ -306,6 +308,30 @@ public class Player {
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
public void onMove() {
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Only heal if player isnt already in anchor range
|
||||
if (anchorRange && anchorRange != this.inAnchorRange) {
|
||||
this.getCurrentLineup().heal(10000);
|
||||
}
|
||||
this.inAnchorRange = anchorRange;
|
||||
}
|
||||
|
||||
public void moveTo(int entryId, Position pos) {
|
||||
this.entryId = entryId;
|
||||
this.moveTo(pos);
|
||||
|
||||
@@ -65,16 +65,25 @@ public class PlayerLineup {
|
||||
}
|
||||
|
||||
public void heal(int heal) {
|
||||
// Flag to set if at least one avatar in the team has been healed
|
||||
boolean hasHealed = false;
|
||||
|
||||
// Add hp to team
|
||||
for (int avatarId : this.getAvatars()) {
|
||||
GameAvatar avatar = this.getOwner().getAvatarById(avatarId);
|
||||
if (avatar == null) continue;
|
||||
|
||||
avatar.setCurrentHp(Math.min(avatar.getCurrentHp() + heal, 10000));
|
||||
if (avatar.getCurrentHp() < 10000) {
|
||||
avatar.setCurrentHp(Math.min(avatar.getCurrentHp() + heal, 10000));
|
||||
avatar.save();
|
||||
hasHealed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Send packet
|
||||
getOwner().sendPacket(new PacketSyncLineupNotify(this));
|
||||
// Send packet if team was healed
|
||||
if (hasHealed) {
|
||||
getOwner().sendPacket(new PacketSyncLineupNotify(this));
|
||||
}
|
||||
}
|
||||
|
||||
public LineupInfo toProto() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||
import emu.lunarcore.data.excel.PropExcel;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.enums.PropState;
|
||||
import emu.lunarcore.game.enums.PropType;
|
||||
import emu.lunarcore.game.player.PlayerLineup;
|
||||
import emu.lunarcore.game.scene.entity.*;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
@@ -40,8 +41,11 @@ public class Scene {
|
||||
private IntSet avatarEntityIds;
|
||||
private Int2ObjectMap<GameAvatar> avatars;
|
||||
|
||||
// Other entities TODO
|
||||
// Other entities
|
||||
private Int2ObjectMap<GameEntity> entities;
|
||||
|
||||
// Cache
|
||||
private List<EntityProp> healingSprings;
|
||||
|
||||
public Scene(Player player, MazePlaneExcel excel, int floorId) {
|
||||
this.player = player;
|
||||
@@ -53,6 +57,7 @@ public class Scene {
|
||||
this.avatarEntityIds = new IntOpenHashSet();
|
||||
this.avatars = new Int2ObjectOpenHashMap<>();
|
||||
this.entities = new Int2ObjectOpenHashMap<>();
|
||||
this.healingSprings = new ArrayList<>();
|
||||
|
||||
PlayerLineup lineup = getPlayer().getCurrentLineup();
|
||||
|
||||
@@ -117,9 +122,13 @@ public class Scene {
|
||||
prop.setInstId(propInfo.getID());
|
||||
prop.setGroupId(group.getId());
|
||||
|
||||
// Hacky fix for rogue entry
|
||||
// Hacky fixes
|
||||
if (prop.getPropId() == 1003) {
|
||||
// Open simulated universe
|
||||
prop.setState(PropState.Open);
|
||||
} else if (prop.getExcel().getPropType() == PropType.PROP_SPRING) {
|
||||
// Teleport anchors cache
|
||||
this.getHealingSprings().add(prop);
|
||||
}
|
||||
|
||||
// Add to monsters
|
||||
|
||||
@@ -15,9 +15,11 @@ public class HandlerSceneEntityMoveCsReq extends PacketHandler {
|
||||
var req = SceneEntityMoveCsReq.parseFrom(data);
|
||||
|
||||
for (var entityMotion : req.getEntityMotionList()) {
|
||||
// Update player position
|
||||
if (session.getPlayer().getScene().getAvatarEntityIds().contains(entityMotion.getEntityId())) {
|
||||
var vec = entityMotion.getMotion().getPos();
|
||||
session.getPlayer().getPos().set(vec.getX(), vec.getY(), vec.getZ());
|
||||
session.getPlayer().onMove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,14 +72,14 @@ public class Position {
|
||||
|
||||
public double get2dDist(Position pos) {
|
||||
int x = this.getX() - pos.getX();
|
||||
int y = this.getY() - pos.getY();
|
||||
return Math.sqrt((x * x) + (y * y));
|
||||
int z = this.getZ() - pos.getZ();
|
||||
return Math.sqrt((x * x) + (z * z));
|
||||
}
|
||||
|
||||
public int getFast2dDist(Position pos) {
|
||||
int x = this.getX() - pos.getX();
|
||||
int y = this.getY() - pos.getY();
|
||||
return (x * x) + (y * y);
|
||||
public long getFast2dDist(Position pos) {
|
||||
long x = this.getX() - pos.getX();
|
||||
long z = this.getZ() - pos.getZ();
|
||||
return (x * x) + (z * z);
|
||||
}
|
||||
|
||||
public Vector toProto() {
|
||||
|
||||
Reference in New Issue
Block a user