1 /* $Id$ */ 2 /*************************************************************************** 3 * (C) Copyright 2003 - Marauroa * 4 *************************************************************************** 5 *************************************************************************** 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 ***************************************************************************/ 13 package games.stendhal.client.entity; 14 15 import marauroa.common.game.RPObject; 16 import marauroa.common.game.RPSlot; 17 18 /** 19 * A chest entity. 20 */ 21 public class Chest extends Entity { 22 /** 23 * Open state property. 24 */ 25 public static final Property PROP_OPEN = new Property(); 26 27 /** 28 * Whether the chest is currently open. 29 */ 30 private boolean open; 31 32 /** 33 * The current content slot. 34 */ 35 private RPSlot content; 36 37 /** 38 * Create a chest entity. 39 */ Chest()40 public Chest() { 41 } 42 43 // 44 // Chest 45 // 46 47 /** 48 * Get the chest contents. 49 * 50 * @return The contents slot. 51 */ getContent()52 public RPSlot getContent() { 53 return content; 54 } 55 56 /** 57 * Determine if the chest is open. 58 * 59 * @return <code>true</code> if the chest is open. 60 */ isOpen()61 public boolean isOpen() { 62 return open; 63 } 64 65 // 66 // Entity 67 // 68 69 /** 70 * Initialize this entity for an object. 71 * 72 * @param object 73 * The object. 74 * 75 * @see #release() 76 */ 77 @Override initialize(final RPObject object)78 public void initialize(final RPObject object) { 79 super.initialize(object); 80 81 if (object.hasSlot("content")) { 82 content = object.getSlot("content"); 83 } else { 84 content = null; 85 } 86 87 open = object.has("open"); 88 } 89 90 // 91 // RPObjectChangeListener 92 // 93 94 /** 95 * The object added/changed attribute(s). 96 * 97 * @param object 98 * The base object. 99 * @param changes 100 * The changes. 101 */ 102 @Override onChangedAdded(final RPObject object, final RPObject changes)103 public void onChangedAdded(final RPObject object, final RPObject changes) { 104 super.onChangedAdded(object, changes); 105 106 if (changes.has("open")) { 107 open = true; 108 fireChange(PROP_OPEN); 109 } 110 } 111 112 /** 113 * The object removed attribute(s). 114 * 115 * @param object 116 * The base object. 117 * @param changes 118 * The changes. 119 */ 120 @Override onChangedRemoved(final RPObject object, final RPObject changes)121 public void onChangedRemoved(final RPObject object, final RPObject changes) { 122 super.onChangedRemoved(object, changes); 123 124 if (changes.has("open")) { 125 open = false; 126 fireChange(PROP_OPEN); 127 } 128 } 129 } 130