mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Battles should have the proper monsters to fight
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
package emu.lunarcore.data.excel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.data.GameResource;
|
||||
import emu.lunarcore.data.ResourceType;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -11,6 +17,12 @@ public class StageExcel extends GameResource {
|
||||
private long StageName;
|
||||
private int Level;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private List<StageMonsterWave> MonsterList;
|
||||
|
||||
// Cache
|
||||
private transient List<IntList> monsterWaves;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return StageID;
|
||||
@@ -18,6 +30,37 @@ public class StageExcel extends GameResource {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
// Cache monster list
|
||||
this.monsterWaves = new ArrayList<>();
|
||||
for (StageMonsterWave wave : MonsterList) {
|
||||
this.monsterWaves.add(wave.toList());
|
||||
}
|
||||
}
|
||||
|
||||
public static class StageMonsterWave {
|
||||
private int Monster0;
|
||||
private int Monster1;
|
||||
private int Monster2;
|
||||
private int Monster3;
|
||||
private int Monster4;
|
||||
|
||||
// Sigh...
|
||||
public IntList toList() {
|
||||
IntList list = new IntArrayList(5);
|
||||
|
||||
if (this.Monster0 != 0) {
|
||||
list.add(this.Monster0);
|
||||
} if (this.Monster1 != 0) {
|
||||
list.add(this.Monster1);
|
||||
} if (this.Monster2 != 0) {
|
||||
list.add(this.Monster2);
|
||||
} if (this.Monster3 != 0) {
|
||||
list.add(this.Monster3);
|
||||
} if (this.Monster4 != 0) {
|
||||
list.add(this.Monster4);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package emu.lunarcore.game.battle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
@@ -14,6 +15,7 @@ import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo;
|
||||
import emu.lunarcore.proto.SceneMonsterOuterClass.SceneMonster;
|
||||
import emu.lunarcore.proto.SceneMonsterWaveOuterClass.SceneMonsterWave;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -22,14 +24,17 @@ public class Battle {
|
||||
private final PlayerLineup lineup;
|
||||
private final List<EntityMonster> npcMonsters;
|
||||
private final List<MazeBuff> buffs;
|
||||
private StageExcel stage;
|
||||
private final List<StageExcel> stages;
|
||||
|
||||
public Battle(Player player, PlayerLineup lineup, StageExcel stage) {
|
||||
// Constructor params subject to change
|
||||
public Battle(Player player, PlayerLineup lineup, Collection<StageExcel> stages) {
|
||||
this.player = player;
|
||||
this.lineup = lineup;
|
||||
this.npcMonsters = new ArrayList<>();
|
||||
this.buffs = new ArrayList<>();
|
||||
this.stage = stage;
|
||||
this.stages = new ArrayList<>();
|
||||
|
||||
this.stages.addAll(stages);
|
||||
}
|
||||
|
||||
public MazeBuff addBuff(int buffId, int ownerId) {
|
||||
@@ -47,23 +52,30 @@ public class Battle {
|
||||
}
|
||||
|
||||
public SceneBattleInfo toProto() {
|
||||
var wave = SceneMonsterWave.newInstance()
|
||||
.setStageId(stage.getId());
|
||||
// Build battle info
|
||||
var proto = SceneBattleInfo.newInstance()
|
||||
.setLogicRandomSeed(Utils.randomRange(1, Short.MAX_VALUE))
|
||||
.setWorldLevel(player.getWorldLevel());
|
||||
|
||||
int[] monsters = {101203002, 100202003, 100204007, 100205006};
|
||||
// Add monster waves from stages
|
||||
for (StageExcel stage : stages) {
|
||||
// Build monster waves
|
||||
for (IntList sceneMonsterWave : stage.getMonsterWaves()) {
|
||||
var wave = SceneMonsterWave.newInstance().setStageId(stage.getId());
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
var m = SceneMonster.newInstance()
|
||||
.setMonsterId(Utils.randomElement(monsters));
|
||||
|
||||
wave.addMonsterList(m);
|
||||
for (int monsterId : sceneMonsterWave) {
|
||||
var monster = SceneMonster.newInstance().setMonsterId(monsterId);
|
||||
wave.addMonsterList(monster);
|
||||
}
|
||||
|
||||
var proto = SceneBattleInfo.newInstance()
|
||||
.setStageId(stage.getId())
|
||||
.setLogicRandomSeed(Utils.randomRange(1, Short.MAX_VALUE))
|
||||
.addMonsterWaveList(wave)
|
||||
.setWorldLevel(player.getWorldLevel());
|
||||
proto.addMonsterWaveList(wave);
|
||||
}
|
||||
|
||||
// Set stage for the battle
|
||||
if (proto.getStageId() == 0) {
|
||||
proto.setStageId(stage.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// Buffs
|
||||
for (MazeBuff buff : this.getBuffs()) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package emu.lunarcore.game.battle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.excel.StageExcel;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.scene.entity.EntityMonster;
|
||||
@@ -18,6 +17,7 @@ import emu.lunarcore.server.game.BaseGameService;
|
||||
import emu.lunarcore.server.game.GameServer;
|
||||
import emu.lunarcore.server.packet.send.PacketSceneCastSkillScRsp;
|
||||
import emu.lunarcore.server.packet.send.PacketSyncLineupNotify;
|
||||
|
||||
import us.hebi.quickbuf.RepeatedInt;
|
||||
import us.hebi.quickbuf.RepeatedMessage;
|
||||
|
||||
@@ -76,8 +76,25 @@ public class BattleService extends BaseGameService {
|
||||
|
||||
// Start battle
|
||||
if (monsters.size() > 0) {
|
||||
// Get stages from monsters
|
||||
List<StageExcel> stages = new ArrayList<>();
|
||||
|
||||
for (var monster : monsters) {
|
||||
StageExcel stage = GameData.getStageExcelMap().get(monster.getStageId(player.getWorldLevel()));
|
||||
|
||||
if (stage != null) {
|
||||
stages.add(stage);
|
||||
}
|
||||
}
|
||||
|
||||
if (stages.size() == 0) {
|
||||
// An error has occurred while trying to get stage data
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(1));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create battle and add npc monsters to it
|
||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), GameData.getStageExcelMap().get(1));
|
||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), stages);
|
||||
battle.getNpcMonsters().addAll(monsters);
|
||||
// Add weakness buff to battle
|
||||
if (isPlayerCaster) {
|
||||
|
||||
@@ -80,11 +80,10 @@ public class Scene {
|
||||
for (MonsterInfo monsterInfo : group.getMonsterList()) {
|
||||
// Get excels from game data
|
||||
NpcMonsterExcel npcMonsterExcel = GameData.getNpcMonsterExcelMap().get(monsterInfo.getNPCMonsterID());
|
||||
StageExcel stage = GameData.getStageExcelMap().get(1);
|
||||
if (excel == null || stage == null) continue;
|
||||
if (excel == null) continue;
|
||||
|
||||
// Create monster with excels
|
||||
EntityMonster monster = new EntityMonster(npcMonsterExcel, stage, monsterInfo.clonePos());
|
||||
EntityMonster monster = new EntityMonster(npcMonsterExcel, monsterInfo.clonePos());
|
||||
monster.getRot().setY((int) (monsterInfo.getRotY() * 1000f));
|
||||
monster.setInstId(monsterInfo.getID());
|
||||
monster.setEventId(monsterInfo.getEventID());
|
||||
|
||||
@@ -19,17 +19,19 @@ public class EntityMonster implements GameEntity {
|
||||
@Setter private int eventId;
|
||||
|
||||
private NpcMonsterExcel excel;
|
||||
private StageExcel stage;
|
||||
private Position pos;
|
||||
private Position rot;
|
||||
|
||||
public EntityMonster(NpcMonsterExcel excel, StageExcel stage, Position pos) {
|
||||
public EntityMonster(NpcMonsterExcel excel, Position pos) {
|
||||
this.excel = excel;
|
||||
this.stage = stage;
|
||||
this.pos = pos;
|
||||
this.rot = new Position();
|
||||
}
|
||||
|
||||
public int getStageId(int worldLevel) {
|
||||
return (this.getEventId() * 10) + worldLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SceneEntityInfo toSceneEntityProto() {
|
||||
var monster = SceneNpcMonsterInfo.newInstance()
|
||||
@@ -46,5 +48,4 @@ public class EntityMonster implements GameEntity {
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user