Ver Fonte

Core Support for Trigger Skills

Added official-like:
Trigger Attack type, we used a custom way.
Trigger Target type, they seems to be different from TargetType.
Zoey76 há 2 anos atrás
pai
commit
37e836425e

+ 56 - 0
src/main/java/com/l2jserver/gameserver/enums/TriggerAttackType.java

@@ -0,0 +1,56 @@
+/*
+ * Copyright © 2004-2023 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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 Server 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.gameserver.enums;
+
+import com.l2jserver.gameserver.model.L2Object;
+import com.l2jserver.gameserver.model.actor.L2Character;
+
+/**
+ * Trigger Attack Type.
+ * @author Zoey76
+ * @version 2.6.3.0
+ */
+public enum TriggerAttackType {
+	NONE {
+		@Override
+		public boolean check(L2Character trigger, L2Object target) {
+			return false;
+		}
+	},
+	ENEMY_ALL {
+		@Override
+		public boolean check(L2Character trigger, L2Object target) {
+			return target.isCharacter() && target.isAutoAttackable(trigger);
+		}
+	},
+	MOB {
+		@Override
+		public boolean check(L2Character trigger, L2Object target) {
+			return target.isAttackable();
+		}
+	},
+	PK {
+		@Override
+		public boolean check(L2Character trigger, L2Object target) {
+			return target.isPlayer() || target.isSummon();
+		}
+	};
+	
+	public abstract boolean check(L2Character trigger, L2Object target);
+}

+ 74 - 0
src/main/java/com/l2jserver/gameserver/enums/TriggerTargetType.java

@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2004-2023 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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 Server 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.gameserver.enums;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.l2jserver.gameserver.model.actor.L2Character;
+
+/**
+ * Trigger Target Type.
+ * @author Zoey76
+ * @version 2.6.3.0
+ */
+public enum TriggerTargetType {
+	ENEMY {
+		@Override
+		public List<L2Character> getTargets(L2Character target, L2Character attacker) {
+			return List.of(attacker);
+		}
+	},
+	SELF {
+		@Override
+		public List<L2Character> getTargets(L2Character target, L2Character attacker) {
+			return List.of(target);
+		}
+	},
+	MY_PARTY {
+		@Override
+		public List<L2Character> getTargets(L2Character target, L2Character attacker) {
+			if (target.isPlayer() || target.isSummon()) {
+				final var player = target.getActingPlayer();
+				if (player.isInParty()) {
+					return new ArrayList<>(player.getParty().getMembers());
+				}
+				return List.of(player);
+			}
+			return List.of();
+		}
+	},
+	TARGET {
+		@Override
+		public List<L2Character> getTargets(L2Character target, L2Character attacker) {
+			return List.of(target);
+		}
+	},
+	SUMMON {
+		@Override
+		public List<L2Character> getTargets(L2Character target, L2Character attacker) {
+			if (target.hasSummon()) {
+				return List.of(target.getSummon());
+			}
+			return List.of();
+		}
+	};
+	
+	public abstract List<L2Character> getTargets(L2Character target, L2Character attacker);
+}

+ 100 - 0
src/test/java/com/l2jserver/gameserver/enums/TriggerAttackTypeTest.java

@@ -0,0 +1,100 @@
+/*
+ * Copyright © 2004-2023 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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 Server 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.gameserver.enums;
+
+import static com.l2jserver.gameserver.enums.TriggerAttackType.ENEMY_ALL;
+import static com.l2jserver.gameserver.enums.TriggerAttackType.MOB;
+import static com.l2jserver.gameserver.enums.TriggerAttackType.NONE;
+import static com.l2jserver.gameserver.enums.TriggerAttackType.PK;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.when;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import com.l2jserver.gameserver.model.L2Object;
+import com.l2jserver.gameserver.model.actor.L2Character;
+
+/**
+ * Trigger Attack Type test.
+ * @author Zoey76
+ * @version 2.6.3.0
+ */
+@ExtendWith(MockitoExtension.class)
+class TriggerAttackTypeTest {
+	@Mock
+	private L2Character trigger;
+	
+	@Mock
+	private L2Object target;
+	
+	@Test
+	void testNone() {
+		assertFalse(NONE.check(trigger, target));
+	}
+	
+	@Test
+    void testEnemyAll() {
+        when(target.isCharacter()).thenReturn(true);
+        when(target.isAutoAttackable(trigger)).thenReturn(true);
+        assertTrue(ENEMY_ALL.check(trigger, target));
+    }
+	
+	@Test
+    void testEnemyAllTargetIsNotACharacter() {
+        when(target.isCharacter()).thenReturn(false);
+        assertFalse(ENEMY_ALL.check(trigger, target));
+    }
+	
+	@Test
+    void testEnemyAllTargetIsNotAnEnemy() {
+        when(target.isCharacter()).thenReturn(true);
+        when(target.isAutoAttackable(trigger)).thenReturn(false);
+        assertFalse(ENEMY_ALL.check(trigger, target));
+    }
+	
+	@Test
+    void testMobTargetIsMonster() {
+        when(target.isAttackable()).thenReturn(true);
+        assertTrue(MOB.check(trigger, target));
+    }
+	
+	@Test
+    void testPKTargetIsPlayer() {
+        when(target.isPlayer()).thenReturn(true);
+        assertTrue(PK.check(trigger, target));
+    }
+	
+	@Test
+    void testPKTargetIsSummon() {
+        when(target.isPlayer()).thenReturn(false);
+        when(target.isSummon()).thenReturn(true);
+        assertTrue(PK.check(trigger, target));
+    }
+	
+	@Test
+    void testPKTargetIsNotPlayerOrSummon() {
+        when(target.isPlayer()).thenReturn(false);
+        when(target.isSummon()).thenReturn(false);
+        assertFalse(PK.check(trigger, target));
+    }
+}

+ 122 - 0
src/test/java/com/l2jserver/gameserver/enums/TriggerTargetTypeTest.java

@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2004-2023 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server 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 Server 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.gameserver.enums;
+
+import static com.l2jserver.gameserver.enums.TriggerTargetType.ENEMY;
+import static com.l2jserver.gameserver.enums.TriggerTargetType.MY_PARTY;
+import static com.l2jserver.gameserver.enums.TriggerTargetType.SELF;
+import static com.l2jserver.gameserver.enums.TriggerTargetType.SUMMON;
+import static com.l2jserver.gameserver.enums.TriggerTargetType.TARGET;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import com.l2jserver.gameserver.model.L2Party;
+import com.l2jserver.gameserver.model.actor.L2Character;
+import com.l2jserver.gameserver.model.actor.L2Summon;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+
+/**
+ * Trigger Target Type test.
+ * @author Zoey76
+ * @version 2.6.3.0
+ */
+@ExtendWith(MockitoExtension.class)
+class TriggerTargetTypeTest {
+	
+	@Mock
+	private L2PcInstance target;
+	@Mock
+	private L2Character attacker;
+	@Mock
+	private L2PcInstance partyMember;
+	@Mock
+	private L2Party party;
+	@Mock
+	private L2Summon summon;
+	
+	@Test
+	void testEnemy() {
+		assertEquals(List.of(attacker), ENEMY.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testSelf() {
+		assertEquals(List.of(target), SELF.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testMyPartyTargetIsPlayerInParty() {
+		when(target.isPlayer()).thenReturn(true);
+		when(target.getActingPlayer()).thenReturn(target);
+		when(target.isInParty()).thenReturn(true);
+		when(target.getParty()).thenReturn(party);
+		when(party.getMembers()).thenReturn(List.of(target, partyMember));
+		assertEquals(List.of(target, partyMember), MY_PARTY.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testMyPartyTargetIsSummonInParty() {
+		when(summon.isPlayer()).thenReturn(false);
+		when(summon.isSummon()).thenReturn(true);
+		when(summon.getActingPlayer()).thenReturn(target);
+		when(target.isInParty()).thenReturn(true);
+		when(target.getParty()).thenReturn(party);
+		when(party.getMembers()).thenReturn(List.of(target, partyMember));
+		assertEquals(List.of(target, partyMember), MY_PARTY.getTargets(summon, attacker));
+	}
+	
+	@Test
+	void testMyPartyPlayerIsNotInParty() {
+		when(target.isPlayer()).thenReturn(true);
+		when(target.getActingPlayer()).thenReturn(target);
+		when(target.isInParty()).thenReturn(false);
+		assertEquals(List.of(target), MY_PARTY.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testMyPartyTargetIsNotPlayerAndIsNotSummon() {
+		when(target.isPlayer()).thenReturn(false);
+		assertEquals(List.of(), MY_PARTY.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testTarget() {
+		assertEquals(List.of(target), TARGET.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testSummon() {
+		when(target.hasSummon()).thenReturn(true);
+		when(target.getSummon()).thenReturn(summon);
+		assertEquals(List.of(summon), SUMMON.getTargets(target, attacker));
+	}
+	
+	@Test
+	void testSummonNoSummon() {
+		when(target.hasSummon()).thenReturn(false);
+		assertEquals(List.of(), SUMMON.getTargets(target, attacker));
+	}
+}