Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs2hd.content;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import com.rs2hd.model.Location;
- import com.rs2hd.model.Player;
- import com.rs2hd.model.World;
- import com.rs2hd.util.*;
- public class DoorManager {
- public DoorManager() throws Throwable {
- final XMLParser doorInstream = new XMLParser("./data/doors.xml");
- doorInstream.setByElement("door");
- for (int i = 0; i < doorInstream.getElements().size(); i++) {
- final Map<String, String> element = doorInstream.getElements().get(i);
- final int doorObject = doorInstream.getIntByTag(element,"doorObject");
- final int absX = doorInstream.getIntByTag(element,"absoulteX");
- final int absY = doorInstream.getIntByTag(element,"absoulteY");
- final Direction direction = getDirection(doorInstream.getStringByTag(element,"direction"));
- final Direction swivel = getDirection(doorInstream.getStringByTag(element,"swivelDirection"));
- doorContainer.add(new Door(doorObject, absX, absY, direction, swivel));
- }
- }
- private List<Door> doorContainer = new ArrayList<Door>();
- public void swivelDoor(int absX, int absY) {
- if(getDoor(absX, absY) == null) {
- return;
- }
- getDoor(absX, absY).swivel();
- }
- public Door getDoor(int absX, int absY) {
- for(int i = 0; i < doorContainer.size(); i++) {
- Door x = doorContainer.get(i);
- if(x.getAbsX() == absX && x.getAbsY() == absY) {
- return x;
- }
- }
- return null;
- }
- public Direction getDirection(String direction) {
- for(Direction x : Direction.values()) {
- if(direction.equalsIgnoreCase(x.toString().split(" ")[0])) {
- return x;
- }
- }
- return null;
- }
- private class Door {
- private final int absX;
- private final int absY;
- private final int doorObject;
- private final Direction baseDirection;
- private final Direction switchDirection;
- private Direction currentDirection;
- public Door(int doorObject, int absX, int absY, Direction baseDirection, Direction switchDirection) {
- this.doorObject = doorObject;
- this.absX = absX;
- this.absY = absY;
- this.currentDirection = baseDirection;
- this.baseDirection = baseDirection;
- this.switchDirection = switchDirection;
- }
- public void swivel() {
- currentDirection = currentDirection == baseDirection ? switchDirection : baseDirection;
- for(Player globalPlayers : World.getInstance().getPlayerList()) {
- if(Math.round(globalPlayers.getLocation().getDistance(globalPlayers.getLocation())) <= 32) {
- RegionManager.sendObjects(globalPlayers);
- }
- }
- RegionManager.removeObject(Location.location(absX, absY, 0));
- RegionManager.addObject(doorObject, currentDirection.getDirectionType(), 0, Location.location(absX, absY, 0));
- }
- public int getAbsX() {
- return absX;
- }
- public int getAbsY() {
- return absY;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement