mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-22 10:55:13 -06:00
Adding more tests
This commit is contained in:
parent
eabd15e2b1
commit
8a17e9ba62
3 changed files with 38 additions and 30 deletions
|
|
@ -174,24 +174,14 @@ public final class HouseManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the player's house.
|
||||
* @param player The player entering.
|
||||
* @param buildingMode If building mode is enabled.
|
||||
* @param teleport if the entry was a teleport.
|
||||
*/
|
||||
public void enter(final Player player, boolean buildingMode, boolean teleport) {
|
||||
enter(player, buildingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter's the player's house.
|
||||
* @param player
|
||||
* @param buildingMode
|
||||
*/
|
||||
public void enter(final Player player, boolean buildingMode) {
|
||||
if (HouseManager.this.buildingMode != buildingMode || !isLoaded()) {
|
||||
HouseManager.this.buildingMode = buildingMode;
|
||||
if (this.buildingMode != buildingMode || !isLoaded()) {
|
||||
this.buildingMode = buildingMode;
|
||||
construct();
|
||||
}
|
||||
player.setAttribute("poh_entry", HouseManager.this);
|
||||
|
|
@ -201,16 +191,16 @@ public final class HouseManager {
|
|||
openLoadInterface(player);
|
||||
checkForAndSpawnServant(player);
|
||||
updateVarbits(player, buildingMode);
|
||||
player.getMusicPlayer().unlock(454, true);
|
||||
unlockMusicTrack(player);
|
||||
}
|
||||
|
||||
public void openLoadInterface(Player player) {
|
||||
private void openLoadInterface(Player player) {
|
||||
player.getInterfaceManager().openComponent(399);
|
||||
player.getAudioManager().send(new Audio(984));
|
||||
submitCloseLoadInterfacePulse(player);
|
||||
}
|
||||
|
||||
public void submitCloseLoadInterfacePulse(Player player) {
|
||||
private void submitCloseLoadInterfacePulse(Player player) {
|
||||
GameWorld.getPulser().submit(new Pulse(1, player) {
|
||||
@Override
|
||||
public boolean pulse() {
|
||||
|
|
@ -220,7 +210,7 @@ public final class HouseManager {
|
|||
});
|
||||
}
|
||||
|
||||
public void checkForAndSpawnServant(Player player) {
|
||||
private void checkForAndSpawnServant(Player player) {
|
||||
if(!hasServant()) return;
|
||||
|
||||
GameWorld.getPulser().submit(new Pulse(1, player) {
|
||||
|
|
@ -235,11 +225,15 @@ public final class HouseManager {
|
|||
});
|
||||
}
|
||||
|
||||
public void updateVarbits(Player player, boolean build) {
|
||||
private void updateVarbits(Player player, boolean build) {
|
||||
player.varpManager.get(261).setVarbit(0, build ? 1 : 0);
|
||||
player.varpManager.get(262).setVarbit(0, getRoomAmount());
|
||||
}
|
||||
|
||||
private void unlockMusicTrack(Player player) {
|
||||
player.getMusicPlayer().unlock(454, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves this house.
|
||||
* @param player The player leaving.
|
||||
|
|
@ -281,17 +275,14 @@ public final class HouseManager {
|
|||
* @param buildingMode If building mode should be enabled.
|
||||
*/
|
||||
public void reload(Player player, boolean buildingMode) {
|
||||
DynamicRegion r = region;
|
||||
if ((player.getViewport().getRegion() == dungeon)) {
|
||||
r = dungeon;
|
||||
}
|
||||
int diffX = player.getLocation().getX() - r.getBaseLocation().getX();
|
||||
int diffY = player.getLocation().getY() - r.getBaseLocation().getY();
|
||||
int diffZ = player.getLocation().getZ() - r.getBaseLocation().getZ();
|
||||
region = null;
|
||||
dungeon = null;
|
||||
enter(player, buildingMode, false);
|
||||
player.getProperties().setTeleportLocation((player.getViewport().getRegion() == dungeon ? dungeon : region).getBaseLocation().transform(diffX, diffY, diffZ));
|
||||
int diffX = player.getLocation().getLocalX();
|
||||
int diffY = player.getLocation().getLocalY();
|
||||
int diffZ = player.getLocation().getZ();
|
||||
boolean inDungeon = player.getViewport().getRegion() == dungeon;
|
||||
this.buildingMode = buildingMode;
|
||||
construct();
|
||||
Location newLoc = (dungeon == null ? region : (inDungeon ? dungeon : region)).getBaseLocation().transform(diffX,diffY,diffZ);
|
||||
player.getProperties().setTeleportLocation(newLoc);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public final class PortalOptionPlugin extends OptionHandler {
|
|||
player.sendMessage("<col=FF0000>Speak with an estate agent to change your house location.");
|
||||
break;
|
||||
}
|
||||
player.getHouseManager().enter(player, buttonId == 2, true);
|
||||
player.getHouseManager().enter(player, buttonId == 2);
|
||||
break;
|
||||
case 3:
|
||||
if(player.getIronmanManager().isIronman()){
|
||||
|
|
@ -147,7 +147,7 @@ public final class PortalOptionPlugin extends OptionHandler {
|
|||
return Unit.INSTANCE;
|
||||
}
|
||||
p.setAttribute("poh_owner", (String) value);
|
||||
p.getHouseManager().enter(player, false, false);
|
||||
p.getHouseManager().enter(player, false);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import api.forceWalk
|
||||
import core.game.node.entity.player.link.music.MusicEntry
|
||||
import core.game.node.entity.skill.construction.HouseManager
|
||||
import core.game.node.entity.skill.construction.Servant
|
||||
import core.game.node.entity.skill.construction.ServantType
|
||||
import org.junit.Assert
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
|
@ -42,4 +44,19 @@ class HouseManagerTests {
|
|||
manager.enter(testPlayer, false)
|
||||
Assertions.assertEquals(true, testPlayer.musicPlayer.unlocked.contains(MusicEntry.forId(454).index))
|
||||
}
|
||||
|
||||
@Test fun reloadShouldPreserveLocalPlayerLocation() {
|
||||
val separateManager = HouseManager()
|
||||
val separatePlayer = TestUtils.getMockPlayer("test2")
|
||||
separateManager.enter(separatePlayer, false)
|
||||
TestUtils.advanceTicks(5)
|
||||
forceWalk(separatePlayer, separatePlayer.location.transform(10,10,0), "smart")
|
||||
TestUtils.advanceTicks(20)
|
||||
val localX = separatePlayer.location.localX
|
||||
val localY = separatePlayer.location.localY
|
||||
separateManager.reload(separatePlayer, true)
|
||||
TestUtils.advanceTicks(20)
|
||||
Assertions.assertEquals(localX, separatePlayer.location.localX)
|
||||
Assertions.assertEquals(localY, separatePlayer.location.localY)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue