mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 15:24:44 +01:00
Refactor spawn command a bit
This commit is contained in:
@@ -6,6 +6,7 @@ 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.GroupInfo;
|
||||||
import emu.lunarcore.data.config.MonsterInfo;
|
import emu.lunarcore.data.config.MonsterInfo;
|
||||||
|
import emu.lunarcore.data.config.PropInfo;
|
||||||
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
import emu.lunarcore.data.excel.NpcMonsterExcel;
|
||||||
import emu.lunarcore.data.excel.PropExcel;
|
import emu.lunarcore.data.excel.PropExcel;
|
||||||
import emu.lunarcore.game.enums.PropState;
|
import emu.lunarcore.game.enums.PropState;
|
||||||
@@ -42,35 +43,33 @@ public class SpawnCommand implements CommandHandler {
|
|||||||
// Spawn monster
|
// Spawn monster
|
||||||
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
|
NpcMonsterExcel monsterExcel = GameData.getNpcMonsterExcelMap().get(id);
|
||||||
if (monsterExcel != null) {
|
if (monsterExcel != null) {
|
||||||
// Try to find monster config
|
// Get first monster config from floor info that isnt a boss monster
|
||||||
GroupInfo group = null;
|
GroupInfo groupInfo = null;
|
||||||
MonsterInfo monsterInfo = null;
|
MonsterInfo monsterInfo = null;
|
||||||
|
|
||||||
for (var groupInfo : target.getScene().getFloorInfo().getGroups().values()) {
|
for (var group : target.getScene().getFloorInfo().getGroups().values()) {
|
||||||
if (groupInfo.getMonsterList().size() == 0) continue;
|
if (group.getMonsterList().size() == 0) continue;
|
||||||
|
|
||||||
for (var m : groupInfo.getMonsterList()) {
|
for (var m : group.getMonsterList()) {
|
||||||
if (m.getFarmElementID() == 0) {
|
if (m.getFarmElementID() == 0) {
|
||||||
group = groupInfo;
|
groupInfo = group;
|
||||||
monsterInfo = groupInfo.getMonsterList().get(0);
|
monsterInfo = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monsterInfo != null) {
|
if (monsterInfo != null) break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (monsterInfo == null) {
|
if (monsterInfo == null || groupInfo == null) {
|
||||||
this.sendMessage(sender, "Error: No monster config found in this scene");
|
this.sendMessage(sender, "Error: No existing monster config found in this scene");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, group, monsterInfo);
|
EntityMonster monster = new EntityMonster(target.getScene(), monsterExcel, groupInfo, monsterInfo);
|
||||||
monster.getPos().set(pos);
|
monster.getPos().set(pos);
|
||||||
monster.setEventId(monsterInfo.getEventID());
|
monster.setEventId(monsterInfo.getEventID());
|
||||||
monster.setOverrideStageId(stage);
|
monster.setOverrideStageId(stage);
|
||||||
@@ -85,11 +84,35 @@ public class SpawnCommand implements CommandHandler {
|
|||||||
|
|
||||||
PropExcel propExcel = GameData.getPropExcelMap().get(id);
|
PropExcel propExcel = GameData.getPropExcelMap().get(id);
|
||||||
if (propExcel != null) {
|
if (propExcel != null) {
|
||||||
|
// Get first prop config from floor info
|
||||||
|
GroupInfo groupInfo = null;
|
||||||
|
PropInfo propInfo = null;
|
||||||
|
|
||||||
|
for (var group : target.getScene().getFloorInfo().getGroups().values()) {
|
||||||
|
if (group.getPropList().size() == 0) continue;
|
||||||
|
|
||||||
|
for (var p : group.getPropList()) {
|
||||||
|
if (p.getFarmElementID() == 0 && p.getAnchorID() == 0 && p.getCocoonID() == 0) {
|
||||||
|
groupInfo = group;
|
||||||
|
propInfo = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propInfo != null) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propInfo == null || groupInfo == null) {
|
||||||
|
this.sendMessage(sender, "Error: No existing prop config found in this scene");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// 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, null, null);
|
EntityProp prop = new EntityProp(target.getScene(), propExcel, groupInfo, propInfo);
|
||||||
prop.getPos().set(pos);
|
prop.getPos().set(pos);
|
||||||
|
prop.getRot().set(0, 0, 0);
|
||||||
prop.setState(PropState.Open);
|
prop.setState(PropState.Open);
|
||||||
|
|
||||||
target.getScene().addEntity(prop, true);
|
target.getScene().addEntity(prop, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user