diff --git a/src/engine/devcmd/cmds/RegionCmd.java b/src/engine/devcmd/cmds/RegionCmd.java index b7b12c7e..dbda7ae7 100644 --- a/src/engine/devcmd/cmds/RegionCmd.java +++ b/src/engine/devcmd/cmds/RegionCmd.java @@ -11,6 +11,7 @@ package engine.devcmd.cmds; import engine.Enum; import engine.devcmd.AbstractDevCmd; +import engine.gameManager.BuildingManager; import engine.objects.*; import java.lang.reflect.Field; @@ -25,6 +26,12 @@ public class RegionCmd extends AbstractDevCmd { protected void _doCmd(PlayerCharacter pc, String[] words, AbstractGameObject target) { + Building building = BuildingManager.getBuildingAtLocation(((AbstractCharacter) target).loc); + if(building == null){ + this.throwbackInfo(pc, "No Building At This Location.") ; + } else{ + this.throwbackInfo(pc, "Building At Location: " + building.getName()); + } Regions region = ((AbstractCharacter)target).region; if (region == null) { this.throwbackInfo(pc, "No Region Found."); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 180504cf..ca32184d 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -18,6 +18,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeBuildingJob; import engine.math.Bounds; +import engine.math.Vector2f; import engine.math.Vector3fImmutable; import engine.net.client.ClientConnection; import engine.net.client.msg.ErrorPopupMsg; @@ -26,7 +27,9 @@ import engine.net.client.msg.PlaceAssetMsg; import engine.objects.*; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; +import org.w3c.dom.css.Rect; +import java.awt.*; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; @@ -945,4 +948,20 @@ public enum BuildingManager { building.isDeranking.compareAndSet(true, false); } + public static Building getBuildingAtLocation(Vector3fImmutable loc){ + for(AbstractWorldObject awo : WorldGrid.getObjectsInRangePartial(loc,128,MBServerStatics.MASK_BUILDING)){ + Building building = (Building)awo; + if(building == null) + continue; + float minX = building.loc.x - building.getBounds().getHalfExtents().x; + float maxX = building.loc.x + building.getBounds().getHalfExtents().x; + float minZ = building.loc.z - building.getBounds().getHalfExtents().y; + float maxZ = building.loc.z + building.getBounds().getHalfExtents().y; + + if(loc.x > minX && loc.x < maxX && loc.z > minZ && loc.x < maxZ) + return building; + + } + return null; + } } diff --git a/src/engine/objects/AbstractCharacter.java b/src/engine/objects/AbstractCharacter.java index f778755a..c8ab7b60 100644 --- a/src/engine/objects/AbstractCharacter.java +++ b/src/engine/objects/AbstractCharacter.java @@ -985,7 +985,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @Override public final void setLoc(final Vector3fImmutable value) { - Regions region = Regions.GetRegionForTeleport(value); + + Building building = BuildingManager.getBuildingAtLocation(this.loc); + Regions region = null; + if(building != null){ + //look for region in the building we are in + for(Regions regionCycle : building.getBounds().getRegions()) + if(regionCycle.isPointInPolygon(value)) + region = regionCycle; + } float regionHeightOffset = 0; if(region != null){ this.region = region;