Fixed incorrect teleporting to house portal on logout
House now kicks guests when owner leaves More aggressively unload old house regions (experiment) Added DEBUG log type (currently unused, but shows up in cyan when used and the world is in development mode)
This commit is contained in:
@@ -64,7 +64,7 @@ public final class HouseManager {
|
|||||||
/**
|
/**
|
||||||
* The house zone.
|
* The house zone.
|
||||||
*/
|
*/
|
||||||
private final HouseZone zone = new HouseZone(this);
|
private HouseZone zone = new HouseZone(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player's house rooms.
|
* The player's house rooms.
|
||||||
@@ -198,10 +198,6 @@ public final class HouseManager {
|
|||||||
player.lock(1);
|
player.lock(1);
|
||||||
player.sendMessage("House location: " + houseRegion.getBaseLocation() + ", entry: " + getEnterLocation());
|
player.sendMessage("House location: " + houseRegion.getBaseLocation() + ", entry: " + getEnterLocation());
|
||||||
player.getProperties().setTeleportLocation(getEnterLocation());
|
player.getProperties().setTeleportLocation(getEnterLocation());
|
||||||
registerLogoutListener(player, "houselogout", (p) -> {
|
|
||||||
p.setLocation(location.getExitLocation());
|
|
||||||
return Unit.INSTANCE;
|
|
||||||
});
|
|
||||||
openLoadInterface(player);
|
openLoadInterface(player);
|
||||||
checkForAndSpawnServant(player);
|
checkForAndSpawnServant(player);
|
||||||
updateVarbits(player, buildingMode);
|
updateVarbits(player, buildingMode);
|
||||||
@@ -254,7 +250,6 @@ public final class HouseManager {
|
|||||||
*/
|
*/
|
||||||
public static void leave(Player player) {
|
public static void leave(Player player) {
|
||||||
HouseManager house = player.getAttribute("poh_entry", player.getHouseManager());
|
HouseManager house = player.getAttribute("poh_entry", player.getHouseManager());
|
||||||
clearLogoutListener(player, "houselogout");
|
|
||||||
if (house.getHouseRegion() == null){
|
if (house.getHouseRegion() == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -278,8 +273,7 @@ public final class HouseManager {
|
|||||||
if (enable) {
|
if (enable) {
|
||||||
expelGuests(player);
|
expelGuests(player);
|
||||||
}
|
}
|
||||||
buildingMode = enable;
|
enter(player, enable);
|
||||||
reload(player, enable);
|
|
||||||
player.getPacketDispatch().sendMessage("Building mode is now " + (buildingMode ? "on." : "off."));
|
player.getPacketDispatch().sendMessage("Building mode is now " + (buildingMode ? "on." : "off."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,6 +282,7 @@ public final class HouseManager {
|
|||||||
* Reloads the house.
|
* Reloads the house.
|
||||||
* @param player The player.
|
* @param player The player.
|
||||||
* @param buildingMode If building mode should be enabled.
|
* @param buildingMode If building mode should be enabled.
|
||||||
|
* NOTE: I think we should avoid this method, it might be causing some issues. It's actually really suspicious...
|
||||||
*/
|
*/
|
||||||
public void reload(Player player, boolean buildingMode) {
|
public void reload(Player player, boolean buildingMode) {
|
||||||
int diffX = player.getLocation().getLocalX();
|
int diffX = player.getLocation().getLocalX();
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import core.game.node.entity.Entity;
|
|||||||
import core.game.node.entity.player.Player;
|
import core.game.node.entity.player.Player;
|
||||||
import core.game.world.map.zone.MapZone;
|
import core.game.world.map.zone.MapZone;
|
||||||
import core.game.world.map.zone.ZoneRestriction;
|
import core.game.world.map.zone.ZoneRestriction;
|
||||||
|
import core.game.world.map.RegionManager;
|
||||||
|
import core.game.world.map.Region;
|
||||||
|
import core.game.system.task.Pulse;
|
||||||
|
|
||||||
|
import static core.api.ContentAPIKt.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the player owned house zone.
|
* Handles the player owned house zone.
|
||||||
@@ -38,20 +43,36 @@ public final class HouseZone extends MapZone {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
if (previousRegion != -1) {
|
unregisterOldRegions();
|
||||||
unregisterRegion(previousRegion);
|
|
||||||
}
|
|
||||||
if (previousDungeon != -1) {
|
|
||||||
unregisterRegion(previousDungeon);
|
|
||||||
}
|
|
||||||
registerRegion(house.getHouseRegion().getId());
|
registerRegion(house.getHouseRegion().getId());
|
||||||
if (house.getDungeonRegion() != null) {
|
if (house.getDungeonRegion() != null) {
|
||||||
registerRegion(house.getDungeonRegion().getId());
|
registerRegion(house.getDungeonRegion().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void unregisterOldRegions() {
|
||||||
|
if (previousRegion != -1) {
|
||||||
|
unregisterRegion(previousRegion);
|
||||||
|
}
|
||||||
|
if (previousDungeon != -1) {
|
||||||
|
unregisterRegion(previousDungeon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean enter(Entity e) {
|
public boolean enter(Entity e) {
|
||||||
|
if (e instanceof Player) {
|
||||||
|
Player pl = (Player) e;
|
||||||
|
if (house == pl.getHouseManager()) {
|
||||||
|
previousRegion = house.getHouseRegion().getId();
|
||||||
|
if (house.getDungeonRegion() != null)
|
||||||
|
previousDungeon = house.getDungeonRegion().getId();
|
||||||
|
}
|
||||||
|
registerLogoutListener(pl, "houselogout", (p) -> {
|
||||||
|
p.setLocation(house.getLocation().getExitLocation());
|
||||||
|
return kotlin.Unit.INSTANCE;
|
||||||
|
});
|
||||||
|
}
|
||||||
return super.enter(e);
|
return super.enter(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +87,30 @@ public final class HouseZone extends MapZone {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean leave(Entity e, boolean logout) {
|
public boolean leave(Entity e, boolean logout) {
|
||||||
if (logout) {
|
|
||||||
if (e instanceof Player) {
|
if (e instanceof Player) {
|
||||||
Player p = (Player) e;
|
Player p = (Player) e;
|
||||||
HouseManager.leave(p);
|
if (house == p.getHouseManager()) {
|
||||||
|
house.expelGuests(p);
|
||||||
|
int toRemove = previousRegion;
|
||||||
|
int dungRemove = previousDungeon;
|
||||||
|
submitWorldPulse(new Pulse(2) {
|
||||||
|
public boolean pulse() {
|
||||||
|
Region r = RegionManager.forId(toRemove);
|
||||||
|
Region dr = dungRemove != -1 ? RegionManager.forId(dungRemove) : null;
|
||||||
|
RegionManager.removeRegion(toRemove);
|
||||||
|
unregisterRegion(toRemove);
|
||||||
|
r.setActive(false);
|
||||||
|
if (dungRemove != -1) {
|
||||||
|
RegionManager.removeRegion(dungRemove);
|
||||||
|
unregisterRegion(dungRemove);
|
||||||
|
dr.setActive(false);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
clearLogoutListener(p, "houselogout");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,11 +268,8 @@ public class Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean flagInactive(boolean force) {
|
||||||
* Flags the region as inactive.
|
if (unload(this, force)) {
|
||||||
*/
|
|
||||||
protected boolean flagInactive() {
|
|
||||||
if(unload(this)) {
|
|
||||||
active = false;
|
active = false;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@@ -280,6 +277,13 @@ public class Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags the region as inactive.
|
||||||
|
*/
|
||||||
|
public boolean flagInactive() {
|
||||||
|
return flagInactive(false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the flags for a region.
|
* Loads the flags for a region.
|
||||||
* @param r The region.
|
* @param r The region.
|
||||||
@@ -341,18 +345,22 @@ public class Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean unload(Region r) {
|
||||||
|
return unload(r, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unloads a region.
|
* Unloads a region.
|
||||||
* @param r The region.
|
* @param r The region.
|
||||||
*/
|
*/
|
||||||
private static boolean unload(Region r) {
|
public static boolean unload(Region r, boolean force) {
|
||||||
if (r.isViewed()) {
|
if (!force && r.isViewed()) {
|
||||||
log(CommunicationInfo.class, Log.ERR, "Players viewing region!");
|
log(CommunicationInfo.class, Log.ERR, "Players viewing region!");
|
||||||
r.flagActive();
|
r.flagActive();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (RegionPlane p : r.planes) {
|
for (RegionPlane p : r.planes) {
|
||||||
if (!p.getPlayers().isEmpty()) {
|
if (!force && !p.getPlayers().isEmpty()) {
|
||||||
log(CommunicationInfo.class, Log.ERR, "Players still in region!");
|
log(CommunicationInfo.class, Log.ERR, "Players still in region!");
|
||||||
r.flagActive();
|
r.flagActive();
|
||||||
return false;
|
return false;
|
||||||
@@ -366,6 +374,7 @@ public class Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
r.activityPulse.stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -855,6 +855,15 @@ object RegionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun removeRegion(id: Int) {
|
||||||
|
if (lock.tryLock() || LOCK.tryLock(10000, TimeUnit.MILLISECONDS)) {
|
||||||
|
val r = REGION_CACHE.remove(id)
|
||||||
|
r?.flagInactive(true)
|
||||||
|
LOCK.unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the regionCache.
|
* Gets the regionCache.
|
||||||
* @return The regionCache.
|
* @return The regionCache.
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ public final class DynamicRegion extends Region {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean flagInactive() {
|
public boolean flagInactive(boolean force) {
|
||||||
if (!permanent) {
|
if (!permanent) {
|
||||||
if (parentRegion != null && parentRegion.isActive()) {
|
if (parentRegion != null && parentRegion.isActive()) {
|
||||||
parentRegion.checkInactive();
|
parentRegion.checkInactive();
|
||||||
@@ -356,7 +356,7 @@ public final class DynamicRegion extends Region {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!super.flagInactive()) {
|
if(!super.flagInactive(force)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (RegionPlane plane : getPlanes()) {
|
for (RegionPlane plane : getPlanes()) {
|
||||||
@@ -381,7 +381,7 @@ public final class DynamicRegion extends Region {
|
|||||||
boolean allLinkedInactive = true;
|
boolean allLinkedInactive = true;
|
||||||
if (linked != null) {
|
if (linked != null) {
|
||||||
for (DynamicRegion r : linked) {
|
for (DynamicRegion r : linked) {
|
||||||
allLinkedInactive &= r.flagInactive();
|
allLinkedInactive &= r.flagInactive(force);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allLinkedInactive;
|
return allLinkedInactive;
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import com.github.ajalt.mordant.rendering.TextColors
|
|||||||
import com.github.ajalt.mordant.terminal.*
|
import com.github.ajalt.mordant.terminal.*
|
||||||
import com.google.protobuf.ByteString.Output
|
import com.google.protobuf.ByteString.Output
|
||||||
import core.ServerConstants
|
import core.ServerConstants
|
||||||
import core.api.log
|
import core.game.world.GameWorld
|
||||||
|
import core.api.*
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@@ -27,6 +28,13 @@ object SystemLogger {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun processLogEntry(clazz: Class<*>, log: Log, message: String) {
|
fun processLogEntry(clazz: Class<*>, log: Log, message: String) {
|
||||||
when (log) {
|
when (log) {
|
||||||
|
Log.DEBUG -> {
|
||||||
|
if (GameWorld.settings?.isDevMode != true)
|
||||||
|
return
|
||||||
|
val msg = TextColors.cyan("${getTime()}: [${clazz.simpleName}] $message")
|
||||||
|
t.println(msg)
|
||||||
|
}
|
||||||
|
|
||||||
Log.FINE -> {
|
Log.FINE -> {
|
||||||
if (ServerConstants.LOG_LEVEL < LogLevel.VERBOSE)
|
if (ServerConstants.LOG_LEVEL < LogLevel.VERBOSE)
|
||||||
return
|
return
|
||||||
@@ -88,5 +96,6 @@ enum class Log {
|
|||||||
FINE,
|
FINE,
|
||||||
INFO,
|
INFO,
|
||||||
WARN,
|
WARN,
|
||||||
ERR
|
ERR,
|
||||||
|
DEBUG
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user