Browse Source

new region lookup

magicbox-1.5.2
FatBoy-DOTC 1 year ago
parent
commit
b928bedeb6
  1. 7
      src/engine/devcmd/cmds/RegionCmd.java
  2. 19
      src/engine/gameManager/BuildingManager.java
  3. 10
      src/engine/objects/AbstractCharacter.java

7
src/engine/devcmd/cmds/RegionCmd.java

@ -11,6 +11,7 @@ package engine.devcmd.cmds; @@ -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 { @@ -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.");

19
src/engine/gameManager/BuildingManager.java

@ -18,6 +18,7 @@ import engine.job.JobContainer; @@ -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; @@ -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 { @@ -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;
}
}

10
src/engine/objects/AbstractCharacter.java

@ -985,7 +985,15 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -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;

Loading…
Cancel
Save