mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 22:04:36 +01:00
Refactor game entity constructors
This commit is contained in:
@@ -4,6 +4,7 @@ import emu.lunarcore.command.Command;
|
|||||||
import emu.lunarcore.command.CommandArgs;
|
import emu.lunarcore.command.CommandArgs;
|
||||||
import emu.lunarcore.command.CommandHandler;
|
import emu.lunarcore.command.CommandHandler;
|
||||||
import emu.lunarcore.data.GameData;
|
import emu.lunarcore.data.GameData;
|
||||||
|
import emu.lunarcore.data.config.GroupInfo;
|
||||||
import emu.lunarcore.data.config.MonsterInfo;
|
import emu.lunarcore.data.config.MonsterInfo;
|
||||||
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||||
import emu.lunarcore.data.excel.PropExcel;
|
import emu.lunarcore.data.excel.PropExcel;
|
||||||
@@ -42,16 +43,16 @@ public class SpawnCommand implements CommandHandler {
|
|||||||
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
|
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
|
||||||
if (monsterExcel != null) {
|
if (monsterExcel != null) {
|
||||||
// Try to find monster config
|
// Try to find monster config
|
||||||
int groupId = 0;
|
GroupInfo group = null;
|
||||||
MonsterInfo monsterInfo = null;
|
MonsterInfo monsterInfo = null;
|
||||||
|
|
||||||
for (var group : target.getScene().getFloorInfo().getGroups().values()) {
|
for (var groupInfo : target.getScene().getFloorInfo().getGroups().values()) {
|
||||||
if (group.getMonsterList().size() == 0) continue;
|
if (groupInfo.getMonsterList().size() == 0) continue;
|
||||||
|
|
||||||
for (var m : group.getMonsterList()) {
|
for (var m : groupInfo.getMonsterList()) {
|
||||||
if (m.getFarmElementID() == 0) {
|
if (m.getFarmElementID() == 0) {
|
||||||
groupId = group.getId();
|
group = groupInfo;
|
||||||
monsterInfo = group.getMonsterList().get(0);
|
monsterInfo = groupInfo.getMonsterList().get(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,9 +70,8 @@ public class SpawnCommand implements CommandHandler {
|
|||||||
// Spawn monster
|
// Spawn monster
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Position pos = target.getPos().clone().add(Utils.randomRange(-radius, radius), 0, Utils.randomRange(-radius, radius));
|
Position pos = target.getPos().clone().add(Utils.randomRange(-radius, radius), 0, Utils.randomRange(-radius, radius));
|
||||||
EntityMonster monster = new EntityMonster(target.getScene(), monsterExcel, pos);
|
EntityMonster monster = new EntityMonster(target.getScene(), monsterExcel, group, monsterInfo);
|
||||||
monster.setGroupId(groupId);
|
monster.getPos().set(pos);
|
||||||
monster.setInstId(monsterInfo.getID());
|
|
||||||
monster.setEventId(monsterInfo.getEventID());
|
monster.setEventId(monsterInfo.getEventID());
|
||||||
monster.setOverrideStageId(stage);
|
monster.setOverrideStageId(stage);
|
||||||
|
|
||||||
@@ -88,7 +88,8 @@ public class SpawnCommand implements CommandHandler {
|
|||||||
// Spawn props
|
// Spawn props
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Position pos = target.getPos().clone().add(Utils.randomRange(-radius, radius), 0, Utils.randomRange(-radius, radius));
|
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);
|
prop.setState(PropState.Open);
|
||||||
|
|
||||||
target.getScene().addEntity(prop, true);
|
target.getScene().addEntity(prop, true);
|
||||||
|
|||||||
@@ -94,9 +94,7 @@ public class ChallengeInstance {
|
|||||||
if (npcMonsterExcel == null) continue;
|
if (npcMonsterExcel == null) continue;
|
||||||
|
|
||||||
// Create monster with excels
|
// Create monster with excels
|
||||||
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, monsterInfo.getPos());
|
EntityMonster monster = new EntityMonster(getScene(), npcMonsterExcel, group, monsterInfo);
|
||||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
|
||||||
monster.setGroupId(group.getId());
|
|
||||||
monster.setInstId(instId);
|
monster.setInstId(instId);
|
||||||
monster.setEventId(eventId);
|
monster.setEventId(eventId);
|
||||||
monster.setOverrideStageId(eventId);
|
monster.setOverrideStageId(eventId);
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ public class RogueEntityLoader extends SceneEntityLoader {
|
|||||||
if (npcMonster == null) return null;
|
if (npcMonster == null) return null;
|
||||||
|
|
||||||
// Actually create the monster now
|
// Actually create the monster now
|
||||||
EntityMonster monster = new EntityMonster(scene, npcMonster, monsterInfo.getPos());
|
EntityMonster monster = new EntityMonster(scene, npcMonster, group, monsterInfo);
|
||||||
monster.getRot().set(monsterInfo.getRot());
|
|
||||||
monster.setGroupId(group.getId());
|
|
||||||
monster.setInstId(monsterInfo.getID());
|
|
||||||
monster.setEventId(rogueMonster.getEventID());
|
monster.setEventId(rogueMonster.getEventID());
|
||||||
monster.setOverrideStageId(rogueMonster.getEventID());
|
monster.setOverrideStageId(rogueMonster.getEventID());
|
||||||
|
|
||||||
@@ -89,11 +86,7 @@ public class RogueEntityLoader extends SceneEntityLoader {
|
|||||||
if (propExcel == null) return null;
|
if (propExcel == null) return null;
|
||||||
|
|
||||||
// Create prop from prop info
|
// Create prop from prop info
|
||||||
EntityProp prop = new EntityProp(scene, propExcel, propInfo.getPos());
|
EntityProp prop = new EntityProp(scene, propExcel, group, propInfo);
|
||||||
prop.getRot().set(propInfo.getRot());
|
|
||||||
prop.setPropInfo(propInfo);
|
|
||||||
prop.setGroupId(group.getId());
|
|
||||||
prop.setInstId(propInfo.getID());
|
|
||||||
prop.setState(state, false);
|
prop.setState(state, false);
|
||||||
|
|
||||||
// Overrides
|
// Overrides
|
||||||
|
|||||||
@@ -25,10 +25,7 @@ public class SceneEntityLoader {
|
|||||||
if (npcMonsterExcel == null) return null;
|
if (npcMonsterExcel == null) return null;
|
||||||
|
|
||||||
// Create monster from group monster info
|
// Create monster from group monster info
|
||||||
EntityMonster monster = new EntityMonster(scene, npcMonsterExcel, monsterInfo.getPos());
|
EntityMonster monster = new EntityMonster(scene, npcMonsterExcel, group, monsterInfo);
|
||||||
monster.getRot().set(monsterInfo.getRot());
|
|
||||||
monster.setGroupId(group.getId());
|
|
||||||
monster.setInstId(monsterInfo.getID());
|
|
||||||
monster.setEventId(monsterInfo.getEventID());
|
monster.setEventId(monsterInfo.getEventID());
|
||||||
monster.setWorldLevel(scene.getPlayer().getWorldLevel());
|
monster.setWorldLevel(scene.getPlayer().getWorldLevel());
|
||||||
|
|
||||||
@@ -44,11 +41,7 @@ public class SceneEntityLoader {
|
|||||||
if (propExcel == null) return null;
|
if (propExcel == null) return null;
|
||||||
|
|
||||||
// Create prop from group prop info
|
// Create prop from group prop info
|
||||||
EntityProp prop = new EntityProp(scene, propExcel, propInfo.getPos());
|
EntityProp prop = new EntityProp(scene, propExcel, group, propInfo);
|
||||||
prop.getRot().set(propInfo.getRot());
|
|
||||||
prop.setPropInfo(propInfo);
|
|
||||||
prop.setGroupId(group.getId());
|
|
||||||
prop.setInstId(propInfo.getID());
|
|
||||||
prop.setState(propInfo.getState(), false);
|
prop.setState(propInfo.getState(), false);
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
@@ -90,12 +83,7 @@ public class SceneEntityLoader {
|
|||||||
}
|
}
|
||||||
if (haseDuplicateNpcId) return null;
|
if (haseDuplicateNpcId) return null;
|
||||||
|
|
||||||
// Create npc from group npc info
|
// Create npc from group and npc info
|
||||||
EntityNpc npc = new EntityNpc(scene, npcInfo.getNPCID(), npcInfo.getPos());
|
return new EntityNpc(scene, group, npcInfo);
|
||||||
npc.getRot().set(npcInfo.getRot());
|
|
||||||
npc.setInstId(npcInfo.getID());
|
|
||||||
npc.setGroupId(group.getId());
|
|
||||||
|
|
||||||
return npc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package emu.lunarcore.game.scene.entity;
|
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.data.excel.NpcMonsterExcel;
|
||||||
import emu.lunarcore.game.scene.Scene;
|
import emu.lunarcore.game.scene.Scene;
|
||||||
import emu.lunarcore.game.scene.triggers.PropTriggerType;
|
import emu.lunarcore.game.scene.triggers.PropTriggerType;
|
||||||
@@ -24,11 +26,13 @@ public class EntityMonster implements GameEntity {
|
|||||||
private final Position pos;
|
private final Position pos;
|
||||||
private final Position rot;
|
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.scene = scene;
|
||||||
this.excel = excel;
|
this.excel = excel;
|
||||||
this.pos = pos;
|
this.pos = monsterInfo.getPos().clone();
|
||||||
this.rot = new Position();
|
this.rot = monsterInfo.getRot().clone();
|
||||||
|
this.groupId = group.getId();
|
||||||
|
this.instId = monsterInfo.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStageId() {
|
public int getStageId() {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package emu.lunarcore.game.scene.entity;
|
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.game.scene.Scene;
|
||||||
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
|
import emu.lunarcore.proto.MotionInfoOuterClass.MotionInfo;
|
||||||
import emu.lunarcore.proto.NpcRogueInfoOuterClass.NpcRogueInfo;
|
import emu.lunarcore.proto.NpcRogueInfoOuterClass.NpcRogueInfo;
|
||||||
@@ -22,11 +24,13 @@ public class EntityNpc implements GameEntity {
|
|||||||
|
|
||||||
@Setter private int rogueNpcId;
|
@Setter private int rogueNpcId;
|
||||||
|
|
||||||
public EntityNpc(Scene scene, int npcId, Position pos) {
|
public EntityNpc(Scene scene, GroupInfo group, NpcInfo npcInfo) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.npcId = npcId;
|
this.npcId = npcInfo.getNPCID();
|
||||||
this.pos = pos;
|
this.pos = npcInfo.getPos().clone();
|
||||||
this.rot = new Position();
|
this.rot = npcInfo.getRot().clone();
|
||||||
|
this.groupId = group.getId();
|
||||||
|
this.instId = npcInfo.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package emu.lunarcore.game.scene.entity;
|
package emu.lunarcore.game.scene.entity;
|
||||||
|
|
||||||
|
import emu.lunarcore.data.config.GroupInfo;
|
||||||
import emu.lunarcore.data.config.PropInfo;
|
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;
|
||||||
@@ -29,12 +30,23 @@ public class EntityProp implements GameEntity {
|
|||||||
|
|
||||||
@Setter private PropRogueData rogueData;
|
@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.scene = scene;
|
||||||
this.excel = excel;
|
this.excel = excel;
|
||||||
this.pos = pos;
|
this.pos = new Position();
|
||||||
this.rot = new Position();
|
this.rot = new Position();
|
||||||
this.state = PropState.Closed;
|
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() {
|
public int getPropId() {
|
||||||
|
|||||||
Reference in New Issue
Block a user