1 /*************************************************************************** 2 * Copyright © 2020 - Arianne * 3 *************************************************************************** 4 *************************************************************************** 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 ***************************************************************************/ 12 package games.stendhal.client.entity; 13 14 import marauroa.common.game.RPObject; 15 16 17 public class BreakableRing extends Ring { 18 /** 19 * Working property. 20 */ 21 public static final Property PROP_WORKING = new Property(); 22 23 /** 24 * Whether the ring is currently working. 25 */ 26 private boolean working; 27 28 29 /** 30 * Create a BreakableRing entity. 31 */ BreakableRing()32 public BreakableRing() {} 33 34 /** 35 * Determine if a ring is working. 36 * 37 * @return <code>true</code> if a ring is working. 38 */ isWorking()39 public boolean isWorking() { 40 return working; 41 } 42 43 /** 44 * Initialize this entity for an object. 45 * 46 * @param object 47 * The object. 48 * 49 * @see #release() 50 */ 51 @Override initialize(final RPObject object)52 public void initialize(final RPObject object) { 53 super.initialize(object); 54 55 /* 56 * A ring works either by not having amount or having amount > 0 57 */ 58 if (object.has("amount")) { 59 working = object.getInt("amount") > 0; 60 } else { 61 working = true; 62 } 63 } 64 65 /** 66 * The object added/changed attribute(s). 67 * 68 * @param object 69 * The base object. 70 * @param changes 71 * The changes. 72 */ 73 @Override onChangedAdded(final RPObject object, final RPObject changes)74 public void onChangedAdded(final RPObject object, final RPObject changes) { 75 super.onChangedAdded(object, changes); 76 77 if (changes.has("amount")) { 78 /* 79 * A ring works either by not having amount of having amount > 0 80 */ 81 working = changes.getInt("amount") > 0; 82 fireChange(PROP_WORKING); 83 } 84 } 85 86 /** 87 * The object removed attribute(s). 88 * 89 * @param object 90 * The base object. 91 * @param changes 92 * The changes. 93 */ 94 @Override onChangedRemoved(final RPObject object, final RPObject changes)95 public void onChangedRemoved(final RPObject object, final RPObject changes) { 96 super.onChangedRemoved(object, changes); 97 98 if (changes.has("amount")) { 99 working = true; 100 fireChange(PROP_WORKING); 101 } 102 } 103 } 104