Skip to content

Commit

Permalink
Fix monsters being added twice in a battle
Browse files Browse the repository at this point in the history
  • Loading branch information
Melledy committed Dec 16, 2023
1 parent 5a88b23 commit 7777b95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
19 changes: 10 additions & 9 deletions src/main/java/emu/lunarcore/game/battle/BattleService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,7 +35,7 @@ public BattleService(GameServer server) {

public void startBattle(Player player, int casterId, int attackedGroupId, MazeSkill castedSkill, IntSet hitTargets, IntSet assistMonsters) {
// Setup variables
List<GameEntity> targetEntities = new ArrayList<>();
List<GameEntity> targets = new ArrayList<>();
GameAvatar castingAvatar = null;

// Check if attacker is the player or not
Expand All @@ -46,30 +48,29 @@ public void startBattle(Player player, int casterId, int attackedGroupId, MazeSk
GameEntity entity = player.getScene().getEntities().get(entityId);

if (entity != null) {
targetEntities.add(entity);
targets.add(entity);
}
}
} else {
// Player is ambushed
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<EntityMonster> monsters = new ArrayList<>();
Set<EntityMonster> 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) {
Expand All @@ -85,7 +86,7 @@ public void startBattle(Player player, int casterId, int attackedGroupId, MazeSk
// 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;
Expand All @@ -104,7 +105,7 @@ public void startBattle(Player player, int casterId, int attackedGroupId, MazeSk
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ public void onCast(GameAvatar caster, MotionInfo castPosition) {
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
public void onCastHit(GameAvatar caster, List<? extends GameEntity> entities) {
for (GameEntity entity : entities) {
Expand All @@ -55,4 +44,14 @@ public void onCastHit(GameAvatar caster, List<? extends GameEntity> entities) {
}
}

@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));
}
}
}
}

0 comments on commit 7777b95

Please sign in to comment.