Thread: [718] Doors

Page 1 of 2 12 LastLast
Results 1 to 10 of 20
  1. #1 [718] Doors 
    Donator
    South-Park's Avatar
    Join Date
    Jul 2012
    Posts
    806
    Thanks given
    191
    Thanks received
    111
    Rep Power
    43
    Not sure if Matrix already had doors, but w.e.

    If any doors go poof or change to the wrong object when clicking, just add the door id into the SpecialDoors array and the door wont change object id's, only faces.

    Doors.java
    Code:
    package com.rs.game.content.objects;
    
    import java.util.ArrayList;
    
    import com.rs.game.World;
    import com.rs.game.WorldObject;
    
    /**
     * Manages all the doors in the game.
     * @author Thomas
     *
     */
    public class Doors {
    	
    	/**
    	 * Constructs a new door.
    	 * @param door The door we're managing.
    	 */
    	public Doors(WorldObject door) {
    		this.object = door;
    		this.originalId = object.getId();
    		this.currentId = object.getId();
    		this.originalX = object.getX();
    		this.originalY = object.getY();
    		this.currentX = originalX;
    		this.currentY = originalY;
    		this.originalRotation = object.getRotation();
    		this.currentRotation = originalRotation;
    		this.open = object.getDefinitions().getFirstOption().equalsIgnoreCase("close");
    	}
    
    	/**
    	 * The door we're managing.
    	 */
    	private WorldObject object;
    	
    	/**
    	 * The doors original object id.
    	 */
    	private int originalId;
    	
    	/**
    	 * The doors current object id.
    	 */
    	private int currentId;
    	
    	/**
    	 * The doors original x coordinate.
    	 */
    	private int originalX;
    	
    	/**
    	 * The doors original y coordinate.
    	 */
    	private int originalY;
    	
    	/**
    	 * The doors current x coordinate.
    	 */
    	private int currentX;
    	
    	/**
    	 * The doors current y coordinate.
    	 */
    	private int currentY;
    	
    	/**
    	 * The doors original rotation.
    	 */
    	private int originalRotation;
    	
    	/**
    	 * The doors current rotation.
    	 */
    	private int currentRotation;
    	
    	/**
    	 * Is the door open?
    	 */
    	private boolean open;
    	
    	/**
    	 * An array of all the doors.
    	 */
    	private static ArrayList<Doors> doors = new ArrayList<Doors>();
    	
    	/**
    	 * An array list of special doors (these doors do not change object id's).
    	 */
    	private static final int[] SpecialDoors = {3014, 24375, 24374, 24379, 24378, 15536};
    	
    	/**
    	 * Gets the door to manage.
    	 * @param door The door to manage.
    	 * @return The <code>Doors</code>.
    	 */
    	private static Doors getDoor(WorldObject door) {
    		for (Doors d : doors) {
    			if (d != null)
    				if (d.currentId == door.getId() && d.currentX == door.getX() && d.currentY == door.getY()) {
    					return d;
    				}
    		}
    		Doors d = new Doors(door);
    		doors.add(d);
    		return d;
    	}
    	
    	/**
    	 * Manages a door.
    	 * @param door The door we're managing.
    	 */
    	public static void manageDoor(WorldObject door) {
    		Doors d = getDoor(door);
    		if (d == null)
    			return;
    		int xAdjustment = 0, yAdjustment = 0;
    		if (d.object.getType() == 0) {
    			if (!d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					xAdjustment = -1;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					yAdjustment = 1;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					yAdjustment = -1;
    				}
    			} else if (d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					yAdjustment = 1;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					yAdjustment = -1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					xAdjustment = -1;
    				}
    			}
    		} else if (d.object.getType() == 9) {
    			if (!d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					xAdjustment = -1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					xAdjustment = -1;
    				}
    			} else if (d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					xAdjustment = 1;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					xAdjustment = -1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					xAdjustment = -1;
    				}
    			}
    		}
    		if (d.originalX == d.currentX && d.originalY == d.currentY) {
    			d.currentX += xAdjustment;
    			d.currentY += yAdjustment;
    		} else {
    			d.currentX = d.originalX;
    			d.currentY = d.originalY;
    		}
    		if (d.currentId == d.originalId) {
    			if (!d.open) {
    				d.currentId += 1;
    			} else if (d.open) {
    				d.currentId -= 1;
    			}
    		} else if (d.currentId != d.originalId) {
    			if (!d.open) {
    				d.currentId -= 1;
    			} else if (d.open) {
    				d.currentId += 1;
    			}
    		}
    		for (int i = 0; i < SpecialDoors.length; i++) {
    			if (d.originalId == SpecialDoors[i])
    				d.currentId = d.originalId;
    		}
    		if (d.object.getType() == 0) {
    			if (!d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					d.currentRotation = 1;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					d.currentRotation = 2;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					d.currentRotation = 3;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					d.currentRotation = 0;
    				} else if (d.originalRotation != d.currentRotation) {
    					d.currentRotation = d.originalRotation;
    				}
    			} else if (d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					d.currentRotation = 3;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					d.currentRotation = 0;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					d.currentRotation = 1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					d.currentRotation = 2;
    				} else if (d.originalRotation != d.currentRotation) {
    					d.currentRotation = d.originalRotation;
    				}
    			}
    		} else if (d.object.getType() == 9) {
    			if (!d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					d.currentRotation = 3;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					d.currentRotation = 2;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					d.currentRotation = 1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					d.currentRotation = 0;
    				} else if (d.originalRotation != d.currentRotation) {
    					d.currentRotation = d.originalRotation;
    				}
    			} else if (d.open) {
    				if (d.originalRotation == 0 && d.currentRotation == 0) {
    					d.currentRotation = 3;
    				} else if (d.originalRotation == 1 && d.currentRotation == 1) {
    					d.currentRotation = 0;
    				} else if (d.originalRotation == 2 && d.currentRotation == 2) {
    					d.currentRotation = 1;
    				} else if (d.originalRotation == 3 && d.currentRotation == 3) {
    					d.currentRotation = 2;
    				} else if (d.originalRotation != d.currentRotation) {
    					d.currentRotation = d.originalRotation;
    				}
    			}
    		}
    		World.removeObject(door, true);
    		World.spawnObject(new WorldObject(d.currentId, d.object.getType(), d.currentRotation, d.currentX, d.currentY, d.object.getPlane()), true);
    	}
    	
    	/**
    	 * Is the object a door?
    	 * @param name The object name.
    	 * @return If yes <code>true</code>, if no <code>false</code>.
    	 */
    	public static boolean isDoor(String name) {
    		return name.equals("Door");
    	}
    	
    }
    In ObjectHandler.java
    Code:
    if (Doors.isDoor(object.getDefinitions().name)) {
    					Doors.manageDoor(object);
    				}
    Spoiler for Door updating fix:

    Go into World.java in the method public static final void updateEntityRegion(Entity entity) at the bottom you should see:
    Code:
    } else {
    			if (entity instanceof Player) {
    				Player player = (Player) entity;
    Add this:
    Code:
    Region region = getRegion(regionId);
    				if (region.getSpawnedObjects() != null) {
    					for (WorldObject object : region.getSpawnedObjects()) {
    						if (object != null) {
    							player.getPackets().sendDestroyObject(object);
    							player.getPackets().sendSpawnedObject(object);
    						}
    					}
    				}
    Then go to the method public static final void removeObject(WorldObject object, boolean clip) Still in World.java and add this:
    Code:
    getRegion(regionId).removeObject(object);
    Above this:
    Code:
    getRegion(regionId).addRemovedObject(object);
    Lastly go into Region.java and replace
    Code:
    private List<WorldObject> spawnedObjects;
    With
    Code:
    private static List<WorldObject> spawnedObjects;


    The community these days makes my lol.

    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member Mariooo's Avatar
    Join Date
    Aug 2012
    Age
    27
    Posts
    161
    Thanks given
    22
    Thanks received
    14
    Rep Power
    11
    Thanks!
    AlRS
    Reply With Quote  
     

  4. #3  
    Donator
    South-Park's Avatar
    Join Date
    Jul 2012
    Posts
    806
    Thanks given
    191
    Thanks received
    111
    Rep Power
    43
    Quote Originally Posted by AlterOPSnet View Post
    Thanks!
    No problem. Will release double doors and gates once I've got them added.


    The community these days makes my lol.

    Reply With Quote  
     

  5. #4  
    Myre


    Join Date
    Apr 2012
    Age
    26
    Posts
    1,519
    Thanks given
    407
    Thanks received
    367
    Rep Power
    475
    Good contribution, although why do you post 718 when you run 2006remade? shouldn't you be working on that?
    Or are you abandoning it..
    Reply With Quote  
     

  6. Thankful users:


  7. #5  
    Donator
    South-Park's Avatar
    Join Date
    Jul 2012
    Posts
    806
    Thanks given
    191
    Thanks received
    111
    Rep Power
    43
    Quote Originally Posted by iRize View Post
    Good contribution, although why do you post 718 when you run 2006remade? shouldn't you be working on that?
    Or are you abandoning it..
    No, I'm just playing around with 718.


    The community these days makes my lol.

    Reply With Quote  
     

  8. #6  
    Developer


    Join Date
    Aug 2012
    Posts
    2,493
    Thanks given
    180
    Thanks received
    1,732
    Rep Power
    2487
    Goodjob, with the release of perfect doors, RSPS will start progressing again.
    Reply With Quote  
     

  9. Thankful users:


  10. #7  
    Donator
    South-Park's Avatar
    Join Date
    Jul 2012
    Posts
    806
    Thanks given
    191
    Thanks received
    111
    Rep Power
    43
    Door updating fixed.

    Go into World.java in the method public static final void updateEntityRegion(Entity entity) at the bottom you should see:
    Code:
    } else {
    			if (entity instanceof Player) {
    				Player player = (Player) entity;
    Add this:
    Code:
    Region region = getRegion(regionId);
    				if (region.getSpawnedObjects() != null) {
    					for (WorldObject object : region.getSpawnedObjects()) {
    						if (object != null) {
    							player.getPackets().sendDestroyObject(object);
    							player.getPackets().sendSpawnedObject(object);
    						}
    					}
    				}
    Then go to the method public static final void removeObject(WorldObject object, boolean clip) Still in World.java and add this:
    Code:
    getRegion(regionId).removeObject(object);
    Above this:
    Code:
    getRegion(regionId).addRemovedObject(object);
    Lastly go into Region.java and replace
    Code:
    private List<WorldObject> spawnedObjects;
    With
    Code:
    private static List<WorldObject> spawnedObjects;


    The community these days makes my lol.

    Reply With Quote  
     

  11. Thankful user:


  12. #8  
    Developer [Java/Python/C++] Chrysus's Avatar
    Join Date
    Dec 2013
    Posts
    6
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Awesome!

    No errors, the doors can now open and close. The fix for disappearing doors also worked.

    Just as a note for others:
    My base used the object handler class to process doors, if yours does the same, just create a new class called Doors and copy the code from the first post into there and change the package. Eclipse should point you in the right direction from there.
    Reply With Quote  
     

  13. #9  
    Registered Member
    Join Date
    Aug 2011
    Posts
    396
    Thanks given
    29
    Thanks received
    57
    Rep Power
    9
    you shouldn't make
    private List<WorldObject> spawnedObjects;
    static because that interferes with logging in.
    Reply With Quote  
     

  14. #10  
    Donator
    South-Park's Avatar
    Join Date
    Jul 2012
    Posts
    806
    Thanks given
    191
    Thanks received
    111
    Rep Power
    43
    Quote Originally Posted by CheaterXman View Post
    you shouldn't make static because that interferes with logging in.
    What are you talking about? You have to make it static or they doors will not save if you relog...


    The community these days makes my lol.

    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. [718] Door Killcount Help!
    By Edimmu in forum Help
    Replies: 2
    Last Post: 11-24-2013, 01:09 AM
  2. Dungeoneering Door code 718
    By the fuzziferus in forum Requests
    Replies: 0
    Last Post: 03-11-2013, 04:00 AM
  3. 718 Door Open Close Automatic
    By Overlord561 in forum Help
    Replies: 0
    Last Post: 02-21-2013, 01:08 AM
  4. [718] Dung doors
    By helpMe in forum Help
    Replies: 4
    Last Post: 12-04-2012, 09:41 PM
  5. Fire door (718)
    By gl til i die in forum Help
    Replies: 3
    Last Post: 10-29-2012, 11:53 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
  •