Skip to content

Commit 49d9254

Browse files
committed
Further improved the reliability of the TrappingXPTest
1 parent d59936f commit 49d9254

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/test/java/com/projectswg/holocore/headless/experience.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
***********************************************************************************/
2626
package com.projectswg.holocore.headless
2727

28+
import com.projectswg.common.network.NetBuffer
2829
import java.util.concurrent.TimeUnit
2930

3031
fun ZonedInCharacter.waitForExperiencePoints(xpType: String) {
31-
val originalXP = getXP(xpType)
32-
player.waitForNextObjectDelta(player.playerObject.objectId, 8, 0, 1, TimeUnit.SECONDS) ?: throw IllegalStateException("No XP delta received")
33-
val newXP = getXP(xpType)
34-
35-
if (newXP == originalXP) {
36-
// We may have received a delta for a different XP type. Try again.
37-
// The exception above will be thrown if we never get the delta we're waiting for, preventing an infinite loop.
38-
waitForExperiencePoints(xpType)
32+
while (true) { // Quits naturally when the packet timeout is exceeded
33+
val experienceDelta = player.waitForNextObjectDelta(player.playerObject.objectId, 8, 0, 50, TimeUnit.MILLISECONDS) ?: throw IllegalStateException("No XP delta received")
34+
// TODO: Add a proper parser for SWGMap deltas
35+
val deltasData = NetBuffer.wrap(experienceDelta.deltaData)
36+
deltasData.seek(9)
37+
val deltaXpType = deltasData.ascii
38+
if (deltaXpType == xpType)
39+
return
3940
}
4041
}
4142

src/test/java/com/projectswg/holocore/services/gameplay/player/experience/TrappingXPTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class TrappingXPTest : AcceptanceTest() {
4141
val character = HeadlessSWGClient.createZonedInCharacter(user.username, user.password, "adminchar")
4242
val npc = spawnNPC("creature_bantha", character.player.creatureObject.location)
4343

44-
waitForIntents()
4544
killTarget(character, npc)
4645

4746
// There are three types of XP we receive from this kill: combat_meleespecialize_unarmed, trapping, and combat_general

src/test/java/com/projectswg/holocore/test/resources/GenericPlayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ public <T extends SWGPacket> T waitForNextPacket(Class<T> type, long timeout, Ti
213213
}
214214
return null;
215215
}
216+
216217
@Nullable
217218
public DeltasMessage waitForNextObjectDelta(long objectId, int num, int update, long timeout, TimeUnit unit) {
218219
Predicate<DeltasMessage> deltaPacketFilter = p -> p.getObjectId() == objectId && p.getNum() == num && p.getUpdate() == update;

0 commit comments

Comments
 (0)