Skip to content
Snippets Groups Projects
Commit 9fe4acf5 authored by Zoey76's avatar Zoey76
Browse files

Fixing build and adding missing Enemy unit tests

parent 9f7a0836
No related branches found
No related tags found
No related merge requests found
......@@ -54,8 +54,12 @@ public class Enemy implements ITargetTypeHandler {
}
final L2PcInstance player = activeChar.getActingPlayer();
if ((player == null) || !player.checkIfPvP(target) && !player.getCurrentSkill().isCtrlPressed()) {
activeChar.sendPacket(INCORRECT_TARGET);
if (player == null) {
return EMPTY_TARGET_LIST;
}
if (!player.checkIfPvP(target) && !player.getCurrentSkill().isCtrlPressed()) {
player.sendPacket(INCORRECT_TARGET);
return EMPTY_TARGET_LIST;
}
......
......@@ -158,7 +158,7 @@ public final class TowerOfNaia extends AbstractNpcAI {
private final Set<L2Npc> _sporeSpawn = ConcurrentHashMap.newKeySet();
static {
// Format: entrance_door, exit_door
DOORS.put(18494, new int[] {
DOORS.put(ROOM_MANAGER_FIRST, new int[] {
18250001,
18250002
});
......@@ -202,12 +202,12 @@ public final class TowerOfNaia extends AbstractNpcAI {
18250021,
18250022
});
DOORS.put(18505, new int[] {
DOORS.put(ROOM_MANAGER_LAST, new int[] {
18250023,
18250024
});
ZONES.put(18494, 200020);
ZONES.put(ROOM_MANAGER_FIRST, 200020);
ZONES.put(18495, 200021);
ZONES.put(18496, 200022);
ZONES.put(18497, 200023);
......@@ -218,9 +218,9 @@ public final class TowerOfNaia extends AbstractNpcAI {
ZONES.put(18502, 200028);
ZONES.put(18503, 200029);
ZONES.put(18504, 200030);
ZONES.put(18505, 200031);
ZONES.put(ROOM_MANAGER_LAST, 200031);
//@formatter:off
SPAWNS.put(18494, new int[][]
SPAWNS.put(ROOM_MANAGER_FIRST, new int[][]
{
{22393, -46371, 246400, -9120, 0},
{22394, -46435, 245830, -9120, 0},
......@@ -309,7 +309,7 @@ public final class TowerOfNaia extends AbstractNpcAI {
{22413, -51500, 245781, -12568, 0},
{22413, -51941, 246045, -12568, 0},
});
SPAWNS.put(18505, new int[][]
SPAWNS.put(ROOM_MANAGER_LAST, new int[][]
{
{18490, -48238, 243347, -13376, 0},
{18490, -48462, 244022, -13376, 0},
......@@ -362,15 +362,12 @@ public final class TowerOfNaia extends AbstractNpcAI {
@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player) {
final int npcId = npc.getId();
if (npcId == CONTROLLER) {
if (_lock == null) {
return "18492-02.htm";
}
return "18492-01.htm";
}
else if ((npcId >= ROOM_MANAGER_FIRST) && (npcId <= ROOM_MANAGER_LAST)) {
} else if ((npcId >= ROOM_MANAGER_FIRST) && (npcId <= ROOM_MANAGER_LAST)) {
if (_activeRooms.containsKey(npcId) && !_activeRooms.get(npcId)) {
if (player.getParty() == null) {
player.sendPacket(SystemMessageId.CAN_OPERATE_MACHINE_WHEN_IN_PARTY);
......
......@@ -99,10 +99,23 @@ public class EnemyOnlyTest extends AbstractTest {
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_non_attackable_target_should_return_empty_target_list_with_invalid_target_message() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isNpc()).andReturn(true);
expect(target.isAttackable()).andReturn(false);
replay(skill, target);
final var actual = enemyOnly.getTargetList(skill, activeChar, false, target);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_attackable_target_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isNpc()).andReturn(true);
expect(target.isAttackable()).andReturn(true);
replay(skill, target);
......@@ -114,7 +127,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_null_player_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(null);
replay(skill, target, activeChar);
......@@ -126,7 +139,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_olympiad_should_return_target_if_target_is_on_the_other_side() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(true);
expect(target.getActingPlayer()).andReturn(targetPlayer);
......@@ -142,7 +155,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_olympiad_should_return_empty_target_list_if_target_is_on_the_same_side() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(true);
expect(target.getActingPlayer()).andReturn(targetPlayer);
......@@ -160,7 +173,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_duel_should_return_target_if_target_is_on_the_other_side() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(true);
......@@ -182,7 +195,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_duel_should_return_empty_target_list_if_target_is_on_the_same_side() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(true);
......@@ -207,7 +220,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_party_with_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -224,7 +237,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_pvp_zone_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -240,7 +253,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_clan_with_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -259,7 +272,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_alliance_with_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -279,7 +292,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_in_command_channel_with_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -300,7 +313,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_cannot_pvp_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......@@ -322,7 +335,7 @@ public class EnemyOnlyTest extends AbstractTest {
public void test_player_can_pvp_target_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(target.isNpc()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.isInOlympiadMode()).andReturn(false);
expect(player.isInDuelWith(target)).andReturn(false);
......
/*
* Copyright © 2004-2020 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.datapack.handlers.targethandlers;
import static com.l2jserver.gameserver.handler.ITargetTypeHandler.EMPTY_TARGET_LIST;
import static com.l2jserver.gameserver.model.skills.targets.AffectScope.NONE;
import static com.l2jserver.gameserver.model.skills.targets.AffectScope.SINGLE;
import static com.l2jserver.gameserver.network.SystemMessageId.INCORRECT_TARGET;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
import static org.powermock.api.easymock.PowerMock.replay;
import static org.testng.Assert.assertEquals;
import org.powermock.api.easymock.annotation.Mock;
import org.testng.annotations.Test;
import com.l2jserver.datapack.test.AbstractTest;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.SkillUseHolder;
import com.l2jserver.gameserver.model.skills.Skill;
/**
* Enemy test.
* @author Zoey76
* @version 2.6.2.0
*/
public class EnemyTest extends AbstractTest {
@Mock
private Skill skill;
@Mock
private SkillUseHolder skillUseHolder;
@Mock
private L2Character activeChar;
@Mock
private L2Character target;
@Mock
private L2PcInstance player;
private final Enemy enemy = new Enemy();
@Test
public void test_invalid_affect_scope_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(NONE);
replay(skill);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_null_target_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
replay(skill);
final var actual = enemy.getTargetList(skill, activeChar, false, null);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_dead_target_should_return_empty_target_list_with_invalid_target_message() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(true);
activeChar.sendPacket(INCORRECT_TARGET);
expectLastCall().once();
replay(skill, target, activeChar);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_attackable_target_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(true);
replay(skill, target);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(target, actual[0]);
}
@Test
public void test_null_player_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(null);
replay(skill, target, activeChar);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_player_cannot_pvp_target_and_no_ctrl_should_return_empty_target_list() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.checkIfPvP(target)).andReturn(false);
expect(player.getCurrentSkill()).andReturn(skillUseHolder);
expect(skillUseHolder.isCtrlPressed()).andReturn(false);
player.sendPacket(INCORRECT_TARGET);
expectLastCall().once();
replay(skill, target, activeChar, player, skillUseHolder);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(EMPTY_TARGET_LIST, actual);
}
@Test
public void test_player_cannot_pvp_target_and_ctrl_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.checkIfPvP(target)).andReturn(false);
expect(player.getCurrentSkill()).andReturn(skillUseHolder);
expect(skillUseHolder.isCtrlPressed()).andReturn(true);
replay(skill, target, activeChar, player, skillUseHolder);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(target, actual[0]);
}
@Test
public void test_player_can_pvp_target_should_return_target() {
expect(skill.getAffectScope()).andReturn(SINGLE);
expect(target.isDead()).andReturn(false);
expect(target.isAttackable()).andReturn(false);
expect(activeChar.getActingPlayer()).andReturn(player);
expect(player.checkIfPvP(target)).andReturn(true);
replay(skill, target, activeChar, player);
final var actual = enemy.getTargetList(skill, activeChar, false, target);
assertEquals(target, actual[0]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment