mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Rework battles
This commit is contained in:
@@ -1,15 +1,61 @@
|
||||
package emu.lunarcore.game.battle;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.player.PlayerLineup;
|
||||
import emu.lunarcore.game.scene.EntityMonster;
|
||||
import emu.lunarcore.proto.SceneBattleInfoOuterClass.SceneBattleInfo;
|
||||
import emu.lunarcore.proto.SceneMonsterOuterClass.SceneMonster;
|
||||
import emu.lunarcore.proto.SceneMonsterWaveOuterClass.SceneMonsterWave;
|
||||
import emu.lunarcore.util.Utils;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class Battle {
|
||||
private final Player player;
|
||||
private final PlayerLineup lineup;
|
||||
private final List<EntityMonster> npcMonsters;
|
||||
private StageExcel stage;
|
||||
|
||||
public Battle(Player player) {
|
||||
public Battle(Player player, PlayerLineup lineup, StageExcel stage) {
|
||||
this.player = player;
|
||||
this.lineup = lineup;
|
||||
this.npcMonsters = new ArrayList<>();
|
||||
this.stage = stage;
|
||||
}
|
||||
|
||||
public SceneBattleInfo toProto() {
|
||||
var wave = SceneMonsterWave.newInstance()
|
||||
.setStageId(stage.getId());
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
int[] monsters = {101203002, 100202003, 100204007, 100205006};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
var m = SceneMonster.newInstance()
|
||||
.setMonsterId(Utils.randomElement(monsters));
|
||||
|
||||
wave.addMonsterList(m);
|
||||
}
|
||||
|
||||
var proto = SceneBattleInfo.newInstance()
|
||||
.setStageId(stage.getId())
|
||||
.setLogicRandomSeed(Utils.randomRange(1, Short.MAX_VALUE))
|
||||
.addMonsterWaveList(wave)
|
||||
.setWorldLevel(player.getWorldLevel());
|
||||
|
||||
// Avatars
|
||||
for (int i = 0; i < lineup.getAvatars().size(); i++) {
|
||||
GameAvatar avatar = getPlayer().getAvatarById(lineup.getAvatars().get(i));
|
||||
if (avatar == null) continue;
|
||||
|
||||
proto.addBattleAvatarList(avatar.toBattleProto(i));
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
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.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.scene.EntityMonster;
|
||||
@@ -25,36 +28,71 @@ public class BattleService extends BaseGameService {
|
||||
}
|
||||
|
||||
public void onBattleStart(Player player, int attackerId, RepeatedInt attackedList) {
|
||||
// Setup variables
|
||||
int entityId = attackedList.get(0);
|
||||
GameEntity entity = null;
|
||||
|
||||
//
|
||||
List<GameEntity> entities = new ArrayList<>();
|
||||
List<EntityMonster> monsters = new ArrayList<>();
|
||||
|
||||
// Check if attacker is the player or not
|
||||
if (player.getScene().getAvatarEntityIds().contains(attackerId)) {
|
||||
entity = player.getScene().getEntities().get(entityId);
|
||||
} else if (player.getScene().getAvatarEntityIds().contains(entityId)) {
|
||||
entity = player.getScene().getEntities().get(attackerId);
|
||||
}
|
||||
|
||||
if (entity != null) {
|
||||
if (entity instanceof EntityMonster) {
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(player, (EntityMonster) entity));
|
||||
return;
|
||||
} else if (entity instanceof EntityProp) {
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(0));
|
||||
return;
|
||||
// Attacker is the player
|
||||
for (int entityId : attackedList) {
|
||||
GameEntity entity = player.getScene().getEntities().get(entityId);
|
||||
|
||||
if (entity != null) {
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Player is ambushed
|
||||
GameEntity entity = player.getScene().getEntities().get(attackerId);
|
||||
|
||||
if (entity != null) {
|
||||
entities.add(entity);
|
||||
}
|
||||
}
|
||||
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(1));
|
||||
// Give the client an error if not attacked entities detected
|
||||
if (entities.size() == 0) {
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(1));
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy props
|
||||
var it = entities.iterator();
|
||||
while (it.hasNext()) {
|
||||
GameEntity entity = it.next();
|
||||
|
||||
if (entity instanceof EntityMonster monster) {
|
||||
monsters.add(monster);
|
||||
} else if (entity instanceof EntityProp) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Start battle
|
||||
if (monsters.size() > 0) {
|
||||
// Create battle and add npc monsters to it
|
||||
Battle battle = new Battle(player, player.getLineupManager().getCurrentLineup(), GameData.getStageExcelMap().get(1));
|
||||
battle.getNpcMonsters().addAll(monsters);
|
||||
// Set battle and send rsp packet
|
||||
player.setBattle(battle);
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(player, battle));
|
||||
return;
|
||||
}
|
||||
|
||||
// Send packet
|
||||
player.sendPacket(new PacketSceneCastSkillScRsp(0));
|
||||
}
|
||||
|
||||
public void onBattleResult(Player player, BattleEndStatus result, RepeatedMessage<AvatarBattleInfo> battleAvatars) {
|
||||
// Lose
|
||||
if (result == BattleEndStatus.BATTLE_END_LOSE) {
|
||||
|
||||
// Sanity
|
||||
if (!player.isInBattle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Get battle object
|
||||
Battle battle = player.getBattle();
|
||||
|
||||
// Set health/energy
|
||||
for (var battleAvatar : battleAvatars) {
|
||||
GameAvatar avatar = player.getAvatarById(battleAvatar.getId());
|
||||
@@ -70,7 +108,15 @@ public class BattleService extends BaseGameService {
|
||||
}
|
||||
|
||||
// Sync with player
|
||||
player.sendPacket(new PacketSyncLineupNotify(player.getLineupManager().getCurrentLineup()));
|
||||
player.sendPacket(new PacketSyncLineupNotify(battle.getLineup()));
|
||||
|
||||
// Delete enemies if the player won
|
||||
if (result == BattleEndStatus.BATTLE_END_WIN) {
|
||||
|
||||
}
|
||||
|
||||
// Done - Clear battle object from player
|
||||
player.setBattle(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import emu.lunarcore.data.excel.MapEntranceExcel;
|
||||
import emu.lunarcore.game.account.Account;
|
||||
import emu.lunarcore.game.avatar.AvatarStorage;
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.battle.Battle;
|
||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||
import emu.lunarcore.game.inventory.Inventory;
|
||||
import emu.lunarcore.game.scene.Scene;
|
||||
@@ -48,6 +49,7 @@ public class Player {
|
||||
private int hcoin; // Jade
|
||||
private int mcoin; // Crystals
|
||||
|
||||
private transient Battle battle;
|
||||
private transient Scene scene;
|
||||
private Position pos;
|
||||
private int planeId;
|
||||
@@ -207,6 +209,14 @@ public class Player {
|
||||
return this.exp - GameData.getPlayerExpRequired(this.level);
|
||||
}
|
||||
|
||||
public boolean isInBattle() {
|
||||
return this.battle != null;
|
||||
}
|
||||
|
||||
public void setBattle(Battle battle) {
|
||||
this.battle = battle;
|
||||
}
|
||||
|
||||
public void enterScene(int entryId, int teleportId) {
|
||||
// Get map entrance excel
|
||||
MapEntranceExcel entry = GameData.getMapEntranceExcelMap().get(entryId);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.avatar.GameAvatar;
|
||||
import emu.lunarcore.game.battle.Battle;
|
||||
import emu.lunarcore.game.player.PlayerLineup;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.scene.EntityMonster;
|
||||
@@ -28,40 +29,13 @@ public class PacketSceneCastSkillScRsp extends BasePacket {
|
||||
}
|
||||
|
||||
// TODO
|
||||
public PacketSceneCastSkillScRsp(Player player, EntityMonster monster) {
|
||||
public PacketSceneCastSkillScRsp(Player player, Battle battle) {
|
||||
super(CmdId.SceneCastSkillScRsp);
|
||||
|
||||
var wave = SceneMonsterWave.newInstance()
|
||||
.setStageId(monster.getStage().getId());
|
||||
|
||||
int[] monsters = {101203002, 100202003, 100204007, 100205006};
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
var m = SceneMonster.newInstance()
|
||||
.setMonsterId(Utils.randomElement(monsters));
|
||||
|
||||
wave.addMonsterList(m);
|
||||
}
|
||||
|
||||
var battle = SceneBattleInfo.newInstance()
|
||||
.setStageId(monster.getStage().getId())
|
||||
.setLogicRandomSeed(Utils.randomRange(1, Short.MAX_VALUE))
|
||||
.addMonsterWaveList(wave)
|
||||
.setWorldLevel(player.getWorldLevel());
|
||||
|
||||
// Avatars
|
||||
PlayerLineup lineup = player.getLineupManager().getCurrentLineup();
|
||||
for (int i = 0; i < lineup.getAvatars().size(); i++) {
|
||||
GameAvatar avatar = player.getAvatarById(lineup.getAvatars().get(i));
|
||||
if (avatar == null) continue;
|
||||
|
||||
battle.addBattleAvatarList(avatar.toBattleProto(i));
|
||||
}
|
||||
|
||||
// Build data
|
||||
var data = SceneCastSkillScRsp.newInstance()
|
||||
.setAttackedGroupId(monster.getGroupId())
|
||||
.setBattleInfo(battle);
|
||||
//.setAttackedGroupId(monster.getGroupId())
|
||||
.setBattleInfo(battle.toProto());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user