Refactor game entity constructors

This commit is contained in:
Melledy
2023-10-29 13:48:58 -07:00
parent 4e65fd6a7d
commit d34b26a86c
7 changed files with 47 additions and 47 deletions

View File

@@ -4,6 +4,7 @@ import emu.lunarcore.command.Command;
import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.config.GroupInfo;
import emu.lunarcore.data.config.MonsterInfo;
import emu.lunarcore.data.excel.NpcMonsterExcel;
import emu.lunarcore.data.excel.PropExcel;
@@ -42,16 +43,16 @@ public class SpawnCommand implements CommandHandler {
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
if (monsterExcel != null) {
// Try to find monster config
int groupId = 0;
GroupInfo group = null;
MonsterInfo monsterInfo = null;
for (var group : target.getScene().getFloorInfo().getGroups().values()) {
if (group.getMonsterList().size() == 0) continue;
for (var groupInfo : target.getScene().getFloorInfo().getGroups().values()) {
if (groupInfo.getMonsterList().size() == 0) continue;
for (var m : group.getMonsterList()) {
for (var m : groupInfo.getMonsterList()) {
if (m.getFarmElementID() == 0) {
groupId = group.getId();
monsterInfo = group.getMonsterList().get(0);
group = groupInfo;
monsterInfo = groupInfo.getMonsterList().get(0);
break;
}
}
@@ -69,9 +70,8 @@ public class SpawnCommand implements CommandHandler {
// Spawn monster
for (int i = 0; i < amount; i++) {
Position pos = target.getPos().clone().add(Utils.randomRange(-radius, radius), 0, Utils.randomRange(-radius, radius));
EntityMonster monster = new EntityMonster(target.getScene(), monsterExcel, pos);
monster.setGroupId(groupId);
monster.setInstId(monsterInfo.getID());
EntityMonster monster = new EntityMonster(target.getScene(), monsterExcel, group, monsterInfo);
monster.getPos().set(pos);
monster.setEventId(monsterInfo.getEventID());
monster.setOverrideStageId(stage);
@@ -88,7 +88,8 @@ public class SpawnCommand implements CommandHandler {
// Spawn props
for (int i = 0; i < amount; i++) {
Position pos = target.getPos().clone().add(Utils.randomRange(-radius, radius), 0, Utils.randomRange(-radius, radius));
EntityProp prop = new EntityProp(target.getScene(), propExcel, pos);
EntityProp prop = new EntityProp(target.getScene(), propExcel, null, null);
prop.getPos().set(pos);
prop.setState(PropState.Open);
target.getScene().addEntity(prop, true);

View File

@@ -94,9 +94,7 @@ public class ChallengeInstance {
if (npcMonsterExcel == null) continue;
// Create monster with excels
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos());
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
monster.setGroupId(group.getId());
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, group, monsterInfo);
monster.setInstId(instId);
monster.setEventId(eventId);
monster.setOverrideStageId(eventId);

View File

@@ -38,10 +38,7 @@ public class RogueEntityLoader extends SceneEntityLoader {
if (npcMonster == null) return null;
// Actually create the monster now
EntityMonster monster = new EntityMonster(scene, npcMonster, monsterInfo.getPos());
monster.getRot().set(monsterInfo.getRot());
monster.setGroupId(group.getId());
monster.setInstId(monsterInfo.getID());
EntityMonster monster = new EntityMonster(scene, npcMonster, group, monsterInfo);
monster.setEventId(rogueMonster.getEventID());
monster.setOverrideStageId(rogueMonster.getEventID());
@@ -89,11 +86,7 @@ public class RogueEntityLoader extends SceneEntityLoader {
if (propExcel == null) return null;
// Create prop from prop info
EntityProp prop = new EntityProp(scene, propExcel, propInfo.getPos());
prop.getRot().set(propInfo.getRot());
prop.setPropInfo(propInfo);
prop.setGroupId(group.getId());
prop.setInstId(propInfo.getID());
EntityProp prop = new EntityProp(scene, propExcel, group, propInfo);
prop.setState(state, false);
// Overrides

View File

@@ -25,10 +25,7 @@ public class SceneEntityLoader {
if (npcMonsterExcel == null) return null;
// Create monster from group monster info
EntityMonster monster = new EntityMonster(scene, npcMonsterExcel, monsterInfo.getPos());
monster.getRot().set(monsterInfo.getRot());
monster.setGroupId(group.getId());
monster.setInstId(monsterInfo.getID());
EntityMonster monster = new EntityMonster(scene, npcMonsterExcel, group, monsterInfo);
monster.setEventId(monsterInfo.getEventID());
monster.setWorldLevel(scene.getPlayer().getWorldLevel());
@@ -44,11 +41,7 @@ public class SceneEntityLoader {
if (propExcel == null) return null;
// Create prop from group prop info
EntityProp prop = new EntityProp(scene, propExcel, propInfo.getPos());
prop.getRot().set(propInfo.getRot());
prop.setPropInfo(propInfo);
prop.setGroupId(group.getId());
prop.setInstId(propInfo.getID());
EntityProp prop = new EntityProp(scene, propExcel, group, propInfo);
prop.setState(propInfo.getState(), false);
// Cache
@@ -90,12 +83,7 @@ public class SceneEntityLoader {
}
if (haseDuplicateNpcId) return null;
// Create npc from group npc info
EntityNpc npc = new EntityNpc(scene, npcInfo.getNPCID(), npcInfo.getPos());
npc.getRot().set(npcInfo.getRot());
npc.setInstId(npcInfo.getID());
npc.setGroupId(group.getId());
return npc;
// Create npc from group and npc info
return new EntityNpc(scene, group, npcInfo);
}
}

View File

@@ -1,5 +1,7 @@
package emu.lunarcore.game.scene.entity;
import emu.lunarcore.data.config.GroupInfo;
import emu.lunarcore.data.config.MonsterInfo;
import emu.lunarcore.data.excel.NpcMonsterExcel;
import emu.lunarcore.game.scene.Scene;
import emu.lunarcore.game.scene.triggers.PropTriggerType;
@@ -24,11 +26,13 @@ public class EntityMonster implements GameEntity {
private final Position pos;
private final Position rot;
public EntityMonster(Scene scene, NpcMonsterExcel excel, Position pos) {
public EntityMonster(Scene scene, NpcMonsterExcel excel, GroupInfo group, MonsterInfo monsterInfo) {
this.scene = scene;
this.excel = excel;
this.pos = pos;
this.rot = new Position();
this.pos = monsterInfo.getPos().clone();
this.rot = monsterInfo.getRot().clone();
this.groupId = group.getId();
this.instId = monsterInfo.getID();
}
public int getStageId() {

View File

@@ -1,5 +1,7 @@
package emu.lunarcore.game.scene.entity;
import emu.lunarcore.data.config.GroupInfo;
import emu.lunarcore.data.config.NpcInfo;
import emu.lunarcore.game.scene.Scene;
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
import emu.lunarcore.proto.NpcRogueInfoOuterClass.NpcRogueInfo;
@@ -22,11 +24,13 @@ public class EntityNpc implements GameEntity {
@Setter private int rogueNpcId;
public EntityNpc(Scene scene, int npcId, Position pos) {
public EntityNpc(Scene scene, GroupInfo group, NpcInfo npcInfo) {
this.scene = scene;
this.npcId = npcId;
this.pos = pos;
this.rot = new Position();
this.npcId = npcInfo.getNPCID();
this.pos = npcInfo.getPos().clone();
this.rot = npcInfo.getRot().clone();
this.groupId = group.getId();
this.instId = npcInfo.getID();
}
@Override

View File

@@ -1,5 +1,6 @@
package emu.lunarcore.game.scene.entity;
import emu.lunarcore.data.config.GroupInfo;
import emu.lunarcore.data.config.PropInfo;
import emu.lunarcore.data.excel.PropExcel;
import emu.lunarcore.game.enums.PropState;
@@ -29,12 +30,23 @@ public class EntityProp implements GameEntity {
@Setter private PropRogueData rogueData;
public EntityProp(Scene scene, PropExcel excel, Position pos) {
public EntityProp(Scene scene, PropExcel excel, GroupInfo group, PropInfo propInfo) {
this.scene = scene;
this.excel = excel;
this.pos = pos;
this.pos = new Position();
this.rot = new Position();
this.state = PropState.Closed;
if (propInfo != null) {
this.propInfo = propInfo;
this.instId = propInfo.getID();
this.getPos().set(propInfo.getPos());
this.getRot().set(propInfo.getRot());
}
if (group != null) {
this.groupId = group.getId();
}
}
public int getPropId() {