Files
Server/src/engine/objects/Portal.java
T

119 lines
3.1 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
package engine.objects;
import engine.Enum;
import engine.Enum.PortalType;
2022-04-30 09:41:17 -04:00
import engine.InterestManagement.WorldGrid;
import engine.gameManager.ConfigManager;
import engine.job.JobScheduler;
import engine.jobs.CloseGateJob;
import engine.math.Vector3fImmutable;
import engine.server.MBServerStatics;
import java.util.HashSet;
/* A Runegate object holds an array of these
* portals. This class controls their triggers
* and visual effects.
*/
public class Portal {
2023-07-15 09:23:48 -04:00
public final Vector3fImmutable portalLocation;
public Enum.PortalType portalType;
public Building sourceGate;
public Building targetGate;
private boolean active;
private long lastActive = 0;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public Portal(Building sourceGate, PortalType portalType, Building targetGate) {
Vector3fImmutable tmpLocation;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
this.active = false;
this.sourceGate = sourceGate;
this.targetGate = targetGate;
this.portalType = portalType;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
tmpLocation = sourceGate.getLoc().add(new Vector3fImmutable(portalType.offset.x, 6, portalType.offset.y));
2023-05-07 08:13:41 -04:00
2023-07-15 09:23:48 -04:00
// Rotate portal by gate rotation
2023-05-07 08:13:41 -04:00
2023-07-15 09:23:48 -04:00
tmpLocation = Vector3fImmutable.rotateAroundPoint(sourceGate.getLoc(), tmpLocation, sourceGate.getBounds().getQuaternion().angleY);
2023-05-07 08:13:41 -04:00
2023-07-15 09:23:48 -04:00
this.portalLocation = tmpLocation;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isActive() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return this.active;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void deactivate() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Remove effect bit from the runegate building, which turns off this
// portal type's particle effect
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
sourceGate.removeEffectBit(portalType.effectFlag);
this.active = false;
sourceGate.updateEffects();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void activate(boolean autoClose) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Building sourceBuilding;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Apply effect bit to the runegate building, which turns on this
// portal type's particle effect
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
sourceGate.addEffectBit(portalType.effectFlag);
this.lastActive = System.currentTimeMillis();
this.active = true;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
// Do not update effects at bootstrap as it
// tries to send a dispatch.
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (ConfigManager.worldServer.isRunning == true)
sourceGate.updateEffects();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (autoClose == true) {
CloseGateJob cgj = new CloseGateJob(sourceGate, portalType);
2023-07-15 09:23:48 -04:00
JobScheduler.getInstance().scheduleJob(cgj, MBServerStatics.RUNEGATE_CLOSE_TIME);
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void collide() {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
HashSet<AbstractWorldObject> playerList;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
playerList = WorldGrid.getObjectsInRangePartial(this.portalLocation, 2, MBServerStatics.MASK_PLAYER);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (playerList.isEmpty())
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
for (AbstractWorldObject player : playerList) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
onEnter((PlayerCharacter) player);
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void onEnter(PlayerCharacter player) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (player.getTimeStamp("lastMoveGate") < this.lastActive)
return;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
player.teleport(targetGate.getLoc());
player.setSafeMode();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
/**
* @return the portalLocation
*/
public Vector3fImmutable getPortalLocation() {
return portalLocation;
}
2022-04-30 09:41:17 -04:00
}