From 7777b9516e5cfb8c652fa08f734174d7cbe52f2e Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Sat, 16 Dec 2023 02:24:56 -0800 Subject: [PATCH] Fix monsters being added twice in a battle --- .../lunarcore/game/battle/BattleService.java | 19 +++++++++-------- .../game/battle/skills/MazeSkillAddBuff.java | 21 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/emu/lunarcore/game/battle/BattleService.java b/src/main/java/emu/lunarcore/game/battle/BattleService.java index 8390a78..9579312 100644 --- a/src/main/java/emu/lunarcore/game/battle/BattleService.java +++ b/src/main/java/emu/lunarcore/game/battle/BattleService.java @@ -1,7 +1,9 @@ package emu.lunarcore.game.battle; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import emu.lunarcore.GameConstants; 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) { // Setup variables - List targetEntities = new ArrayList<>(); + List targets = new ArrayList<>(); GameAvatar castingAvatar = null; // Check if attacker is the player or not @@ -46,7 +48,7 @@ public class BattleService extends BaseGameService { GameEntity entity = player.getScene().getEntities().get(entityId); if (entity != null) { - targetEntities.add(entity); + targets.add(entity); } } } else { @@ -54,22 +56,21 @@ public class BattleService extends BaseGameService { GameEntity entity = player.getScene().getEntities().get(casterId); if (entity != null) { - targetEntities.add(entity); + targets.add(entity); } } // Skip if no attacked entities detected - if (targetEntities.size() == 0) { + if (targets.size() == 0) { player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId)); return; } // Separate entities into monster list - List monsters = new ArrayList<>(); + Set monsters = new HashSet<>(); // Destroy props - var it = targetEntities.iterator(); - while (it.hasNext()) { + for (var it = targets.iterator(); it.hasNext();) { GameEntity entity = it.next(); 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 if (castedSkill != null && !castedSkill.isTriggerBattle()) { // Apply buffs to monsters - castedSkill.onAttack(player.getCurrentLeaderAvatar(), monsters); + castedSkill.onCastHit(player.getCurrentLeaderAvatar(), targets); // Skip battle if our technique does not trigger a battle player.sendPacket(new PacketSceneCastSkillScRsp(attackedGroupId)); return; @@ -104,7 +105,7 @@ public class BattleService extends BaseGameService { if (monsters.size() > 0) { // Maze skill attack event if (castedSkill != null && castingAvatar != null) { - castedSkill.onAttack(castingAvatar, targetEntities); + castedSkill.onAttack(castingAvatar, targets); } // Create battle and add npc monsters to it diff --git a/src/main/java/emu/lunarcore/game/battle/skills/MazeSkillAddBuff.java b/src/main/java/emu/lunarcore/game/battle/skills/MazeSkillAddBuff.java index 6632674..13d8f40 100644 --- a/src/main/java/emu/lunarcore/game/battle/skills/MazeSkillAddBuff.java +++ b/src/main/java/emu/lunarcore/game/battle/skills/MazeSkillAddBuff.java @@ -29,17 +29,6 @@ public class MazeSkillAddBuff extends MazeSkillAction { caster.addBuff(buffId, duration); } - @Override - public void onAttack(GameAvatar caster, List 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 public void onCastHit(GameAvatar caster, List entities) { for (GameEntity entity : entities) { @@ -55,4 +44,14 @@ public class MazeSkillAddBuff extends MazeSkillAction { } } + @Override + public void onAttack(GameAvatar caster, List 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)); + } + } + } }