Class RPObject

All Implemented Interfaces:
Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
Entity

public class RPObject extends SlotOwner
This class implements an Object.

An object is the basic abstraction at marauroa. Players are objects, creatures are objects, the maze at pacman is an object, each gladiator is an object... everything is an object.
But don't get confused with all the object keyword usage out there. An object is anything that can be though as an object ( physical or logical thing ).

Objects are stored at IRPZones.

Objects contains:

  • RPSlots
  • RPLinks
  • RPEvents
  • Field Details

    • INVALID_ID

      public static final RPObject.ID INVALID_ID
      Defines an invalid object id
  • Constructor Details

    • RPObject

      public RPObject()
      Constructor
    • RPObject

      public RPObject(RPClass rpclass)
      Constructor
      Parameters:
      rpclass - of this object
    • RPObject

      public RPObject(String rpclass)
      Constructor
      Parameters:
      rpclass - of this object
    • RPObject

      public RPObject(RPObject object)
      Copy constructor
      Parameters:
      object - the object that is going to be copied.
  • Method Details

    • fill

      public void fill(RPObject object)
      Copy constructor
      Parameters:
      object - the object that is going to be copied.
    • getID

      public RPObject.ID getID()
      Returns an ID object representing the id of this object.
      Returns:
      the identifier of the object
    • setID

      public void setID(RPObject.ID id)
      Sets the attributes that define the ID of the object.
      Parameters:
      id - the object id to set for this object
    • hide

      public void hide()
      Makes this object invisible, so it is not added in any perception. This method is not callable directly from the object once it has been added to a zone. If it is already added, this method must be called from IRPZone.hide()
    • unhide

      public void unhide()
      Makes this object visible again. This method is not callable directly from the object once it has been added to a zone. If it is already added, this method must be called from IRPZone.unhide()
    • isHidden

      public boolean isHidden()
      Return true if this object is hidden.
      Returns:
      true if this object is hidden.
    • store

      public void store()
      Define this object as storable, but it doesn't in fact store the object. The object is stored on zone.finish
    • unstore

      public void unstore()
      Declare that this object should not be stored at zones.
    • isStorable

      public boolean isStorable()
      Return true if the object should be stored at database.
      Returns:
      true if the object should be stored at database.
    • isContained

      public boolean isContained()
      Returns true if this object is contained inside another one.
      Returns:
      true if this object is contained inside another one.
    • setContainer

      public void setContainer(SlotOwner slotOwner, RPSlot slot)
      This make this object to be contained in the slot of container.
      Parameters:
      slotOwner - the object that is going to contain this object.
      slot - the slot of the object that contains this object.
    • getContainer

      public RPObject getContainer()
      Returns the container where this object is
      Returns:
      the container of this object.
    • getBaseContainer

      public RPObject getBaseContainer()
      Returns the base container where this object is
      Returns:
      the base container of this object.
    • getContainerOwner

      public SlotOwner getContainerOwner()
      Returns the container where this object is
      Returns:
      the container of this object.
    • getContainerBaseOwner

      public SlotOwner getContainerBaseOwner()
      Returns the base container where this object is
      Returns:
      the base container of this object.
    • getContainerSlot

      public RPSlot getContainerSlot()
      Returns the slot where this object is contained
      Returns:
      the slot of the object that contains this object.
    • getFromSlots

      public RPObject getFromSlots(int id)
      Gets and object from the tree of RPSlots using its id ( that it is unique ). Return null if it is not found.
      Parameters:
      id - the id of the object to look for.
      Returns:
      RPObject
    • addSlot

      public void addSlot(String name) throws SlotAlreadyAddedException
      This method add the slot to the object
      Overrides:
      addSlot in class SlotOwner
      Parameters:
      name - the RPSlot name to be added
      Throws:
      SlotAlreadyAddedException - if the slot already exists
    • addSlot

      public void addSlot(RPSlot slot) throws SlotAlreadyAddedException
      This method add the slot to the object
      Overrides:
      addSlot in class SlotOwner
      Parameters:
      slot - the RPSlot to be added
      Throws:
      SlotAlreadyAddedException - if the slot already exists
    • removeSlot

      public RPSlot removeSlot(String name)
      This method is used to remove an slot of the object
      Overrides:
      removeSlot in class SlotOwner
      Parameters:
      name - the name of the slot
      Returns:
      the removed slot if it is found or null if it is not found.
    • addEvent

      public void addEvent(RPEvent event)
      Add an event to this object and set event's owner to this object.
      Parameters:
      event - the event to add.
    • clearEvents

      public void clearEvents()
      Empty the list of events. This method is called at the end of each turn.
    • eventsIterator

      public Iterator<RPEvent> eventsIterator()
      Iterate over the events list
      Returns:
      an iterator over the events
    • events

      public List<RPEvent> events()
      Returns an unmodifiable list of the events
      Returns:
      a list of the events
    • addLink

      public void addLink(String name, RPObject object)
      Adds a new link to the object.
      Parameters:
      name - the name of the link
      object - the object to link.
    • addLink

      public void addLink(RPLink link)
      Adds a new link to the object.
      Parameters:
      link - the link to add.
    • getLink

      public RPLink getLink(String name)
      Returns the link with given name or null if not found.
      Parameters:
      name - the name of the link to find.
      Returns:
      the link with given name or null if not found.
    • getLinkedObject

      public RPObject getLinkedObject(String name)
      Return the linked object by the given link or null if the link doesn't exist.
      Parameters:
      name - the name of the link.
      Returns:
      the object linked by the given link.
    • hasLink

      public boolean hasLink(String name)
      Returns true if the object has that link.
      Parameters:
      name - the name of the link
      Returns:
      true if the link exists.
    • removeLink

      public RPLink removeLink(String name)
      Removes a link from this object and return it.
      Parameters:
      name - the name of the link to remove.
      Returns:
      the removed link or null if it was not found.
    • put

      public void put(String map, String key, String value)
      Puts a value for a key in a given map
      Parameters:
      map - the name of the map to put in the value
      key - the key to store for the value
      value - the value
    • put

      public void put(String map, String key, int value)
      Puts a value for a key in a given map
      Parameters:
      map - the name of the map to put in the value
      key - the key to store for the value
      value - the value
    • put

      public void put(String map, String key, double value)
      Puts a value for a key in a given map
      Parameters:
      map - the name of the map to put in the value
      key - the key to store for the value
      value - the value
    • put

      public void put(String map, String key, boolean value)
      Puts a value for a key in a given map
      Parameters:
      map - the name of the map to put in the value
      key - the key to store for the value
      value - the value
    • has

      public boolean has(String map, String key)
      Checks if a map has an entry
      Parameters:
      map - the name of the map to search in
      key - the key to search for
      Returns:
      true, if the entry exists; false otherwise
    • get

      public String get(String map, String key)
      Retrieves a value
      Parameters:
      map - the name of the map to search in
      key - the key to search for
      Returns:
      the value found
    • getInt

      public int getInt(String map, String key)
      Retrieves a value
      Parameters:
      map - the name of the map to search in
      key - the key to search for
      Returns:
      the value found
    • getDouble

      public double getDouble(String map, String key)
      Retrieves a value
      Parameters:
      map - the name of the map to search in
      key - the key to search for
      Returns:
      the value found
    • getBoolean

      public boolean getBoolean(String map, String key)
      Retrieves a value
      Parameters:
      map - the name of the map to search in
      key - the key to search for
      Returns:
      the value found
    • getMap

      public Map<String,​String> getMap(String map)
      Retrieves a full map with the given name
      Parameters:
      map - the name of the map
      Returns:
      a copy of the map or null if no map with the given name is present
    • removeMap

      public Attributes removeMap(String map)
      Remove a map from this RPObject
      Parameters:
      map - the name of the map to remove
      Returns:
      the RPObject representing the map or null if map not existing
    • addMap

      public void addMap(String map)
      adds a Map to this RPObject
      Parameters:
      map -
    • remove

      public String remove(String map, String key)
      removes an entry from a map
      Parameters:
      map - the name of the map
      key - the key of the entry to remove
      Returns:
      old value
    • maps

      public Map<String,​Map<String,​String>> maps()
      gets all maps and their names as a map
      Returns:
      a map with key name of map and value the map itself
    • hasMap

      public boolean hasMap(String map)
      check if a map is present in this object
      Parameters:
      map - the name of the map
      Returns:
      true iff this objects has a map with that name
    • containsKey

      public boolean containsKey(String map, String key)
      check if a map of this object contains a key
      Parameters:
      map - the name of the map
      key - the key to check for
      Returns:
      true iff map has a value stored for key
    • toString

      public String toString()
      This method returns a String that represent the object
      Overrides:
      toString in class SlotOwner
      Returns:
      a string representing the object.
    • writeObject

      public void writeObject(OutputSerializer out) throws IOException
      This method serialize the object with the default level of detail, that removes private and hidden attributes
      Specified by:
      writeObject in interface Serializable
      Overrides:
      writeObject in class Attributes
      Parameters:
      out - the output serializer
      Throws:
      IOException - in case of an IO-error
    • writeObject

      public void writeObject(OutputSerializer out, DetailLevel level) throws IOException
      This method serialize the object with the given level of detail.
      Overrides:
      writeObject in class Attributes
      Parameters:
      out - the output serializer
      level - the level of Detail
      Throws:
      IOException - in case of an IO error
    • writeToJson

      public void writeToJson(StringBuilder out, DetailLevel level)
      This method serialize the object with the given level of detail.
      Overrides:
      writeToJson in class SlotOwner
      Parameters:
      out - the output buffer
      level - the level of Detail
    • readObject

      public void readObject(InputSerializer in) throws IOException
      Fills this object with the data that has been serialized.
      Specified by:
      readObject in interface Serializable
      Overrides:
      readObject in class Attributes
      Parameters:
      in - the input serializer
      Throws:
      IOException - in case of unexpected attributes
    • equals

      public boolean equals(Object obj)
      Returns true if two objects are exactly equal
      Overrides:
      equals in class Attributes
      Parameters:
      obj - the object to compare with this one.
      Returns:
      true if they are equal, or false otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Attributes
    • isEmpty

      public boolean isEmpty()
      Returns true if the object is empty
      Overrides:
      isEmpty in class Attributes
      Returns:
      true if the object lacks of any attribute, slots, maps or events.
    • size

      public int size()
      Returns the number of attributes and events this object is made of.
      Overrides:
      size in class Attributes
      Returns:
      amount of attributes
    • clearVisible

      public void clearVisible(boolean sync)
      Removes the visible attributes and events from this object. It iterates through the slots to remove the attributes too of the contained objects if they are empty.
      Overrides:
      clearVisible in class Attributes
      Parameters:
      sync - keep the structure intact, by not removing empty slots and links.
    • clone

      public Object clone()
      Create a depth copy of the object
      Overrides:
      clone in class Attributes
      Returns:
      a copy of this object.
    • resetAddedAndDeleted

      public void resetAddedAndDeleted()
      Clean delta^2 information about added and deleted. It also empty the event list. It is called by Marauroa, don't use :)
    • resetAddedAndDeletedRPSlot

      public void resetAddedAndDeletedRPSlot()
      Clean delta^2 data in the slots. It is called by Marauroa, don't use :)
    • resetAddedAndDeletedRPLink

      public void resetAddedAndDeletedRPLink()
      Clean delta^2 data in the links. It is called by Marauroa, don't use :)
    • resetAddedAndDeletedMaps

      public void resetAddedAndDeletedMaps()
      Clean delta^2 data in the maps. It is called by Marauroa, don't use :)
    • setAddedRPSlot

      public void setAddedRPSlot(RPObject object)
      Set added objects in slots for this object and fill object passed as param. * It is called by Marauroa, don't use :)
      Parameters:
      object - the object to fill with added data.
    • setDeletedRPSlot

      public void setDeletedRPSlot(RPObject object)
      Set deleted objects in slots for this object and fill object passed as param. * It is called by Marauroa, don't use :)
      Parameters:
      object - the object to fill with deleted data.
    • setAddedMaps

      public void setAddedMaps(RPObject object)
      adds the maps added in the specified object as maps to this object
      Parameters:
      object - RPObject to copy the added maps from
    • setDeletedMaps

      public void setDeletedMaps(RPObject object)
      adds the maps deleted in the specified object as maps to this object
      Parameters:
      object - RPObject to copy the deleted maps from
    • getDifferences

      public void getDifferences(RPObject addedChanges, RPObject deletedChanges)
      Retrieve the differences stored in this object and add them to two new objects added changes and delete changes that will contains added and modified attributes, slots and events and on the other hand deleted changes that will contain the removes slots and attributes. We don't care about RP Events because they are removed on each turn.
      Parameters:
      addedChanges - an empty object
      deletedChanges - an empty object
    • applyDifferences

      public void applyDifferences(RPObject addedChanges, RPObject deletedChanges)
      With the differences computed by getDifferences in added and deleted we build an update object by applying the changes.
      Parameters:
      addedChanges - the added and modified attributes, slots and events or null
      deletedChanges - the deleted attributes and slots or null
    • hasSlot

      public boolean hasSlot(String name)
      This method returns true if the object has that slot
      Overrides:
      hasSlot in class SlotOwner
      Parameters:
      name - the name of the slot
      Returns:
      true if slot exists or false otherwise
    • getSlot

      public RPSlot getSlot(String name)
      This method returns a slot whose name is name
      Overrides:
      getSlot in class SlotOwner
      Parameters:
      name - the name of the slot
      Returns:
      the slot or null if the slot is not found
    • slotsIterator

      public Iterator<RPSlot> slotsIterator()
      Returns a iterator over the slots
      Overrides:
      slotsIterator in class SlotOwner
      Returns:
      an iterator over the slots
    • slots

      public List<RPSlot> slots()
      Returns an unmodifiable list of the slots
      Overrides:
      slots in class SlotOwner
      Returns:
      a list of the slots