From: Hendrik <nh...@us...> - 2006-10-18 20:25:51
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/portal In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv22908/src/games/stendhal/server/entity/portal Modified Files: LockedDoor.java Door.java Log Message: moved key handling from Door.java to LockedDoor.java Index: LockedDoor.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/portal/LockedDoor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LockedDoor.java 18 Oct 2006 20:03:36 -0000 1.1 --- LockedDoor.java 18 Oct 2006 20:25:39 -0000 1.2 *************** *** 14,19 **** import games.stendhal.common.Direction; import games.stendhal.server.events.TurnListener; ! import marauroa.common.game.AttributeNotFoundException; /** --- 14,20 ---- import games.stendhal.common.Direction; + import games.stendhal.server.entity.RPEntity; import games.stendhal.server.events.TurnListener; ! import games.stendhal.server.events.TurnNotifier; /** *************** *** 27,34 **** */ public class LockedDoor extends Door implements TurnListener { ! ! public LockedDoor(String key, String clazz, Direction dir) ! throws AttributeNotFoundException { ! super(key, clazz, dir); } } --- 28,82 ---- */ public class LockedDoor extends Door implements TurnListener { ! ! /** ! * How many turns it takes until door automatically closes itself ! * after somebody walked through it. ! */ ! private static final int TURNS_TO_STAY_OPEN = 9; /* 3 seconds */ ! ! /** ! * Creates a new locked door. ! * ! * @param key name of required key ! * @param clazz class of door ! * @param dir direction of door ! */ ! public LockedDoor(String key, String clazz, Direction dir) { ! super(clazz, dir); ! put("locked", key); ! } ! ! @Override ! public void onUsed(RPEntity user) { ! if (has("locked") && user.isEquipped(get("locked"))) { ! TurnNotifier turnNotifier = TurnNotifier.get(); ! if (isOpen()) { ! // The door is still open because another player just used it. ! // Thus, it is scheduled to auto-close soon. We delay this ! // auto-closing. ! turnNotifier.dontNotify(this, null); ! } else { ! open(); ! } ! ! // register automatic close ! turnNotifier.notifyInTurns(TURNS_TO_STAY_OPEN, this, null); ! ! } else { // player may not use it ! if (isOpen()) { ! // close now to make visible that the entity is not allowed ! // to pass ! close(); ! return; ! } ! } ! ! super.onUsed(user); } + + public void onTurnReached(int currentTurn, String message) { + close(); + notifyWorldAboutChanges(); + } + } Index: Door.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/server/entity/portal/Door.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Door.java 7 Oct 2006 09:27:19 -0000 1.6 --- Door.java 18 Oct 2006 20:25:39 -0000 1.7 *************** *** 15,20 **** import games.stendhal.common.Direction; import games.stendhal.server.entity.RPEntity; - import games.stendhal.server.events.TurnListener; - import games.stendhal.server.events.TurnNotifier; import java.awt.geom.Rectangle2D; --- 15,18 ---- *************** *** 24,50 **** /** ! * A door is a special kind of portal which requires a key to pass it. ! * If the player carries the key with him, he can use the door just ! * like a normal portal; it will automatically open and close. ! * * Note that you can link a door with a portal; that way, people only * require the key when walking in one direction and can walk in the * other direction without any key. */ ! public class Door extends Portal implements TurnListener { ! /** Whether or not the door is currently open */ private boolean open; - - /** - * How many turns it takes until door automatically closes itself - * after somebody walked through it. - */ - private static final int TURNS_TO_STAY_OPEN = 9; /* 3 seconds */ - - /** - * The turn at which this door should close the next time. - */ - // private int turnToClose = 0; public static void generateRPClass() { --- 22,35 ---- /** ! * A door is a special kind of portal which can be open or closed. ! * * Note that you can link a door with a portal; that way, people only * require the key when walking in one direction and can walk in the * other direction without any key. */ ! public class Door extends Portal { ! /** Whether or not the door is currently open */ private boolean open; public static void generateRPClass() { *************** *** 58,62 **** /** * Creates a new door. - * @param key The item that must be carried to pass through this door * @param clazz The class. Responsible for how this door looks like. * @param dir The direction in which one has to walk in order to pass --- 43,46 ---- *************** *** 64,73 **** * @throws AttributeNotFoundException */ ! public Door(String key, String clazz, Direction dir) ! throws AttributeNotFoundException { super(); put("type", "door"); put("class", clazz); - put("locked", key); setDirection(dir); --- 48,55 ---- * @throws AttributeNotFoundException */ ! public Door(String clazz, Direction dir) { super(); put("type", "door"); put("class", clazz); setDirection(dir); *************** *** 90,103 **** * Opens the door. */ ! private void open() { ! TurnNotifier turnNotifier = TurnNotifier.get(); ! if (open) { ! // The door is still open because another player just used it. ! // Thus, it is scheduled to auto-close soon. We delay this ! // auto-closing. ! turnNotifier.dontNotify(this, null); ! } ! turnNotifier.notifyInTurns(TURNS_TO_STAY_OPEN, this, null); ! open = true; put("open", ""); --- 72,76 ---- * Opens the door. */ ! protected void open() { open = true; put("open", ""); *************** *** 108,112 **** * Closes the door. */ ! private void close() { this.open = false; remove("open"); --- 81,85 ---- * Closes the door. */ ! protected void close() { this.open = false; remove("open"); *************** *** 114,134 **** } ! private boolean isOpen() { return open; } ! @Override public void onUsed(RPEntity user) { ! if (has("locked") && user.isEquipped(get("locked"))) { ! // open it, even it is already open to reset the auto-close ! // countdown. ! open(); ! } else if (open) { ! // close now to make visible that the entity is not allowed ! // to pass ! close(); ! return; ! } ! if (open) { super.onUsed(user); } --- 87,100 ---- } ! protected boolean isOpen() { return open; } ! ! /** ! * teleport (if the door is now open) ! */ public void onUsed(RPEntity user) { ! if (isOpen()) { super.onUsed(user); } *************** *** 151,158 **** } - public void onTurnReached(int currentTurn, String message) { - close(); - notifyWorldAboutChanges(); - } - } --- 117,119 ---- |