Class RPClass

java.lang.Object
marauroa.common.game.RPClass
All Implemented Interfaces:
Serializable

public class RPClass extends Object implements Serializable
An RPClass is a entity that define the attributes, events and slots of an Object. TODO: Creating a new RPClass does in fact add it to a global list of RPClasses. Search for a way of making this in a different way so test added for equality works.

The idea behind RPClass is not define members as a OOP language but to save bandwidth usage by replacing these members text definitions with a short integer.

Also RPClass define a set of properties over attributes, events and slots, like being private, hidden or volatile.

It is very important that if you extend a class with isA, you completely define the superclass before calling isA method.
For example:

   RPClass foo=new RPClass("foo");
   foo.add(....)
   foo.add(....)
   foo.add(....)

   RPClass bar=new RPClass("bar");
   bar.isA(foo);
   bar.add(....)
   bar.add(....)
 
Author:
miguel
See Also:
Definition
  • Constructor Details

    • RPClass

      public RPClass()
      Constructor Only used in serialization.
    • RPClass

      public RPClass(String name)
      Constructor. It adds the RPClass to a global list of rp classes.
      Parameters:
      name - the class name
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasRPClass

      public static boolean hasRPClass(String name)
      Returns true if the global list contains the name rpclass
      Parameters:
      name - the class name to query
      Returns:
      true if the global list contains the name rpclass
    • getRPClass

      public static RPClass getRPClass(String name)
      Returns the name rpclass from the global list
      Parameters:
      name - the name of the class
      Returns:
      the class or null if it doesn't exist.
    • isA

      public void isA(RPClass parent)
      This method sets the parent of this rpclass
      Parameters:
      parent - the super class of this class.
    • isA

      public void isA(String parent)
      This method sets the parent of this rpclass
      Parameters:
      parent - the super class of this class.
    • subclassOf

      public boolean subclassOf(String parentClass)
      This method returns true if it is a subclass of parentClass or if it is the class itself.
      Parameters:
      parentClass - the super class of this class
      Returns:
      true if it is a subclass of parentClass or if it is the class itself.
    • getName

      public String getName()
      Returns the name of the rpclass
      Returns:
      the name of the rpclass
    • getParent

      public RPClass getParent()
      gets the parent class or null if this is a root class.
      Returns:
      RPClass or null.
    • add

      public void add(Definition.DefinitionClass clazz, String name, Definition.Type type)
      Adds a definition of an attribute with the given type and with the standard flags ( STORABLE and VISIBLE )
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      type - type or capacity if it is an slot
    • add

      public void add(Definition.DefinitionClass clazz, String name, Definition.Type type, byte flags)
      Adds a definition of an attribute with the given type and flags.
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      type - type or capacity if it is an slot
      flags - like visibility, storability, etc...
    • add

      public void add(Definition.DefinitionClass clazz, String name, byte flags)
      Adds a definition of an event or rplink with the given flags.
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      flags - like visibility, storability, etc...
    • add

      public void add(Definition.DefinitionClass clazz, String name, int capacity, byte flags)
      Adds a definition of an slot with the given capacity and flags.
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      capacity - capacity if it is an slot
      flags - like visibility, storability, etc...
    • add

      public void add(Definition.DefinitionClass clazz, String name, String value, byte flags)
      Adds a static definition of an attribute that will be set for any object of the class. Its value must be set as a string, but it can be accessed later using Attributes.get method. NOTE: This type of attributes can't be set.
      Parameters:
      clazz - It must be DefinitionClass.STATIC
      name - name of the static attribute
      value - value of the attribute
      flags - like visibility, storability, etc...
    • addAttribute

      public void addAttribute(String name, Definition.Type type, byte flags)
      Adds a definition of an attribute with the given type and flags.
      Parameters:
      name - name of the definition
      type - type or capacity if it is an slot
      flags - like visibility, storability, etc...
    • addAttribute

      public void addAttribute(String name, Definition.Type type)
      Adds a definition of an attribute with the given type and standard flags: VISIBLE and STORABLE.
      Parameters:
      name - name of the definition
      type - type or capacity if it is an slot
    • addStaticAttribute

      public void addStaticAttribute(String name, String value, byte flags)
      Adds a static definition of an attribute that will be set for any object of the class. Its value must be set as a string, but it can be accessed later using Attributes.get method. NOTE: This type of attributes can't be set.
      Parameters:
      name - name of the static attribute
      value - value of the attribute
      flags - like visibility, storability, etc...
    • addRPSlot

      public void addRPSlot(String name, int capacity, byte flags)
      Adds a definition of an slot with the given capacity and flags.
      Parameters:
      name - name of the definition
      capacity - capacity if it is an slot
      flags - like visibility, storability, etc...
    • addRPSlot

      public void addRPSlot(String name, int capacity)
      Adds a definition of an slot with the given capacity and standard flags: VISIBLE and STORABLE
      Parameters:
      name - name of the definition
      capacity - capacity if it is an slot
    • addRPLink

      public void addRPLink(String name, byte flags)
      Adds a definition of a rplink with the given flags.
      Parameters:
      name - name of the definition
      flags - like visibility, storability, etc...
    • addRPEvent

      public void addRPEvent(String name, byte flags)
      Adds a definition of an event with the given flags.
      Parameters:
      name - name of the definition
      flags - like visibility, storability, etc...
    • getDefinition

      public Definition getDefinition(Definition.DefinitionClass clazz, String name)
      Returns the definition object itself.
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      Returns:
      this definition object or null if it is not found
    • getDefinitions

      public List<Definition> getDefinitions()
      Returns a list of all definitions of this class (not including parent classes)
      Returns:
      list of definitions
    • bake

      public void bake()
      Bakes the RPClass by including copies of all the definitions of the parent class to improve performance.
    • bakeAll

      public static void bakeAll()
      Bales all RPClasses to optimize performance.
    • hasDefinition

      public boolean hasDefinition(Definition.DefinitionClass clazz, String name)
      Returns true if name attributes, slot, event or rplink exists in this RPClass or any of its ancestors.
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      Returns:
      returns true if name attributes, slot, event or rplink exists in this RPClass or any of its ancestors.
    • getCode

      public short getCode(Definition.DefinitionClass clazz, String name)
      Returns the code of the attribute/event/slot whose name is name for this rpclass
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      name - name of the definition
      Returns:
      definition code
      Throws:
      SyntaxException - if the definition is not found.
    • getName

      public String getName(Definition.DefinitionClass clazz, short code)
      Returns the name of the attribute whose code is code for this rpclass
      Parameters:
      clazz - type of definition ( attribute, event or slot )
      code - definition code
      Returns:
      name of the definition
      Throws:
      SyntaxException - if the definition is not found.
    • writeObject

      public void writeObject(OutputSerializer out) throws IOException
      Serialize the object into the output
      Specified by:
      writeObject in interface Serializable
      Parameters:
      out - the output serializer
      Throws:
      IOException - if there is any problem serializing.
    • readObject

      public void readObject(InputSerializer in) throws IOException
      Fill the object from data deserialized from the serializer
      Specified by:
      readObject in interface Serializable
      Parameters:
      in - input serializer
      Throws:
      IOException - if there is any problem in the serialization.
    • iterator

      public static Iterator<RPClass> iterator()
      Iterates over the global list of rpclasses
      Returns:
      an iterator
    • size

      public static int size()
      Returns the size of the rpclass global list
      Returns:
      number of defined classes.
    • getBaseRPObjectDefault

      public static RPClass getBaseRPObjectDefault()
      Returns a default rpclass for lazy developers. You won't get any advantages on the engine by using it.
      Returns:
      RPClass
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object ot)
      Returns true if two objects are exactly equal
      Overrides:
      equals in class Object
      Parameters:
      ot - the object to compare with this one.