Fix monsters being added twice in a battle

This commit is contained in:
Melledy
2023-12-16 02:24:56 -08:00
parent 5a88b233b2
commit 7777b9516e
2 changed files with 20 additions and 20 deletions

View File

@@ -1,7 +1,9 @@
package emu.lunarcore.game.battle; package emu.lunarcore.game.battle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import emu.lunarcore.GameConstants; import emu.lunarcore.GameConstants;
import emu.lunarcore.data.GameData; import emu.lunarcore.data.GameData;
@@ -33,7 +35,7 @@ public class BattleService extends BaseGameService {
public void startBattle(Player player, int casterId, int attackedGroupId, MazeSkill castedSkill, IntSet hitTargets, IntSet assistMonsters) { public void startBattle(Player player, int casterId, int attackedGroupId, MazeSkill castedSkill, IntSet hitTargets, IntSet assistMonsters) {
// Setup variables // Setup variables
List<GameEntity> targetEntities = new ArrayList<>(); List<GameEntity> targets = new ArrayList<>();
GameAvatar castingAvatar = null; GameAvatar castingAvatar = null;
// Check if attacker is the player or not // Check if attacker is the player or not
@@ -46,7 +48,7 @@ public class BattleService extends BaseGameService {
GameEntity entity = player.getScene().getEntities().get(entityId); GameEntity entity = player.getScene().getEntities().get(entityId);
if (entity != null) { if (entity != null) {
targetEntities.add(entity); targets.add(entity);
} }
} }
} else { } else {
@@ -54,22 +56,21 @@ public class BattleService extends BaseGameService {
GameEntity entity = player.getScene().getEntities().get(casterId); GameEntity entity = player.getScene().getEntities().get(casterId);
if (entity != null) { if (entity != null) {
targetEntities.add(entity); targets.add(entity);
} }
} }
// Skip if no attacked entities detected // Skip if no attacked entities detected
if (targetEntities.size() == 0) { if (targets.size() == 0) {
player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId)); player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId));
return; return;
} }
// Separate entities into monster list // Separate entities into monster list
List<EntityMonster> monsters = new ArrayList<>(); Set<EntityMonster> monsters = new HashSet<>();
// Destroy props // Destroy props
var it = targetEntities.iterator(); for (var it = targets.iterator(); it.hasNext();) {
while (it.hasNext()) {
GameEntity entity = it.next(); GameEntity entity = it.next();
if (entity instanceof EntityMonster monster) { if (entity instanceof EntityMonster monster) {
@@ -85,7 +86,7 @@ public class BattleService extends BaseGameService {
// Check if we are using a skill that doesnt trigger a battle // Check if we are using a skill that doesnt trigger a battle
if (castedSkill != null && !castedSkill.isTriggerBattle()) { if (castedSkill != null && !castedSkill.isTriggerBattle()) {
// Apply buffs to monsters // Apply buffs to monsters
castedSkill.onAttack(player.getCurrentLeaderAvatar(), monsters); castedSkill.onCastHit(player.getCurrentLeaderAvatar(), targets);
// Skip battle if our technique does not trigger a battle // Skip battle if our technique does not trigger a battle
player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId)); player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId));
return; return;
@@ -104,7 +105,7 @@ public class BattleService extends BaseGameService {
if (monsters.size() > 0) { if (monsters.size() > 0) {
// Maze skill attack event // Maze skill attack event
if (castedSkill != null && castingAvatar != null) { if (castedSkill != null && castingAvatar != null) {
castedSkill.onAttack(castingAvatar, targetEntities); castedSkill.onAttack(castingAvatar, targets);
} }
// Create battle and add npc monsters to it // Create battle and add npc monsters to it

View File

@@ -29,17 +29,6 @@ public class MazeSkillAddBuff extends MazeSkillAction {
caster.addBuff(buffId, duration); caster.addBuff(buffId, duration);
} }
@Override
public void onAttack(GameAvatar caster, List<? extends GameEntity> targets) {
// Add debuff to monsters
for (GameEntity target : targets) {
if (target instanceof EntityMonster monster) {
// Set as temp buff
monster.setTempBuff(new SceneBuff(caster.getAvatarId(), buffId));
}
}
}
@Override @Override
public void onCastHit(GameAvatar caster, List<? extends GameEntity> entities) { public void onCastHit(GameAvatar caster, List<? extends GameEntity> entities) {
for (GameEntity entity : entities) { for (GameEntity entity : entities) {
@@ -55,4 +44,14 @@ public class MazeSkillAddBuff extends MazeSkillAction {
} }
} }
@Override
public void onAttack(GameAvatar caster, List<? extends GameEntity> targets) {
// Add debuff to monsters
for (GameEntity target : targets) {
if (target instanceof EntityMonster monster) {
// Set as temp buff
monster.setTempBuff(new SceneBuff(caster.getAvatarId(), buffId));
}
}
}
} }