Package marauroa.common.game
Class RPObject
java.lang.Object
marauroa.common.game.Attributes
marauroa.common.game.SlotOwner
marauroa.common.game.RPObject
- All Implemented Interfaces:
Cloneable,Iterable<String>,Serializable
- Direct Known Subclasses:
Entity
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class stores the basic identification for a RPObject -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an event to this object and set event's owner to this object.voidAdds a new link to the object.voidAdds a new link to the object.voidadds a Map to this RPObjectvoidThis method add the slot to the objectvoidThis method add the slot to the objectvoidapplyDifferences(RPObject addedChanges, RPObject deletedChanges)With the differences computed by getDifferences in added and deleted we build an update object by applying the changes.voidEmpty the list of events.voidclearVisible(boolean sync)Removes the visible attributes and events from this object.clone()Create a depth copy of the objectbooleancontainsKey(String map, String key)check if a map of this object contains a keybooleanReturns true if two objects are exactly equalevents()Returns an unmodifiable list of the eventsIterate over the events listvoidCopy constructorRetrieves a valueReturns the base container where this object isbooleangetBoolean(String map, String key)Retrieves a valueReturns the container where this object isReturns the base container where this object isReturns the container where this object isReturns the slot where this object is containedvoidgetDifferences(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.doubleRetrieves a valuegetFromSlots(int id)Gets and object from the tree of RPSlots using its id ( that it is unique ).getID()Returns an ID object representing the id of this object.intRetrieves a valueReturns the link with given name or null if not found.getLinkedObject(String name)Return the linked object by the given link or null if the link doesn't exist.Retrieves a full map with the given nameThis method returns a slot whose name is namebooleanChecks if a map has an entryinthashCode()booleanReturns true if the object has that link.booleancheck if a map is present in this objectbooleanThis method returns true if the object has that slotvoidhide()Makes this object invisible, so it is not added in any perception.booleanReturns true if this object is contained inside another one.booleanisEmpty()Returns true if the object is emptybooleanisHidden()Return true if this object is hidden.booleanReturn true if the object should be stored at database.maps()gets all maps and their names as a mapvoidPuts a value for a key in a given mapvoidPuts a value for a key in a given mapvoidPuts a value for a key in a given mapvoidPuts a value for a key in a given mapvoidFills this object with the data that has been serialized.removes an entry from a mapremoveLink(String name)Removes a link from this object and return it.Remove a map from this RPObjectremoveSlot(String name)This method is used to remove an slot of the objectvoidClean delta^2 information about added and deleted.voidClean delta^2 data in the maps.voidClean delta^2 data in the links.voidClean delta^2 data in the slots.voidsetAddedMaps(RPObject object)adds the maps added in the specified object as maps to this objectvoidsetAddedRPSlot(RPObject object)Set added objects in slots for this object and fill object passed as param.voidsetContainer(SlotOwner slotOwner, RPSlot slot)This make this object to be contained in the slot of container.voidsetDeletedMaps(RPObject object)adds the maps deleted in the specified object as maps to this objectvoidsetDeletedRPSlot(RPObject object)Set deleted objects in slots for this object and fill object passed as param.voidsetID(RPObject.ID id)Sets the attributes that define the ID of the object.intsize()Returns the number of attributes and events this object is made of.slots()Returns an unmodifiable list of the slotsReturns a iterator over the slotsvoidstore()Define this object as storable, but it doesn't in fact store the object.toString()This method returns a String that represent the objectvoidunhide()Makes this object visible again.voidunstore()Declare that this object should not be stored at zones.voidwriteObject(OutputSerializer out)This method serialize the object with the default level of detail, that removes private and hidden attributesvoidwriteObject(OutputSerializer out, DetailLevel level)This method serialize the object with the given level of detail.voidwriteToJson(StringBuilder out, DetailLevel level)This method serialize the object with the given level of detail.Methods inherited from class marauroa.common.game.SlotOwner
deserializeRPSlots, fill, serializeRPSlotsMethods inherited from class marauroa.common.game.Attributes
add, applyDifferences, get, getBool, getDouble, getInt, getList, getLong, getRPClass, has, instanceOf, iterator, put, put, put, put, put, readFromMap, remove, resetAddedAndDeletedAttributes, setAddedAttributes, setDeletedAttributes, setRPClass, setRPClass, toAttributeStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
INVALID_ID
Defines an invalid object id
-
-
Constructor Details
-
RPObject
public RPObject()Constructor -
RPObject
Constructor- Parameters:
rpclass- of this object
-
RPObject
Constructor- Parameters:
rpclass- of this object
-
RPObject
Copy constructor- Parameters:
object- the object that is going to be copied.
-
-
Method Details
-
fill
Copy constructor- Parameters:
object- the object that is going to be copied.
-
getID
Returns an ID object representing the id of this object.- Returns:
- the identifier of the object
-
setID
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
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
Returns the container where this object is- Returns:
- the container of this object.
-
getBaseContainer
Returns the base container where this object is- Returns:
- the base container of this object.
-
getContainerOwner
Returns the container where this object is- Returns:
- the container of this object.
-
getContainerBaseOwner
Returns the base container where this object is- Returns:
- the base container of this object.
-
getContainerSlot
Returns the slot where this object is contained- Returns:
- the slot of the object that contains this object.
-
getFromSlots
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
This method add the slot to the object- Overrides:
addSlotin classSlotOwner- Parameters:
name- the RPSlot name to be added- Throws:
SlotAlreadyAddedException- if the slot already exists
-
addSlot
This method add the slot to the object- Overrides:
addSlotin classSlotOwner- Parameters:
slot- the RPSlot to be added- Throws:
SlotAlreadyAddedException- if the slot already exists
-
removeSlot
This method is used to remove an slot of the object- Overrides:
removeSlotin classSlotOwner- Parameters:
name- the name of the slot- Returns:
- the removed slot if it is found or null if it is not found.
-
addEvent
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
Iterate over the events list- Returns:
- an iterator over the events
-
events
Returns an unmodifiable list of the events- Returns:
- a list of the events
-
addLink
Adds a new link to the object.- Parameters:
name- the name of the linkobject- the object to link.
-
addLink
Adds a new link to the object.- Parameters:
link- the link to add.
-
getLink
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
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
Returns true if the object has that link.- Parameters:
name- the name of the link- Returns:
- true if the link exists.
-
removeLink
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
Puts a value for a key in a given map- Parameters:
map- the name of the map to put in the valuekey- the key to store for the valuevalue- the value
-
put
Puts a value for a key in a given map- Parameters:
map- the name of the map to put in the valuekey- the key to store for the valuevalue- the value
-
put
Puts a value for a key in a given map- Parameters:
map- the name of the map to put in the valuekey- the key to store for the valuevalue- the value
-
put
Puts a value for a key in a given map- Parameters:
map- the name of the map to put in the valuekey- the key to store for the valuevalue- the value
-
has
Checks if a map has an entry- Parameters:
map- the name of the map to search inkey- the key to search for- Returns:
- true, if the entry exists; false otherwise
-
get
Retrieves a value- Parameters:
map- the name of the map to search inkey- the key to search for- Returns:
- the value found
-
getInt
Retrieves a value- Parameters:
map- the name of the map to search inkey- the key to search for- Returns:
- the value found
-
getDouble
Retrieves a value- Parameters:
map- the name of the map to search inkey- the key to search for- Returns:
- the value found
-
getBoolean
Retrieves a value- Parameters:
map- the name of the map to search inkey- the key to search for- Returns:
- the value found
-
getMap
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
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
adds a Map to this RPObject- Parameters:
map-
-
remove
removes an entry from a map- Parameters:
map- the name of the mapkey- the key of the entry to remove- Returns:
- old value
-
maps
gets all maps and their names as a map- Returns:
- a map with key name of map and value the map itself
-
hasMap
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
check if a map of this object contains a key- Parameters:
map- the name of the mapkey- the key to check for- Returns:
- true iff map has a value stored for key
-
toString
This method returns a String that represent the object -
writeObject
This method serialize the object with the default level of detail, that removes private and hidden attributes- Specified by:
writeObjectin interfaceSerializable- Overrides:
writeObjectin classAttributes- Parameters:
out- the output serializer- Throws:
IOException- in case of an IO-error
-
writeObject
This method serialize the object with the given level of detail.- Overrides:
writeObjectin classAttributes- Parameters:
out- the output serializerlevel- the level of Detail- Throws:
IOException- in case of an IO error
-
writeToJson
This method serialize the object with the given level of detail.- Overrides:
writeToJsonin classSlotOwner- Parameters:
out- the output bufferlevel- the level of Detail
-
readObject
Fills this object with the data that has been serialized.- Specified by:
readObjectin interfaceSerializable- Overrides:
readObjectin classAttributes- Parameters:
in- the input serializer- Throws:
IOException- in case of unexpected attributes
-
equals
Returns true if two objects are exactly equal- Overrides:
equalsin classAttributes- Parameters:
obj- the object to compare with this one.- Returns:
- true if they are equal, or false otherwise.
-
hashCode
public int hashCode()- Overrides:
hashCodein classAttributes
-
isEmpty
public boolean isEmpty()Returns true if the object is empty- Overrides:
isEmptyin classAttributes- 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:
sizein classAttributes- 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:
clearVisiblein classAttributes- Parameters:
sync- keep the structure intact, by not removing empty slots and links.
-
clone
Create a depth copy of the object- Overrides:
clonein classAttributes- 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
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
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
adds the maps added in the specified object as maps to this object- Parameters:
object- RPObject to copy the added maps from
-
setDeletedMaps
adds the maps deleted in the specified object as maps to this object- Parameters:
object- RPObject to copy the deleted maps from
-
getDifferences
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 objectdeletedChanges- an empty object
-
applyDifferences
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 nulldeletedChanges- the deleted attributes and slots or null
-
hasSlot
This method returns true if the object has that slot -
getSlot
This method returns a slot whose name is name -
slotsIterator
Returns a iterator over the slots- Overrides:
slotsIteratorin classSlotOwner- Returns:
- an iterator over the slots
-
slots
Returns an unmodifiable list of the slots
-