Thread: [Elvarg V3.2] Working doors (almost) 😁

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 [Elvarg V3.2] Working doors (almost) 😁 
    Registered Member Fozzey's Avatar
    Join Date
    Jan 2014
    Posts
    33
    Thanks given
    8
    Thanks received
    1
    Rep Power
    11
    And here we go again, another door post. I've done pretty extensive googling and the best i came up with led me to a dead end with half working doors.

    These are the links of posts ive read through:

    Main help thread

    These are other ones that dont help my situation much:

    Link 1
    Link 2
    Link 3
    Link 4

    Basically my issue is that my door will open and deregister the original door and then register the new door, but the player will still be clipped to the old door that should be deregistered. So i have put the code for my DoorHandler.java, objectactionpacketlistener.java and objectManager.java.
    And i will also put some media to show the issue as well.

    Spoiler for DoorHandler.java:

    Code:
    package com.elvarg.game.model.doors;
    
    import com.elvarg.game.entity.impl.object.GameObject;
    import com.elvarg.game.entity.impl.object.ObjectManager;
    import com.elvarg.game.model.Location;
    import com.elvarg.game.model.areas.impl.PrivateArea;
    import com.elvarg.game.task.Task;
    import com.elvarg.game.task.TaskManager;
    
    import javax.swing.text.Position;
    import java.util.HashMap;
    
    public class DoorHandler {
    
        private static final int[][] COORD_OFFSETS = new int[][] { new int[] { -1, 0 }, new int[] { 0, 1 }, new int[] { 1, 0 },
                new int[] { 0, -1 } };
    
        public static HashMap<Integer, Integer> MAP = new HashMap<>();
    
        static {
            MAP.put(1535, 1536);
        }
        public static boolean HandleDoor(GameObject door) {
    
            int doorId = door.getId();
            boolean open = door.getDefinition().interactions[0].contains("Close");
            int type = door.getType();
            int rotation = door.getFace();
            int nextRotation = open ? ((rotation + 1) & 0x3) : rotation;
            int[] offsets = COORD_OFFSETS[type == 9 ? ((nextRotation + 1) & 0x3) : nextRotation];
            int id = MAP.getOrDefault(doorId, doorId);
            Location position = new Location(door.getLocation().getX() + offsets[0], door.getLocation().getY() + offsets[1], door.getLocation().getZ());
            GameObject object = new GameObject(id, position, type, open ? ((rotation - 1) & 0x3) : ((rotation + 1) & 0x3), door.getPrivateArea());
    
            TaskManager.submit(new Task(1) {
                public void execute() {
                    ObjectManager.register(object, true);
                    ObjectManager.deregister(door, true);
                    stop();
                }
            });
            return true;
        }
    
    }

    Spoiler for ObjectManager.java:

    Code:
        /**
         * Deregisters a {@link GameObject} from the world.
         *
         *    @Param object       The object to deregister.
         *    @Param playerUpdate Should the object removal packet be sent to nearby players?
         */
        public static void deregister(GameObject object, boolean playerUpdate) {
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext(); ) {
                GameObject o = iterator.next();
                if (o.equals(object)) {
                    iterator.remove();
                }
            }
            if (playerUpdate) {
                perform(object, OperationType.DESPAWN);
            }
        }

    Spoiler for ObjectActionPacketListener:

    Code:
            case 1535:
            case 1536:
                DoorHandler.HandleDoor(object);
                break;

    This is what occurs when i first click the door.
    Spoiler for Gif 1:


    This is after i log out and log in again. If i restart the server it will go back to normal.
    Spoiler for Gif 2:


    This one is a bit wierd.
    Spoiler for Gif 3:


    Is there something i'm missing? Anyway id really appreciate any help as this is the most core aspect of the game and a server/client would be a laughing stock without working doors
    Reply With Quote  
     

  2. #2  
    Super Donator

    Chivvon's Avatar
    Join Date
    May 2016
    Posts
    487
    Thanks given
    68
    Thanks received
    139
    Rep Power
    249
    Quote Originally Posted by Fozzey View Post
    And here we go again, another door post. I've done pretty extensive googling and the best i came up with led me to a dead end with half working doors.

    These are the links of posts ive read through:

    Main help thread

    These are other ones that dont help my situation much:

    Link 1
    Link 2
    Link 3
    Link 4

    Basically my issue is that my door will open and deregister the original door and then register the new door, but the play will still be clipped to the old door that should be deregistered. So i have put the code for my DoorHandler.java, objectactionpacketlistener.java and objectManager.java.
    And i will also put some media to show the issue as well.

    Spoiler for DoorHandler.java:

    Code:
    package com.elvarg.game.model.doors;
    
    import com.elvarg.game.entity.impl.object.GameObject;
    import com.elvarg.game.entity.impl.object.ObjectManager;
    import com.elvarg.game.model.Location;
    import com.elvarg.game.model.areas.impl.PrivateArea;
    import com.elvarg.game.task.Task;
    import com.elvarg.game.task.TaskManager;
    
    import javax.swing.text.Position;
    import java.util.HashMap;
    
    public class DoorHandler {
    
        private static final int[][] COORD_OFFSETS = new int[][] { new int[] { -1, 0 }, new int[] { 0, 1 }, new int[] { 1, 0 },
                new int[] { 0, -1 } };
    
        public static HashMap<Integer, Integer> MAP = new HashMap<>();
    
        static {
            MAP.put(1535, 1536);
        }
        public static boolean HandleDoor(GameObject door) {
    
            int doorId = door.getId();
            boolean open = door.getDefinition().interactions[0].contains("Close");
            int type = door.getType();
            int rotation = door.getFace();
            int nextRotation = open ? ((rotation + 1) & 0x3) : rotation;
            int[] offsets = COORD_OFFSETS[type == 9 ? ((nextRotation + 1) & 0x3) : nextRotation];
            int id = MAP.getOrDefault(doorId, doorId);
            Location position = new Location(door.getLocation().getX() + offsets[0], door.getLocation().getY() + offsets[1], door.getLocation().getZ());
            GameObject object = new GameObject(id, position, type, open ? ((rotation - 1) & 0x3) : ((rotation + 1) & 0x3), door.getPrivateArea());
    
            TaskManager.submit(new Task(1) {
                public void execute() {
                    ObjectManager.register(object, true);
                    ObjectManager.deregister(door, true);
                    stop();
                }
            });
            return true;
        }
    
    }

    Spoiler for ObjectManager.java:

    Code:
        /**
         * Deregisters a {@link GameObject} from the world.
         *
         *   @Param object       The object to deregister.
         *   @Param playerUpdate Should the object removal packet be sent to nearby players?
         */
        public static void deregister(GameObject object, boolean playerUpdate) {
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext(); ) {
                GameObject o = iterator.next();
                if (o.equals(object)) {
                    iterator.remove();
                }
            }
            if (playerUpdate) {
                perform(object, OperationType.DESPAWN);
            }
        }

    Spoiler for ObjectActionPacketListener:

    Code:
            case 1535:
            case 1536:
                DoorHandler.HandleDoor(object);
                break;

    This is what occurs when i first click the door.
    Spoiler for Gif 1:


    This is after i log out and log in again. If i restart the server it will go back to normal.
    Spoiler for Gif 2:


    This one is a bit wierd.
    Spoiler for Gif 3:


    Is there something i'm missing? Anyway id really appreciate any help as this is the most core aspect of the game and a server/client would be a laughing stock without working doors
    If I recall correctly; the object 'system' server sided had some issues. Just check how "getObjects()" from World.java is filled and send on the OnRegionChangeListener. There were also some changes required in how the RegionManager checks if new objects exists. Also, spawning objects on different heights does not work correctly afaik.
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member Fozzey's Avatar
    Join Date
    Jan 2014
    Posts
    33
    Thanks given
    8
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Chivvon View Post
    If I recall correctly; the object 'system' server sided had some issues. Just check how "getObjects()" from World.java is filled and send on the OnRegionChangeListener. There were also some changes required in how the RegionManager checks if new objects exists. Also, spawning objects on different heights does not work correctly afaik.
    Thankyou very much for your response im going to check this stuff out now. Ill post any more error or if i get it working ill add it for others to see.

    Spoiler for ObjectManager:
    Code:
        /**
         * Handles what happens when a player enters a new region. We need to send all
         * the objects related to that region.
         *
         *   @Param player The player whose changing region.
         */
        public static void onRegionChange(Player player) {
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext(); ) {
                GameObject object = iterator.next();
                perform(object, OperationType.SPAWN);
            }
        }
    
        /**
         * Registers a {@link GameObject} to the world.
         *
         *   @Param object       The object being registered.
         *   @Param playerUpdate Should the send object packet be sent to nearby players?
         */
        public static void register(GameObject object, boolean playerUpdate) {
            // Check for matching object on this tile.
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext();) {
                GameObject o = iterator.next();
                if (o.getLocation().equals(object.getLocation()) && object.getPrivateArea() == o.getPrivateArea()) {
                    iterator.remove();
                }
            }
            World.getObjects().add(object);
            if (playerUpdate) {
                perform(object, OperationType.SPAWN);
            }
        }


    Spoiler for World.java:
    Code:
    	/**
    	 * Saves all players in the game.
    	 */
    	public static void savePlayers() {
    		players.forEach(PlayerSaving::save);
    	}
    
    	public static MobileList<Player> getPlayers() {
    		return players;
    	}
    
    	public static MobileList<NPC> getNpcs() {
    		return npcs;
    	}
    
    	public static List<ItemOnGround> getItems() {
    		return items;
    	}
    
    	public static List<GameObject> getObjects() { return objects; }
    
    	public static Queue<Player> getAddPlayerQueue() {
    		return addPlayerQueue;
    	}
    
    	public static Queue<Player> getRemovePlayerQueue() {
    		return removePlayerQueue;
    	}
    
    	public static Queue<NPC> getAddNPCQueue() {
    		return addNPCQueue;
    	}
    
    	public static Queue<NPC> getRemoveNPCQueue() {
    		return removeNPCQueue;
    	}
    }


    Spoiler for World.java:
    Code:
    	public static void process() {
    		// Process all active {@link Task}s..
    		TaskManager.process();


    Spoiler for world.java:
    Code:
    private static List<GameObject> objects = new LinkedList<>();


    Spoiler for RegionManager.java remove clipping for variable objects:
    Code:
     private static void removeClippingForVariableObject(int x, int y, int height, int type, int direction,
                                                            boolean flag, PrivateArea privateArea) {
            if (type == 0) {
                if (direction == 0) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x - 1, y, height, 0, privateArea);
                } else if (direction == 1) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x, y + 1, height, 0, privateArea);
                } else if (direction == 2) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x + 1, y, height, 0, privateArea);
                } else if (direction == 3) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x, y - 1, height, 0, privateArea);
                }
            } else if (type == 1 || type == 3) {
                if (direction == 0) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x - 1, y, height, 0, privateArea);
                } else if (direction == 1) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x + 1, y + 1, height, 0, privateArea);
                } else if (direction == 2) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x + 1, y - 1, height, 0, privateArea);
                } else if (direction == 3) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x - 1, y - 1, height, 0, privateArea);
                }
            } else if (type == 2) {
                if (direction == 0) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x - 1, y, height, 0, privateArea);
                    addClipping(x, y + 1, height, 0, privateArea);
                } else if (direction == 1) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x, y + 1, height, 0, privateArea);
                    addClipping(x + 1, y, height, 0, privateArea);
                } else if (direction == 2) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x + 1, y, height, 0, privateArea);
                    addClipping(x, y - 1, height, 0, privateArea);
                } else if (direction == 3) {
                    addClipping(x, y, height, 0, privateArea);
                    addClipping(x, y - 1, height, 0, privateArea);
                    addClipping(x - 1, y, height, 0, privateArea);
                }
            }
            if (flag) {
                if (type == 0) {
                    if (direction == 0) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x - 1, y, height, 0, privateArea);
                    } else if (direction == 1) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x, y + 1, height, 0, privateArea);
                    } else if (direction == 2) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x + 1, y, height, 0, privateArea);
                    } else if (direction == 3) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x, y - 1, height, 0, privateArea);
                    }
                }
                if (type == 1 || type == 3) {
                    if (direction == 0) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x - 1, y + 1, height, 0, privateArea);
                    } else if (direction == 1) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x + 1, y + 1, height, 0, privateArea);
                    } else if (direction == 2) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x + 1, y + 1, height, 0, privateArea);
                    } else if (direction == 3) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x - 1, y - 1, height, 0, privateArea);
                    }
                } else if (type == 2) {
                    if (direction == 0) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x - 1, y, height, 0, privateArea);
                        addClipping(x, y + 1, height, 0, privateArea);
                    } else if (direction == 1) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x, y + 1, height, 0, privateArea);
                        addClipping(x + 1, y, height, 0, privateArea);
                    } else if (direction == 2) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x + 1, y, height, 0, privateArea);
                        addClipping(x, y - 1, height, 0, privateArea);
                    } else if (direction == 3) {
                        addClipping(x, y, height, 0, privateArea);
                        addClipping(x, y - 1, height, 0, privateArea);
                        addClipping(x - 1, y, height, 0, privateArea);
                    }
                }
            }
        }



    This is what im looking at currently, right now i cant see any issues, mainly curious about this remove clipping from variable objects. I think this might be the cause as the object is deregistering and registering fine i think, its just the clipping change that's not registering. I believe this because multiple players can see the object update in real time.\
    Spoiler for dual player image:


    I think this is what Chivvon was talking about seeing if the object still exists.

    Spoiler for Checking if object exists:
    Code:
     /**
         * Checks if a {@link GameObject} exists at the given location.
         *
         * @Param position
         * @Return
         */
        public static boolean exists(Location position) {
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext(); ) {
                GameObject object = iterator.next();
                if (object.getLocation().equals(position)) {
                    return true;
                }
            }
            return false;
        }
    
        /**
         * Checks if a {@link GameObject} exists at the given location with the given
         * id.
         *
         * @Param position
         * @Return
         */
        public static boolean exists(int id, Location position) {
            Iterator<GameObject> iterator = World.getObjects().iterator();
            for (; iterator.hasNext(); ) {
                GameObject object = iterator.next();
                if (object.getLocation().equals(position)) {
                    if (object.getId() == id) {
                        return true;
                    }
                }
            }
            return false;
        }
    Reply With Quote  
     

  5. #4  
    Super Donator

    Chivvon's Avatar
    Join Date
    May 2016
    Posts
    487
    Thanks given
    68
    Thanks received
    139
    Rep Power
    249
    All the
    Code:
    addClipping(..)
    are wrong.
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member Fozzey's Avatar
    Join Date
    Jan 2014
    Posts
    33
    Thanks given
    8
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Chivvon View Post
    All the
    Code:
    addClipping(..)
    are wrong.
    Didn't even realise untill you said, got the clipping working now.


    my only issue is that i can only open the door on one side which i assume is the objects location square.
    Reply With Quote  
     

  8. #6  
    Super Donator

    Chivvon's Avatar
    Join Date
    May 2016
    Posts
    487
    Thanks given
    68
    Thanks received
    139
    Rep Power
    249
    Quote Originally Posted by Fozzey View Post
    Didn't even realise untill you said, got the clipping working now.


    my only issue is that i can only open the door on one side which i assume is the objects location square.
    Glad to hear it works. I don't quite understand your conclusion here. Please elaborate with more info for further help.
    Reply With Quote  
     

  9. #7  
    Registered Member Fozzey's Avatar
    Join Date
    Jan 2014
    Posts
    33
    Thanks given
    8
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Chivvon View Post
    Glad to hear it works. I don't quite understand your conclusion here. Please elaborate with more info for further help.
    This is my issues at the moment:

    Reply With Quote  
     

  10. #8  
    Super Donator

    Chivvon's Avatar
    Join Date
    May 2016
    Posts
    487
    Thanks given
    68
    Thanks received
    139
    Rep Power
    249
    Quote Originally Posted by Fozzey View Post
    This is my issues at the moment:

    Object validation is broken. Needs to be redone.
    Reply With Quote  
     

  11. #9  
    Registered Member Fozzey's Avatar
    Join Date
    Jan 2014
    Posts
    33
    Thanks given
    8
    Thanks received
    1
    Rep Power
    11
    Quote Originally Posted by Chivvon View Post
    Object validation is broken. Needs to be redone.
    Is that server or client sided, Im guessing i need to look into world.java, and objectMangager to fix object validation.
    Reply With Quote  
     

  12. #10  
    Registered Member
    Join Date
    Jan 2017
    Posts
    183
    Thanks given
    10
    Thanks received
    26
    Discord
    View profile
    Rep Power
    9
    its not updating the objects on region change

    you have sometihng similar to "updateregionobjects()" or whatever its called put that under the method that reads packet for region change
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. PI Adding Working Doors???
    By Fraddy in forum Help
    Replies: 8
    Last Post: 08-11-2011, 11:49 AM
  2. [PI] Working Doors [POSSIBLE $30]
    By Respected in forum Help
    Replies: 9
    Last Post: 12-07-2010, 11:49 PM
  3. [317]Adding Working Doors
    By v0xy in forum Tutorials
    Replies: 11
    Last Post: 08-23-2010, 11:24 AM
  4. [508] Working Doors
    By steth60 in forum Requests
    Replies: 6
    Last Post: 10-16-2008, 09:53 PM
  5. Moparscape v3 SOURCE CODE :O[Almost finshed]
    By arberb in forum Downloads
    Replies: 13
    Last Post: 12-24-2007, 06:48 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •